xref: /minix3/usr.bin/patch/common.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1757e8328SLionel Sambuc /*
2757e8328SLionel Sambuc  * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $
3757e8328SLionel Sambuc  * $DragonFly: src/usr.bin/patch/common.h,v 1.5 2008/08/10 23:50:12 joerg Exp $
4*0a6a1f1dSLionel Sambuc  * $NetBSD: common.h,v 1.21 2015/07/24 18:56:44 christos Exp $
5757e8328SLionel Sambuc  */
6757e8328SLionel Sambuc 
7757e8328SLionel Sambuc /*
8757e8328SLionel Sambuc  * patch - a program to apply diffs to original files
9757e8328SLionel Sambuc  *
10757e8328SLionel Sambuc  * Copyright 1986, Larry Wall
11757e8328SLionel Sambuc  *
12757e8328SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
13757e8328SLionel Sambuc  * modification, are permitted provided that the following condition is met:
14757e8328SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright notice,
15757e8328SLionel Sambuc  * this condition and the following disclaimer.
16757e8328SLionel Sambuc  *
17757e8328SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
18757e8328SLionel Sambuc  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19757e8328SLionel Sambuc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20757e8328SLionel Sambuc  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21757e8328SLionel Sambuc  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22757e8328SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23757e8328SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24757e8328SLionel Sambuc  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25757e8328SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26757e8328SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27757e8328SLionel Sambuc  * SUCH DAMAGE.
28757e8328SLionel Sambuc  *
29757e8328SLionel Sambuc  * -C option added in 1998, original code by Marc Espie, based on FreeBSD
30757e8328SLionel Sambuc  * behaviour
31757e8328SLionel Sambuc  */
32757e8328SLionel Sambuc 
33757e8328SLionel Sambuc #include <sys/types.h>
34757e8328SLionel Sambuc 
35757e8328SLionel Sambuc #include <stdbool.h>
36757e8328SLionel Sambuc #include <stdint.h>
37757e8328SLionel Sambuc 
38757e8328SLionel Sambuc #define DEBUGGING
39757e8328SLionel Sambuc 
40757e8328SLionel Sambuc /* constants */
41757e8328SLionel Sambuc 
42757e8328SLionel Sambuc #define MAXHUNKSIZE 100000	/* is this enough lines? */
43757e8328SLionel Sambuc #define INITHUNKMAX 125		/* initial dynamic allocation size */
44757e8328SLionel Sambuc #define MAXLINELEN 8192
45757e8328SLionel Sambuc #define BUFFERSIZE 1024
46*0a6a1f1dSLionel Sambuc #define LINENUM_MAX LONG_MAX
47757e8328SLionel Sambuc 
48757e8328SLionel Sambuc #define SCCSPREFIX "s."
49757e8328SLionel Sambuc #define GET "get -e %s"
50757e8328SLionel Sambuc #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
51757e8328SLionel Sambuc 
52757e8328SLionel Sambuc #define RCSSUFFIX ",v"
53d8127f84SDavid van Moolenbroek #define CHECKOUT "/usr/bin/co"
54d8127f84SDavid van Moolenbroek #define RCSDIFF "/usr/bin/rcsdiff"
55757e8328SLionel Sambuc 
56757e8328SLionel Sambuc #define ORIGEXT ".orig"
57757e8328SLionel Sambuc #define REJEXT ".rej"
58757e8328SLionel Sambuc 
59757e8328SLionel Sambuc /* handy definitions */
60757e8328SLionel Sambuc 
61757e8328SLionel Sambuc #define strNE(s1,s2) (strcmp(s1, s2))
62757e8328SLionel Sambuc #define strEQ(s1,s2) (!strcmp(s1, s2))
63757e8328SLionel Sambuc #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
64757e8328SLionel Sambuc #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
65757e8328SLionel Sambuc 
66757e8328SLionel Sambuc /* typedefs */
67757e8328SLionel Sambuc 
68757e8328SLionel Sambuc typedef long    LINENUM;	/* must be signed */
69757e8328SLionel Sambuc 
70757e8328SLionel Sambuc /* globals */
71757e8328SLionel Sambuc 
72757e8328SLionel Sambuc extern mode_t	filemode;
73757e8328SLionel Sambuc 
74757e8328SLionel Sambuc extern char	buf[MAXLINELEN];/* general purpose buffer */
75757e8328SLionel Sambuc extern size_t	buf_len;
76757e8328SLionel Sambuc 
77757e8328SLionel Sambuc extern bool	using_plan_a;	/* try to keep everything in memory */
78757e8328SLionel Sambuc extern bool	out_of_mem;	/* ran out of memory in plan a */
79757e8328SLionel Sambuc 
80757e8328SLionel Sambuc #define MAXFILEC 2
81757e8328SLionel Sambuc 
82757e8328SLionel Sambuc extern char	*filearg[MAXFILEC];
83757e8328SLionel Sambuc extern bool	ok_to_create_file;
84757e8328SLionel Sambuc extern char	*outname;
85757e8328SLionel Sambuc extern char	*origprae;
86757e8328SLionel Sambuc 
87757e8328SLionel Sambuc extern char	*TMPOUTNAME;
88757e8328SLionel Sambuc extern char	*TMPINNAME;
89757e8328SLionel Sambuc extern char	*TMPREJNAME;
90757e8328SLionel Sambuc extern char	*TMPPATNAME;
91757e8328SLionel Sambuc extern bool	toutkeep;
92757e8328SLionel Sambuc extern bool	trejkeep;
93757e8328SLionel Sambuc 
94757e8328SLionel Sambuc #ifdef DEBUGGING
95757e8328SLionel Sambuc extern int	debug;
96757e8328SLionel Sambuc #endif
97757e8328SLionel Sambuc 
98757e8328SLionel Sambuc extern bool	force;
99757e8328SLionel Sambuc extern bool	batch;
100757e8328SLionel Sambuc extern bool	verbose;
101757e8328SLionel Sambuc extern bool	reverse;
102757e8328SLionel Sambuc extern bool	noreverse;
103757e8328SLionel Sambuc extern bool	skip_rest_of_patch;
104757e8328SLionel Sambuc extern int	strippath;
105757e8328SLionel Sambuc extern bool	canonicalize;
106757e8328SLionel Sambuc /* TRUE if -C was specified on command line.  */
107757e8328SLionel Sambuc extern bool	check_only;
108757e8328SLionel Sambuc extern bool	warn_on_invalid_line;
109757e8328SLionel Sambuc extern bool	last_line_missing_eol;
110757e8328SLionel Sambuc 
111757e8328SLionel Sambuc 
112757e8328SLionel Sambuc #define CONTEXT_DIFF 1
113757e8328SLionel Sambuc #define NORMAL_DIFF 2
114757e8328SLionel Sambuc #define ED_DIFF 3
115757e8328SLionel Sambuc #define NEW_CONTEXT_DIFF 4
116757e8328SLionel Sambuc #define UNI_DIFF 5
117757e8328SLionel Sambuc 
118757e8328SLionel Sambuc extern int	diff_type;
119757e8328SLionel Sambuc extern char	*revision;	/* prerequisite revision, if any */
120757e8328SLionel Sambuc extern LINENUM	input_lines;	/* how long is input file in lines */
121757e8328SLionel Sambuc 
122757e8328SLionel Sambuc extern int	posix;
123757e8328SLionel Sambuc 
124