common.h revision 191910
1/* $FreeBSD: head/gnu/usr.bin/patch/common.h 191910 2009-05-08 02:18:46Z sepotvin $ 2 * 3 * $Log: common.h,v $ 4 * Revision 2.0.1.2 88/06/22 20:44:53 lwall 5 * patch12: sprintf was declared wrong 6 * 7 * Revision 2.0.1.1 88/06/03 15:01:56 lwall 8 * patch10: support for shorter extensions. 9 * 10 * Revision 2.0 86/09/17 15:36:39 lwall 11 * Baseline for netwide release. 12 * 13 */ 14 15#define DEBUGGING 16 17#define VOIDUSED 7 18#include "config.h" 19 20/* shut lint up about the following when return value ignored */ 21 22#define Signal (void)signal 23#define Unlink (void)unlink 24#define Lseek (void)lseek 25#define Fseek (void)fseek 26#define Fstat (void)fstat 27#define Pclose (void)pclose 28#define Close (void)close 29#define Fclose (void)fclose 30#define Fflush (void)fflush 31#define Sprintf (void)sprintf 32#define Snprintf (void)snprintf 33#define Mktemp (void)mktemp 34#define Strcpy (void)strcpy 35#define Strcat (void)strcat 36#define Strlcpy (void)strlcpy 37#define Strlcat (void)strlcat 38 39/* NeXT declares malloc and realloc incompatibly from us in some of 40 these files. Temporarily redefine them to prevent errors. */ 41#define malloc system_malloc 42#define realloc system_realloc 43#include <stdio.h> 44#include <assert.h> 45#include <sys/types.h> 46#include <sys/stat.h> 47#include <ctype.h> 48#include <signal.h> 49#undef malloc 50#undef realloc 51 52/* constants */ 53 54/* AIX predefines these. */ 55#ifdef TRUE 56#undef TRUE 57#endif 58#ifdef FALSE 59#undef FALSE 60#endif 61#define TRUE (1) 62#define FALSE (0) 63 64#define MAXHUNKSIZE 200000 /* is this enough lines? */ 65#define INITHUNKMAX 125 /* initial dynamic allocation size */ 66#define INITLINELEN 4096 67#define BUFFERSIZE 4096 68 69#define SCCSPREFIX "s." 70#define GET "get %s" 71#define GET_LOCKED "get -e %s" 72#define SCCSDIFF "get -p %s | diff - %s >/dev/null" 73 74#define RCSSUFFIX ",v" 75#define CHECKOUT "co %s" 76#define CHECKOUT_LOCKED "co -l %s" 77#define RCSDIFF "rcsdiff %s > /dev/null" 78 79/* handy definitions */ 80 81#define Null(t) ((t)0) 82#define Nullch Null(char *) 83#define Nullfp Null(FILE *) 84#define Nulline Null(LINENUM) 85 86#define Ctl(ch) ((ch) & 037) 87 88#define strNE(s1,s2) (strcmp(s1, s2)) 89#define strEQ(s1,s2) (!strcmp(s1, s2)) 90#define strnNE(s1,s2,l) (strncmp(s1, s2, l)) 91#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) 92 93/* typedefs */ 94 95typedef char bool; 96typedef long LINENUM; /* must be signed */ 97typedef unsigned MEM; /* what to feed malloc */ 98 99/* globals */ 100 101EXT int Argc; /* guess */ 102EXT char **Argv; 103EXT int optind_last; /* for restarting plan_b */ 104 105EXT struct stat filestat; /* file statistics area */ 106EXT int filemode INIT(0644); 107 108EXT char *buf; /* general purpose buffer */ 109EXT size_t buf_size; /* size of the general purpose buffer */ 110EXT FILE *ofp INIT(Nullfp); /* output file pointer */ 111EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */ 112 113EXT int myuid; /* cache getuid return value */ 114 115EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ 116EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */ 117 118#define MAXFILEC 2 119EXT int filec INIT(0); /* how many file arguments? */ 120EXT char *filearg[MAXFILEC]; 121EXT bool ok_to_create_file INIT(FALSE); 122EXT char *bestguess INIT(Nullch); /* guess at correct filename */ 123 124EXT char *outname INIT(Nullch); 125EXT char rejname[128]; 126 127EXT char *origprae INIT(Nullch); 128 129EXT char *TMPOUTNAME; 130EXT char *TMPINNAME; 131EXT char *TMPREJNAME; 132EXT char *TMPPATNAME; 133EXT bool toutkeep INIT(FALSE); 134EXT bool trejkeep INIT(FALSE); 135 136EXT LINENUM last_offset INIT(0); 137#ifdef DEBUGGING 138EXT int debug INIT(0); 139#endif 140EXT LINENUM maxfuzz INIT(2); 141EXT bool force INIT(FALSE); 142EXT bool batch INIT(FALSE); 143EXT bool verbose INIT(TRUE); 144EXT bool reverse INIT(FALSE); 145EXT bool noreverse INIT(FALSE); 146EXT bool skip_rest_of_patch INIT(FALSE); 147EXT int strippath INIT(957); 148EXT bool canonicalize INIT(FALSE); 149 150#define CONTEXT_DIFF 1 151#define NORMAL_DIFF 2 152#define ED_DIFF 3 153#define NEW_CONTEXT_DIFF 4 154#define UNI_DIFF 5 155EXT int diff_type INIT(0); 156 157EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */ 158EXT char if_defined[128]; /* #ifdef xyzzy */ 159EXT char not_defined[128]; /* #ifndef xyzzy */ 160EXT char else_defined[] INIT("#else\n");/* #else */ 161EXT char end_defined[128]; /* #endif xyzzy */ 162 163EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ 164 165#include <errno.h> 166#ifdef STDC_HEADERS 167#include <stdlib.h> 168#include <string.h> 169#else 170extern int errno; 171FILE *popen(); 172char *malloc(); 173char *realloc(); 174long atol(); 175char *getenv(); 176char *strcpy(); 177char *strcat(); 178#endif 179char *mktemp(char *); 180#ifdef HAVE_UNISTD_H 181#include <unistd.h> 182#else 183long lseek(); 184#endif 185#if defined(_POSIX_VERSION) || defined(HAVE_FCNTL_H) 186#include <fcntl.h> 187#endif 188 189#if !defined(S_ISDIR) && defined(S_IFDIR) 190#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 191#endif 192#if !defined(S_ISREG) && defined(S_IFREG) 193#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 194#endif 195