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

1.2     ! niklas      1: /*     $OpenBSD: common.h,v 1.1.1.1 1995/10/18 08:45:55 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 Mktemp (void)mktemp
                     21: #define Strcpy (void)strcpy
                     22: #define Strcat (void)strcat
                     23:
                     24: /* NeXT declares malloc and realloc incompatibly from us in some of
                     25:    these files.  Temporarily redefine them to prevent errors.  */
                     26: #define malloc system_malloc
                     27: #define realloc system_realloc
                     28: #include <stdio.h>
                     29: #include <string.h>
                     30: #include <assert.h>
                     31: #include <sys/types.h>
                     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:
                     85: /* typedefs */
                     86:
                     87: typedef char bool;
                     88: typedef long LINENUM;                  /* must be signed */
                     89: typedef unsigned MEM;                  /* what to feed malloc */
                     90:
                     91: /* globals */
                     92:
                     93: EXT int Argc;                          /* guess */
                     94: EXT char **Argv;
                     95: EXT int Argc_last;                     /* for restarting plan_b */
                     96: EXT char **Argv_last;
                     97:
                     98: EXT struct stat filestat;              /* file statistics area */
                     99: EXT int filemode INIT(0644);
                    100:
                    101: EXT char buf[MAXLINELEN];              /* general purpose buffer */
                    102: EXT FILE *ofp INIT(Nullfp);            /* output file pointer */
                    103: EXT FILE *rejfp INIT(Nullfp);          /* reject file pointer */
                    104:
                    105: EXT int myuid;                         /* cache getuid return value */
                    106:
                    107: EXT bool using_plan_a INIT(TRUE);      /* try to keep everything in memory */
                    108: EXT bool out_of_mem INIT(FALSE);       /* ran out of memory in plan a */
                    109:
                    110: #define MAXFILEC 2
                    111: EXT int filec INIT(0);                 /* how many file arguments? */
                    112: EXT char *filearg[MAXFILEC];
                    113: EXT bool ok_to_create_file 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: #ifndef errno
                    159: extern int errno;
                    160: #endif
                    161:
                    162: FILE *popen();
                    163: char *malloc();
                    164: char *realloc();
                    165: long atol();
                    166: char *getenv();
                    167: char *strcpy();
                    168: char *strcat();
                    169: char *rindex();
                    170: char *mktemp();
                    171: #if 0                          /* This can cause a prototype conflict.  */
                    172: #ifdef CHARSPRINTF
                    173: char *sprintf();
                    174: #else
                    175: int sprintf();
                    176: #endif
                    177: #endif
                    178:
                    179: #if !defined(S_ISDIR) && defined(S_IFDIR)
                    180: #define        S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
                    181: #endif
                    182: #if !defined(S_ISREG) && defined(S_IFREG)
                    183: #define        S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
                    184: #endif