164 lines
4.4 KiB
C
164 lines
4.4 KiB
C
/* $NetBSD: common.h,v 1.17 2005/03/25 23:00:55 skd Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 1988, Larry Wall
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following condition
|
|
* is met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this condition and the following disclaimer.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#define DEBUGGING
|
|
|
|
/* shut lint up about the following when return value ignored */
|
|
|
|
#define Signal (void)signal
|
|
#define Unlink (void)unlink
|
|
#define Lseek (void)lseek
|
|
#define Fseek (void)fseek
|
|
#define Fstat (void)fstat
|
|
#define Pclose (void)pclose
|
|
#define Close (void)close
|
|
#define Fclose (void)fclose
|
|
#define Fflush (void)fflush
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <ctype.h>
|
|
#include <signal.h>
|
|
|
|
/* constants */
|
|
|
|
/* AIX predefines these. */
|
|
#ifdef TRUE
|
|
#undef TRUE
|
|
#endif
|
|
#ifdef FALSE
|
|
#undef FALSE
|
|
#endif
|
|
#define TRUE (1)
|
|
#define FALSE (0)
|
|
|
|
#define MAXHUNKSIZE 100000 /* is this enough lines? */
|
|
#define INITHUNKMAX 125 /* initial dynamic allocation size */
|
|
#define MAXLINELEN 10240
|
|
|
|
#define SCCSPREFIX "s."
|
|
#define GET "get -e %s"
|
|
#define SCCSDIFF "get -p %s | diff - %s >/dev/null"
|
|
|
|
#define RCSSUFFIX ",v"
|
|
#define CHECKOUT "co -l %s"
|
|
#define RCSDIFF "rcsdiff %s > /dev/null"
|
|
|
|
#define ORIGEXT ".orig"
|
|
#define REJEXT ".rej"
|
|
|
|
/* handy definitions */
|
|
|
|
#define Nulline 0
|
|
|
|
#define strNE(s1,s2) (strcmp(s1, s2))
|
|
#define strEQ(s1,s2) (!strcmp(s1, s2))
|
|
#define strnNE(s1,s2,l) (strncmp(s1, s2, l))
|
|
#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
|
|
|
|
/* typedefs */
|
|
|
|
typedef char bool;
|
|
typedef int LINENUM; /* must be signed */
|
|
|
|
/* globals */
|
|
|
|
EXT int Argc; /* guess */
|
|
EXT char **Argv;
|
|
|
|
/* TRUE if -C was specified on command line. */
|
|
EXT int check_only;
|
|
|
|
EXT struct stat filestat; /* file statistics area */
|
|
EXT mode_t filemode INIT(0644);
|
|
|
|
EXT char buf[MAXLINELEN]; /* general purpose buffer */
|
|
EXT FILE *ofp INIT(NULL); /* output file pointer */
|
|
EXT FILE *rejfp INIT(NULL); /* reject file pointer */
|
|
|
|
EXT int myuid; /* cache getuid return value */
|
|
|
|
#define MAXFILEC 2
|
|
EXT int filec INIT(0); /* how many file arguments? */
|
|
EXT char *filearg[MAXFILEC];
|
|
EXT bool ok_to_create_file INIT(FALSE);
|
|
EXT bool filename_is_dev_null INIT(FALSE);
|
|
EXT bool old_file_is_dev_null INIT(FALSE);
|
|
EXT char *bestguess INIT(NULL); /* guess at correct filename */
|
|
|
|
EXT char *outname INIT(NULL);
|
|
EXT char rejname[128];
|
|
|
|
EXT char *origprae INIT(NULL);
|
|
|
|
EXT char *TMPOUTNAME;
|
|
EXT char *TMPINNAME;
|
|
EXT char *TMPREJNAME;
|
|
EXT char *TMPPATNAME;
|
|
EXT bool toutkeep INIT(FALSE);
|
|
EXT bool trejkeep INIT(FALSE);
|
|
|
|
EXT LINENUM last_offset INIT(0);
|
|
#ifdef DEBUGGING
|
|
EXT int debug INIT(0);
|
|
#endif
|
|
EXT LINENUM maxfuzz INIT(2);
|
|
EXT bool force INIT(FALSE);
|
|
EXT bool batch INIT(FALSE);
|
|
EXT bool verbose INIT(TRUE);
|
|
EXT bool reverse INIT(FALSE);
|
|
EXT bool noreverse INIT(FALSE);
|
|
EXT bool skip_rest_of_patch INIT(FALSE);
|
|
EXT int strippath INIT(957);
|
|
EXT bool canonicalize INIT(FALSE);
|
|
|
|
#define CONTEXT_DIFF 1
|
|
#define NORMAL_DIFF 2
|
|
#define ED_DIFF 3
|
|
#define NEW_CONTEXT_DIFF 4
|
|
#define UNI_DIFF 5
|
|
EXT int diff_type INIT(0);
|
|
|
|
EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
|
|
EXT char if_defined[128]; /* #ifdef xyzzy */
|
|
EXT char not_defined[128]; /* #ifndef xyzzy */
|
|
EXT char else_defined[] INIT("#else\n");/* #else */
|
|
EXT char end_defined[128]; /* #endif xyzzy */
|
|
|
|
EXT char *revision INIT(NULL); /* prerequisite revision, if any */
|
|
|
|
#include <errno.h>
|
|
|
|
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
|
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
#endif
|
|
#if !defined(S_ISREG) && defined(S_IFREG)
|
|
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
#endif
|
|
|
|
void my_exit(int) __attribute__((__noreturn__));
|