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

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

1.15    ! itojun      1: /*     $NetBSD: common.h,v 1.14 2003/05/30 22:33:58 kristerw Exp $     */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1988, Larry Wall
        !             5:  *
        !             6:  * Redistribution and use in source and binary forms, with or without
        !             7:  * modification, are permitted provided that the following condition
        !             8:  * is met:
        !             9:  *  1. Redistributions of source code must retain the above copyright
        !            10:  *     notice, this condition and the following disclaimer.
        !            11:  *
        !            12:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            13:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            14:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            15:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
        !            16:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            17:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            18:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            19:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            20:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            21:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            22:  * SUCH DAMAGE.
        !            23:  */
1.1       cgd        24:
                     25: #define DEBUGGING
                     26:
                     27: /* shut lint up about the following when return value ignored */
                     28:
                     29: #define Signal (void)signal
                     30: #define Unlink (void)unlink
                     31: #define Lseek (void)lseek
                     32: #define Fseek (void)fseek
                     33: #define Fstat (void)fstat
                     34: #define Pclose (void)pclose
                     35: #define Close (void)close
                     36: #define Fclose (void)fclose
                     37: #define Fflush (void)fflush
                     38: #define Sprintf (void)sprintf
                     39: #define Strcpy (void)strcpy
                     40: #define Strcat (void)strcat
                     41:
                     42: #include <stdio.h>
1.4       cgd        43: #include <string.h>
1.1       cgd        44: #include <assert.h>
                     45: #include <sys/types.h>
                     46: #include <sys/stat.h>
                     47: #include <ctype.h>
                     48: #include <signal.h>
                     49:
                     50: /* constants */
                     51:
                     52: /* AIX predefines these.  */
                     53: #ifdef TRUE
                     54: #undef TRUE
                     55: #endif
                     56: #ifdef FALSE
                     57: #undef FALSE
                     58: #endif
                     59: #define TRUE (1)
                     60: #define FALSE (0)
                     61:
                     62: #define MAXHUNKSIZE 100000             /* is this enough lines? */
                     63: #define INITHUNKMAX 125                        /* initial dynamic allocation size */
1.7       augustss   64: #define MAXLINELEN 10240
1.1       cgd        65:
                     66: #define SCCSPREFIX "s."
                     67: #define GET "get -e %s"
                     68: #define SCCSDIFF "get -p %s | diff - %s >/dev/null"
                     69:
                     70: #define RCSSUFFIX ",v"
                     71: #define CHECKOUT "co -l %s"
                     72: #define RCSDIFF "rcsdiff %s > /dev/null"
                     73:
                     74: #define ORIGEXT ".orig"
                     75: #define REJEXT ".rej"
                     76:
                     77: /* handy definitions */
                     78:
1.11      kristerw   79: #define Nulline 0
1.1       cgd        80:
                     81: #define strNE(s1,s2) (strcmp(s1, s2))
                     82: #define strEQ(s1,s2) (!strcmp(s1, s2))
                     83: #define strnNE(s1,s2,l) (strncmp(s1, s2, l))
                     84: #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
                     85:
                     86: /* typedefs */
                     87:
                     88: typedef char bool;
1.12      kristerw   89: typedef int LINENUM;                   /* must be signed */
1.1       cgd        90:
                     91: /* globals */
                     92:
                     93: EXT int Argc;                          /* guess */
                     94: EXT char **Argv;
                     95:
                     96: EXT struct stat filestat;              /* file statistics area */
1.12      kristerw   97: EXT mode_t filemode INIT(0644);
1.1       cgd        98:
                     99: EXT char buf[MAXLINELEN];              /* general purpose buffer */
1.11      kristerw  100: EXT FILE *ofp INIT(NULL);              /* output file pointer */
                    101: EXT FILE *rejfp INIT(NULL);            /* reject file pointer */
1.1       cgd       102:
                    103: EXT int myuid;                         /* cache getuid return value */
                    104:
                    105: #define MAXFILEC 2
                    106: EXT int filec INIT(0);                 /* how many file arguments? */
                    107: EXT char *filearg[MAXFILEC];
                    108: EXT bool ok_to_create_file INIT(FALSE);
1.9       sommerfe  109: EXT bool filename_is_dev_null INIT(FALSE);
                    110: EXT bool old_file_is_dev_null INIT(FALSE);
1.11      kristerw  111: EXT char *bestguess INIT(NULL);                /* guess at correct filename */
1.1       cgd       112:
1.11      kristerw  113: EXT char *outname INIT(NULL);
1.1       cgd       114: EXT char rejname[128];
                    115:
1.11      kristerw  116: EXT char *origprae INIT(NULL);
1.1       cgd       117:
                    118: EXT char *TMPOUTNAME;
                    119: EXT char *TMPINNAME;
                    120: EXT char *TMPREJNAME;
                    121: EXT char *TMPPATNAME;
                    122: EXT bool toutkeep INIT(FALSE);
                    123: EXT bool trejkeep INIT(FALSE);
                    124:
                    125: EXT LINENUM last_offset INIT(0);
                    126: #ifdef DEBUGGING
                    127: EXT int debug INIT(0);
                    128: #endif
                    129: EXT LINENUM maxfuzz INIT(2);
                    130: EXT bool force INIT(FALSE);
                    131: EXT bool batch INIT(FALSE);
                    132: EXT bool verbose INIT(TRUE);
                    133: EXT bool reverse INIT(FALSE);
                    134: EXT bool noreverse INIT(FALSE);
                    135: EXT bool skip_rest_of_patch INIT(FALSE);
                    136: EXT int strippath INIT(957);
                    137: EXT bool canonicalize INIT(FALSE);
                    138:
                    139: #define CONTEXT_DIFF 1
                    140: #define NORMAL_DIFF 2
                    141: #define ED_DIFF 3
                    142: #define NEW_CONTEXT_DIFF 4
                    143: #define UNI_DIFF 5
                    144: EXT int diff_type INIT(0);
                    145:
                    146: EXT bool do_defines INIT(FALSE);       /* patch using ifdef, ifndef, etc. */
                    147: EXT char if_defined[128];              /* #ifdef xyzzy */
                    148: EXT char not_defined[128];             /* #ifndef xyzzy */
                    149: EXT char else_defined[] INIT("#else\n");/* #else */
                    150: EXT char end_defined[128];             /* #endif xyzzy */
                    151:
1.11      kristerw  152: EXT char *revision INIT(NULL);         /* prerequisite revision, if any */
1.1       cgd       153:
                    154: #include <errno.h>
                    155:
                    156: #if !defined(S_ISDIR) && defined(S_IFDIR)
                    157: #define        S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
                    158: #endif
                    159: #if !defined(S_ISREG) && defined(S_IFREG)
                    160: #define        S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
                    161: #endif
1.8       christos  162:
1.10      kristerw  163: void my_exit(int) __attribute__((__noreturn__));

CVSweb <webmaster@jp.NetBSD.org>