1: /* $Header: common.h,v 2.0.1.2 88/06/22 20:44:53 lwall Locked $
2: *
3: * $Log: common.h,v $
4: * Revision 2.0.1.2 88/06/22 20:44:53 lwall
5: * patch12: sprintf was declared wrong
6: *
7: * Revision 2.0.1.1 88/06/03 15:01:56 lwall
8: * patch10: support for shorter extensions.
9: *
10: * Revision 2.0 86/09/17 15:36:39 lwall
11: * Baseline for netwide release.
12: *
13: */
14:
15: #define DEBUGGING
16:
17: #include "config.h"
18:
19: /* shut lint up about the following when return value ignored */
20:
21: #define Signal (void)signal
22: #define Unlink (void)unlink
23: #define Lseek (void)lseek
24: #define Fseek (void)fseek
25: #define Fstat (void)fstat
26: #define Pclose (void)pclose
27: #define Close (void)close
28: #define Fclose (void)fclose
29: #define Fflush (void)fflush
30: #define Sprintf (void)sprintf
31: #define Mktemp (void)mktemp
32: #define Strcpy (void)strcpy
33: #define Strcat (void)strcat
34:
35: #include <stdio.h>
36: #include <assert.h>
37: #include <sys/types.h>
38: #include <sys/stat.h>
39: #include <ctype.h>
40: #include <signal.h>
41:
42: /* constants */
43:
44: #define TRUE (1)
45: #define FALSE (0)
46:
47: #define MAXHUNKSIZE 100000 /* is this enough lines? */
48: #define INITHUNKMAX 125 /* initial dynamic allocation size */
49: #define MAXLINELEN 1024
50: #define BUFFERSIZE 1024
51: #define SCCSPREFIX "s."
52: #define GET "get -e %s"
53: #define RCSSUFFIX ",v"
54: #define CHECKOUT "co -l %s"
55:
56: #ifdef FLEXFILENAMES
57: #define ORIGEXT ".orig"
58: #define REJEXT ".rej"
59: #else
60: #define ORIGEXT "~"
61: #define REJEXT "#"
62: #endif
63:
64: /* handy definitions */
65:
66: #define Null(t) ((t)0)
67: #define Nullch Null(char *)
68: #define Nullfp Null(FILE *)
69: #define Nulline Null(LINENUM)
70:
71: #define Ctl(ch) ((ch) & 037)
72:
73: #define strNE(s1,s2) (strcmp(s1, s2))
74: #define strEQ(s1,s2) (!strcmp(s1, s2))
75: #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
76: #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
77:
78: /* typedefs */
79:
80: typedef char bool;
81: typedef long LINENUM; /* must be signed */
82: typedef unsigned MEM; /* what to feed malloc */
83:
84: /* globals */
85:
86: EXT int Argc; /* guess */
87: EXT char **Argv;
88: EXT int Argc_last; /* for restarting plan_b */
89: EXT char **Argv_last;
90:
91: EXT struct stat filestat; /* file statistics area */
92: EXT int filemode INIT(0644);
93:
94: EXT char buf[MAXLINELEN]; /* general purpose buffer */
95: EXT FILE *ofp INIT(Nullfp); /* output file pointer */
96: EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */
97:
98: EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */
99: EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */
100:
101: #define MAXFILEC 2
102: EXT int filec INIT(0); /* how many file arguments? */
103: EXT char *filearg[MAXFILEC];
104: EXT bool ok_to_create_file INIT(FALSE);
105: EXT char *bestguess INIT(Nullch); /* guess at correct filename */
106:
107: EXT char *outname INIT(Nullch);
108: EXT char rejname[128];
109:
110: EXT char *origext INIT(Nullch);
111: EXT char *origprae INIT(Nullch);
112:
113: EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
114: EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX"); /* might want /usr/tmp here */
115: EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
116: EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
117: EXT bool toutkeep INIT(FALSE);
118: EXT bool trejkeep INIT(FALSE);
119:
120: EXT LINENUM last_offset INIT(0);
121: #ifdef DEBUGGING
122: EXT int debug INIT(0);
123: #endif
124: EXT LINENUM maxfuzz INIT(2);
125: EXT bool force INIT(FALSE);
126: EXT bool verbose INIT(TRUE);
127: EXT bool reverse INIT(FALSE);
128: EXT bool noreverse INIT(FALSE);
129: EXT bool skip_rest_of_patch INIT(FALSE);
130: EXT int strippath INIT(957);
131: EXT bool canonicalize INIT(FALSE);
132:
133: #define CONTEXT_DIFF 1
134: #define NORMAL_DIFF 2
135: #define ED_DIFF 3
136: #define NEW_CONTEXT_DIFF 4
137: EXT int diff_type INIT(0);
138:
139: EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
140: EXT char if_defined[128]; /* #ifdef xyzzy */
141: EXT char not_defined[128]; /* #ifndef xyzzy */
142: EXT char else_defined[] INIT("#else\n");/* #else */
143: EXT char end_defined[128]; /* #endif xyzzy */
144:
145: EXT char *revision INIT(Nullch); /* prerequisite revision, if any */
146:
147: char *malloc();
148: char *realloc();
149: char *strcpy();
150: char *strcat();
151: long atol();
152: long lseek();
153: char *mktemp();
154: #ifdef CHARSPRINTF
155: char *sprintf();
156: #else
157: int sprintf();
158: #endif
Defined variables
Argc
defined in line
86; used 13 times
Argv
defined in line
87; used 19 times
buf
defined in line
94; used 126 times
- in /usr/src/usr.bin/patch/inp.c line
95-112(10),
199,
226-229(4),
244
- in /usr/src/usr.bin/patch/patch.c line
216-218(2)
- in /usr/src/usr.bin/patch/pch.c line
86-87(3),
179-187(4),
235(2),
250,
399-401(3),
447-449(3),
457-461(3),
472,
478-480(2),
494-502(3),
527,
562,
568,
588,
599-601(5),
611,
623,
637,
645,
730-737(5),
758-764(3),
771-778(4),
787-796(5),
803-810(4),
842,
860,
867-868(2),
1076-1099(12)
- in /usr/src/usr.bin/patch/util.c line
27-28(3),
87-88(3),
113-114(3),
197-228(21),
308-309(2),
316
debug
defined in line
122; used 10 times
diff_type
defined in line
137; used 23 times
- in /usr/src/usr.bin/patch/patch.c line
160,
347,
396,
419,
433,
532-533(2)
- in /usr/src/usr.bin/patch/pch.c line
152-153(2),
165-167(3),
280(2),
290(2),
304(2),
430(2),
619,
686,
693
filearg
defined in line
103; used 22 times
- in /usr/src/usr.bin/patch/patch.c line
132,
147,
153,
170,
335-337(3),
383
- in /usr/src/usr.bin/patch/pch.c line
172-175(2),
183-185(2),
192,
223,
324-333(5),
339-340(2),
1074
out_of_mem
defined in line
99; used 16 times
- in /usr/src/usr.bin/patch/inp.c line
131-133(2)
- in /usr/src/usr.bin/patch/patch.c line
178,
263,
335
- in /usr/src/usr.bin/patch/pch.c line
136,
498,
563,
612,
624,
646,
765,
779,
797,
811
- in /usr/src/usr.bin/patch/util.c line
136
skip_rest_of_patch
defined in line
129; used 18 times
- in /usr/src/usr.bin/patch/patch.c line
156,
169,
185,
209,
219,
227-230(2),
237,
273-278(2),
307,
355,
458
- in /usr/src/usr.bin/patch/pch.c line
193,
1072,
1092-1097(2),
1109
verbose
defined in line
126; used 21 times
- in /usr/src/usr.bin/patch/inp.c line
72,
89,
98,
109,
190,
203,
235,
248
- in /usr/src/usr.bin/patch/patch.c line
240,
246-251(2),
455
- in /usr/src/usr.bin/patch/pch.c line
146-155(3),
162,
169,
190,
395,
688,
1075
Defined typedef's
LINENUM
defined in line
81; used 84 times
- in line 120-69(3)
- in /usr/src/usr.bin/patch/inp.c line
32-33(2),
86,
283,
291-292(2)
- in /usr/src/usr.bin/patch/patch.c line
102,
121-124(4),
477-486(7),
525-531(6),
571-575(4),
582,
714-716(2),
745,
758-764(6)
- in /usr/src/usr.bin/patch/pch.c line
41-48(8),
54-60(7),
71,
433-436(4),
443-444(2),
507,
513,
571,
577,
726,
736-739(2),
747-750(2),
881-882(2),
980,
988,
996,
1004,
1012,
1020,
1030,
1039,
1048,
1055
MEM
defined in line
82; used 11 times
bool
defined in line
80; used 37 times
- in line 98-104(3),
117-118(2),
125-131(6),
139
- in /usr/src/usr.bin/patch/inp.c line
80,
219,
312
- in /usr/src/usr.bin/patch/patch.c line
110-111(2),
496-497(2),
581,
756,
783
- in /usr/src/usr.bin/patch/pch.c line
142,
209-212(4),
223,
412,
437-440(3),
875,
883,
1068
- in /usr/src/usr.bin/patch/util.c line
195,
284
Defined macros
Close
defined in line
27; used 10 times
Ctl
defined in line
71;
never used
FALSE
defined in line
45; used 53 times
- in line 99-104(2),
117-118(2),
125-131(5),
139
- in /usr/src/usr.bin/patch/inp.c line
129-134(3),
143,
150,
172,
221,
330
- in /usr/src/usr.bin/patch/patch.c line
178,
354-355(2),
455,
771-776(2),
792,
801
- in /usr/src/usr.bin/patch/pch.c line
148,
160,
183,
209-212(4),
225,
437-440(2),
451,
500,
565,
592-597(2),
614,
626,
648,
734,
767,
781,
799,
813,
844,
883,
911,
1068
Fseek
defined in line
24; used 5 times
Fstat
defined in line
25; used 1 times
GET
defined in line
52; used 1 times
Lseek
defined in line
23; used 1 times
Null
defined in line
66; used 23 times
Nullch
defined in line
67; used 77 times
- in line 105-111(4),
145
- in /usr/src/usr.bin/patch/inp.c line
47-49(2),
58,
137-142(2),
187,
219,
226-232(3),
257,
264,
319
- in /usr/src/usr.bin/patch/patch.c line
132,
152,
335-342(4),
349-351(2)
- in /usr/src/usr.bin/patch/pch.c line
51,
82-86(2),
111,
126,
132,
172,
185,
216-223(7),
235,
277,
316-320(3),
337-346(5),
359-369(6),
400,
449,
459,
474-476(2),
732,
773,
789,
805,
859,
897-899(2),
908,
973,
1083,
1095
- in /usr/src/usr.bin/patch/util.c line
134,
333,
342,
364
Nullfp
defined in line
68; used 10 times
TRUE
defined in line
44; used 45 times
- in line 98,
126
- in /usr/src/usr.bin/patch/inp.c line
53,
91,
207,
228,
320-327(3)
- in /usr/src/usr.bin/patch/patch.c line
209,
219,
280,
316,
407,
422,
430,
436,
452,
458,
778,
805
- in /usr/src/usr.bin/patch/pch.c line
136,
176,
192-197(4),
293,
342-347(3),
438,
464,
482,
491,
542,
603,
620,
639,
653,
839,
918,
975,
1117
- in /usr/src/usr.bin/patch/util.c line
136
strEQ
defined in line
74; used 5 times
strNE
defined in line
73;
never used
strnEQ
defined in line
76; used 13 times
Usage of this include