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