[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.9

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