xref: /netbsd-src/usr.bin/patch/common.h (revision 5e4c038a45edbc7d63b7c2daa76e29f88b64a4e3)
1 /*	$NetBSD: common.h,v 1.11 2002/03/11 18:47:51 kristerw Exp $	*/
2 
3 #define DEBUGGING
4 
5 /* shut lint up about the following when return value ignored */
6 
7 #define Signal (void)signal
8 #define Unlink (void)unlink
9 #define Lseek (void)lseek
10 #define Fseek (void)fseek
11 #define Fstat (void)fstat
12 #define Pclose (void)pclose
13 #define Close (void)close
14 #define Fclose (void)fclose
15 #define Fflush (void)fflush
16 #define Sprintf (void)sprintf
17 #define Strcpy (void)strcpy
18 #define Strcat (void)strcat
19 
20 #include <stdio.h>
21 #include <string.h>
22 #include <assert.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <ctype.h>
26 #include <signal.h>
27 
28 /* constants */
29 
30 /* AIX predefines these.  */
31 #ifdef TRUE
32 #undef TRUE
33 #endif
34 #ifdef FALSE
35 #undef FALSE
36 #endif
37 #define TRUE (1)
38 #define FALSE (0)
39 
40 #define MAXHUNKSIZE 100000		/* is this enough lines? */
41 #define INITHUNKMAX 125			/* initial dynamic allocation size */
42 #define MAXLINELEN 10240
43 #define BUFFERSIZE 1024
44 
45 #define SCCSPREFIX "s."
46 #define GET "get -e %s"
47 #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
48 
49 #define RCSSUFFIX ",v"
50 #define CHECKOUT "co -l %s"
51 #define RCSDIFF "rcsdiff %s > /dev/null"
52 
53 #define ORIGEXT ".orig"
54 #define REJEXT ".rej"
55 
56 /* handy definitions */
57 
58 #define Nulline 0
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 
72 /* globals */
73 
74 EXT int Argc;				/* guess */
75 EXT char **Argv;
76 EXT int Argc_last;			/* for restarting plan_b */
77 EXT char **Argv_last;
78 
79 EXT struct stat filestat;		/* file statistics area */
80 EXT int filemode INIT(0644);
81 
82 EXT char buf[MAXLINELEN];		/* general purpose buffer */
83 EXT FILE *ofp INIT(NULL);		/* output file pointer */
84 EXT FILE *rejfp INIT(NULL);		/* reject file pointer */
85 
86 EXT int myuid;				/* cache getuid return value */
87 
88 EXT bool using_plan_a INIT(TRUE);	/* try to keep everything in memory */
89 EXT bool out_of_mem INIT(FALSE);	/* ran out of memory in plan a */
90 
91 #define MAXFILEC 2
92 EXT int filec INIT(0);			/* how many file arguments? */
93 EXT char *filearg[MAXFILEC];
94 EXT bool ok_to_create_file INIT(FALSE);
95 EXT bool filename_is_dev_null INIT(FALSE);
96 EXT bool old_file_is_dev_null INIT(FALSE);
97 EXT char *bestguess INIT(NULL);		/* guess at correct filename */
98 
99 EXT char *outname INIT(NULL);
100 EXT char rejname[128];
101 
102 EXT char *origprae INIT(NULL);
103 
104 EXT char *TMPOUTNAME;
105 EXT char *TMPINNAME;
106 EXT char *TMPREJNAME;
107 EXT char *TMPPATNAME;
108 EXT bool toutkeep INIT(FALSE);
109 EXT bool trejkeep INIT(FALSE);
110 
111 EXT LINENUM last_offset INIT(0);
112 #ifdef DEBUGGING
113 EXT int debug INIT(0);
114 #endif
115 EXT LINENUM maxfuzz INIT(2);
116 EXT bool force INIT(FALSE);
117 EXT bool batch INIT(FALSE);
118 EXT bool verbose INIT(TRUE);
119 EXT bool reverse INIT(FALSE);
120 EXT bool noreverse INIT(FALSE);
121 EXT bool skip_rest_of_patch INIT(FALSE);
122 EXT int strippath INIT(957);
123 EXT bool canonicalize INIT(FALSE);
124 
125 #define CONTEXT_DIFF 1
126 #define NORMAL_DIFF 2
127 #define ED_DIFF 3
128 #define NEW_CONTEXT_DIFF 4
129 #define UNI_DIFF 5
130 EXT int diff_type INIT(0);
131 
132 EXT bool do_defines INIT(FALSE);	/* patch using ifdef, ifndef, etc. */
133 EXT char if_defined[128];		/* #ifdef xyzzy */
134 EXT char not_defined[128];		/* #ifndef xyzzy */
135 EXT char else_defined[] INIT("#else\n");/* #else */
136 EXT char end_defined[128];		/* #endif xyzzy */
137 
138 EXT char *revision INIT(NULL);		/* prerequisite revision, if any */
139 
140 #include <errno.h>
141 
142 #if !defined(S_ISDIR) && defined(S_IFDIR)
143 #define	S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
144 #endif
145 #if !defined(S_ISREG) && defined(S_IFREG)
146 #define	S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
147 #endif
148 
149 void my_exit(int) __attribute__((__noreturn__));
150