1 /* ::[[ @(#) flip.h 1.16 89/07/04 17:00:46 ]]:: */ 2 3 /* 4 Copyright 1989 Rahul Dhesi, All rights reserved. 5 6 Checksum: 2652839101 (check or update with "brik") 7 8 ANSI-compatibility strategy: 9 10 1. If ANSIPROTO is defined, function prototypes are used, ANSI-style. 11 If it is not defined, regular function declarations (without a 12 parameter list) are used. This is achieved with the use of 13 the PARMS macro. 14 2. If STDINCLUDE is defined, ANSI-conformant header files are 15 included. Otherwise functions that would be declared in such 16 header files are declared individually. 17 */ 18 19 #ifndef OK_NL 20 21 /* Define ANSIPROTO and/or STDINCLUDE here if needed */ 22 #ifdef TURBOC 23 # define ANSIPROTO 24 # define STDINCLUDE 25 #endif /* TURBOC */ 26 27 28 29 #include <stdio.h> 30 31 #ifndef PARMS 32 # ifdef ANSIPROTO 33 # define PARMS(x) x 34 # else 35 # define PARMS(x) () 36 # endif 37 #endif 38 39 /************************************************************/ 40 /*** change following definitions as needed for your system */ 41 /************************************************************/ 42 /* 43 BIGBUF If defined, setvbuf() will be used to set input and 44 output buffers to BIGBUF characters 45 BINCHAR This must be a macro accepting a single character 46 argument and returning nonzero if and only if that 47 character is a binary character. By default, BINCHAR 48 is defined to look up a table, and the table is compiled 49 in by defining USE_TABLE. 50 CHECK_BREAK If your operating system requires programs to check 51 for user interrupts at intervals, define CHECK_BREAK to 52 be a function or macro that checks for a user interrupt. 53 Flip will call this at intervals. If not needed, 54 define CHECK_BREAK to be null. 55 DELFILE Must be a function or macro that will accept one filenames 56 and delete that file, returning zero on success, nonzero 57 on failure. 58 GETFT Must be a macro with usage GETFT(file,name,var) that will 59 take an open file, a filename, and a variable name, and 60 put in that variable the timestamp of the file. 61 INT_EXIT If USE_SIG is defined, INT_EXIT must be defined to 62 be the exit code returned by flip when its execution 63 is aborted by a user interrupt. 64 MVFILE Must be a function or macro that will take two filenames 65 and rename the first file to the second file, returning 66 zero on success, nonzero on failure. 67 NIX If this symbol is defined, some things common to most 68 implementations of **IX get defined and need not be 69 individually defined. 70 PATHSIZE size of buffer(s) to use to hold pathname(s) 71 PICKNAME Do "#define PICKNAME" if you want the program to know its 72 name and respond to it. If PICKNAME is not defined, the 73 program will assume that it is called "flip". 74 SETFT Must be a function or macro with usage SETFT(file,name,var) 75 that will take an open file, a filename, and a variable 76 name, and set the timestamp of the file from the variable. 77 SIG_T If USE_SIG is defined, then SIG_T must be defined 78 (or typedef'd) to be the data type returned by 79 (*signal). Usually int or void. 80 SPEC_EXIT Like SPEC_INIT, but is called just before flip exits. 81 SPEC_INIT This is invoked to initialize flip. Should be defined to 82 be either a function call (with trailing semicolon) or 83 null string. 84 SGFTIME This must be a typedef for a data type suitable to store 85 file times. 86 USE_TABLE If this is defined, flip code will use a table look-up 87 to decide which characters should be considered binary. 88 See also BINCHAR. 89 ULTRIX_BUG At least one version of Ultrix chokes on a trailing "b" 90 in the mode string for fopen(). If ULTRIX_BUG is defined 91 no trailing "b" will be used. 92 USE_SIG If this is defined, then signal() will be used so flip 93 may trap user interrupts and delete temporary files. 94 If USE_SIG is defined, then SIG_T and INT_EXIT must also 95 be defined (below). 96 WILDCARD If this is defined, the function nextfile() will be called 97 to expand wildcards. If WILDCARD is not defined, no 98 wildcard expansion will be done and nextfile() is not 99 needed. For a description of nextfile() see turboc.c. 100 */ 101 102 #ifdef TURBOC 103 # define PATHSIZE 200 104 # define PICKNAME 105 # define BIGBUF 16384 106 # define DELFILE remove 107 extern int MVFILE PARMS ((char *src, char *dest)); /* Turbo C */ 108 # define USE_SIG 109 # define SIG_T void /* return type from (*signal) */ 110 # define INT_EXIT 127 /* status when a signal causes exit */ 111 # define CHECK_BREAK brktst(); 112 void brktst PARMS ((void)); 113 # define SPEC_INIT spec_init(); 114 # define SPEC_EXIT spec_exit(); 115 void spec_init PARMS ((void)); 116 void spec_exit PARMS ((void)); 117 # define WILDCARD 118 119 /* date and time */ 120 # include <io.h> 121 typedef struct ftime SGFTIME; 122 # define GETFT(f,name,var) getftime(fileno(f), &var) 123 # define SETFT(f,name,var) setftime(fileno(f), &var) 124 #endif /* TURBOC */ 125 126 #ifdef SYS_V 127 # define NIX /* see below */ 128 # define PATHSIZE 200 129 # define BIGBUF 16384 130 # define MVFILE(src,dest) (!(!link(src,dest)&&!unlink(src))) 131 # define SIG_T int 132 #endif /* SYS_V */ 133 134 #ifdef BSD 135 # define NIX /* see below */ 136 # define PATHSIZE 1027 137 # undef BIGBUF 138 # define MVFILE rename 139 # define SIG_T int 140 #endif /* BSD */ 141 142 #ifdef VMS 143 # define PATHSIZE 1024 144 # define PICKNAME 145 # define BIGBUF 16384 146 # define DELFILE delete 147 # define MVFILE rename 148 # define USE_SIG 149 # define SIG_T int 150 # define INT_EXIT 127 151 # define SPEC_INIT 152 # define SPEC_EXIT 153 #endif /* VMS */ 154 155 /************************************************************/ 156 /*** remaining definitions should not need to be changed ****/ 157 /************************************************************/ 158 159 /* define ASCII character values for linefeed, carriage return, control Z */ 160 #define LF 10 161 #define CR 13 162 #define CTRLZ 26 163 164 /* error codes */ 165 #define ERRBINF 1 /* binary file */ 166 #define ERRSIG 2 /* interrupted by signal */ 167 168 /* how to strip high bit */ 169 #define STRIP(c) c &= 0x7f 170 171 /**** BINCHAR(c) returns nonzero if c is a binary char ****/ 172 #ifndef BINCHAR 173 # define USE_TABLE /* use internal table -- see flip.c */ 174 # define BINCHAR(c) bintab[c] 175 #endif 176 177 /**** mode strings for fopen() -- to work around Ultrix problem ****/ 178 /**** (Thanks to Taso N. Devetzis for reporting this) ****/ 179 #ifdef ULTRIX_BUG 180 # define WB "w" 181 # define RB "r" 182 # define R_PL_B "r+" 183 #else 184 # define WB "wb" /* write binary */ 185 # define RB "rb" /* read binary */ 186 # define R_PL_B "r+b" /* read + update binary */ 187 #endif /* ULTRIX_BUG */ 188 189 /* things common to most **IX systems */ 190 #ifdef NIX 191 # define SPEC_INIT 192 # define SPEC_EXIT 193 # define CHECK_BREAK 194 # define PICKNAME 195 # define DELFILE unlink 196 # define USE_SIG 197 # define INT_EXIT 127 198 # include <sys/types.h> /* for file time */ 199 # include <sys/stat.h> /* for file time */ 200 typedef struct stat SGFTIME; 201 # define GETFT(file,name,var) fstat(fileno(file),&var) 202 # define SETFT(file,name,var) do { time_t x[2]; x[0] = var.st_atime; \ 203 x[1] = var.st_mtime; utime (name, x); \ 204 } while (0) 205 #endif /* NIX */ 206 207 #endif /* OK_NL */ 208