xref: /freebsd/usr.bin/patch/common.h (revision d3fc0cb884f8858c0ae5f94c51587e717e3f9065)
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
43*d3fc0cb8SPedro F. Giffuni #define	LINENUM_MAX LONG_MAX
442dd076b8SGabor Kovesdan 
452dd076b8SGabor Kovesdan #define	SCCSPREFIX "s."
462dd076b8SGabor Kovesdan #define	GET "get -e %s"
472dd076b8SGabor Kovesdan #define	SCCSDIFF "get -p %s | diff - %s >/dev/null"
482dd076b8SGabor Kovesdan 
492dd076b8SGabor Kovesdan #define	RCSSUFFIX ",v"
502dd076b8SGabor Kovesdan #define	CHECKOUT "co -l %s"
512dd076b8SGabor Kovesdan #define	RCSDIFF "rcsdiff %s > /dev/null"
522dd076b8SGabor Kovesdan 
532dd076b8SGabor Kovesdan #define	ORIGEXT ".orig"
542dd076b8SGabor Kovesdan #define	REJEXT ".rej"
552dd076b8SGabor Kovesdan 
562dd076b8SGabor Kovesdan /* handy definitions */
572dd076b8SGabor Kovesdan 
582dd076b8SGabor Kovesdan #define	strNE(s1,s2) (strcmp(s1, s2))
592dd076b8SGabor Kovesdan #define	strEQ(s1,s2) (!strcmp(s1, s2))
602dd076b8SGabor Kovesdan #define	strnNE(s1,s2,l) (strncmp(s1, s2, l))
612dd076b8SGabor Kovesdan #define	strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
622dd076b8SGabor Kovesdan 
632dd076b8SGabor Kovesdan /* typedefs */
642dd076b8SGabor Kovesdan 
652dd076b8SGabor Kovesdan typedef long    LINENUM;	/* must be signed */
662dd076b8SGabor Kovesdan 
672dd076b8SGabor Kovesdan /* globals */
682dd076b8SGabor Kovesdan 
692dd076b8SGabor Kovesdan extern mode_t	filemode;
702dd076b8SGabor Kovesdan 
712dd076b8SGabor Kovesdan extern char	*buf;		/* general purpose buffer */
722dd076b8SGabor Kovesdan extern size_t	buf_size;	/* size of general purpose buffer */
732dd076b8SGabor Kovesdan 
742dd076b8SGabor Kovesdan extern bool	using_plan_a;	/* try to keep everything in memory */
752dd076b8SGabor Kovesdan extern bool	out_of_mem;	/* ran out of memory in plan a */
762dd076b8SGabor Kovesdan 
772dd076b8SGabor Kovesdan #define	MAXFILEC 2
782dd076b8SGabor Kovesdan 
792dd076b8SGabor Kovesdan extern char	*filearg[MAXFILEC];
802dd076b8SGabor Kovesdan extern bool	ok_to_create_file;
812dd076b8SGabor Kovesdan extern char	*outname;
822dd076b8SGabor Kovesdan extern char	*origprae;
832dd076b8SGabor Kovesdan 
842dd076b8SGabor Kovesdan extern char	*TMPOUTNAME;
852dd076b8SGabor Kovesdan extern char	*TMPINNAME;
862dd076b8SGabor Kovesdan extern char	*TMPREJNAME;
872dd076b8SGabor Kovesdan extern char	*TMPPATNAME;
882dd076b8SGabor Kovesdan extern bool	toutkeep;
892dd076b8SGabor Kovesdan extern bool	trejkeep;
902dd076b8SGabor Kovesdan 
912dd076b8SGabor Kovesdan #ifdef DEBUGGING
922dd076b8SGabor Kovesdan extern int	debug;
932dd076b8SGabor Kovesdan #endif
942dd076b8SGabor Kovesdan 
952dd076b8SGabor Kovesdan extern bool	force;
962dd076b8SGabor Kovesdan extern bool	batch;
972dd076b8SGabor Kovesdan extern bool	verbose;
982dd076b8SGabor Kovesdan extern bool	reverse;
992dd076b8SGabor Kovesdan extern bool	noreverse;
1002dd076b8SGabor Kovesdan extern bool	skip_rest_of_patch;
1012dd076b8SGabor Kovesdan extern int	strippath;
1022dd076b8SGabor Kovesdan extern bool	canonicalize;
1032dd076b8SGabor Kovesdan /* TRUE if -C was specified on command line.  */
1042dd076b8SGabor Kovesdan extern bool	check_only;
1052dd076b8SGabor Kovesdan extern bool	warn_on_invalid_line;
1062dd076b8SGabor Kovesdan extern bool	last_line_missing_eol;
1072dd076b8SGabor Kovesdan 
1082dd076b8SGabor Kovesdan 
1092dd076b8SGabor Kovesdan #define	CONTEXT_DIFF 1
1102dd076b8SGabor Kovesdan #define	NORMAL_DIFF 2
1112dd076b8SGabor Kovesdan #define	ED_DIFF 3
1122dd076b8SGabor Kovesdan #define	NEW_CONTEXT_DIFF 4
1132dd076b8SGabor Kovesdan #define	UNI_DIFF 5
1142dd076b8SGabor Kovesdan 
1152dd076b8SGabor Kovesdan extern int	diff_type;
1162dd076b8SGabor Kovesdan extern char	*revision;	/* prerequisite revision, if any */
1172dd076b8SGabor Kovesdan extern LINENUM	input_lines;	/* how long is input file in lines */
1182dd076b8SGabor Kovesdan 
1192dd076b8SGabor Kovesdan extern int	posix;
1202dd076b8SGabor Kovesdan 
121