xref: /dragonfly/usr.bin/patch/common.h (revision 8e9b4bd4)
1 /*
2  * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $
3  * $DragonFly: src/usr.bin/patch/common.h,v 1.4 2007/09/29 23:11:10 swildner Exp $
4  */
5 
6 /*
7  * patch - a program to apply diffs to original files
8  *
9  * Copyright 1986, Larry Wall
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following condition is met:
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this condition and the following disclaimer.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * -C option added in 1998, original code by Marc Espie, based on FreeBSD
29  * behaviour
30  */
31 
32 #include <sys/types.h>
33 
34 #include <stdbool.h>
35 
36 /*
37  * SIZE_MAX: older BSD compatibility for buildworld bootstrap mode only
38  */
39 #if defined(BOOTSTRAPPING) && !defined(SIZE_MAX)
40 #define SIZE_MAX	0x7fffffff
41 #endif
42 
43 #define DEBUGGING
44 
45 /* constants */
46 
47 #define MAXHUNKSIZE 100000	/* is this enough lines? */
48 #define INITHUNKMAX 125		/* initial dynamic allocation size */
49 #define MAXLINELEN 8192
50 #define BUFFERSIZE 1024
51 
52 #define SCCSPREFIX "s."
53 #define GET "get -e %s"
54 #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
55 
56 #define RCSSUFFIX ",v"
57 #define CHECKOUT "co -l %s"
58 #define RCSDIFF "rcsdiff %s > /dev/null"
59 
60 #define ORIGEXT ".orig"
61 #define REJEXT ".rej"
62 
63 /* handy definitions */
64 
65 #define strNE(s1,s2) (strcmp(s1, s2))
66 #define strEQ(s1,s2) (!strcmp(s1, s2))
67 #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
68 #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
69 
70 /* typedefs */
71 
72 typedef long    LINENUM;	/* must be signed */
73 
74 /* globals */
75 
76 extern mode_t	filemode;
77 
78 extern char	buf[MAXLINELEN];/* general purpose buffer */
79 extern size_t	buf_len;
80 
81 extern bool	using_plan_a;	/* try to keep everything in memory */
82 extern bool	out_of_mem;	/* ran out of memory in plan a */
83 
84 #define MAXFILEC 2
85 
86 extern char	*filearg[MAXFILEC];
87 extern bool	ok_to_create_file;
88 extern char	*outname;
89 extern char	*origprae;
90 
91 extern char	*TMPOUTNAME;
92 extern char	*TMPINNAME;
93 extern char	*TMPREJNAME;
94 extern char	*TMPPATNAME;
95 extern bool	toutkeep;
96 extern bool	trejkeep;
97 
98 #ifdef DEBUGGING
99 extern int	debug;
100 #endif
101 
102 extern bool	force;
103 extern bool	batch;
104 extern bool	verbose;
105 extern bool	reverse;
106 extern bool	noreverse;
107 extern bool	skip_rest_of_patch;
108 extern int	strippath;
109 extern bool	canonicalize;
110 /* TRUE if -C was specified on command line.  */
111 extern bool	check_only;
112 extern bool	warn_on_invalid_line;
113 extern bool	last_line_missing_eol;
114 
115 
116 #define CONTEXT_DIFF 1
117 #define NORMAL_DIFF 2
118 #define ED_DIFF 3
119 #define NEW_CONTEXT_DIFF 4
120 #define UNI_DIFF 5
121 
122 extern int	diff_type;
123 extern char	*revision;	/* prerequisite revision, if any */
124 extern LINENUM	input_lines;	/* how long is input file in lines */
125 
126 extern int	posix;
127 
128