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