Commit | Line | Data |
---|---|---|
455391f1 PR |
1 | /* $Header: /a/cvs/386BSD/src/gnu/patch/common.h,v 1.1.1.1 1993/06/19 14:21:52 paul Exp $ |
2 | * | |
3 | * $Log: common.h,v $ | |
4 | * Revision 1.1.1.1 1993/06/19 14:21:52 paul | |
5 | * b-maked patch-2.10 | |
fb3ebe05 | 6 | * |
fb3ebe05 PR |
7 | * Revision 2.0.1.2 88/06/22 20:44:53 lwall |
8 | * patch12: sprintf was declared wrong | |
9 | * | |
10 | * Revision 2.0.1.1 88/06/03 15:01:56 lwall | |
11 | * patch10: support for shorter extensions. | |
12 | * | |
13 | * Revision 2.0 86/09/17 15:36:39 lwall | |
14 | * Baseline for netwide release. | |
15 | * | |
16 | */ | |
17 | ||
18 | #define DEBUGGING | |
19 | ||
20 | #define VOIDUSED 7 | |
21 | #include "config.h" | |
22 | ||
23 | /* shut lint up about the following when return value ignored */ | |
24 | ||
25 | #define Signal (void)signal | |
26 | #define Unlink (void)unlink | |
27 | #define Lseek (void)lseek | |
28 | #define Fseek (void)fseek | |
29 | #define Fstat (void)fstat | |
30 | #define Pclose (void)pclose | |
31 | #define Close (void)close | |
32 | #define Fclose (void)fclose | |
33 | #define Fflush (void)fflush | |
34 | #define Sprintf (void)sprintf | |
35 | #define Mktemp (void)mktemp | |
36 | #define Strcpy (void)strcpy | |
37 | #define Strcat (void)strcat | |
38 | ||
39 | /* NeXT declares malloc and realloc incompatibly from us in some of | |
40 | these files. Temporarily redefine them to prevent errors. */ | |
41 | #define malloc system_malloc | |
42 | #define realloc system_realloc | |
43 | #include <stdio.h> | |
44 | #include <assert.h> | |
45 | #include <sys/types.h> | |
46 | #include <sys/stat.h> | |
47 | #include <ctype.h> | |
48 | #include <signal.h> | |
49 | #undef malloc | |
50 | #undef realloc | |
51 | ||
52 | /* constants */ | |
53 | ||
54 | /* AIX predefines these. */ | |
55 | #ifdef TRUE | |
56 | #undef TRUE | |
57 | #endif | |
58 | #ifdef FALSE | |
59 | #undef FALSE | |
60 | #endif | |
61 | #define TRUE (1) | |
62 | #define FALSE (0) | |
63 | ||
455391f1 | 64 | #define MAXHUNKSIZE 200000 /* is this enough lines? */ |
fb3ebe05 | 65 | #define INITHUNKMAX 125 /* initial dynamic allocation size */ |
455391f1 PR |
66 | #define MAXLINELEN 4096 |
67 | #define BUFFERSIZE 4096 | |
fb3ebe05 PR |
68 | |
69 | #define SCCSPREFIX "s." | |
70 | #define GET "get %s" | |
71 | #define GET_LOCKED "get -e %s" | |
72 | #define SCCSDIFF "get -p %s | diff - %s >/dev/null" | |
73 | ||
74 | #define RCSSUFFIX ",v" | |
75 | #define CHECKOUT "co %s" | |
76 | #define CHECKOUT_LOCKED "co -l %s" | |
77 | #define RCSDIFF "rcsdiff %s > /dev/null" | |
78 | ||
79 | /* handy definitions */ | |
80 | ||
81 | #define Null(t) ((t)0) | |
82 | #define Nullch Null(char *) | |
83 | #define Nullfp Null(FILE *) | |
84 | #define Nulline Null(LINENUM) | |
85 | ||
86 | #define Ctl(ch) ((ch) & 037) | |
87 | ||
88 | #define strNE(s1,s2) (strcmp(s1, s2)) | |
89 | #define strEQ(s1,s2) (!strcmp(s1, s2)) | |
90 | #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) | |
91 | #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) | |
92 | ||
93 | /* typedefs */ | |
94 | ||
95 | typedef char bool; | |
96 | typedef long LINENUM; /* must be signed */ | |
97 | typedef unsigned MEM; /* what to feed malloc */ | |
98 | ||
99 | /* globals */ | |
100 | ||
101 | EXT int Argc; /* guess */ | |
102 | EXT char **Argv; | |
103 | EXT int optind_last; /* for restarting plan_b */ | |
104 | ||
105 | EXT struct stat filestat; /* file statistics area */ | |
106 | EXT int filemode INIT(0644); | |
107 | ||
108 | EXT char buf[MAXLINELEN]; /* general purpose buffer */ | |
109 | EXT FILE *ofp INIT(Nullfp); /* output file pointer */ | |
110 | EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */ | |
111 | ||
112 | EXT int myuid; /* cache getuid return value */ | |
113 | ||
114 | EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ | |
115 | EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */ | |
116 | ||
117 | #define MAXFILEC 2 | |
118 | EXT int filec INIT(0); /* how many file arguments? */ | |
119 | EXT char *filearg[MAXFILEC]; | |
120 | EXT bool ok_to_create_file INIT(FALSE); | |
121 | EXT char *bestguess INIT(Nullch); /* guess at correct filename */ | |
122 | ||
123 | EXT char *outname INIT(Nullch); | |
124 | EXT char rejname[128]; | |
125 | ||
126 | EXT char *origprae INIT(Nullch); | |
127 | ||
128 | EXT char *TMPOUTNAME; | |
129 | EXT char *TMPINNAME; | |
130 | EXT char *TMPREJNAME; | |
131 | EXT char *TMPPATNAME; | |
132 | EXT bool toutkeep INIT(FALSE); | |
133 | EXT bool trejkeep INIT(FALSE); | |
134 | ||
135 | EXT LINENUM last_offset INIT(0); | |
136 | #ifdef DEBUGGING | |
137 | EXT int debug INIT(0); | |
138 | #endif | |
139 | EXT LINENUM maxfuzz INIT(2); | |
140 | EXT bool force INIT(FALSE); | |
141 | EXT bool batch INIT(FALSE); | |
142 | EXT bool verbose INIT(TRUE); | |
143 | EXT bool reverse INIT(FALSE); | |
144 | EXT bool noreverse INIT(FALSE); | |
145 | EXT bool skip_rest_of_patch INIT(FALSE); | |
146 | EXT int strippath INIT(957); | |
147 | EXT bool canonicalize INIT(FALSE); | |
148 | ||
149 | #define CONTEXT_DIFF 1 | |
150 | #define NORMAL_DIFF 2 | |
151 | #define ED_DIFF 3 | |
152 | #define NEW_CONTEXT_DIFF 4 | |
153 | #define UNI_DIFF 5 | |
154 | EXT int diff_type INIT(0); | |
155 | ||
156 | EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */ | |
157 | EXT char if_defined[128]; /* #ifdef xyzzy */ | |
158 | EXT char not_defined[128]; /* #ifndef xyzzy */ | |
159 | EXT char else_defined[] INIT("#else\n");/* #else */ | |
160 | EXT char end_defined[128]; /* #endif xyzzy */ | |
161 | ||
162 | EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ | |
163 | ||
164 | #include <errno.h> | |
165 | #ifdef STDC_HEADERS | |
166 | #include <stdlib.h> | |
167 | #include <string.h> | |
168 | #else | |
169 | extern int errno; | |
170 | FILE *popen(); | |
171 | char *malloc(); | |
172 | char *realloc(); | |
173 | long atol(); | |
174 | char *getenv(); | |
175 | char *strcpy(); | |
176 | char *strcat(); | |
177 | #endif | |
178 | char *mktemp(); | |
179 | #ifdef HAVE_UNISTD_H | |
180 | #include <unistd.h> | |
181 | #else | |
182 | long lseek(); | |
183 | #endif | |
184 | #if defined(_POSIX_VERSION) || defined(HAVE_FCNTL_H) | |
185 | #include <fcntl.h> | |
186 | #endif | |
187 | ||
188 | #if !defined(S_ISDIR) && defined(S_IFDIR) | |
189 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
190 | #endif | |
191 | #if !defined(S_ISREG) && defined(S_IFREG) | |
192 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | |
193 | #endif |