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