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