xref: /freebsd/usr.bin/patch/common.h (revision ef30b5a80910bd877f582248004200065eeb3ef5)
12dd076b8SGabor Kovesdan /*-
22dd076b8SGabor Kovesdan  * Copyright 1986, Larry Wall
32dd076b8SGabor Kovesdan  *
42dd076b8SGabor Kovesdan  * Redistribution and use in source and binary forms, with or without
52dd076b8SGabor Kovesdan  * modification, are permitted provided that the following condition is met:
62dd076b8SGabor Kovesdan  * 1. Redistributions of source code must retain the above copyright notice,
72dd076b8SGabor Kovesdan  * this condition and the following disclaimer.
82dd076b8SGabor Kovesdan  *
92dd076b8SGabor Kovesdan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
102dd076b8SGabor Kovesdan  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
112dd076b8SGabor Kovesdan  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
122dd076b8SGabor Kovesdan  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
132dd076b8SGabor Kovesdan  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
142dd076b8SGabor Kovesdan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
152dd076b8SGabor Kovesdan  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
162dd076b8SGabor Kovesdan  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
172dd076b8SGabor Kovesdan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
182dd076b8SGabor Kovesdan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
192dd076b8SGabor Kovesdan  * SUCH DAMAGE.
202dd076b8SGabor Kovesdan  *
212dd076b8SGabor Kovesdan  * patch - a program to apply diffs to original files
222dd076b8SGabor Kovesdan  *
232dd076b8SGabor Kovesdan  * -C option added in 1998, original code by Marc Espie, based on FreeBSD
242dd076b8SGabor Kovesdan  * behaviour
252dd076b8SGabor Kovesdan  *
262dd076b8SGabor Kovesdan  * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $
27e56ef7d3SXin LI  * $FreeBSD$
282dd076b8SGabor Kovesdan  */
292dd076b8SGabor Kovesdan 
302dd076b8SGabor Kovesdan #include <sys/types.h>
312dd076b8SGabor Kovesdan 
322dd076b8SGabor Kovesdan #include <stdbool.h>
332dd076b8SGabor Kovesdan #include <stdint.h>
342dd076b8SGabor Kovesdan 
352dd076b8SGabor Kovesdan #define	DEBUGGING
362dd076b8SGabor Kovesdan 
372dd076b8SGabor Kovesdan /* constants */
382dd076b8SGabor Kovesdan 
392dd076b8SGabor Kovesdan #define	MAXHUNKSIZE 200000	/* is this enough lines? */
402dd076b8SGabor Kovesdan #define	INITHUNKMAX 125		/* initial dynamic allocation size */
412dd076b8SGabor Kovesdan #define	INITLINELEN 4096
422dd076b8SGabor Kovesdan #define	BUFFERSIZE 4096
43d3fc0cb8SPedro F. Giffuni #define	LINENUM_MAX LONG_MAX
442dd076b8SGabor Kovesdan 
452dd076b8SGabor Kovesdan #define	ORIGEXT ".orig"
462dd076b8SGabor Kovesdan #define	REJEXT ".rej"
472dd076b8SGabor Kovesdan 
482dd076b8SGabor Kovesdan /* handy definitions */
492dd076b8SGabor Kovesdan 
50c7ef297aSPedro F. Giffuni #define	strEQ(s1,s2) (strcmp(s1, s2) == 0)
51758a3cffSPedro F. Giffuni #define	strnNE(s1,s2,l) (strncmp(s1, s2, l) != 0)
52c7ef297aSPedro F. Giffuni #define	strnEQ(s1,s2,l) (strncmp(s1, s2, l) == 0)
532dd076b8SGabor Kovesdan 
542dd076b8SGabor Kovesdan /* typedefs */
552dd076b8SGabor Kovesdan 
562dd076b8SGabor Kovesdan typedef long    LINENUM;	/* must be signed */
572dd076b8SGabor Kovesdan 
582dd076b8SGabor Kovesdan /* globals */
592dd076b8SGabor Kovesdan 
602dd076b8SGabor Kovesdan extern mode_t	filemode;
612dd076b8SGabor Kovesdan 
622dd076b8SGabor Kovesdan extern char	*buf;		/* general purpose buffer */
632dd076b8SGabor Kovesdan extern size_t	buf_size;	/* size of general purpose buffer */
642dd076b8SGabor Kovesdan 
652dd076b8SGabor Kovesdan extern bool	using_plan_a;	/* try to keep everything in memory */
662dd076b8SGabor Kovesdan extern bool	out_of_mem;	/* ran out of memory in plan a */
67*ef30b5a8SKyle Evans extern bool	nonempty_patchf_seen;	/* seen a non-zero-length patch file? */
682dd076b8SGabor Kovesdan 
692dd076b8SGabor Kovesdan #define	MAXFILEC 2
702dd076b8SGabor Kovesdan 
712dd076b8SGabor Kovesdan extern char	*filearg[MAXFILEC];
722dd076b8SGabor Kovesdan extern bool	ok_to_create_file;
732dd076b8SGabor Kovesdan extern char	*outname;
742dd076b8SGabor Kovesdan extern char	*origprae;
752dd076b8SGabor Kovesdan 
762dd076b8SGabor Kovesdan extern char	*TMPOUTNAME;
772dd076b8SGabor Kovesdan extern char	*TMPINNAME;
782dd076b8SGabor Kovesdan extern char	*TMPREJNAME;
792dd076b8SGabor Kovesdan extern char	*TMPPATNAME;
802dd076b8SGabor Kovesdan extern bool	toutkeep;
812dd076b8SGabor Kovesdan extern bool	trejkeep;
822dd076b8SGabor Kovesdan 
832dd076b8SGabor Kovesdan #ifdef DEBUGGING
842dd076b8SGabor Kovesdan extern int	debug;
852dd076b8SGabor Kovesdan #endif
862dd076b8SGabor Kovesdan 
872dd076b8SGabor Kovesdan extern bool	force;
882dd076b8SGabor Kovesdan extern bool	batch;
892dd076b8SGabor Kovesdan extern bool	verbose;
902dd076b8SGabor Kovesdan extern bool	reverse;
912dd076b8SGabor Kovesdan extern bool	noreverse;
922dd076b8SGabor Kovesdan extern bool	skip_rest_of_patch;
932dd076b8SGabor Kovesdan extern int	strippath;
942dd076b8SGabor Kovesdan extern bool	canonicalize;
952dd076b8SGabor Kovesdan /* TRUE if -C was specified on command line.  */
962dd076b8SGabor Kovesdan extern bool	check_only;
972dd076b8SGabor Kovesdan extern bool	warn_on_invalid_line;
982dd076b8SGabor Kovesdan extern bool	last_line_missing_eol;
992dd076b8SGabor Kovesdan 
1002dd076b8SGabor Kovesdan 
1012dd076b8SGabor Kovesdan #define	CONTEXT_DIFF 1
1022dd076b8SGabor Kovesdan #define	NORMAL_DIFF 2
1032dd076b8SGabor Kovesdan #define	ED_DIFF 3
1042dd076b8SGabor Kovesdan #define	NEW_CONTEXT_DIFF 4
1052dd076b8SGabor Kovesdan #define	UNI_DIFF 5
1062dd076b8SGabor Kovesdan 
1072dd076b8SGabor Kovesdan extern int	diff_type;
1082dd076b8SGabor Kovesdan extern char	*revision;	/* prerequisite revision, if any */
1092dd076b8SGabor Kovesdan extern LINENUM	input_lines;	/* how long is input file in lines */
1102dd076b8SGabor Kovesdan 
1112dd076b8SGabor Kovesdan extern int	posix;
1122dd076b8SGabor Kovesdan 
113