diff -pru busybox/editors/sed.c busybox.14536_sed9/editors/sed.c --- busybox/editors/sed.c 2006-03-14 16:17:58.000000000 +0100 +++ busybox.14536_sed9/editors/sed.c 2006-03-14 16:27:52.000000000 +0100 @@ -99,6 +99,8 @@ typedef struct sed_cmd_s { static int be_quiet, in_place, regex_type; static FILE *nonstdout; static char *outname,*hold_space; +static unsigned long endzero = 0; +static char prisubst = 0; /* List of input files */ static int input_file_count,current_input_file; @@ -367,7 +369,6 @@ static int parse_subst_cmd(sed_cmd_t * c { char *temp; idx+=parse_file_cmd(sed_cmd,substr+idx,&temp); - break; } /* Ignore case (gnu exension) */ @@ -385,7 +386,8 @@ static int parse_subst_cmd(sed_cmd_t * c default: bb_error_msg_and_die("bad option in substitution expression"); } - } + } + out: /* compile the match string into a regex */ if (*match != '\0') { @@ -631,7 +633,7 @@ static int do_subst_command(sed_cmd_t * pipeline.idx=0; /* Now loop through, substituting for matches */ - do { + if (sed_cmd->sub_p || !sed_cmd->which_match || !prisubst) do { int i; /* Work around bug in glibc regexec, demonstrated by: @@ -726,18 +728,27 @@ static void add_input_file(FILE *file) */ static char *get_next_line(int *no_newline) { + static char reset_prisubst = 0; char *temp=NULL; int len; flush_append(); + if(reset_prisubst) { + prisubst = 0; + reset_prisubst = 0; + } while (current_input_file0) endzero--; + } fputs(s,file); - if(!no_newline) fputc('\n',file); + if(!no_newline) { + prisubst = 0; + fputc('\n',file); + } if(ferror(file)) { fprintf(stderr,"Write failed.\n"); @@ -767,8 +784,8 @@ static int puts_maybe_newline(char *s, F static void process_files(void) { - char *pattern_space, *next_line; - int linenum = 0, missing_newline=0; + char *pattern_space, *next_line, prisubs_tmp=0; + int linenum=0, missing_newline=0; int no_newline,next_no_newline=0; /* Prime the pump */ @@ -894,14 +911,16 @@ restart: case 's': if(do_subst_command(sed_cmd, &pattern_space)) { substituted|=1; + /* handle NUL embedded, not the same as prisub_tmp because -t */ + prisubs_tmp|=1; /* handle p option */ if(sed_cmd->sub_p) sed_puts(pattern_space,no_newline); + /* handle w option */ if(sed_cmd->file) sed_cmd->no_newline=puts_maybe_newline(pattern_space, sed_cmd->file, sed_cmd->no_newline, no_newline); - } break; @@ -1074,6 +1093,8 @@ restart: } } } + /* to manage NUL embedded */ + prisubst=prisubs_tmp; /* * exit point from sedding... @@ -1088,6 +1109,8 @@ discard_line: flush_append(); free(pattern_space); } + /* Writing the ending zero if it exist */ + if (!be_quiet && endzero>0) sed_puts("",1); } /* It is possible to have a command line argument with embedded Only in busybox.14536_sed9/editors: sed.c~