xref: /openbsd-src/usr.bin/patch/common.h (revision 62a742911104f98b9185b2c6b6007d9b1c36396c)
1 /*	$OpenBSD: common.h,v 1.10 1999/01/03 05:33:48 millert Exp $ */
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 Snprintf (void)snprintf
20 #define Strcpy (void)strcpy
21 #define Strcat (void)strcat
22 
23 /* NeXT declares malloc and realloc incompatibly from us in some of
24    these files.  Temporarily redefine them to prevent errors.  */
25 #define malloc system_malloc
26 #define realloc system_realloc
27 #include <stdio.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <sys/types.h>
31 #include <sys/file.h>
32 #include <sys/stat.h>
33 #include <sys/param.h>
34 #include <ctype.h>
35 #include <paths.h>
36 #include <signal.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <libgen.h>
40 #undef malloc
41 #undef realloc
42 
43 /* constants */
44 
45 /* AIX predefines these.  */
46 #ifdef TRUE
47 #undef TRUE
48 #endif
49 #ifdef FALSE
50 #undef FALSE
51 #endif
52 #define TRUE (1)
53 #define FALSE (0)
54 
55 #define MAXHUNKSIZE 100000		/* is this enough lines? */
56 #define INITHUNKMAX 125			/* initial dynamic allocation size */
57 #define MAXLINELEN 8192
58 #define BUFFERSIZE 1024
59 
60 #define SCCSPREFIX "s."
61 #define GET "get -e %s"
62 #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
63 
64 #define RCSSUFFIX ",v"
65 #define CHECKOUT "co -l %s"
66 #define RCSDIFF "rcsdiff %s > /dev/null"
67 
68 #ifdef FLEXFILENAMES
69 #define ORIGEXT ".orig"
70 #define REJEXT ".rej"
71 #else
72 #define ORIGEXT "~"
73 #define REJEXT "#"
74 #endif
75 
76 /* handy definitions */
77 
78 #define Null(t) ((t)0)
79 #define Nullch Null(char *)
80 #define Nullfp Null(FILE *)
81 #define Nulline Null(LINENUM)
82 
83 #define Ctl(ch) ((ch) & 037)
84 
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))
89 
90 /* typedefs */
91 
92 typedef char bool;
93 typedef long LINENUM;			/* must be signed */
94 typedef unsigned MEM;			/* what to feed malloc */
95 
96 /* globals */
97 
98 EXT int Argc;				/* guess */
99 EXT char **Argv;
100 EXT int Argc_last;			/* for restarting plan_b */
101 EXT char **Argv_last;
102 
103 EXT struct stat filestat;		/* file statistics area */
104 EXT int filemode INIT(0644);
105 
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 */
109 
110 EXT int myuid;				/* cache getuid return value */
111 
112 EXT bool using_plan_a INIT(TRUE);	/* try to keep everything in memory */
113 EXT bool out_of_mem INIT(FALSE);	/* ran out of memory in plan a */
114 
115 #define MAXFILEC 2
116 EXT int filec INIT(0);			/* how many file arguments? */
117 EXT char *filearg[MAXFILEC];
118 EXT bool ok_to_create_file INIT(FALSE);
119 EXT char *bestguess INIT(Nullch);	/* guess at correct filename */
120 
121 EXT char *outname INIT(Nullch);
122 EXT char rejname[128];
123 
124 EXT char *origprae INIT(Nullch);
125 
126 EXT char *TMPOUTNAME;
127 EXT char *TMPINNAME;
128 EXT char *TMPREJNAME;
129 EXT char *TMPPATNAME;
130 EXT bool toutkeep INIT(FALSE);
131 EXT bool trejkeep INIT(FALSE);
132 
133 EXT LINENUM last_offset INIT(0);
134 #ifdef DEBUGGING
135 EXT int debug INIT(0);
136 #endif
137 EXT LINENUM maxfuzz INIT(2);
138 EXT bool force INIT(FALSE);
139 EXT bool batch INIT(FALSE);
140 EXT bool verbose INIT(TRUE);
141 EXT bool reverse INIT(FALSE);
142 EXT bool noreverse INIT(FALSE);
143 EXT bool skip_rest_of_patch INIT(FALSE);
144 EXT int strippath INIT(957);
145 EXT bool canonicalize INIT(FALSE);
146 
147 #define CONTEXT_DIFF 1
148 #define NORMAL_DIFF 2
149 #define ED_DIFF 3
150 #define NEW_CONTEXT_DIFF 4
151 #define UNI_DIFF 5
152 EXT int diff_type INIT(0);
153 
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 */
159 
160 EXT char *revision INIT(Nullch);	/* prerequisite revision, if any */
161 
162 #include <errno.h>
163 #ifndef errno
164 extern int errno;
165 #endif
166 
167 FILE *popen();
168 char *malloc();
169 char *realloc();
170 long atol();
171 char *getenv();
172 char *strcpy();
173 char *strcat();
174 char *strrchr();
175 int  mkstemp();
176 #if 0				/* This can cause a prototype conflict.  */
177 #ifdef CHARSPRINTF
178 char *snprintf();
179 #else
180 int snprintf();
181 #endif
182 #endif
183 
184 #if !defined(S_ISDIR) && defined(S_IFDIR)
185 #define	S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
186 #endif
187 #if !defined(S_ISREG) && defined(S_IFREG)
188 #define	S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
189 #endif
190