1 /* $NetBSD: common.h,v 1.14 2003/05/30 22:33:58 kristerw Exp $ */ 2 3 #define DEBUGGING 4 5 /* shut lint up about the following when return value ignored */ 6 7 #define Signal (void)signal 8 #define Unlink (void)unlink 9 #define Lseek (void)lseek 10 #define Fseek (void)fseek 11 #define Fstat (void)fstat 12 #define Pclose (void)pclose 13 #define Close (void)close 14 #define Fclose (void)fclose 15 #define Fflush (void)fflush 16 #define Sprintf (void)sprintf 17 #define Strcpy (void)strcpy 18 #define Strcat (void)strcat 19 20 #include <stdio.h> 21 #include <string.h> 22 #include <assert.h> 23 #include <sys/types.h> 24 #include <sys/stat.h> 25 #include <ctype.h> 26 #include <signal.h> 27 28 /* constants */ 29 30 /* AIX predefines these. */ 31 #ifdef TRUE 32 #undef TRUE 33 #endif 34 #ifdef FALSE 35 #undef FALSE 36 #endif 37 #define TRUE (1) 38 #define FALSE (0) 39 40 #define MAXHUNKSIZE 100000 /* is this enough lines? */ 41 #define INITHUNKMAX 125 /* initial dynamic allocation size */ 42 #define MAXLINELEN 10240 43 44 #define SCCSPREFIX "s." 45 #define GET "get -e %s" 46 #define SCCSDIFF "get -p %s | diff - %s >/dev/null" 47 48 #define RCSSUFFIX ",v" 49 #define CHECKOUT "co -l %s" 50 #define RCSDIFF "rcsdiff %s > /dev/null" 51 52 #define ORIGEXT ".orig" 53 #define REJEXT ".rej" 54 55 /* handy definitions */ 56 57 #define Nulline 0 58 59 #define strNE(s1,s2) (strcmp(s1, s2)) 60 #define strEQ(s1,s2) (!strcmp(s1, s2)) 61 #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) 62 #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) 63 64 /* typedefs */ 65 66 typedef char bool; 67 typedef int LINENUM; /* must be signed */ 68 69 /* globals */ 70 71 EXT int Argc; /* guess */ 72 EXT char **Argv; 73 74 EXT struct stat filestat; /* file statistics area */ 75 EXT mode_t filemode INIT(0644); 76 77 EXT char buf[MAXLINELEN]; /* general purpose buffer */ 78 EXT FILE *ofp INIT(NULL); /* output file pointer */ 79 EXT FILE *rejfp INIT(NULL); /* reject file pointer */ 80 81 EXT int myuid; /* cache getuid return value */ 82 83 #define MAXFILEC 2 84 EXT int filec INIT(0); /* how many file arguments? */ 85 EXT char *filearg[MAXFILEC]; 86 EXT bool ok_to_create_file INIT(FALSE); 87 EXT bool filename_is_dev_null INIT(FALSE); 88 EXT bool old_file_is_dev_null INIT(FALSE); 89 EXT char *bestguess INIT(NULL); /* guess at correct filename */ 90 91 EXT char *outname INIT(NULL); 92 EXT char rejname[128]; 93 94 EXT char *origprae INIT(NULL); 95 96 EXT char *TMPOUTNAME; 97 EXT char *TMPINNAME; 98 EXT char *TMPREJNAME; 99 EXT char *TMPPATNAME; 100 EXT bool toutkeep INIT(FALSE); 101 EXT bool trejkeep INIT(FALSE); 102 103 EXT LINENUM last_offset INIT(0); 104 #ifdef DEBUGGING 105 EXT int debug INIT(0); 106 #endif 107 EXT LINENUM maxfuzz INIT(2); 108 EXT bool force INIT(FALSE); 109 EXT bool batch INIT(FALSE); 110 EXT bool verbose INIT(TRUE); 111 EXT bool reverse INIT(FALSE); 112 EXT bool noreverse INIT(FALSE); 113 EXT bool skip_rest_of_patch INIT(FALSE); 114 EXT int strippath INIT(957); 115 EXT bool canonicalize INIT(FALSE); 116 117 #define CONTEXT_DIFF 1 118 #define NORMAL_DIFF 2 119 #define ED_DIFF 3 120 #define NEW_CONTEXT_DIFF 4 121 #define UNI_DIFF 5 122 EXT int diff_type INIT(0); 123 124 EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */ 125 EXT char if_defined[128]; /* #ifdef xyzzy */ 126 EXT char not_defined[128]; /* #ifndef xyzzy */ 127 EXT char else_defined[] INIT("#else\n");/* #else */ 128 EXT char end_defined[128]; /* #endif xyzzy */ 129 130 EXT char *revision INIT(NULL); /* prerequisite revision, if any */ 131 132 #include <errno.h> 133 134 #if !defined(S_ISDIR) && defined(S_IFDIR) 135 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 136 #endif 137 #if !defined(S_ISREG) && defined(S_IFREG) 138 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 139 #endif 140 141 void my_exit(int) __attribute__((__noreturn__)); 142