1*33303Sbostic /* $Header: common.h,v 2.0 86/09/17 15:36:39 lwall Exp $ 2*33303Sbostic * 3*33303Sbostic * $Log: common.h,v $ 4*33303Sbostic * Revision 2.0 86/09/17 15:36:39 lwall 5*33303Sbostic * Baseline for netwide release. 6*33303Sbostic * 7*33303Sbostic */ 8*33303Sbostic 9*33303Sbostic #define DEBUGGING 10*33303Sbostic 11*33303Sbostic #include "config.h" 12*33303Sbostic 13*33303Sbostic /* shut lint up about the following when return value ignored */ 14*33303Sbostic 15*33303Sbostic #define Signal (void)signal 16*33303Sbostic #define Unlink (void)unlink 17*33303Sbostic #define Lseek (void)lseek 18*33303Sbostic #define Fseek (void)fseek 19*33303Sbostic #define Fstat (void)fstat 20*33303Sbostic #define Pclose (void)pclose 21*33303Sbostic #define Close (void)close 22*33303Sbostic #define Fclose (void)fclose 23*33303Sbostic #define Fflush (void)fflush 24*33303Sbostic #define Sprintf (void)sprintf 25*33303Sbostic #define Mktemp (void)mktemp 26*33303Sbostic #define Strcpy (void)strcpy 27*33303Sbostic #define Strcat (void)strcat 28*33303Sbostic 29*33303Sbostic #include <stdio.h> 30*33303Sbostic #include <assert.h> 31*33303Sbostic #include <sys/types.h> 32*33303Sbostic #include <sys/stat.h> 33*33303Sbostic #include <ctype.h> 34*33303Sbostic #include <signal.h> 35*33303Sbostic 36*33303Sbostic /* constants */ 37*33303Sbostic 38*33303Sbostic #define TRUE (1) 39*33303Sbostic #define FALSE (0) 40*33303Sbostic 41*33303Sbostic #define MAXHUNKSIZE 100000 /* is this enough lines? */ 42*33303Sbostic #define INITHUNKMAX 125 /* initial dynamic allocation size */ 43*33303Sbostic #define MAXLINELEN 1024 44*33303Sbostic #define BUFFERSIZE 1024 45*33303Sbostic #define ORIGEXT ".orig" 46*33303Sbostic #define SCCSPREFIX "s." 47*33303Sbostic #define GET "get -e %s" 48*33303Sbostic #define RCSSUFFIX ",v" 49*33303Sbostic #define CHECKOUT "co -l %s" 50*33303Sbostic 51*33303Sbostic /* handy definitions */ 52*33303Sbostic 53*33303Sbostic #define Null(t) ((t)0) 54*33303Sbostic #define Nullch Null(char *) 55*33303Sbostic #define Nullfp Null(FILE *) 56*33303Sbostic #define Nulline Null(LINENUM) 57*33303Sbostic 58*33303Sbostic #define Ctl(ch) ((ch) & 037) 59*33303Sbostic 60*33303Sbostic #define strNE(s1,s2) (strcmp(s1, s2)) 61*33303Sbostic #define strEQ(s1,s2) (!strcmp(s1, s2)) 62*33303Sbostic #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) 63*33303Sbostic #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) 64*33303Sbostic 65*33303Sbostic /* typedefs */ 66*33303Sbostic 67*33303Sbostic typedef char bool; 68*33303Sbostic typedef long LINENUM; /* must be signed */ 69*33303Sbostic typedef unsigned MEM; /* what to feed malloc */ 70*33303Sbostic 71*33303Sbostic /* globals */ 72*33303Sbostic 73*33303Sbostic EXT int Argc; /* guess */ 74*33303Sbostic EXT char **Argv; 75*33303Sbostic EXT int Argc_last; /* for restarting plan_b */ 76*33303Sbostic EXT char **Argv_last; 77*33303Sbostic 78*33303Sbostic EXT struct stat filestat; /* file statistics area */ 79*33303Sbostic EXT int filemode INIT(0644); 80*33303Sbostic 81*33303Sbostic EXT char buf[MAXLINELEN]; /* general purpose buffer */ 82*33303Sbostic EXT FILE *ofp INIT(Nullfp); /* output file pointer */ 83*33303Sbostic EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */ 84*33303Sbostic 85*33303Sbostic EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ 86*33303Sbostic EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */ 87*33303Sbostic 88*33303Sbostic #define MAXFILEC 2 89*33303Sbostic EXT int filec INIT(0); /* how many file arguments? */ 90*33303Sbostic EXT char *filearg[MAXFILEC]; 91*33303Sbostic EXT bool ok_to_create_file INIT(FALSE); 92*33303Sbostic EXT char *bestguess INIT(Nullch); /* guess at correct filename */ 93*33303Sbostic 94*33303Sbostic EXT char *outname INIT(Nullch); 95*33303Sbostic EXT char rejname[128]; 96*33303Sbostic 97*33303Sbostic EXT char *origext INIT(Nullch); 98*33303Sbostic 99*33303Sbostic EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX"); 100*33303Sbostic EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX"); /* might want /usr/tmp here */ 101*33303Sbostic EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX"); 102*33303Sbostic EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX"); 103*33303Sbostic EXT bool toutkeep INIT(FALSE); 104*33303Sbostic EXT bool trejkeep INIT(FALSE); 105*33303Sbostic 106*33303Sbostic EXT LINENUM last_offset INIT(0); 107*33303Sbostic #ifdef DEBUGGING 108*33303Sbostic EXT int debug INIT(0); 109*33303Sbostic #endif 110*33303Sbostic EXT LINENUM maxfuzz INIT(2); 111*33303Sbostic EXT bool force INIT(FALSE); 112*33303Sbostic EXT bool verbose INIT(TRUE); 113*33303Sbostic EXT bool reverse INIT(FALSE); 114*33303Sbostic EXT bool noreverse INIT(FALSE); 115*33303Sbostic EXT bool skip_rest_of_patch INIT(FALSE); 116*33303Sbostic EXT int strippath INIT(957); 117*33303Sbostic EXT bool canonicalize INIT(FALSE); 118*33303Sbostic 119*33303Sbostic #define CONTEXT_DIFF 1 120*33303Sbostic #define NORMAL_DIFF 2 121*33303Sbostic #define ED_DIFF 3 122*33303Sbostic #define NEW_CONTEXT_DIFF 4 123*33303Sbostic EXT int diff_type INIT(0); 124*33303Sbostic 125*33303Sbostic EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */ 126*33303Sbostic EXT char if_defined[128]; /* #ifdef xyzzy */ 127*33303Sbostic EXT char not_defined[128]; /* #ifndef xyzzy */ 128*33303Sbostic EXT char else_defined[] INIT("#else\n");/* #else */ 129*33303Sbostic EXT char end_defined[128]; /* #endif xyzzy */ 130*33303Sbostic 131*33303Sbostic EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ 132*33303Sbostic 133*33303Sbostic char *malloc(); 134*33303Sbostic char *realloc(); 135*33303Sbostic char *strcpy(); 136*33303Sbostic char *strcat(); 137*33303Sbostic long atol(); 138*33303Sbostic char *mktemp(); 139