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