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