xref: /openbsd/usr.bin/patch/common.h (revision 898184e3)
1 /*	$OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto 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 <stdbool.h>
32 
33 #define DEBUGGING
34 
35 /* constants */
36 
37 #define MAXHUNKSIZE 100000	/* is this enough lines? */
38 #define INITHUNKMAX 125		/* initial dynamic allocation size */
39 #define MAXLINELEN 8192
40 #define BUFFERSIZE 1024
41 
42 #define SCCSPREFIX "s."
43 #define GET "get -e %s"
44 #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
45 
46 #define RCSSUFFIX ",v"
47 #define CHECKOUT "co -l %s"
48 #define RCSDIFF "rcsdiff %s > /dev/null"
49 
50 #define ORIGEXT ".orig"
51 #define REJEXT ".rej"
52 
53 /* handy definitions */
54 
55 #define strNE(s1,s2) (strcmp(s1, s2))
56 #define strEQ(s1,s2) (!strcmp(s1, s2))
57 #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
58 #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
59 
60 /* typedefs */
61 
62 typedef long    LINENUM;	/* must be signed */
63 
64 /* globals */
65 
66 extern mode_t	filemode;
67 
68 extern char	buf[MAXLINELEN];/* general purpose buffer */
69 
70 extern bool	using_plan_a;	/* try to keep everything in memory */
71 extern bool	out_of_mem;	/* ran out of memory in plan a */
72 
73 #define MAXFILEC 2
74 
75 extern char	*filearg[MAXFILEC];
76 extern bool	ok_to_create_file;
77 extern char	*outname;
78 extern char	*origprae;
79 
80 extern char	*TMPOUTNAME;
81 extern char	*TMPINNAME;
82 extern char	*TMPREJNAME;
83 extern char	*TMPPATNAME;
84 extern bool	toutkeep;
85 extern bool	trejkeep;
86 
87 #ifdef DEBUGGING
88 extern int	debug;
89 #endif
90 
91 extern bool	force;
92 extern bool	batch;
93 extern bool	verbose;
94 extern bool	reverse;
95 extern bool	noreverse;
96 extern bool	skip_rest_of_patch;
97 extern int	strippath;
98 extern bool	canonicalize;
99 /* TRUE if -C was specified on command line.  */
100 extern bool	check_only;
101 extern bool	warn_on_invalid_line;
102 extern bool	last_line_missing_eol;
103 
104 
105 #define CONTEXT_DIFF 1
106 #define NORMAL_DIFF 2
107 #define ED_DIFF 3
108 #define NEW_CONTEXT_DIFF 4
109 #define UNI_DIFF 5
110 
111 extern int	diff_type;
112 extern char	*revision;	/* prerequisite revision, if any */
113 extern LINENUM	input_lines;	/* how long is input file in lines */
114 
115 extern int	posix;
116 
117