1 1.19 joerg /* 2 1.19 joerg * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $ 3 1.19 joerg * $DragonFly: src/usr.bin/patch/common.h,v 1.5 2008/08/10 23:50:12 joerg Exp $ 4 1.22 cjep * $NetBSD: common.h,v 1.22 2021/05/25 11:25:59 cjep Exp $ 5 1.19 joerg */ 6 1.15 itojun 7 1.15 itojun /* 8 1.19 joerg * patch - a program to apply diffs to original files 9 1.19 joerg * 10 1.19 joerg * Copyright 1986, Larry Wall 11 1.19 joerg * 12 1.15 itojun * Redistribution and use in source and binary forms, with or without 13 1.19 joerg * modification, are permitted provided that the following condition is met: 14 1.19 joerg * 1. Redistributions of source code must retain the above copyright notice, 15 1.19 joerg * this condition and the following disclaimer. 16 1.19 joerg * 17 1.19 joerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 18 1.19 joerg * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 1.19 joerg * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 1.19 joerg * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 1.19 joerg * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 1.19 joerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 1.19 joerg * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 1.19 joerg * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 1.15 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 1.15 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 1.15 itojun * SUCH DAMAGE. 28 1.19 joerg * 29 1.19 joerg * -C option added in 1998, original code by Marc Espie, based on FreeBSD 30 1.19 joerg * behaviour 31 1.15 itojun */ 32 1.1 cgd 33 1.19 joerg #include <sys/types.h> 34 1.1 cgd 35 1.19 joerg #include <stdbool.h> 36 1.19 joerg #include <stdint.h> 37 1.1 cgd 38 1.19 joerg #define DEBUGGING 39 1.1 cgd 40 1.1 cgd /* constants */ 41 1.1 cgd 42 1.19 joerg #define MAXHUNKSIZE 100000 /* is this enough lines? */ 43 1.19 joerg #define INITHUNKMAX 125 /* initial dynamic allocation size */ 44 1.22 cjep #define INITLINELEN 8192 45 1.19 joerg #define BUFFERSIZE 1024 46 1.20 christos #define LINENUM_MAX LONG_MAX 47 1.1 cgd 48 1.1 cgd #define SCCSPREFIX "s." 49 1.1 cgd #define GET "get -e %s" 50 1.1 cgd #define SCCSDIFF "get -p %s | diff - %s >/dev/null" 51 1.1 cgd 52 1.1 cgd #define RCSSUFFIX ",v" 53 1.21 christos #define CHECKOUT "/usr/bin/co" 54 1.21 christos #define RCSDIFF "/usr/bin/rcsdiff" 55 1.1 cgd 56 1.1 cgd #define ORIGEXT ".orig" 57 1.1 cgd #define REJEXT ".rej" 58 1.1 cgd 59 1.1 cgd /* handy definitions */ 60 1.1 cgd 61 1.1 cgd #define strNE(s1,s2) (strcmp(s1, s2)) 62 1.1 cgd #define strEQ(s1,s2) (!strcmp(s1, s2)) 63 1.1 cgd #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) 64 1.1 cgd #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) 65 1.1 cgd 66 1.1 cgd /* typedefs */ 67 1.1 cgd 68 1.19 joerg typedef long LINENUM; /* must be signed */ 69 1.1 cgd 70 1.1 cgd /* globals */ 71 1.1 cgd 72 1.19 joerg extern mode_t filemode; 73 1.1 cgd 74 1.22 cjep extern char *buf; /* general purpose buffer */ 75 1.22 cjep extern size_t bufsz; /* general purpose buffer size */ 76 1.17 skd 77 1.19 joerg extern bool using_plan_a; /* try to keep everything in memory */ 78 1.19 joerg extern bool out_of_mem; /* ran out of memory in plan a */ 79 1.1 cgd 80 1.19 joerg #define MAXFILEC 2 81 1.1 cgd 82 1.19 joerg extern char *filearg[MAXFILEC]; 83 1.19 joerg extern bool ok_to_create_file; 84 1.19 joerg extern char *outname; 85 1.19 joerg extern char *origprae; 86 1.19 joerg 87 1.19 joerg extern char *TMPOUTNAME; 88 1.19 joerg extern char *TMPINNAME; 89 1.19 joerg extern char *TMPREJNAME; 90 1.19 joerg extern char *TMPPATNAME; 91 1.19 joerg extern bool toutkeep; 92 1.19 joerg extern bool trejkeep; 93 1.1 cgd 94 1.1 cgd #ifdef DEBUGGING 95 1.19 joerg extern int debug; 96 1.1 cgd #endif 97 1.19 joerg 98 1.19 joerg extern bool force; 99 1.19 joerg extern bool batch; 100 1.19 joerg extern bool verbose; 101 1.19 joerg extern bool reverse; 102 1.19 joerg extern bool noreverse; 103 1.19 joerg extern bool skip_rest_of_patch; 104 1.19 joerg extern int strippath; 105 1.19 joerg extern bool canonicalize; 106 1.19 joerg /* TRUE if -C was specified on command line. */ 107 1.19 joerg extern bool check_only; 108 1.19 joerg extern bool warn_on_invalid_line; 109 1.19 joerg extern bool last_line_missing_eol; 110 1.19 joerg 111 1.1 cgd 112 1.1 cgd #define CONTEXT_DIFF 1 113 1.1 cgd #define NORMAL_DIFF 2 114 1.1 cgd #define ED_DIFF 3 115 1.1 cgd #define NEW_CONTEXT_DIFF 4 116 1.1 cgd #define UNI_DIFF 5 117 1.1 cgd 118 1.19 joerg extern int diff_type; 119 1.19 joerg extern char *revision; /* prerequisite revision, if any */ 120 1.19 joerg extern LINENUM input_lines; /* how long is input file in lines */ 121 1.1 cgd 122 1.19 joerg extern int posix; 123 1.8 christos 124