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