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: stable/10/usr.bin/patch/common.h 306914 2016-10-09 20:13:53Z pfg $ 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 56306914Spfg#define strEQ(s1,s2) (strcmp(s1, s2) == 0) 57306914Spfg#define strnNE(s1,s2,l) (strncmp(s1, s2, l) != 0) 58306914Spfg#define strnEQ(s1,s2,l) (strncmp(s1, s2, l) == 0) 59246074Sgabor 60246074Sgabor/* typedefs */ 61246074Sgabor 62246074Sgabortypedef long LINENUM; /* must be signed */ 63246074Sgabor 64246074Sgabor/* globals */ 65246074Sgabor 66246074Sgaborextern mode_t filemode; 67246074Sgabor 68246074Sgaborextern char *buf; /* general purpose buffer */ 69246074Sgaborextern size_t buf_size; /* size of general purpose buffer */ 70246074Sgabor 71246074Sgaborextern bool using_plan_a; /* try to keep everything in memory */ 72246074Sgaborextern bool out_of_mem; /* ran out of memory in plan a */ 73246074Sgabor 74265160Spfg#define MAXFILEC 2 75246074Sgabor 76246074Sgaborextern char *filearg[MAXFILEC]; 77246074Sgaborextern bool ok_to_create_file; 78246074Sgaborextern char *outname; 79246074Sgaborextern char *origprae; 80246074Sgabor 81246074Sgaborextern char *TMPOUTNAME; 82246074Sgaborextern char *TMPINNAME; 83246074Sgaborextern char *TMPREJNAME; 84246074Sgaborextern char *TMPPATNAME; 85246074Sgaborextern bool toutkeep; 86246074Sgaborextern bool trejkeep; 87246074Sgabor 88246074Sgabor#ifdef DEBUGGING 89246074Sgaborextern int debug; 90246074Sgabor#endif 91246074Sgabor 92246074Sgaborextern bool force; 93246074Sgaborextern bool batch; 94246074Sgaborextern bool verbose; 95246074Sgaborextern bool reverse; 96246074Sgaborextern bool noreverse; 97246074Sgaborextern bool skip_rest_of_patch; 98246074Sgaborextern int strippath; 99246074Sgaborextern bool canonicalize; 100246074Sgabor/* TRUE if -C was specified on command line. */ 101246074Sgaborextern bool check_only; 102246074Sgaborextern bool warn_on_invalid_line; 103246074Sgaborextern bool last_line_missing_eol; 104246074Sgabor 105246074Sgabor 106265160Spfg#define CONTEXT_DIFF 1 107265160Spfg#define NORMAL_DIFF 2 108265160Spfg#define ED_DIFF 3 109265160Spfg#define NEW_CONTEXT_DIFF 4 110265160Spfg#define UNI_DIFF 5 111246074Sgabor 112246074Sgaborextern int diff_type; 113246074Sgaborextern char *revision; /* prerequisite revision, if any */ 114246074Sgaborextern LINENUM input_lines; /* how long is input file in lines */ 115246074Sgabor 116246074Sgaborextern int posix; 117246074Sgabor 118