The following patch changes the check for end of line, so that a comment on the first line must be preceded by white space (' ' or '\t'). [main.c] #include <stdio.h> int main(int ac, char **av) { int i; printf("Main.c test\n"); for(i = 0; i < ac; i++) { printf("%s\n", av[i]); } } [tst.sh] #! ./main -arg1 -#! # comment echo ok Running tst.sh now produces: # ./tst.sh Main.c test ./main -arg1 -#! ./tst.sh Index: imgact_shell.c =================================================================== RCS file: /home/ncvs/src/sys/kern/imgact_shell.c,v retrieving revision 1.26 diff -u -r1.26 imgact_shell.c --- imgact_shell.c 11 Jun 2003 00:56:54 -0000 1.26 +++ imgact_shell.c 1 Oct 2004 12:15:48 -0000 _at__at_ -49,8 +49,11 _at__at_ struct image_params *imgp; { const char *image_header = imgp->image_header; - const char *ihp, *line_endp; + const char *ihp, *prev, *line_endp; char *interp; + boolean_t comment = FALSE; + + prev = NULL; /* a shell script? */ if (((const short *) image_header)[0] != SHELLMAGIC) _at__at_ -73,7 +76,16 _at__at_ /* * Find end of line; return if the line > MAXSHELLCMDLEN long. */ - for (ihp = &image_header[2]; *ihp != '\n' && *ihp != '#'; ++ihp) { + for (ihp = &image_header[2]; *ihp != '\n' && !comment; ++ihp) { + if ( prev != NULL && + (( *prev == ' ' || *prev == '\t' ) && *ihp == '#' )) { + ihp = prev; + comment = TRUE; + /* Skip over trailing spaces */ + while ((*ihp == ' ') || (*ihp == '\t')) ihp--; + } else + prev = ihp; + if (ihp >= &image_header[MAXSHELLCMDLEN]) return(ENAMETOOLONG); }Received on Sat Oct 02 2004 - 02:06:46 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:15 UTC