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