Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/patch KNF
details: https://anonhg.NetBSD.org/src/rev/ca9cb837554d
branches: trunk
changeset: 523770:ca9cb837554d
user: kristerw <kristerw%NetBSD.org@localhost>
date: Fri Mar 15 19:44:54 2002 +0000
description:
KNF
diffstat:
usr.bin/patch/pch.c | 1033 ++++++++++++++++++++++++++------------------------
1 files changed, 538 insertions(+), 495 deletions(-)
diffs (truncated from 1188 to 300 lines):
diff -r d4c98795d593 -r ca9cb837554d usr.bin/patch/pch.c
--- a/usr.bin/patch/pch.c Fri Mar 15 19:01:39 2002 +0000
+++ b/usr.bin/patch/pch.c Fri Mar 15 19:44:54 2002 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: pch.c,v 1.9 2002/03/11 18:47:51 kristerw Exp $ */
+/* $NetBSD: pch.c,v 1.10 2002/03/15 19:44:54 kristerw Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pch.c,v 1.9 2002/03/11 18:47:51 kristerw Exp $");
+__RCSID("$NetBSD: pch.c,v 1.10 2002/03/15 19:44:54 kristerw Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -43,368 +43,396 @@
void
re_patch(void)
{
- p_first = Nulline;
- p_newfirst = Nulline;
- p_ptrn_lines = Nulline;
- p_repl_lines = Nulline;
- p_end = -1;
- p_max = Nulline;
- p_indent = 0;
+ p_first = Nulline;
+ p_newfirst = Nulline;
+ p_ptrn_lines = Nulline;
+ p_repl_lines = Nulline;
+ p_end = -1;
+ p_max = Nulline;
+ p_indent = 0;
}
-/* Open the patch file at the beginning of time. */
-
+/*
+ * Open the patch file at the beginning of time.
+ */
void
open_patch_file(char *filename)
{
- if (filename == NULL || !*filename || strEQ(filename, "-")) {
- pfp = fopen(TMPPATNAME, "w");
+ if (filename == NULL || !*filename || strEQ(filename, "-")) {
+ pfp = fopen(TMPPATNAME, "w");
+ if (pfp == NULL)
+ pfatal("can't create %s", TMPPATNAME);
+ while (fgets(buf, sizeof buf, stdin) != NULL)
+ fputs(buf, pfp);
+ Fclose(pfp);
+ filename = TMPPATNAME;
+ }
+ pfp = fopen(filename, "r");
if (pfp == NULL)
- pfatal("can't create %s", TMPPATNAME);
- while (fgets(buf, sizeof buf, stdin) != NULL)
- fputs(buf, pfp);
- Fclose(pfp);
- filename = TMPPATNAME;
- }
- pfp = fopen(filename, "r");
- if (pfp == NULL)
- pfatal("patch file %s not found", filename);
- Fstat(fileno(pfp), &filestat);
- p_filesize = filestat.st_size;
- next_intuit_at(0L,1L); /* start at the beginning */
- set_hunkmax();
+ pfatal("patch file %s not found", filename);
+ Fstat(fileno(pfp), &filestat);
+ p_filesize = filestat.st_size;
+ next_intuit_at(0L,1L); /* start at the beginning */
+ set_hunkmax();
}
-/* Make sure our dynamically realloced tables are malloced to begin with. */
-
+/*
+ * Make sure our dynamically realloced tables are malloced to begin with.
+ */
void
set_hunkmax(void)
{
- if (p_line == NULL)
- p_line = malloc(hunkmax * sizeof(char *));
- if (p_len == NULL)
- p_len = malloc(hunkmax * sizeof(short));
- if (p_char == NULL)
- p_char = malloc(hunkmax * sizeof(char));
+ if (p_line == NULL)
+ p_line = malloc(hunkmax * sizeof(char *));
+ if (p_len == NULL)
+ p_len = malloc(hunkmax * sizeof(short));
+ if (p_char == NULL)
+ p_char = malloc(hunkmax * sizeof(char));
}
-/* Enlarge the arrays containing the current hunk of patch. */
-
+/*
+ * Enlarge the arrays containing the current hunk of patch.
+ */
void
grow_hunkmax(void)
{
- hunkmax *= 2;
- /*
- * 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
- * p_len's old space. Not on PDP-11's however. But it doesn't matter.
- */
- assert(p_line != NULL && p_len != NULL && p_char != NULL);
- p_line = realloc(p_line, hunkmax * sizeof(char *));
- p_len = realloc(p_len, hunkmax * sizeof(short));
- p_char = realloc(p_char, hunkmax * sizeof(char));
- if (p_line != NULL && p_len != NULL && p_char != NULL)
- return;
- if (!using_plan_a)
- fatal("out of memory\n");
- out_of_mem = TRUE; /* whatever is null will be allocated again */
+ hunkmax *= 2;
+ /*
+ * 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 p_len's old space. Not on PDP-11's however. But
+ * it doesn't matter.
+ */
+ assert(p_line != NULL && p_len != NULL && p_char != NULL);
+ p_line = realloc(p_line, hunkmax * sizeof(char *));
+ p_len = realloc(p_len, hunkmax * sizeof(short));
+ p_char = realloc(p_char, hunkmax * sizeof(char));
+ if (p_line != NULL && p_len != NULL && p_char != NULL)
+ return;
+ if (!using_plan_a)
+ fatal("out of memory\n");
+ out_of_mem = TRUE; /* whatever is null will be allocated again */
/* from within plan_a(), of all places */
}
-/* True if the remainder of the patch file contains a diff of some sort. */
-
+/*
+ * True if the remainder of the patch file contains a diff of some sort.
+ */
bool
there_is_another_patch(void)
{
- if (p_base != 0L && p_base >= p_filesize) {
+ if (p_base != 0L && p_base >= p_filesize) {
+ if (verbose)
+ say("done\n");
+ return FALSE;
+ }
if (verbose)
- say("done\n");
- return FALSE;
- }
- if (verbose)
- say("Hmm...");
- diff_type = intuit_diff_type();
- if (!diff_type) {
- if (p_base != 0L) {
- if (verbose)
- say(" Ignoring the trailing garbage.\ndone\n");
+ say("Hmm...");
+ diff_type = intuit_diff_type();
+ if (!diff_type) {
+ if (p_base != 0L) {
+ if (verbose)
+ say(" Ignoring the trailing garbage.\ndone\n");
+ }
+ else
+ say(" I can't seem to find a patch in there anywhere.\n");
+ return FALSE;
}
- else
- say(" I can't seem to find a patch in there anywhere.\n");
- return FALSE;
- }
- if (verbose)
- say(" %sooks like %s to me...\n",
- (p_base == 0L ? "L" : "The next patch l"),
- diff_type == UNI_DIFF ? "a unified diff" :
- diff_type == CONTEXT_DIFF ? "a context diff" :
- diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
- diff_type == NORMAL_DIFF ? "a normal diff" :
- "an ed script" );
- if (p_indent && verbose)
- say("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
- skip_to(p_start,p_sline);
- while (filearg[0] == NULL) {
- if (force || batch) {
- say("No file to patch. Skipping...\n");
- filearg[0] = savestr(bestguess);
- skip_rest_of_patch = TRUE;
- return TRUE;
+ if (verbose)
+ say(" %sooks like %s to me...\n",
+ (p_base == 0L ? "L" : "The next patch l"),
+ diff_type == UNI_DIFF ? "a unified diff" :
+ diff_type == CONTEXT_DIFF ? "a context diff" :
+ diff_type == NEW_CONTEXT_DIFF ?
+ "a new-style context diff" :
+ diff_type == NORMAL_DIFF ? "a normal diff" :
+ "an ed script" );
+ if (p_indent && verbose)
+ say("(Patch is indented %d space%s.)\n",
+ p_indent, p_indent==1?"":"s");
+ skip_to(p_start,p_sline);
+ while (filearg[0] == NULL) {
+ if (force || batch) {
+ say("No file to patch. Skipping...\n");
+ filearg[0] = savestr(bestguess);
+ skip_rest_of_patch = TRUE;
+ return TRUE;
+ }
+ ask("File to patch: ");
+ if (*buf != '\n') {
+ if (bestguess)
+ free(bestguess);
+ bestguess = savestr(buf);
+ filearg[0] = fetchname(buf, 0, FALSE);
+ }
+ if (filearg[0] == NULL) {
+ ask("No file found--skip this patch? [n] ");
+ if (*buf != 'y') {
+ continue;
+ }
+ if (verbose)
+ say("Skipping patch...\n");
+ filearg[0] = fetchname(bestguess, 0, TRUE);
+ skip_rest_of_patch = TRUE;
+ return TRUE;
+ }
}
- ask("File to patch: ");
- if (*buf != '\n') {
- if (bestguess)
- free(bestguess);
- bestguess = savestr(buf);
- filearg[0] = fetchname(buf, 0, FALSE);
- }
- if (filearg[0] == NULL) {
- ask("No file found--skip this patch? [n] ");
- if (*buf != 'y') {
- continue;
- }
- if (verbose)
- say("Skipping patch...\n");
- filearg[0] = fetchname(bestguess, 0, TRUE);
- skip_rest_of_patch = TRUE;
- return TRUE;
- }
- }
- return TRUE;
+ return TRUE;
}
-/* Determine what kind of diff is in the remaining part of the patch file. */
-
+/*
+ * Determine what kind of diff is in the remaining part of the patch file.
+ */
int
intuit_diff_type(void)
{
- long this_line = 0;
- long previous_line;
- long first_command_line = -1;
- long fcl_line = -1;
- bool last_line_was_command = FALSE;
- bool this_is_a_command = FALSE;
- bool stars_last_line = FALSE;
- bool stars_this_line = FALSE;
- int indent;
- char *s;
- char *t;
- char *indtmp = NULL;
- char *oldtmp = NULL;
- char *newtmp = NULL;
- char *indname = NULL;
- char *oldname = NULL;
- char *newname = NULL;
- int retval;
- bool no_filearg = (filearg[0] == NULL);
+ long this_line = 0;
+ long previous_line;
+ long first_command_line = -1;
+ long fcl_line = -1;
+ bool last_line_was_command = FALSE;
+ bool this_is_a_command = FALSE;
+ bool stars_last_line = FALSE;
+ bool stars_this_line = FALSE;
+ int indent;
+ char *s;
+ char *t;
+ char *indtmp = NULL;
+ char *oldtmp = NULL;
+ char *newtmp = NULL;
+ char *indname = NULL;
+ char *oldname = NULL;
Home |
Main Index |
Thread Index |
Old Index