Back to index

tetex-bin  3.0
cpascal.h
Go to the documentation of this file.
00001 /* cpascal.h: implement various bits of standard and other Pascal that
00002    we use in the change files.  Public domain.
00003    
00004    This is the top-level include file for all the web2c-generated C
00005    programs except TeX and Metafont themselves, which use texmf.h.  It's
00006    not included by the web2c programs, though.  */
00007 
00008 #ifndef CPASCAL_H
00009 #define CPASCAL_H
00010 
00011 #ifdef WIN32
00012 #pragma warning( disable : 4018 4244 )  
00013 #endif
00014 
00015 /* We must include this first, to resolve many C issues.  */
00016 #include "config.h"
00017 
00018 /* We only use getopt in the applications, not in web2c itself.  */
00019 #include <kpathsea/getopt.h>
00020 
00021 /* Almost everybody needs path searching.  May as well always include
00022    them and simplify the change files.  */
00023 #include <kpathsea/progname.h>
00024 #include <kpathsea/proginit.h>
00025 #include <kpathsea/tex-file.h>
00026 
00027 /* Help messages.  */
00028 #include "help.h"
00029 
00030 /* Allow translation files.  */
00031 #define       Xchr(x) xchr[x]
00032 
00033 /* Pieces of predefined Pascal web2c doesn't convert.  */
00034 
00035 /* Absolute value.  Without the casts to integer here, the Ultrix and
00036    AIX compilers (at least) produce bad code (or maybe it's that I don't
00037    understand all the casting rules in C) for tests on memory fields. 
00038    Specifically, a test in diag_round (in Metafont) on a quarterword
00039    comes out differently without the cast, thus causing the trap test to
00040    fail.  (A path at line 86 is constructed slightly differently).  */
00041 /* If the system had an abs #define already, get rid of it.  */
00042 #undef abs
00043 #define abs(x) ((integer)(x) >= 0 ? (integer)(x) : (integer)-(x))
00044 
00045 #define chr(x)              (x)
00046 #define ord(x)              (x)
00047 #define odd(x)              ((x) & 1)
00048 #define round(x)     zround ((double) (x))
00049 #define trunc(x)     ((integer) (x))
00050 #define floor(x)     ((integer)floor((double)(x)))
00051 #define input stdin
00052 #define output stdout
00053 #define maxint INTEGER_MAX
00054 #define nil NULL
00055 
00056 #define floorunscaled(i) ((i)>>16)
00057 #define floorscaled(i) ((i)&(-65536))
00058 #define roundunscaled(i) (((i>>15)+1)>>1)
00059 #define roundfraction(i) (((i>>11)+1)>>1)
00060 #ifndef TeX
00061 /* In TeX, the half routine is always applied to positive integers.
00062    In MF and MP, it isn't; therefore, we can't portably use the C shift
00063    operator -- whether zeros or the sign bit will be shifted in on
00064    negative left operands is implementation-defined.
00065    
00066    It might be worth going through MF and using halfp where possible, as
00067    in MP.  */
00068 #define half(i) ( ((i)<0) ? (((i)+1)>>1) : ((i)>>1) )
00069 #endif
00070 #define halfp(i) ((i) >> 1)
00071 
00072 /* Standard Pascal file routines.  These are used for both binary and
00073    text files, but binary is more common.  If you want it 100% right,
00074    fix the change files to pass the fopen mode to reset in all cases and
00075    send me the changes; it doesn't matter for Unix, so I'm not going to
00076    spend any more time on it.  */
00077 #define reset(f,n) f = xfopen (n, FOPEN_R_MODE)
00078 #define rewrite(f,n) f = xfopen (n, FOPEN_W_MODE)
00079 #define resetbin(f,n) f = xfopen (n, FOPEN_RBIN_MODE)
00080 #define rewritebin(f,n) f = xfopen (n, FOPEN_WBIN_MODE)
00081 
00082 #if defined(read)
00083 #undef read
00084 #endif
00085 #define read(f,b) ((b) = getc (f))
00086 
00087 /* We hope this will be efficient than the `x = x - 1' that decr would
00088    otherwise be translated to.  Likewise for incr.  */
00089 #define decr(x) --(x)
00090 #define incr(x) ++(x)
00091 
00092 /* `real' is used for noncritical floating-point stuff.  */
00093 typedef double real;
00094 
00095 /* C doesn't need to distinguish between text files and other files.  */
00096 typedef FILE *text;
00097 
00098 /* Extra stuff used in various change files for various reasons.  */
00099 
00100 /* Pascal has no address-of operator, and we need pointers to integers
00101    to set up the option table.  */
00102 #define addressof(x) (&(x))
00103 
00104 /* So dvicopy can use stdin/stdout.  */
00105 #if defined (__DJGPP__) || defined (WIN32)
00106 #include <io.h>
00107 /* Don't set console device to binary.  */
00108 #define makebinaryfile(arg) ((!isatty(fileno(arg)) && setmode(fileno(arg), O_BINARY)), arg)
00109 #else
00110 #define makebinaryfile(arg) (arg)
00111 #endif
00112 
00113 /* It's not worth fixing fixwrites to handle Pascal-style n:m write
00114    specifiers for reals, so the change files call print_real instead.  */
00115 #define printreal(r,n,m) fprintreal (stdout, r, n, m)
00116 
00117 /* Write the byte X to the file F.  */
00118 #define putbyte(x,f) \
00119  do { if (putc ((char) (x) & 255, f) == EOF) \
00120         FATAL1 ("putbyte(%ld) failed", (long) x); } while (0)
00121 
00122 /* To work around casting problems.  */
00123 #define intcast(x) ((integer) (x))
00124 #define stringcast(x) ((string) (x))
00125 
00126 /* For throwing away input from the file F.  */
00127 #define vgetc(f) (void) getc (f)
00128 
00129 /* The fixwrites program outputs this, for diagnostics and such, that
00130    aren't worth checking the return value on.  */
00131 #define Fputs(f,s) (void) fputs (s, f)
00132 
00133 /* `aopenin' is used for all kinds of input text files, so it
00134    needs to know what path to use.  Used by BibTeX, MF, TeX.  */
00135 #define aopenin(f,p) open_input (&(f), p, FOPEN_RBIN_MODE)
00136 #define aopenout(f)  open_output (&(f), FOPEN_W_MODE)
00137 
00138 /* For faking arrays in tftopl.  */
00139 typedef unsigned char *pointertobyte;
00140 #define casttobytepointer(e) ((pointertobyte) e)
00141 
00142 /* Write out elements START through END of BUF to the file F.  For gftodvi.  */
00143 #define writechunk(f, buf, start, end) \
00144   (void) fwrite (&buf[start], sizeof (buf[start]), end - start + 1, f)
00145 
00146 /* PatGen 2 uses this.  */
00147 #define input2ints(a,b) zinput2ints (&a, &b)
00148 
00149 /* We need this only if TeX is being debugged.  */
00150 #define input3ints(a,b,c) zinput3ints (&a, &b, &c)
00151 
00152 /* Allocate an array of a given type. Add 1 to size to account for the
00153    fact that Pascal arrays are used from [1..size], unlike C arrays which
00154    use [0..size). */
00155 #define xmallocarray(type,size) ((type*)xmalloc((size+1)*sizeof(type)))
00156 
00157 /* BibTeX needs this to dynamically reallocate arrays.  Too bad we can't
00158    rely on stringification, or we could avoid the ARRAY_NAME arg.
00159    Actually allocate one more than requests, so we can index the last
00160    entry, as Pascal wants to do.  */
00161 #define BIBXRETALLOC(array_name, array_var, type, size_var, new_size) do { \
00162   fprintf (logfile, "Reallocated %s (elt_size=%d) to %ld items from %ld.\n", \
00163            array_name, (int) sizeof (type), new_size, size_var); \
00164   XRETALLOC (array_var, new_size + 1, type); \
00165   size_var = new_size; \
00166 } while (0)
00167   
00168 /* Need precisely int for getopt, etc. */
00169 #define cinttype int
00170 
00171 /* Need this because web2c doesn't translate `var1,var2:^char' correctly
00172    -- var2 lacks the *.  */
00173 #define cstring string
00174 
00175 /* Not all C libraries have fabs, so we'll roll our own.  */
00176 #undef fabs
00177 #define fabs(x) ((x) >= 0.0 ? (x) : -(x))
00178 
00179 /* TeX et al. have a variable free, but we also need the C routine.  */
00180 #define libcfree free
00181 
00182 /* Tangle removes underscores from names.  Put them back for things that
00183    are defined in C with _'s.  */
00184 #define extendfilename      extend_filename
00185 #define findsuffix   find_suffix
00186 #define FOPENRBINMODE       FOPEN_RBIN_MODE
00187 #define FOPENRMODE   FOPEN_R_MODE
00188 #define getoptlongonly      getopt_long_only
00189 #define hasarg              has_arg
00190 #define ISDIRSEP     IS_DIR_SEP
00191 #define kpsebibformat       kpse_bib_format
00192 #define kpsebstformat       kpse_bst_format
00193 #define kpsefindfile kpse_find_file
00194 #define kpsefindmf   kpse_find_mf
00195 #define kpsefindmft  kpse_find_mft
00196 #define kpsefindofm    kpse_find_ofm
00197 #define kpsefindovf    kpse_find_ovf
00198 #define kpsefindtex  kpse_find_tex
00199 #define kpsefindtfm  kpse_find_tfm
00200 #define kpsefindvf   kpse_find_vf
00201 #define kpseinitprog kpse_init_prog
00202 #define kpsesetprogname kpse_set_progname
00203 #define kpsesetprogramname kpse_set_program_name
00204 #define kpseresetprogramname kpse_reset_program_name
00205 #define kpsegfformat kpse_gf_format
00206 #define kpselastformat      kpse_last_format
00207 #define kpsemaketexdiscarderrors kpse_make_tex_discard_errors
00208 #define kpsemfformat kpse_mf_format
00209 #define kpsemftformat       kpse_mft_format
00210 #define kpsempformat kpse_mp_format
00211 #define kpseocpformat       kpse_ocp_format
00212 #define kpseofmformat       kpse_ofm_format
00213 #define kpseoplformat       kpse_opl_format
00214 #define kpseotpformat       kpse_otp_format
00215 #define kpseovpformat       kpse_ovp_format
00216 #define kpseovfformat       kpse_ovf_format
00217 #define kpseopenfile kpse_open_file
00218 #define kpsepkformat kpse_pk_format
00219 #define kpsetfmformat       kpse_tfm_format
00220 #define kpsevfformat kpse_vf_format
00221 #define kpsewebformat       kpse_web_format
00222 #define kpsevarvalue kpse_var_value
00223 #define kpsesetprogramenabled      kpse_set_program_enabled
00224 #define kpsesrccmdline      kpse_src_cmdline
00225 #define makesuffix   make_suffix
00226 #define recorderchangefilename     recorder_change_filename
00227 #define recorderenabled     recorder_enabled
00228 #define removesuffix remove_suffix
00229 
00230 /* We need a new type for the argument parsing, too.  */
00231 typedef struct option getoptstruct;
00232 
00233 /* We never need the `link' system call, which may be declared in
00234    <unistd.h>, but we do have variables named `link' in the webs.  */
00235 #undef link
00236 #define link link_var
00237 
00238 /* Throw away VMS' library routine `getname', as WEB uses that name.  */
00239 #ifdef VMS
00240 #undef getname
00241 #define getname vms_getname
00242 #endif
00243 
00244 /* Declarations for the routines we provide ourselves in lib/.  */
00245 
00246 extern string basenamechangesuffix P3H(const_string,const_string,const_string);
00247 extern string chartostring P1H(char);
00248 extern boolean eof P1H(FILE *);
00249 extern boolean eoln P1H(FILE *);
00250 extern void readln P1H(FILE *);
00251 extern void fprintreal P4H(FILE *, double, int, int);
00252 extern integer inputint P1H(FILE *);
00253 extern void printversionandexit P3H(const_string, const_string, const_string);
00254 extern void zinput2ints P2H(integer *, integer *);
00255 extern void zinput3ints P3H(integer *, integer *, integer *);
00256 extern integer zround P1H(double);
00257 
00258 /* main.c */
00259 extern int argc;
00260 extern string *argv;
00261 extern string cmdline P1H(int);
00262 extern TEXDLL void mainbody P1H(void); /* generated by web2c */
00263 
00264 /* openclose.c */
00265 extern boolean open_input P3H(FILE **, int, const_string fopen_mode);
00266 extern boolean open_output P2H(FILE **, const_string fopen_mode);
00267 extern void aclose P1H(FILE *);
00268 extern void recorder_change_filename P1H(string);
00269 extern boolean recorder_enabled;
00270 extern string output_directory;
00271 
00272 /* version.c */
00273 extern string versionstring;
00274 
00275 #endif /* not CPASCAL_H */