1246074Sgabor/*-
2246074Sgabor * Copyright 1986, Larry Wall
3246074Sgabor *
4246074Sgabor * Redistribution and use in source and binary forms, with or without
5246074Sgabor * modification, are permitted provided that the following condition is met:
6246074Sgabor * 1. Redistributions of source code must retain the above copyright notice,
7246074Sgabor * this condition and the following disclaimer.
8246074Sgabor *
9246074Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
10246074Sgabor * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
11246074Sgabor * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
12246074Sgabor * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
13246074Sgabor * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
14246074Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
15246074Sgabor * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
16246074Sgabor * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
17246074Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
18246074Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
19246074Sgabor * SUCH DAMAGE.
20246074Sgabor *
21246074Sgabor * patch - a program to apply diffs to original files
22246074Sgabor *
23246074Sgabor * -C option added in 1998, original code by Marc Espie, based on FreeBSD
24246074Sgabor * behaviour
25246074Sgabor *
26246074Sgabor * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $
27246091Sdelphij * $FreeBSD: releng/10.3/usr.bin/patch/common.h 285976 2015-07-28 19:58:44Z delphij $
28246074Sgabor */
29246074Sgabor
30246074Sgabor#include <sys/types.h>
31246074Sgabor
32246074Sgabor#include <stdbool.h>
33246074Sgabor#include <stdint.h>
34246074Sgabor
35265160Spfg#define	DEBUGGING
36246074Sgabor
37246074Sgabor/* constants */
38246074Sgabor
39265160Spfg#define	MAXHUNKSIZE 200000	/* is this enough lines? */
40265160Spfg#define	INITHUNKMAX 125		/* initial dynamic allocation size */
41265160Spfg#define	INITLINELEN 4096
42265160Spfg#define	BUFFERSIZE 4096
43275841Spfg#define	LINENUM_MAX LONG_MAX
44246074Sgabor
45265160Spfg#define	SCCSPREFIX "s."
46246074Sgabor
47265160Spfg#define	RCSSUFFIX ",v"
48285976Sdelphij#define	CHECKOUT "/usr/bin/co"
49285976Sdelphij#define	RCSDIFF "/usr/bin/rcsdiff"
50246074Sgabor
51265160Spfg#define	ORIGEXT ".orig"
52265160Spfg#define	REJEXT ".rej"
53246074Sgabor
54246074Sgabor/* handy definitions */
55246074Sgabor
56265160Spfg#define	strNE(s1,s2) (strcmp(s1, s2))
57265160Spfg#define	strEQ(s1,s2) (!strcmp(s1, s2))
58265160Spfg#define	strnNE(s1,s2,l) (strncmp(s1, s2, l))
59265160Spfg#define	strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
60246074Sgabor
61246074Sgabor/* typedefs */
62246074Sgabor
63246074Sgabortypedef long    LINENUM;	/* must be signed */
64246074Sgabor
65246074Sgabor/* globals */
66246074Sgabor
67246074Sgaborextern mode_t	filemode;
68246074Sgabor
69246074Sgaborextern char	*buf;		/* general purpose buffer */
70246074Sgaborextern size_t	buf_size;	/* size of general purpose buffer */
71246074Sgabor
72246074Sgaborextern bool	using_plan_a;	/* try to keep everything in memory */
73246074Sgaborextern bool	out_of_mem;	/* ran out of memory in plan a */
74246074Sgabor
75265160Spfg#define	MAXFILEC 2
76246074Sgabor
77246074Sgaborextern char	*filearg[MAXFILEC];
78246074Sgaborextern bool	ok_to_create_file;
79246074Sgaborextern char	*outname;
80246074Sgaborextern char	*origprae;
81246074Sgabor
82246074Sgaborextern char	*TMPOUTNAME;
83246074Sgaborextern char	*TMPINNAME;
84246074Sgaborextern char	*TMPREJNAME;
85246074Sgaborextern char	*TMPPATNAME;
86246074Sgaborextern bool	toutkeep;
87246074Sgaborextern bool	trejkeep;
88246074Sgabor
89246074Sgabor#ifdef DEBUGGING
90246074Sgaborextern int	debug;
91246074Sgabor#endif
92246074Sgabor
93246074Sgaborextern bool	force;
94246074Sgaborextern bool	batch;
95246074Sgaborextern bool	verbose;
96246074Sgaborextern bool	reverse;
97246074Sgaborextern bool	noreverse;
98246074Sgaborextern bool	skip_rest_of_patch;
99246074Sgaborextern int	strippath;
100246074Sgaborextern bool	canonicalize;
101246074Sgabor/* TRUE if -C was specified on command line.  */
102246074Sgaborextern bool	check_only;
103246074Sgaborextern bool	warn_on_invalid_line;
104246074Sgaborextern bool	last_line_missing_eol;
105246074Sgabor
106246074Sgabor
107265160Spfg#define	CONTEXT_DIFF 1
108265160Spfg#define	NORMAL_DIFF 2
109265160Spfg#define	ED_DIFF 3
110265160Spfg#define	NEW_CONTEXT_DIFF 4
111265160Spfg#define	UNI_DIFF 5
112246074Sgabor
113246074Sgaborextern int	diff_type;
114246074Sgaborextern char	*revision;	/* prerequisite revision, if any */
115246074Sgaborextern LINENUM	input_lines;	/* how long is input file in lines */
116246074Sgabor
117246074Sgaborextern int	posix;
118246074Sgabor
119