xref: /freebsd/usr.bin/patch/common.h (revision 42b388439bd3795e09258c57a74ce9eec3651c7b)
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 $
272dd076b8SGabor Kovesdan  */
282dd076b8SGabor Kovesdan 
292dd076b8SGabor Kovesdan #include <sys/types.h>
302dd076b8SGabor Kovesdan 
312dd076b8SGabor Kovesdan #include <stdbool.h>
322dd076b8SGabor Kovesdan #include <stdint.h>
332dd076b8SGabor Kovesdan 
342dd076b8SGabor Kovesdan #define	DEBUGGING
352dd076b8SGabor Kovesdan 
362dd076b8SGabor Kovesdan /* constants */
372dd076b8SGabor Kovesdan 
382dd076b8SGabor Kovesdan #define	MAXHUNKSIZE 200000	/* is this enough lines? */
392dd076b8SGabor Kovesdan #define	INITHUNKMAX 125		/* initial dynamic allocation size */
402dd076b8SGabor Kovesdan #define	INITLINELEN 4096
412dd076b8SGabor Kovesdan #define	BUFFERSIZE 4096
42d3fc0cb8SPedro F. Giffuni #define	LINENUM_MAX LONG_MAX
432dd076b8SGabor Kovesdan 
442dd076b8SGabor Kovesdan #define	ORIGEXT ".orig"
452dd076b8SGabor Kovesdan #define	REJEXT ".rej"
462dd076b8SGabor Kovesdan 
472dd076b8SGabor Kovesdan /* handy definitions */
482dd076b8SGabor Kovesdan 
49c7ef297aSPedro F. Giffuni #define	strEQ(s1,s2) (strcmp(s1, s2) == 0)
50758a3cffSPedro F. Giffuni #define	strnNE(s1,s2,l) (strncmp(s1, s2, l) != 0)
51c7ef297aSPedro F. Giffuni #define	strnEQ(s1,s2,l) (strncmp(s1, s2, l) == 0)
522dd076b8SGabor Kovesdan 
532dd076b8SGabor Kovesdan /* typedefs */
542dd076b8SGabor Kovesdan 
552dd076b8SGabor Kovesdan typedef long    LINENUM;	/* must be signed */
562dd076b8SGabor Kovesdan 
572dd076b8SGabor Kovesdan /* globals */
582dd076b8SGabor Kovesdan 
592dd076b8SGabor Kovesdan extern mode_t	filemode;
602dd076b8SGabor Kovesdan 
612dd076b8SGabor Kovesdan extern char	*buf;		/* general purpose buffer */
622dd076b8SGabor Kovesdan extern size_t	buf_size;	/* size of general purpose buffer */
632dd076b8SGabor Kovesdan 
642dd076b8SGabor Kovesdan extern bool	using_plan_a;	/* try to keep everything in memory */
652dd076b8SGabor Kovesdan extern bool	out_of_mem;	/* ran out of memory in plan a */
66*ef30b5a8SKyle Evans extern bool	nonempty_patchf_seen;	/* seen a non-zero-length patch file? */
672dd076b8SGabor Kovesdan 
682dd076b8SGabor Kovesdan #define	MAXFILEC 2
692dd076b8SGabor Kovesdan 
702dd076b8SGabor Kovesdan extern char	*filearg[MAXFILEC];
712dd076b8SGabor Kovesdan extern bool	ok_to_create_file;
722dd076b8SGabor Kovesdan extern char	*outname;
732dd076b8SGabor Kovesdan extern char	*origprae;
742dd076b8SGabor Kovesdan 
752dd076b8SGabor Kovesdan extern char	*TMPOUTNAME;
762dd076b8SGabor Kovesdan extern char	*TMPINNAME;
772dd076b8SGabor Kovesdan extern char	*TMPREJNAME;
782dd076b8SGabor Kovesdan extern char	*TMPPATNAME;
792dd076b8SGabor Kovesdan extern bool	toutkeep;
802dd076b8SGabor Kovesdan extern bool	trejkeep;
812dd076b8SGabor Kovesdan 
822dd076b8SGabor Kovesdan #ifdef DEBUGGING
832dd076b8SGabor Kovesdan extern int	debug;
842dd076b8SGabor Kovesdan #endif
852dd076b8SGabor Kovesdan 
862dd076b8SGabor Kovesdan extern bool	force;
872dd076b8SGabor Kovesdan extern bool	batch;
882dd076b8SGabor Kovesdan extern bool	verbose;
892dd076b8SGabor Kovesdan extern bool	reverse;
902dd076b8SGabor Kovesdan extern bool	noreverse;
912dd076b8SGabor Kovesdan extern bool	skip_rest_of_patch;
922dd076b8SGabor Kovesdan extern int	strippath;
932dd076b8SGabor Kovesdan extern bool	canonicalize;
942dd076b8SGabor Kovesdan /* TRUE if -C was specified on command line.  */
952dd076b8SGabor Kovesdan extern bool	check_only;
962dd076b8SGabor Kovesdan extern bool	warn_on_invalid_line;
972dd076b8SGabor Kovesdan extern bool	last_line_missing_eol;
982dd076b8SGabor Kovesdan 
992dd076b8SGabor Kovesdan 
1002dd076b8SGabor Kovesdan #define	CONTEXT_DIFF 1
1012dd076b8SGabor Kovesdan #define	NORMAL_DIFF 2
1022dd076b8SGabor Kovesdan #define	ED_DIFF 3
1032dd076b8SGabor Kovesdan #define	NEW_CONTEXT_DIFF 4
1042dd076b8SGabor Kovesdan #define	UNI_DIFF 5
1052dd076b8SGabor Kovesdan 
1062dd076b8SGabor Kovesdan extern int	diff_type;
1072dd076b8SGabor Kovesdan extern char	*revision;	/* prerequisite revision, if any */
1082dd076b8SGabor Kovesdan extern LINENUM	input_lines;	/* how long is input file in lines */
1092dd076b8SGabor Kovesdan 
1102dd076b8SGabor Kovesdan extern int	posix;
1112dd076b8SGabor Kovesdan 
112