Annotation of src/usr.bin/patch/common.h, Revision 1.13
1.13 ! deraadt 1: /* $OpenBSD: common.h,v 1.12 2003/04/08 01:54:56 deraadt Exp $ */
1.1 deraadt 2:
3: #define DEBUGGING
4:
5: #include "config.h"
6:
7: /* shut lint up about the following when return value ignored */
8:
9: #include <stdio.h>
10: #include <string.h>
11: #include <assert.h>
12: #include <sys/types.h>
1.3 deraadt 13: #include <sys/file.h>
1.1 deraadt 14: #include <sys/stat.h>
1.9 millert 15: #include <sys/param.h>
1.1 deraadt 16: #include <ctype.h>
1.9 millert 17: #include <paths.h>
1.1 deraadt 18: #include <signal.h>
1.7 dgregor 19: #include <stdlib.h>
1.9 millert 20: #include <unistd.h>
1.13 ! deraadt 21: #include <stdarg.h>
1.10 millert 22: #include <libgen.h>
1.13 ! deraadt 23: #include <errno.h>
1.1 deraadt 24:
25: /* constants */
26:
27: /* AIX predefines these. */
28: #ifdef TRUE
29: #undef TRUE
30: #endif
31: #ifdef FALSE
32: #undef FALSE
33: #endif
34: #define TRUE (1)
35: #define FALSE (0)
36:
37: #define MAXHUNKSIZE 100000 /* is this enough lines? */
38: #define INITHUNKMAX 125 /* initial dynamic allocation size */
1.8 niklas 39: #define MAXLINELEN 8192
1.1 deraadt 40: #define BUFFERSIZE 1024
41:
42: #define SCCSPREFIX "s."
43: #define GET "get -e %s"
44: #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
45:
46: #define RCSSUFFIX ",v"
47: #define CHECKOUT "co -l %s"
48: #define RCSDIFF "rcsdiff %s > /dev/null"
49:
50: #define ORIGEXT ".orig"
51: #define REJEXT ".rej"
52:
53: /* handy definitions */
54:
55: #define Null(t) ((t)0)
56: #define Nullch Null(char *)
57: #define Nullfp Null(FILE *)
58: #define Nulline Null(LINENUM)
59:
60: #define Ctl(ch) ((ch) & 037)
61:
62: #define strNE(s1,s2) (strcmp(s1, s2))
63: #define strEQ(s1,s2) (!strcmp(s1, s2))
64: #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
65: #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
66:
67: /* typedefs */
68:
69: typedef char bool;
70: typedef long LINENUM; /* must be signed */
71: typedef unsigned MEM; /* what to feed malloc */
72:
73: /* globals */
74:
75: EXT int Argc; /* guess */
76: EXT char **Argv;
77: EXT int Argc_last; /* for restarting plan_b */
78: EXT char **Argv_last;
79:
80: EXT struct stat filestat; /* file statistics area */
81: EXT int filemode INIT(0644);
82:
83: EXT char buf[MAXLINELEN]; /* general purpose buffer */
84: EXT FILE *ofp INIT(Nullfp); /* output file pointer */
85: EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */
86:
87: EXT int myuid; /* cache getuid return value */
88:
89: EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */
90: EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */
91:
92: #define MAXFILEC 2
93: EXT int filec INIT(0); /* how many file arguments? */
94: EXT char *filearg[MAXFILEC];
95: EXT bool ok_to_create_file INIT(FALSE);
96: EXT char *bestguess INIT(Nullch); /* guess at correct filename */
97:
98: EXT char *outname INIT(Nullch);
99: EXT char rejname[128];
100:
101: EXT char *origprae INIT(Nullch);
102:
103: EXT char *TMPOUTNAME;
104: EXT char *TMPINNAME;
105: EXT char *TMPREJNAME;
106: EXT char *TMPPATNAME;
107: EXT bool toutkeep INIT(FALSE);
108: EXT bool trejkeep INIT(FALSE);
109:
110: EXT LINENUM last_offset INIT(0);
111: #ifdef DEBUGGING
112: EXT int debug INIT(0);
113: #endif
114: EXT LINENUM maxfuzz INIT(2);
115: EXT bool force INIT(FALSE);
116: EXT bool batch INIT(FALSE);
117: EXT bool verbose INIT(TRUE);
118: EXT bool reverse INIT(FALSE);
119: EXT bool noreverse INIT(FALSE);
120: EXT bool skip_rest_of_patch INIT(FALSE);
121: EXT int strippath INIT(957);
122: EXT bool canonicalize INIT(FALSE);
123:
124: #define CONTEXT_DIFF 1
125: #define NORMAL_DIFF 2
126: #define ED_DIFF 3
127: #define NEW_CONTEXT_DIFF 4
128: #define UNI_DIFF 5
129: EXT int diff_type INIT(0);
130:
131: EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
132: EXT char if_defined[128]; /* #ifdef xyzzy */
133: EXT char not_defined[128]; /* #ifndef xyzzy */
134: EXT char else_defined[] INIT("#else\n");/* #else */
135: EXT char end_defined[128]; /* #endif xyzzy */
136:
137: EXT char *revision INIT(Nullch); /* prerequisite revision, if any */
138:
139: #if !defined(S_ISDIR) && defined(S_IFDIR)
140: #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
141: #endif
142: #if !defined(S_ISREG) && defined(S_IFREG)
143: #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
144: #endif