1757e8328SLionel Sambuc /* 2757e8328SLionel Sambuc * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $ 3757e8328SLionel Sambuc * $DragonFly: src/usr.bin/patch/common.h,v 1.5 2008/08/10 23:50:12 joerg Exp $ 4757e8328SLionel Sambuc * $NetBSD: common.h,v 1.19 2008/09/19 18:33:34 joerg Exp $ 5757e8328SLionel Sambuc */ 6757e8328SLionel Sambuc 7757e8328SLionel Sambuc /* 8757e8328SLionel Sambuc * patch - a program to apply diffs to original files 9757e8328SLionel Sambuc * 10757e8328SLionel Sambuc * Copyright 1986, Larry Wall 11757e8328SLionel Sambuc * 12757e8328SLionel Sambuc * Redistribution and use in source and binary forms, with or without 13757e8328SLionel Sambuc * modification, are permitted provided that the following condition is met: 14757e8328SLionel Sambuc * 1. Redistributions of source code must retain the above copyright notice, 15757e8328SLionel Sambuc * this condition and the following disclaimer. 16757e8328SLionel Sambuc * 17757e8328SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 18757e8328SLionel Sambuc * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19757e8328SLionel Sambuc * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20757e8328SLionel Sambuc * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21757e8328SLionel Sambuc * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22757e8328SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23757e8328SLionel Sambuc * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24757e8328SLionel Sambuc * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25757e8328SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26757e8328SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27757e8328SLionel Sambuc * SUCH DAMAGE. 28757e8328SLionel Sambuc * 29757e8328SLionel Sambuc * -C option added in 1998, original code by Marc Espie, based on FreeBSD 30757e8328SLionel Sambuc * behaviour 31757e8328SLionel Sambuc */ 32757e8328SLionel Sambuc 33757e8328SLionel Sambuc #include <sys/types.h> 34757e8328SLionel Sambuc 35757e8328SLionel Sambuc #include <stdbool.h> 36757e8328SLionel Sambuc #include <stdint.h> 37757e8328SLionel Sambuc 38757e8328SLionel Sambuc #define DEBUGGING 39757e8328SLionel Sambuc 40757e8328SLionel Sambuc /* constants */ 41757e8328SLionel Sambuc 42757e8328SLionel Sambuc #define MAXHUNKSIZE 100000 /* is this enough lines? */ 43757e8328SLionel Sambuc #define INITHUNKMAX 125 /* initial dynamic allocation size */ 44757e8328SLionel Sambuc #define MAXLINELEN 8192 45757e8328SLionel Sambuc #define BUFFERSIZE 1024 46757e8328SLionel Sambuc 47757e8328SLionel Sambuc #define SCCSPREFIX "s." 48757e8328SLionel Sambuc #define GET "get -e %s" 49757e8328SLionel Sambuc #define SCCSDIFF "get -p %s | diff - %s >/dev/null" 50757e8328SLionel Sambuc 51757e8328SLionel Sambuc #define RCSSUFFIX ",v" 52*d8127f84SDavid van Moolenbroek #define CHECKOUT "/usr/bin/co" 53*d8127f84SDavid van Moolenbroek #define RCSDIFF "/usr/bin/rcsdiff" 54757e8328SLionel Sambuc 55757e8328SLionel Sambuc #define ORIGEXT ".orig" 56757e8328SLionel Sambuc #define REJEXT ".rej" 57757e8328SLionel Sambuc 58757e8328SLionel Sambuc /* handy definitions */ 59757e8328SLionel Sambuc 60757e8328SLionel Sambuc #define strNE(s1,s2) (strcmp(s1, s2)) 61757e8328SLionel Sambuc #define strEQ(s1,s2) (!strcmp(s1, s2)) 62757e8328SLionel Sambuc #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) 63757e8328SLionel Sambuc #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) 64757e8328SLionel Sambuc 65757e8328SLionel Sambuc /* typedefs */ 66757e8328SLionel Sambuc 67757e8328SLionel Sambuc typedef long LINENUM; /* must be signed */ 68757e8328SLionel Sambuc 69757e8328SLionel Sambuc /* globals */ 70757e8328SLionel Sambuc 71757e8328SLionel Sambuc extern mode_t filemode; 72757e8328SLionel Sambuc 73757e8328SLionel Sambuc extern char buf[MAXLINELEN];/* general purpose buffer */ 74757e8328SLionel Sambuc extern size_t buf_len; 75757e8328SLionel Sambuc 76757e8328SLionel Sambuc extern bool using_plan_a; /* try to keep everything in memory */ 77757e8328SLionel Sambuc extern bool out_of_mem; /* ran out of memory in plan a */ 78757e8328SLionel Sambuc 79757e8328SLionel Sambuc #define MAXFILEC 2 80757e8328SLionel Sambuc 81757e8328SLionel Sambuc extern char *filearg[MAXFILEC]; 82757e8328SLionel Sambuc extern bool ok_to_create_file; 83757e8328SLionel Sambuc extern char *outname; 84757e8328SLionel Sambuc extern char *origprae; 85757e8328SLionel Sambuc 86757e8328SLionel Sambuc extern char *TMPOUTNAME; 87757e8328SLionel Sambuc extern char *TMPINNAME; 88757e8328SLionel Sambuc extern char *TMPREJNAME; 89757e8328SLionel Sambuc extern char *TMPPATNAME; 90757e8328SLionel Sambuc extern bool toutkeep; 91757e8328SLionel Sambuc extern bool trejkeep; 92757e8328SLionel Sambuc 93757e8328SLionel Sambuc #ifdef DEBUGGING 94757e8328SLionel Sambuc extern int debug; 95757e8328SLionel Sambuc #endif 96757e8328SLionel Sambuc 97757e8328SLionel Sambuc extern bool force; 98757e8328SLionel Sambuc extern bool batch; 99757e8328SLionel Sambuc extern bool verbose; 100757e8328SLionel Sambuc extern bool reverse; 101757e8328SLionel Sambuc extern bool noreverse; 102757e8328SLionel Sambuc extern bool skip_rest_of_patch; 103757e8328SLionel Sambuc extern int strippath; 104757e8328SLionel Sambuc extern bool canonicalize; 105757e8328SLionel Sambuc /* TRUE if -C was specified on command line. */ 106757e8328SLionel Sambuc extern bool check_only; 107757e8328SLionel Sambuc extern bool warn_on_invalid_line; 108757e8328SLionel Sambuc extern bool last_line_missing_eol; 109757e8328SLionel Sambuc 110757e8328SLionel Sambuc 111757e8328SLionel Sambuc #define CONTEXT_DIFF 1 112757e8328SLionel Sambuc #define NORMAL_DIFF 2 113757e8328SLionel Sambuc #define ED_DIFF 3 114757e8328SLionel Sambuc #define NEW_CONTEXT_DIFF 4 115757e8328SLionel Sambuc #define UNI_DIFF 5 116757e8328SLionel Sambuc 117757e8328SLionel Sambuc extern int diff_type; 118757e8328SLionel Sambuc extern char *revision; /* prerequisite revision, if any */ 119757e8328SLionel Sambuc extern LINENUM input_lines; /* how long is input file in lines */ 120757e8328SLionel Sambuc 121757e8328SLionel Sambuc extern int posix; 122757e8328SLionel Sambuc 123