common.h revision 1.1.1.1 1 /* $Header: /tank/opengrok/rsync2/NetBSD/src/usr.bin/patch/common.h,v 1.1.1.1 1997/01/09 14:47:38 tls Exp $
2 *
3 * $Log: common.h,v $
4 * Revision 1.1.1.1 1997/01/09 14:47:38 tls
5 * Import from 4.4BSD-Lite2
6 *
7 * Revision 2.0 86/09/17 15:36:39 lwall
8 * Baseline for netwide release.
9 *
10 */
11
12 #define DEBUGGING
13
14 #include "config.h"
15
16 /* shut lint up about the following when return value ignored */
17
18 #define Signal (void)signal
19 #define Unlink (void)unlink
20 #define Lseek (void)lseek
21 #define Fseek (void)fseek
22 #define Fstat (void)fstat
23 #define Pclose (void)pclose
24 #define Close (void)close
25 #define Fclose (void)fclose
26 #define Fflush (void)fflush
27 #define Sprintf (void)sprintf
28 #define Mktemp (void)mktemp
29 #define Strcpy (void)strcpy
30 #define Strcat (void)strcat
31
32 #include <stdio.h>
33 #include <assert.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <ctype.h>
37 #include <signal.h>
38
39 /* constants */
40
41 #define TRUE (1)
42 #define FALSE (0)
43
44 #define MAXHUNKSIZE 100000 /* is this enough lines? */
45 #define INITHUNKMAX 125 /* initial dynamic allocation size */
46 #define MAXLINELEN 1024
47 #define BUFFERSIZE 1024
48 #define ORIGEXT ".orig"
49 #define SCCSPREFIX "s."
50 #define GET "get -e %s"
51 #define RCSSUFFIX ",v"
52 #define CHECKOUT "co -l %s"
53
54 /* handy definitions */
55
56 #define Null(t) ((t)0)
57 #define Nullch Null(char *)
58 #define Nullfp Null(FILE *)
59 #define Nulline Null(LINENUM)
60
61 #define Ctl(ch) ((ch) & 037)
62
63 #define strNE(s1,s2) (strcmp(s1, s2))
64 #define strEQ(s1,s2) (!strcmp(s1, s2))
65 #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
66 #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
67
68 /* typedefs */
69
70 typedef char bool;
71 typedef long LINENUM; /* must be signed */
72 typedef unsigned MEM; /* what to feed malloc */
73
74 /* globals */
75
76 EXT int Argc; /* guess */
77 EXT char **Argv;
78 EXT int Argc_last; /* for restarting plan_b */
79 EXT char **Argv_last;
80
81 EXT struct stat filestat; /* file statistics area */
82 EXT int filemode INIT(0644);
83
84 EXT char buf[MAXLINELEN]; /* general purpose buffer */
85 EXT FILE *ofp INIT(Nullfp); /* output file pointer */
86 EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */
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 char *bestguess INIT(Nullch); /* guess at correct filename */
96
97 EXT char *outname INIT(Nullch);
98 EXT char rejname[128];
99
100 EXT char *origext INIT(Nullch);
101
102 EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
103 EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX"); /* might want /usr/tmp here */
104 EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
105 EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
106 EXT bool toutkeep INIT(FALSE);
107 EXT bool trejkeep INIT(FALSE);
108
109 EXT LINENUM last_offset INIT(0);
110 #ifdef DEBUGGING
111 EXT int debug INIT(0);
112 #endif
113 EXT LINENUM maxfuzz INIT(2);
114 EXT bool force INIT(FALSE);
115 EXT bool verbose INIT(TRUE);
116 EXT bool reverse INIT(FALSE);
117 EXT bool noreverse INIT(FALSE);
118 EXT bool skip_rest_of_patch INIT(FALSE);
119 EXT int strippath INIT(957);
120 EXT bool canonicalize INIT(FALSE);
121
122 #define CONTEXT_DIFF 1
123 #define NORMAL_DIFF 2
124 #define ED_DIFF 3
125 #define NEW_CONTEXT_DIFF 4
126 EXT int diff_type INIT(0);
127
128 EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
129 EXT char if_defined[128]; /* #ifdef xyzzy */
130 EXT char not_defined[128]; /* #ifndef xyzzy */
131 EXT char else_defined[] INIT("#else\n");/* #else */
132 EXT char end_defined[128]; /* #endif xyzzy */
133
134 EXT char *revision INIT(Nullch); /* prerequisite revision, if any */
135
136 char *malloc();
137 char *realloc();
138 char *strcpy();
139 char *strcat();
140 long atol();
141 char *mktemp();
142