common.h revision 1.16 1 /* $NetBSD: common.h,v 1.16 2003/07/30 08:51:55 itojun Exp $ */
2
3 /*
4 * Copyright (c) 1988, Larry Wall
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following condition
8 * is met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this condition and the following disclaimer.
11 *
12 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 * SUCH DAMAGE.
23 */
24
25 #define DEBUGGING
26
27 /* shut lint up about the following when return value ignored */
28
29 #define Signal (void)signal
30 #define Unlink (void)unlink
31 #define Lseek (void)lseek
32 #define Fseek (void)fseek
33 #define Fstat (void)fstat
34 #define Pclose (void)pclose
35 #define Close (void)close
36 #define Fclose (void)fclose
37 #define Fflush (void)fflush
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <assert.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <ctype.h>
45 #include <signal.h>
46
47 /* constants */
48
49 /* AIX predefines these. */
50 #ifdef TRUE
51 #undef TRUE
52 #endif
53 #ifdef FALSE
54 #undef FALSE
55 #endif
56 #define TRUE (1)
57 #define FALSE (0)
58
59 #define MAXHUNKSIZE 100000 /* is this enough lines? */
60 #define INITHUNKMAX 125 /* initial dynamic allocation size */
61 #define MAXLINELEN 10240
62
63 #define SCCSPREFIX "s."
64 #define GET "get -e %s"
65 #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
66
67 #define RCSSUFFIX ",v"
68 #define CHECKOUT "co -l %s"
69 #define RCSDIFF "rcsdiff %s > /dev/null"
70
71 #define ORIGEXT ".orig"
72 #define REJEXT ".rej"
73
74 /* handy definitions */
75
76 #define Nulline 0
77
78 #define strNE(s1,s2) (strcmp(s1, s2))
79 #define strEQ(s1,s2) (!strcmp(s1, s2))
80 #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
81 #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
82
83 /* typedefs */
84
85 typedef char bool;
86 typedef int LINENUM; /* must be signed */
87
88 /* globals */
89
90 EXT int Argc; /* guess */
91 EXT char **Argv;
92
93 EXT struct stat filestat; /* file statistics area */
94 EXT mode_t filemode INIT(0644);
95
96 EXT char buf[MAXLINELEN]; /* general purpose buffer */
97 EXT FILE *ofp INIT(NULL); /* output file pointer */
98 EXT FILE *rejfp INIT(NULL); /* reject file pointer */
99
100 EXT int myuid; /* cache getuid return value */
101
102 #define MAXFILEC 2
103 EXT int filec INIT(0); /* how many file arguments? */
104 EXT char *filearg[MAXFILEC];
105 EXT bool ok_to_create_file INIT(FALSE);
106 EXT bool filename_is_dev_null INIT(FALSE);
107 EXT bool old_file_is_dev_null INIT(FALSE);
108 EXT char *bestguess INIT(NULL); /* guess at correct filename */
109
110 EXT char *outname INIT(NULL);
111 EXT char rejname[128];
112
113 EXT char *origprae INIT(NULL);
114
115 EXT char *TMPOUTNAME;
116 EXT char *TMPINNAME;
117 EXT char *TMPREJNAME;
118 EXT char *TMPPATNAME;
119 EXT bool toutkeep INIT(FALSE);
120 EXT bool trejkeep INIT(FALSE);
121
122 EXT LINENUM last_offset INIT(0);
123 #ifdef DEBUGGING
124 EXT int debug INIT(0);
125 #endif
126 EXT LINENUM maxfuzz INIT(2);
127 EXT bool force INIT(FALSE);
128 EXT bool batch INIT(FALSE);
129 EXT bool verbose INIT(TRUE);
130 EXT bool reverse INIT(FALSE);
131 EXT bool noreverse INIT(FALSE);
132 EXT bool skip_rest_of_patch INIT(FALSE);
133 EXT int strippath INIT(957);
134 EXT bool canonicalize INIT(FALSE);
135
136 #define CONTEXT_DIFF 1
137 #define NORMAL_DIFF 2
138 #define ED_DIFF 3
139 #define NEW_CONTEXT_DIFF 4
140 #define UNI_DIFF 5
141 EXT int diff_type INIT(0);
142
143 EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
144 EXT char if_defined[128]; /* #ifdef xyzzy */
145 EXT char not_defined[128]; /* #ifndef xyzzy */
146 EXT char else_defined[] INIT("#else\n");/* #else */
147 EXT char end_defined[128]; /* #endif xyzzy */
148
149 EXT char *revision INIT(NULL); /* prerequisite revision, if any */
150
151 #include <errno.h>
152
153 #if !defined(S_ISDIR) && defined(S_IFDIR)
154 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
155 #endif
156 #if !defined(S_ISREG) && defined(S_IFREG)
157 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
158 #endif
159
160 void my_exit(int) __attribute__((__noreturn__));
161