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

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