version 1.15, 2003/07/17 19:16:31 |
version 1.16, 2003/07/18 02:00:09 |
|
|
if (filename == Nullch || !*filename || strEQ(filename, "-")) { |
if (filename == Nullch || !*filename || strEQ(filename, "-")) { |
pfp = fopen(TMPPATNAME, "w"); |
pfp = fopen(TMPPATNAME, "w"); |
if (pfp == Nullfp) |
if (pfp == Nullfp) |
pfatal2("can't create %s", TMPPATNAME); |
pfatal("can't create %s", TMPPATNAME); |
while (fgets(buf, sizeof buf, stdin) != Nullch) |
while (fgets(buf, sizeof buf, stdin) != Nullch) |
fputs(buf, pfp); |
fputs(buf, pfp); |
Fclose(pfp); |
fclose(pfp); |
filename = TMPPATNAME; |
filename = TMPPATNAME; |
} |
} |
pfp = fopen(filename, "r"); |
pfp = fopen(filename, "r"); |
if (pfp == Nullfp) |
if (pfp == Nullfp) |
pfatal2("patch file %s not found", filename); |
pfatal("patch file %s not found", filename); |
Fstat(fileno(pfp), &filestat); |
fstat(fileno(pfp), &filestat); |
p_filesize = filestat.st_size; |
p_filesize = filestat.st_size; |
next_intuit_at(0L,1L); /* start at the beginning */ |
next_intuit_at(0L,1L); /* start at the beginning */ |
set_hunkmax(); |
set_hunkmax(); |
|
|
grow_hunkmax() |
grow_hunkmax() |
{ |
{ |
hunkmax *= 2; |
hunkmax *= 2; |
/* |
/* |
* Note that on most systems, only the p_line array ever gets fresh memory |
* Note that on most systems, only the p_line array ever gets fresh memory |
* since p_len can move into p_line's old space, and p_char can move into |
* since p_len can move into p_line's old space, and p_char can move into |
* p_len's old space. Not on PDP-11's however. But it doesn't matter. |
* p_len's old space. Not on PDP-11's however. But it doesn't matter. |
|
|
if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch) |
if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch) |
return; |
return; |
if (!using_plan_a) |
if (!using_plan_a) |
fatal1("out of memory\n"); |
fatal("out of memory\n"); |
out_of_mem = TRUE; /* whatever is null will be allocated again */ |
out_of_mem = TRUE; /* whatever is null will be allocated again */ |
/* from within plan_a(), of all places */ |
/* from within plan_a(), of all places */ |
} |
} |
|
|
{ |
{ |
if (p_base != 0L && p_base >= p_filesize) { |
if (p_base != 0L && p_base >= p_filesize) { |
if (verbose) |
if (verbose) |
say1("done\n"); |
say("done\n"); |
return FALSE; |
return FALSE; |
} |
} |
if (verbose) |
if (verbose) |
say1("Hmm..."); |
say("Hmm..."); |
diff_type = intuit_diff_type(); |
diff_type = intuit_diff_type(); |
if (!diff_type) { |
if (!diff_type) { |
if (p_base != 0L) { |
if (p_base != 0L) { |
if (verbose) |
if (verbose) |
say1(" Ignoring the trailing garbage.\ndone\n"); |
say(" Ignoring the trailing garbage.\ndone\n"); |
} |
} |
else |
else |
say1(" I can't seem to find a patch in there anywhere.\n"); |
say(" I can't seem to find a patch in there anywhere.\n"); |
return FALSE; |
return FALSE; |
} |
} |
if (verbose) |
if (verbose) |
say3(" %sooks like %s to me...\n", |
say(" %sooks like %s to me...\n", |
(p_base == 0L ? "L" : "The next patch l"), |
(p_base == 0L ? "L" : "The next patch l"), |
diff_type == UNI_DIFF ? "a unified diff" : |
diff_type == UNI_DIFF ? "a unified diff" : |
diff_type == CONTEXT_DIFF ? "a context diff" : |
diff_type == CONTEXT_DIFF ? "a context diff" : |
|
|
diff_type == NORMAL_DIFF ? "a normal diff" : |
diff_type == NORMAL_DIFF ? "a normal diff" : |
"an ed script" ); |
"an ed script" ); |
if (p_indent && verbose) |
if (p_indent && verbose) |
say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s"); |
say("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s"); |
skip_to(p_start,p_sline); |
skip_to(p_start,p_sline); |
while (filearg[0] == Nullch) { |
while (filearg[0] == Nullch) { |
if (force || batch) { |
if (force || batch) { |
say1("No file to patch. Skipping...\n"); |
say("No file to patch. Skipping...\n"); |
filearg[0] = savestr(bestguess); |
filearg[0] = savestr(bestguess); |
skip_rest_of_patch = TRUE; |
skip_rest_of_patch = TRUE; |
return TRUE; |
return TRUE; |
} |
} |
ask1("File to patch: "); |
ask("File to patch: "); |
if (*buf != '\n') { |
if (*buf != '\n') { |
if (bestguess) |
if (bestguess) |
free(bestguess); |
free(bestguess); |
|
|
filearg[0] = fetchname(buf, 0, FALSE); |
filearg[0] = fetchname(buf, 0, FALSE); |
} |
} |
if (filearg[0] == Nullch) { |
if (filearg[0] == Nullch) { |
ask1("No file found--skip this patch? [n] "); |
ask("No file found--skip this patch? [n] "); |
if (*buf != 'y') { |
if (*buf != 'y') { |
continue; |
continue; |
} |
} |
if (verbose) |
if (verbose) |
say1("Skipping patch...\n"); |
say("Skipping patch...\n"); |
filearg[0] = fetchname(bestguess, 0, TRUE); |
filearg[0] = fetchname(bestguess, 0, TRUE); |
skip_rest_of_patch = TRUE; |
skip_rest_of_patch = TRUE; |
return TRUE; |
return TRUE; |
|
|
int |
int |
intuit_diff_type() |
intuit_diff_type() |
{ |
{ |
Reg4 long this_line = 0; |
long this_line = 0; |
Reg5 long previous_line; |
long previous_line; |
Reg6 long first_command_line = -1; |
long first_command_line = -1; |
long fcl_line; |
long fcl_line; |
Reg7 bool last_line_was_command = FALSE; |
bool last_line_was_command = FALSE; |
Reg8 bool this_is_a_command = FALSE; |
bool this_is_a_command = FALSE; |
Reg9 bool stars_last_line = FALSE; |
bool stars_last_line = FALSE; |
Reg10 bool stars_this_line = FALSE; |
bool stars_this_line = FALSE; |
Reg3 int indent; |
int indent; |
Reg1 char *s; |
char *s; |
Reg2 char *t; |
char *t; |
char *indtmp = Nullch; |
char *indtmp = Nullch; |
char *oldtmp = Nullch; |
char *oldtmp = Nullch; |
char *newtmp = Nullch; |
char *newtmp = Nullch; |
char *indname = Nullch; |
char *indname = Nullch; |
char *oldname = Nullch; |
char *oldname = Nullch; |
char *newname = Nullch; |
char *newname = Nullch; |
Reg11 int retval; |
int retval; |
bool no_filearg = (filearg[0] == Nullch); |
bool no_filearg = (filearg[0] == Nullch); |
|
|
ok_to_create_file = FALSE; |
ok_to_create_file = FALSE; |
Fseek(pfp, p_base, 0); |
fseek(pfp, p_base, 0); |
p_input_line = p_bline - 1; |
p_input_line = p_bline - 1; |
for (;;) { |
for (;;) { |
previous_line = this_line; |
previous_line = this_line; |
|
|
else |
else |
indent++; |
indent++; |
} |
} |
for (t=s; isdigit(*t) || *t == ','; t++) ; |
for (t=s; isdigit(*t) || *t == ','; t++) ; |
this_is_a_command = (isdigit(*s) && |
this_is_a_command = (isdigit(*s) && |
(*t == 'd' || *t == 'c' || *t == 'a') ); |
(*t == 'd' || *t == 'c' || *t == 'a') ); |
if (first_command_line < 0L && this_is_a_command) { |
if (first_command_line < 0L && this_is_a_command) { |
first_command_line = this_line; |
first_command_line = this_line; |
fcl_line = p_input_line; |
fcl_line = p_input_line; |
p_indent = indent; /* assume this for now */ |
p_indent = indent; /* assume this for now */ |
|
|
retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF); |
retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF); |
goto scan_exit; |
goto scan_exit; |
} |
} |
if ((!diff_type || diff_type == NORMAL_DIFF) && |
if ((!diff_type || diff_type == NORMAL_DIFF) && |
last_line_was_command && |
last_line_was_command && |
(strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) { |
(strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) { |
p_start = previous_line; |
p_start = previous_line; |
|
|
|
|
assert(p_base <= file_pos); |
assert(p_base <= file_pos); |
if (verbose && p_base < file_pos) { |
if (verbose && p_base < file_pos) { |
Fseek(pfp, p_base, 0); |
fseek(pfp, p_base, 0); |
say1("The text leading up to this was:\n--------------------------\n"); |
say("The text leading up to this was:\n--------------------------\n"); |
while (ftell(pfp) < file_pos) { |
while (ftell(pfp) < file_pos) { |
ret = fgets(buf, sizeof buf, pfp); |
ret = fgets(buf, sizeof buf, pfp); |
assert(ret != Nullch); |
assert(ret != Nullch); |
say2("|%s", buf); |
say("|%s", buf); |
} |
} |
say1("--------------------------\n"); |
say("--------------------------\n"); |
} |
} |
else |
else |
Fseek(pfp, file_pos, 0); |
fseek(pfp, file_pos, 0); |
p_input_line = file_line - 1; |
p_input_line = file_line - 1; |
} |
} |
|
|
/* Make this a function for better debugging. */ |
/* Make this a function for better debugging. */ |
static void |
static void |
malformed () |
malformed(void) |
{ |
{ |
fatal3("malformed patch at line %ld: %s", p_input_line, buf); |
fatal("malformed patch at line %ld: %s", p_input_line, buf); |
/* about as informative as "Syntax error" in C */ |
/* about as informative as "Syntax error" in C */ |
} |
} |
|
|
|
|
bool |
bool |
another_hunk() |
another_hunk() |
{ |
{ |
Reg1 char *s; |
char *s; |
Reg8 char *ret; |
char *ret; |
Reg2 int context = 0; |
int context = 0; |
|
|
while (p_end >= 0) { |
while (p_end >= 0) { |
if (p_end == p_efake) |
if (p_end == p_efake) |
|
|
long line_beginning = ftell(pfp); |
long line_beginning = ftell(pfp); |
/* file pos of the current line */ |
/* file pos of the current line */ |
LINENUM repl_beginning = 0; /* index of --- line */ |
LINENUM repl_beginning = 0; /* index of --- line */ |
Reg4 LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */ |
LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */ |
Reg5 LINENUM fillsrc; /* index of first line to copy */ |
LINENUM fillsrc; /* index of first line to copy */ |
Reg6 LINENUM filldst; /* index of first missing line */ |
LINENUM filldst; /* index of first missing line */ |
bool ptrn_spaces_eaten = FALSE; /* ptrn was slightly misformed */ |
bool ptrn_spaces_eaten = FALSE; /* ptrn was slightly misformed */ |
Reg9 bool repl_could_be_missing = TRUE; |
bool repl_could_be_missing = TRUE; |
/* no + or ! lines in this hunk */ |
/* no + or ! lines in this hunk */ |
bool repl_missing = FALSE; /* we are now backtracking */ |
bool repl_missing = FALSE; /* we are now backtracking */ |
long repl_backtrack_position = 0; |
long repl_backtrack_position = 0; |
/* file pos of first repl line */ |
/* file pos of first repl line */ |
LINENUM repl_patch_line; /* input line number for same */ |
LINENUM repl_patch_line; /* input line number for same */ |
Reg7 LINENUM ptrn_copiable = 0; |
LINENUM ptrn_copiable = 0; |
/* # of copiable lines in ptrn */ |
/* # of copiable lines in ptrn */ |
|
|
ret = pgets(buf, sizeof buf, pfp); |
ret = pgets(buf, sizeof buf, pfp); |
|
|
repl_missing = TRUE; |
repl_missing = TRUE; |
goto hunk_done; |
goto hunk_done; |
} |
} |
fatal1("unexpected end of file in patch\n"); |
fatal("unexpected end of file in patch\n"); |
} |
} |
} |
} |
p_end++; |
p_end++; |
|
|
goto hunk_done; |
goto hunk_done; |
} |
} |
else |
else |
fatal2("unexpected end of hunk at line %ld\n", |
fatal("unexpected end of hunk at line %ld\n", |
p_input_line); |
p_input_line); |
} |
} |
if (p_end != 0) { |
if (p_end != 0) { |
|
|
repl_missing = TRUE; |
repl_missing = TRUE; |
goto hunk_done; |
goto hunk_done; |
} |
} |
fatal3("unexpected *** at line %ld: %s", p_input_line, buf); |
fatal("unexpected *** at line %ld: %s", p_input_line, buf); |
} |
} |
context = 0; |
context = 0; |
p_line[p_end] = savestr(buf); |
p_line[p_end] = savestr(buf); |
|
|
repl_missing = TRUE; |
repl_missing = TRUE; |
goto hunk_done; |
goto hunk_done; |
} |
} |
fatal3( |
fatal( |
"duplicate \"---\" at line %ld--check line numbers at line %ld\n", |
"duplicate \"---\" at line %ld--check line numbers at line %ld\n", |
p_input_line, p_hunk_beg + repl_beginning); |
p_input_line, p_hunk_beg + repl_beginning); |
} |
} |
else { |
else { |
fatal4( |
fatal( |
"%s \"---\" at line %ld--check line numbers at line %ld\n", |
"%s \"---\" at line %ld--check line numbers at line %ld\n", |
(p_end <= p_ptrn_lines |
(p_end <= p_ptrn_lines |
? "Premature" |
? "Premature" |
|
|
} |
} |
p_max = p_repl_lines + p_end; |
p_max = p_repl_lines + p_end; |
if (p_max > MAXHUNKSIZE) |
if (p_max > MAXHUNKSIZE) |
fatal4("hunk too large (%ld lines) at line %ld: %s", |
fatal("hunk too large (%ld lines) at line %ld: %s", |
p_max, p_input_line, buf); |
p_max, p_input_line, buf); |
while (p_max >= hunkmax) |
while (p_max >= hunkmax) |
grow_hunkmax(); |
grow_hunkmax(); |
|
|
else |
else |
p_len[p_end] = 0; |
p_len[p_end] = 0; |
} |
} |
|
|
hunk_done: |
hunk_done: |
if (p_end >=0 && !repl_beginning) |
if (p_end >=0 && !repl_beginning) |
fatal2("no --- found in patch at line %ld\n", pch_hunk_beg()); |
fatal("no --- found in patch at line %ld\n", pch_hunk_beg()); |
|
|
if (repl_missing) { |
if (repl_missing) { |
|
|
/* reset state back to just after --- */ |
/* reset state back to just after --- */ |
p_input_line = repl_patch_line; |
p_input_line = repl_patch_line; |
for (p_end--; p_end > repl_beginning; p_end--) |
for (p_end--; p_end > repl_beginning; p_end--) |
free(p_line[p_end]); |
free(p_line[p_end]); |
Fseek(pfp, repl_backtrack_position, 0); |
fseek(pfp, repl_backtrack_position, 0); |
|
|
/* redundant 'new' context lines were omitted - set */ |
/* redundant 'new' context lines were omitted - set */ |
/* up to fill them in from the old file context */ |
/* up to fill them in from the old file context */ |
if (!p_context && p_repl_lines == 1) { |
if (!p_context && p_repl_lines == 1) { |
|
|
if (diff_type == CONTEXT_DIFF && |
if (diff_type == CONTEXT_DIFF && |
(fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) { |
(fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) { |
if (verbose) |
if (verbose) |
say4("%s\n%s\n%s\n", |
say("%s\n%s\n%s\n", |
"(Fascinating--this is really a new-style context diff but without", |
"(Fascinating--this is really a new-style context diff but without", |
"the telltale extra asterisks on the *** line that usually indicate", |
"the telltale extra asterisks on the *** line that usually indicate", |
"the new style...)"); |
"the new style...)"); |
diff_type = NEW_CONTEXT_DIFF; |
diff_type = NEW_CONTEXT_DIFF; |
} |
} |
|
|
/* if there were omitted context lines, fill them in now */ |
/* if there were omitted context lines, fill them in now */ |
if (fillcnt) { |
if (fillcnt) { |
p_bfake = filldst; /* remember where not to free() */ |
p_bfake = filldst; /* remember where not to free() */ |
|
|
while (fillsrc <= p_end && p_char[fillsrc] != ' ') |
while (fillsrc <= p_end && p_char[fillsrc] != ' ') |
fillsrc++; |
fillsrc++; |
if (fillsrc > p_end) |
if (fillsrc > p_end) |
fatal2("replacement text or line numbers mangled in hunk at line %ld\n", |
fatal("replacement text or line numbers mangled in hunk at line %ld\n", |
p_hunk_beg); |
p_hunk_beg); |
p_line[filldst] = p_line[fillsrc]; |
p_line[filldst] = p_line[fillsrc]; |
p_char[filldst] = p_char[fillsrc]; |
p_char[filldst] = p_char[fillsrc]; |
|
|
else if (diff_type == UNI_DIFF) { |
else if (diff_type == UNI_DIFF) { |
long line_beginning = ftell(pfp); |
long line_beginning = ftell(pfp); |
/* file pos of the current line */ |
/* file pos of the current line */ |
Reg4 LINENUM fillsrc; /* index of old lines */ |
LINENUM fillsrc; /* index of old lines */ |
Reg5 LINENUM filldst; /* index of new lines */ |
LINENUM filldst; /* index of new lines */ |
char ch; |
char ch; |
|
|
ret = pgets(buf, sizeof buf, pfp); |
ret = pgets(buf, sizeof buf, pfp); |
|
|
fillsrc = 1; |
fillsrc = 1; |
filldst = fillsrc + p_ptrn_lines; |
filldst = fillsrc + p_ptrn_lines; |
p_end = filldst + p_repl_lines; |
p_end = filldst + p_repl_lines; |
Snprintf(buf, sizeof buf, "*** %ld,%ld ****\n", p_first, |
snprintf(buf, sizeof buf, "*** %ld,%ld ****\n", p_first, |
p_first + p_ptrn_lines - 1); |
p_first + p_ptrn_lines - 1); |
p_line[0] = savestr(buf); |
p_line[0] = savestr(buf); |
if (out_of_mem) { |
if (out_of_mem) { |
|
|
return FALSE; |
return FALSE; |
} |
} |
p_char[0] = '*'; |
p_char[0] = '*'; |
Snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, |
snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, |
p_newfirst + p_repl_lines - 1); |
p_newfirst + p_repl_lines - 1); |
p_line[filldst] = savestr(buf); |
p_line[filldst] = savestr(buf); |
if (out_of_mem) { |
if (out_of_mem) { |
|
|
/* assume blank lines got chopped */ |
/* assume blank lines got chopped */ |
strlcpy(buf, " \n", sizeof buf); |
strlcpy(buf, " \n", sizeof buf); |
} else { |
} else { |
fatal1("unexpected end of file in patch\n"); |
fatal("unexpected end of file in patch\n"); |
} |
} |
} |
} |
if (*buf == '\t' || *buf == '\n') { |
if (*buf == '\t' || *buf == '\n') { |
|
|
} |
} |
else { /* normal diff--fake it up */ |
else { /* normal diff--fake it up */ |
char hunk_type; |
char hunk_type; |
Reg3 int i; |
int i; |
LINENUM min, max; |
LINENUM min, max; |
long line_beginning = ftell(pfp); |
long line_beginning = ftell(pfp); |
|
|
|
|
min++; |
min++; |
p_end = p_ptrn_lines + 1 + max - min + 1; |
p_end = p_ptrn_lines + 1 + max - min + 1; |
if (p_end > MAXHUNKSIZE) |
if (p_end > MAXHUNKSIZE) |
fatal4("hunk too large (%ld lines) at line %ld: %s", |
fatal("hunk too large (%ld lines) at line %ld: %s", |
p_end, p_input_line, buf); |
p_end, p_input_line, buf); |
while (p_end >= hunkmax) |
while (p_end >= hunkmax) |
grow_hunkmax(); |
grow_hunkmax(); |
p_newfirst = min; |
p_newfirst = min; |
p_repl_lines = max - min + 1; |
p_repl_lines = max - min + 1; |
Snprintf(buf, sizeof buf, "*** %ld,%ld\n", p_first, |
snprintf(buf, sizeof buf, "*** %ld,%ld\n", p_first, |
p_first + p_ptrn_lines - 1); |
p_first + p_ptrn_lines - 1); |
p_line[0] = savestr(buf); |
p_line[0] = savestr(buf); |
if (out_of_mem) { |
if (out_of_mem) { |
|
|
ret = pgets(buf, sizeof buf, pfp); |
ret = pgets(buf, sizeof buf, pfp); |
p_input_line++; |
p_input_line++; |
if (ret == Nullch) |
if (ret == Nullch) |
fatal2("unexpected end of file in patch at line %ld\n", |
fatal("unexpected end of file in patch at line %ld\n", |
p_input_line); |
p_input_line); |
if (*buf != '<') |
if (*buf != '<') |
fatal2("< expected at line %ld of patch\n", p_input_line); |
fatal("< expected at line %ld of patch\n", p_input_line); |
p_line[i] = savestr(buf+2); |
p_line[i] = savestr(buf+2); |
if (out_of_mem) { |
if (out_of_mem) { |
p_end = i-1; |
p_end = i-1; |
|
|
ret = pgets(buf, sizeof buf, pfp); |
ret = pgets(buf, sizeof buf, pfp); |
p_input_line++; |
p_input_line++; |
if (ret == Nullch) |
if (ret == Nullch) |
fatal2("unexpected end of file in patch at line %ld\n", |
fatal("unexpected end of file in patch at line %ld\n", |
p_input_line); |
p_input_line); |
if (*buf != '-') |
if (*buf != '-') |
fatal2("--- expected at line %ld of patch\n", p_input_line); |
fatal("--- expected at line %ld of patch\n", p_input_line); |
} |
} |
Snprintf(buf, sizeof(buf), "--- %ld,%ld\n", min, max); |
snprintf(buf, sizeof(buf), "--- %ld,%ld\n", min, max); |
p_line[i] = savestr(buf); |
p_line[i] = savestr(buf); |
if (out_of_mem) { |
if (out_of_mem) { |
p_end = i-1; |
p_end = i-1; |
|
|
ret = pgets(buf, sizeof buf, pfp); |
ret = pgets(buf, sizeof buf, pfp); |
p_input_line++; |
p_input_line++; |
if (ret == Nullch) |
if (ret == Nullch) |
fatal2("unexpected end of file in patch at line %ld\n", |
fatal("unexpected end of file in patch at line %ld\n", |
p_input_line); |
p_input_line); |
if (*buf != '>') |
if (*buf != '>') |
fatal2("> expected at line %ld of patch\n", p_input_line); |
fatal("> expected at line %ld of patch\n", p_input_line); |
p_line[i] = savestr(buf+2); |
p_line[i] = savestr(buf+2); |
if (out_of_mem) { |
if (out_of_mem) { |
p_end = i-1; |
p_end = i-1; |
|
|
} |
} |
if (reverse) /* backwards patch? */ |
if (reverse) /* backwards patch? */ |
if (!pch_swap()) |
if (!pch_swap()) |
say1("Not enough memory to swap next hunk!\n"); |
say("Not enough memory to swap next hunk!\n"); |
#ifdef DEBUGGING |
#ifdef DEBUGGING |
if (debug & 2) { |
if (debug & 2) { |
int i; |
int i; |
|
|
else |
else |
special = ' '; |
special = ' '; |
fprintf(stderr, "%3d %c %c %s", i, p_char[i], special, p_line[i]); |
fprintf(stderr, "%3d %c %c %s", i, p_char[i], special, p_line[i]); |
Fflush(stderr); |
fflush(stderr); |
} |
} |
} |
} |
#endif |
#endif |
|
|
FILE *fp; |
FILE *fp; |
{ |
{ |
char *ret = fgets(bf, sz, fp); |
char *ret = fgets(bf, sz, fp); |
Reg1 char *s; |
char *s; |
Reg2 int indent = 0; |
int indent = 0; |
|
|
if (p_indent && ret != Nullch) { |
if (p_indent && ret != Nullch) { |
for (s=buf; |
for (s=buf; |
|
|
indent++; |
indent++; |
} |
} |
if (buf != s && strlcpy(buf, s, sizeof(buf)) >= sizeof(buf)) |
if (buf != s && strlcpy(buf, s, sizeof(buf)) >= sizeof(buf)) |
fatal1("buffer too small in pgets()\n"); |
fatal("buffer too small in pgets()\n"); |
} |
} |
return ret; |
return ret; |
} |
} |
|
|
char **tp_line; /* the text of the hunk */ |
char **tp_line; /* the text of the hunk */ |
short *tp_len; /* length of each line */ |
short *tp_len; /* length of each line */ |
char *tp_char; /* +, -, and ! */ |
char *tp_char; /* +, -, and ! */ |
Reg1 LINENUM i; |
LINENUM i; |
Reg2 LINENUM n; |
LINENUM n; |
bool blankline = FALSE; |
bool blankline = FALSE; |
Reg3 char *s; |
char *s; |
|
|
i = p_first; |
i = p_first; |
p_first = p_newfirst; |
p_first = p_newfirst; |
p_newfirst = i; |
p_newfirst = i; |
|
|
/* make a scratch copy */ |
/* make a scratch copy */ |
|
|
tp_line = p_line; |
tp_line = p_line; |
|
|
void |
void |
do_ed_script() |
do_ed_script() |
{ |
{ |
Reg1 char *t; |
char *t; |
Reg2 long beginning_of_this_line; |
long beginning_of_this_line; |
Reg3 bool this_line_is_command = FALSE; |
bool this_line_is_command = FALSE; |
Reg4 FILE *pipefp; |
FILE *pipefp; |
|
|
if (!skip_rest_of_patch) { |
if (!skip_rest_of_patch) { |
Unlink(TMPOUTNAME); |
unlink(TMPOUTNAME); |
copy_file(filearg[0], TMPOUTNAME); |
copy_file(filearg[0], TMPOUTNAME); |
if (verbose) |
if (verbose) |
Snprintf(buf, sizeof buf, "/bin/ed %s", TMPOUTNAME); |
snprintf(buf, sizeof buf, "/bin/ed %s", TMPOUTNAME); |
else |
else |
Snprintf(buf, sizeof buf, "/bin/ed - %s", TMPOUTNAME); |
snprintf(buf, sizeof buf, "/bin/ed - %s", TMPOUTNAME); |
pipefp = popen(buf, "w"); |
pipefp = popen(buf, "w"); |
} |
} |
for (;;) { |
for (;;) { |
|
|
return; |
return; |
fprintf(pipefp, "w\n"); |
fprintf(pipefp, "w\n"); |
fprintf(pipefp, "q\n"); |
fprintf(pipefp, "q\n"); |
Fflush(pipefp); |
fflush(pipefp); |
Pclose(pipefp); |
pclose(pipefp); |
ignore_signals(); |
ignore_signals(); |
if (!check_only) { |
if (!check_only) { |
if (move_file(TMPOUTNAME, outname) < 0) { |
if (move_file(TMPOUTNAME, outname) < 0) { |