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