common.h revision 1.18 1 /* $NetBSD: common.h,v 1.18 2007/10/14 04:54:34 lukem 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 /* TRUE if -C was specified on command line. */
94 EXT int check_only;
95
96 EXT struct stat filestat; /* file statistics area */
97 EXT mode_t filemode INIT(0644);
98
99 EXT char buf[MAXLINELEN]; /* general purpose buffer */
100 EXT FILE *ofp INIT(NULL); /* output file pointer */
101 EXT FILE *rejfp INIT(NULL); /* reject file pointer */
102
103 EXT int myuid; /* cache getuid return value */
104
105 #define MAXFILEC 2
106 EXT int filec INIT(0); /* how many file arguments? */
107 EXT char *filearg[MAXFILEC];
108 EXT bool ok_to_create_file INIT(FALSE);
109 EXT bool filename_is_dev_null INIT(FALSE);
110 EXT bool old_file_is_dev_null INIT(FALSE);
111 EXT char *bestguess INIT(NULL); /* guess at correct filename */
112
113 EXT char *outname INIT(NULL);
114 EXT char rejname[128];
115
116 EXT char *origprae INIT(NULL);
117
118 EXT char *TMPOUTNAME;
119 EXT char *TMPINNAME;
120 EXT char *TMPREJNAME;
121 EXT char *TMPPATNAME;
122 EXT bool toutkeep INIT(FALSE);
123 EXT bool trejkeep INIT(FALSE);
124
125 EXT LINENUM last_offset INIT(0);
126 #ifdef DEBUGGING
127 EXT int debug INIT(0);
128 #endif
129 EXT LINENUM maxfuzz INIT(2);
130 EXT bool force INIT(FALSE);
131 EXT bool batch INIT(FALSE);
132 EXT bool verbose INIT(TRUE);
133 EXT bool reverse INIT(FALSE);
134 EXT bool noreverse INIT(FALSE);
135 EXT bool skip_rest_of_patch INIT(FALSE);
136 EXT int strippath INIT(957);
137 EXT bool canonicalize INIT(FALSE);
138
139 #define CONTEXT_DIFF 1
140 #define NORMAL_DIFF 2
141 #define ED_DIFF 3
142 #define NEW_CONTEXT_DIFF 4
143 #define UNI_DIFF 5
144 EXT int diff_type INIT(0);
145
146 EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
147 EXT char if_defined[128]; /* #ifdef xyzzy */
148 EXT char not_defined[128]; /* #ifndef xyzzy */
149 EXT char else_defined[] INIT("#else\n");/* #else */
150 EXT char end_defined[128]; /* #endif xyzzy */
151
152 EXT char *revision INIT(NULL); /* prerequisite revision, if any */
153
154 #include <errno.h>
155
156 #if !defined(S_ISDIR) && defined(S_IFDIR)
157 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
158 #endif
159 #if !defined(S_ISREG) && defined(S_IFREG)
160 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
161 #endif
162
163 void my_exit(int) __attribute__((__noreturn__));
164 void my_sig_exit(int) __attribute__((__noreturn__));
165