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