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