[BACK]Return to common.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / patch

Annotation of src/usr.bin/patch/common.h, Revision 1.4

1.4     ! millert     1: /*     $OpenBSD: common.h,v 1.3 1996/06/25 23:06:36 deraadt Exp $ */
1.1       deraadt     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>
1.3       deraadt    31: #include <sys/file.h>
1.1       deraadt    32: #include <sys/stat.h>
                     33: #include <ctype.h>
                     34: #include <signal.h>
                     35: #undef malloc
                     36: #undef realloc
                     37:
                     38: /* constants */
                     39:
                     40: /* AIX predefines these.  */
                     41: #ifdef TRUE
                     42: #undef TRUE
                     43: #endif
                     44: #ifdef FALSE
                     45: #undef FALSE
                     46: #endif
                     47: #define TRUE (1)
                     48: #define FALSE (0)
                     49:
                     50: #define MAXHUNKSIZE 100000             /* is this enough lines? */
                     51: #define INITHUNKMAX 125                        /* initial dynamic allocation size */
                     52: #define MAXLINELEN 1024
                     53: #define BUFFERSIZE 1024
                     54:
                     55: #define SCCSPREFIX "s."
                     56: #define GET "get -e %s"
                     57: #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
                     58:
                     59: #define RCSSUFFIX ",v"
                     60: #define CHECKOUT "co -l %s"
                     61: #define RCSDIFF "rcsdiff %s > /dev/null"
                     62:
                     63: #ifdef FLEXFILENAMES
                     64: #define ORIGEXT ".orig"
                     65: #define REJEXT ".rej"
                     66: #else
                     67: #define ORIGEXT "~"
                     68: #define REJEXT "#"
                     69: #endif
                     70:
                     71: /* handy definitions */
                     72:
                     73: #define Null(t) ((t)0)
                     74: #define Nullch Null(char *)
                     75: #define Nullfp Null(FILE *)
                     76: #define Nulline Null(LINENUM)
                     77:
                     78: #define Ctl(ch) ((ch) & 037)
                     79:
                     80: #define strNE(s1,s2) (strcmp(s1, s2))
                     81: #define strEQ(s1,s2) (!strcmp(s1, s2))
                     82: #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
                     83: #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
                     84:
1.4     ! millert    85: #define Mkstemp mkstemp
        !            86:
1.1       deraadt    87: /* typedefs */
                     88:
                     89: typedef char bool;
                     90: typedef long LINENUM;                  /* must be signed */
                     91: typedef unsigned MEM;                  /* what to feed malloc */
                     92:
                     93: /* globals */
                     94:
                     95: EXT int Argc;                          /* guess */
                     96: EXT char **Argv;
                     97: EXT int Argc_last;                     /* for restarting plan_b */
                     98: EXT char **Argv_last;
                     99:
                    100: EXT struct stat filestat;              /* file statistics area */
                    101: EXT int filemode INIT(0644);
                    102:
                    103: EXT char buf[MAXLINELEN];              /* general purpose buffer */
                    104: EXT FILE *ofp INIT(Nullfp);            /* output file pointer */
                    105: EXT FILE *rejfp INIT(Nullfp);          /* reject file pointer */
                    106:
                    107: EXT int myuid;                         /* cache getuid return value */
                    108:
                    109: EXT bool using_plan_a INIT(TRUE);      /* try to keep everything in memory */
                    110: EXT bool out_of_mem INIT(FALSE);       /* ran out of memory in plan a */
                    111:
                    112: #define MAXFILEC 2
                    113: EXT int filec INIT(0);                 /* how many file arguments? */
                    114: EXT char *filearg[MAXFILEC];
                    115: EXT bool ok_to_create_file INIT(FALSE);
                    116: EXT char *bestguess INIT(Nullch);      /* guess at correct filename */
                    117:
                    118: EXT char *outname INIT(Nullch);
                    119: EXT char rejname[128];
                    120:
                    121: EXT char *origprae INIT(Nullch);
                    122:
                    123: EXT char *TMPOUTNAME;
                    124: EXT char *TMPINNAME;
                    125: EXT char *TMPREJNAME;
                    126: EXT char *TMPPATNAME;
                    127: EXT bool toutkeep INIT(FALSE);
                    128: EXT bool trejkeep INIT(FALSE);
                    129:
                    130: EXT LINENUM last_offset INIT(0);
                    131: #ifdef DEBUGGING
                    132: EXT int debug INIT(0);
                    133: #endif
                    134: EXT LINENUM maxfuzz INIT(2);
                    135: EXT bool force INIT(FALSE);
                    136: EXT bool batch INIT(FALSE);
                    137: EXT bool verbose INIT(TRUE);
                    138: EXT bool reverse INIT(FALSE);
                    139: EXT bool noreverse INIT(FALSE);
                    140: EXT bool skip_rest_of_patch INIT(FALSE);
                    141: EXT int strippath INIT(957);
                    142: EXT bool canonicalize INIT(FALSE);
                    143:
                    144: #define CONTEXT_DIFF 1
                    145: #define NORMAL_DIFF 2
                    146: #define ED_DIFF 3
                    147: #define NEW_CONTEXT_DIFF 4
                    148: #define UNI_DIFF 5
                    149: EXT int diff_type INIT(0);
                    150:
                    151: EXT bool do_defines INIT(FALSE);       /* patch using ifdef, ifndef, etc. */
                    152: EXT char if_defined[128];              /* #ifdef xyzzy */
                    153: EXT char not_defined[128];             /* #ifndef xyzzy */
                    154: EXT char else_defined[] INIT("#else\n");/* #else */
                    155: EXT char end_defined[128];             /* #endif xyzzy */
                    156:
                    157: EXT char *revision INIT(Nullch);       /* prerequisite revision, if any */
                    158:
                    159: #include <errno.h>
                    160: #ifndef errno
                    161: extern int errno;
                    162: #endif
                    163:
                    164: FILE *popen();
                    165: char *malloc();
                    166: char *realloc();
                    167: long atol();
                    168: char *getenv();
                    169: char *strcpy();
                    170: char *strcat();
                    171: char *rindex();
1.4     ! millert   172: int  mkstemp();
1.1       deraadt   173: #if 0                          /* This can cause a prototype conflict.  */
                    174: #ifdef CHARSPRINTF
                    175: char *sprintf();
                    176: #else
                    177: int sprintf();
                    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