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