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