version 1.36, 2003/08/10 18:39:43 |
version 1.37, 2003/08/10 21:28:48 |
|
|
bool toutkeep = false; |
bool toutkeep = false; |
bool trejkeep = false; |
bool trejkeep = false; |
bool warn_on_invalid_line; |
bool warn_on_invalid_line; |
|
bool last_line_missing_eol; |
|
|
#ifdef DEBUGGING |
#ifdef DEBUGGING |
int debug = 0; |
int debug = 0; |
|
|
static void apply_hunk(LINENUM); |
static void apply_hunk(LINENUM); |
static void init_output(const char *); |
static void init_output(const char *); |
static void init_reject(const char *); |
static void init_reject(const char *); |
static void copy_till(LINENUM); |
static void copy_till(LINENUM, bool); |
static void spew_output(void); |
static void spew_output(void); |
static void dump_line(LINENUM); |
static void dump_line(LINENUM, bool); |
static bool patch_match(LINENUM, LINENUM, LINENUM); |
static bool patch_match(LINENUM, LINENUM, LINENUM); |
static bool similar(const char *, const char *, int); |
static bool similar(const char *, const char *, int); |
static __dead void usage(void); |
static __dead void usage(void); |
|
|
|
|
while (old <= lastline) { |
while (old <= lastline) { |
if (pch_char(old) == '-') { |
if (pch_char(old) == '-') { |
copy_till(where + old - 1); |
copy_till(where + old - 1, false); |
if (do_defines) { |
if (do_defines) { |
if (def_state == OUTSIDE) { |
if (def_state == OUTSIDE) { |
fputs(not_defined, ofp); |
fputs(not_defined, ofp); |
|
|
} else if (new > pat_end) { |
} else if (new > pat_end) { |
break; |
break; |
} else if (pch_char(new) == '+') { |
} else if (pch_char(new) == '+') { |
copy_till(where + old - 1); |
copy_till(where + old - 1, false); |
if (do_defines) { |
if (do_defines) { |
if (def_state == IN_IFNDEF) { |
if (def_state == IN_IFNDEF) { |
fputs(else_defined, ofp); |
fputs(else_defined, ofp); |
|
|
#endif |
#endif |
my_exit(2); |
my_exit(2); |
} else if (pch_char(new) == '!') { |
} else if (pch_char(new) == '!') { |
copy_till(where + old - 1); |
copy_till(where + old - 1, false); |
if (do_defines) { |
if (do_defines) { |
fputs(not_defined, ofp); |
fputs(not_defined, ofp); |
def_state = IN_IFNDEF; |
def_state = IN_IFNDEF; |
|
|
} |
} |
} |
} |
if (new <= pat_end && pch_char(new) == '+') { |
if (new <= pat_end && pch_char(new) == '+') { |
copy_till(where + old - 1); |
copy_till(where + old - 1, false); |
if (do_defines) { |
if (do_defines) { |
if (def_state == OUTSIDE) { |
if (def_state == OUTSIDE) { |
fputs(if_defined, ofp); |
fputs(if_defined, ofp); |
|
|
|
|
/* |
/* |
* Copy input file to output, up to wherever hunk is to be applied. |
* Copy input file to output, up to wherever hunk is to be applied. |
|
* If endoffile is true, treat the last line specially since it may |
|
* lack a newline. |
*/ |
*/ |
static void |
static void |
copy_till(LINENUM lastline) |
copy_till(LINENUM lastline, bool endoffile) |
{ |
{ |
if (last_frozen_line > lastline) |
if (last_frozen_line > lastline) |
fatal("misordered hunks! output would be garbled\n"); |
fatal("misordered hunks! output would be garbled\n"); |
while (last_frozen_line < lastline) |
while (last_frozen_line < lastline) { |
dump_line(++last_frozen_line); |
if (++last_frozen_line == lastline && endoffile) |
|
dump_line(last_frozen_line, !last_line_missing_eol); |
|
else |
|
dump_line(last_frozen_line, true); |
|
} |
} |
} |
|
|
/* |
/* |
|
|
say("il=%ld lfl=%ld\n", input_lines, last_frozen_line); |
say("il=%ld lfl=%ld\n", input_lines, last_frozen_line); |
#endif |
#endif |
if (input_lines) |
if (input_lines) |
copy_till(input_lines); /* dump remainder of file */ |
copy_till(input_lines, true); /* dump remainder of file */ |
fclose(ofp); |
fclose(ofp); |
ofp = NULL; |
ofp = NULL; |
} |
} |
|
|
* Copy one line from input to output. |
* Copy one line from input to output. |
*/ |
*/ |
static void |
static void |
dump_line(LINENUM line) |
dump_line(LINENUM line, bool write_newline) |
{ |
{ |
char *s; |
char *s; |
|
|
|
|
if (s == NULL) |
if (s == NULL) |
return; |
return; |
/* Note: string is not NUL terminated. */ |
/* Note: string is not NUL terminated. */ |
for (; putc(*s, ofp) != '\n'; s++) |
for (; *s != '\n'; s++) |
; |
putc(*s, ofp); |
|
if (write_newline) |
|
putc('\n', ofp); |
} |
} |
|
|
/* |
/* |