4 * Revision 1.1 2005/04/21 14:55:10 beng
7 * Revision 1.1.1.1 2005/04/20 13:33:18 beng
8 * Initial import of minix 2.0.4
10 * Revision 2.0.1.2 88/06/22 20:44:53 lwall
11 * patch12: sprintf was declared wrong
13 * Revision 2.0.1.1 88/06/03 15:01:56 lwall
14 * patch10: support for shorter extensions.
16 * Revision 2.0 86/09/17 15:36:39 lwall
17 * Baseline for netwide release.
24 #include <sys/types.h>
31 /* shut lint up about the following when return value ignored */
33 #define Signal (void)signal
34 #define Unlink (void)unlink
35 #define Lseek (void)lseek
36 #define Fseek (void)fseek
37 #define Fstat (void)fstat
38 #define Pclose (void)pclose
39 #define Close (void)close
40 #define Fclose (void)fclose
41 #define Fflush (void)fflush
42 #define Sprintf (void)sprintf
43 #define Mktemp (void)mktemp
44 #define Strcpy (void)strcpy
45 #define Strcat (void)strcat
47 #include <sys/types.h>
59 #define MAXHUNKSIZE 100000 /* is this enough lines? */
60 #define INITHUNKMAX 125 /* initial dynamic allocation size */
61 #define MAXLINELEN 1024
62 #define BUFFERSIZE 1024
63 #define SCCSPREFIX "s."
64 #define GET "get -e %s"
65 #define RCSSUFFIX ",v"
66 #define CHECKOUT "co -l %s"
69 #define ORIGEXT ".orig"
76 /* handy definitions */
78 #define Null(t) ((t)0)
79 #define Nullch Null(char *)
80 #define Nullfp Null(FILE *)
81 #define Nulline Null(LINENUM)
83 #define Ctl(ch) ((ch) & 037)
85 #define strNE(s1,s2) (strcmp(s1, s2))
86 #define strEQ(s1,s2) (!strcmp(s1, s2))
87 #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
88 #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
93 typedef long LINENUM
; /* must be signed */
94 typedef unsigned MEM
; /* what to feed malloc */
98 EXT
int Argc
; /* guess */
100 EXT
int Argc_last
; /* for restarting plan_b */
101 EXT
char **Argv_last
;
103 EXT
struct stat filestat
; /* file statistics area */
104 EXT
int filemode
INIT(0644);
106 EXT
char buf
[MAXLINELEN
]; /* general purpose buffer */
107 EXT
FILE *ofp
INIT(Nullfp
); /* output file pointer */
108 EXT
FILE *rejfp
INIT(Nullfp
); /* reject file pointer */
110 EXT
bool using_plan_a
INIT(TRUE
); /* try to keep everything in memory */
111 EXT
bool out_of_mem
INIT(FALSE
); /* ran out of memory in plan a */
114 EXT
int filec
INIT(0); /* how many file arguments? */
115 EXT
char *filearg
[MAXFILEC
];
116 EXT
bool ok_to_create_file
INIT(FALSE
);
117 EXT
char *bestguess
INIT(Nullch
); /* guess at correct filename */
119 EXT
char *outname
INIT(Nullch
);
120 EXT
char rejname
[128];
122 EXT
char *origext
INIT(Nullch
);
123 EXT
char *origprae
INIT(Nullch
);
125 EXT
char TMPOUTNAME
[] INIT("/tmp/patchoXXXXXX");
126 EXT
char TMPINNAME
[] INIT("/tmp/patchiXXXXXX"); /* might want /usr/tmp here */
127 EXT
char TMPREJNAME
[] INIT("/tmp/patchrXXXXXX");
128 EXT
char TMPPATNAME
[] INIT("/tmp/patchpXXXXXX");
130 EXT
char TMPSTRNAME
[] INIT("/tmp/patchsXXXXXX");
132 EXT
bool toutkeep
INIT(FALSE
);
133 EXT
bool trejkeep
INIT(FALSE
);
135 EXT LINENUM last_offset
INIT(0);
137 EXT
int debug
INIT(0);
139 EXT LINENUM maxfuzz
INIT(2);
140 EXT
bool force
INIT(FALSE
);
141 EXT
bool verbose
INIT(TRUE
);
142 EXT
bool reverse
INIT(FALSE
);
143 EXT
bool noreverse
INIT(FALSE
);
144 EXT
bool skip_rest_of_patch
INIT(FALSE
);
145 EXT
int strippath
INIT(957);
146 EXT
bool canonicalize
INIT(FALSE
);
148 #define CONTEXT_DIFF 1
149 #define NORMAL_DIFF 2
151 #define NEW_CONTEXT_DIFF 4
152 EXT
int diff_type
INIT(0);
154 EXT
bool do_defines
INIT(FALSE
); /* patch using ifdef, ifndef, etc. */
155 EXT
char if_defined
[128]; /* #ifdef xyzzy */
156 EXT
char not_defined
[128]; /* #ifndef xyzzy */
157 EXT
char else_defined
[] INIT("#else\n");/* #else */
158 EXT
char end_defined
[128]; /* #endif xyzzy */
160 EXT
char *revision
INIT(Nullch
); /* prerequisite revision, if any */
162 _PROTOTYPE(void my_exit
, (int status
));