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