home *** CD-ROM | disk | FTP | other *** search
- Path: j.cc.purdue.edu!mentor.cc.purdue.edu!purdue!bu.edu!snorkelwacker.mit.edu!apple!usc!julius.cs.uiuc.edu!wuarchive!uunet!papaya.bbn.com!rsalz
- From: rsalz@bbn.com (Rich Salz)
- Newsgroups: comp.sources.unix
- Subject: v23i055: Line oriented macro processor, Part05/09
- Message-ID: <3030@litchi.bbn.com>
- Date: 29 Nov 90 17:43:38 GMT
- Organization: BBN Systems and Technologies, Cambridge MA
- Lines: 563
- Approved: rsalz@uunet.UU.NET
-
- Submitted-by: Darren New <new@ee.udel.edu>
- Posting-number: Volume 23, Issue 55
- Archive-name: lome/part05
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 8 (of 9)."
- # Contents: PPL/PPLUnix.h
- # Wrapped by new@estelle.ee.udel.edu on Tue Aug 14 16:10:03 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'PPL/PPLUnix.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'PPL/PPLUnix.h'\"
- else
- echo shar: Extracting \"'PPL/PPLUnix.h'\" \(17468 characters\)
- sed "s/^X//" >'PPL/PPLUnix.h' <<'END_OF_FILE'
- X/*
- X * PPLUnix.h
- X * Portable Programmer's Library General Host Parameters
- X * Copyright 1988,1990 Darren New. All Rights Reserved.
- X * Unix version (SunOS 4.x with GCC)
- X *
- X * Started 19-Feb-88 DHN
- X * LastMod 19-Jul-90 DHN
- X *
- X */
- X
- X#ifndef PPL_h
- X#define PPL_h
- X
- X
- X/*****************************************************************
- X *
- X * This file gets included into every PPL source file.
- X * This one of the few include files that the host programmer
- X * should be changing.
- X *
- X */
- X
- X/*****************************************************************
- X *
- X * Include whatever files you need here to supply
- X * strlen, strcpy, strncmp, strcmp, strchr
- X * toupper, tolower
- X * isalnum, isaplha, isdigit, isupper, islower, isspace
- X * fault, assert, bomb
- X *
- X * Note that assert can be compiled out, fault can always return
- X * false, and bomb can call PLExit(PLsev_bomb).
- X *
- X */
- X
- X#include "stdio.h"
- X#include "stdlib.h"
- X#include "string.h"
- X#include "ctype.h"
- X#include "errno.h"
- X#include "unistd.h"
- X
- X#undef TRUE
- X#undef FALSE
- X#undef BITSPERLONG
- X#undef NULL
- X
- X
- X#define USE_ASSERT 1
- X
- X#include "Fault.h"
- X
- X/*****************************************************************
- X *
- X * These parameters describe your C compiler:
- X *
- X */
- X
- X/* First, some raw, low-level information advantage of which should
- X * probably never be taken.
- X */
- X#define BITSPERCHAR 8
- X#define BITSPERSHORT (BITSPERCHAR*sizeof(short))
- X#define BITSPERLONG (BITSPERCHAR*sizeof(long))
- X#define BITSPERFLOAT (BITSPERCHAR*sizeof(float))
- X#define BITSPERDOUBLE (BITSPERCHAR*sizeof(double))
- X
- X/* To account for character-set differences, this macro (or function)
- X * must accept a digit and return an integer from 0 to 9.
- X * The other macro goes the other direction.
- X */
- X#define PLToInt(a) (a - '0')
- X#define PLToDig(a) (a + '0')
- X
- X/* Set this to the most efficient small integer value for your compiler.
- X * You may include "register" and "unsigned" without ill effect.
- X * Vars of this type are never passed as parameters and are usually
- X * loop indicies or array subscripts.
- X */
- Xtypedef unsigned short inx;
- X
- X/* Set this to a "generic pointer" (either void * or char *).
- X */
- Xtypedef void * ptr;
- X
- X/* Set this to a "boolean". This is not used for arrays, so faster
- X * over smaller is better. Do not make it "register".
- X */
- Xtypedef short bool;
- X
- X/* Set this to the proper value for your computer.
- X */
- X#ifndef NULL
- X#define NULL ((ptr)0)
- X#endif
- X
- X/* Set this to the size of the longest legal file name under the native
- X * operating system calls.
- X * Note that this MUST be declared as a LONG literal.
- X */
- X#define BIGFNAME 512L
- X
- X/* Set this to the largest piece of contiguous memory that can be
- X * allocated and accessed. I.e., this is the sizeof the largest
- X * character array that PLallocmem can return. E.g., IBM PC = 64K.
- X * This limits PLfillmem, PLallocmem, and other functions that
- X * access large chunks of contiguous memory.
- X * Note that this MUST be declared as a LONG literal.
- X */
- X#define BIGMEM 65530L
- X
- X/* Set this to the largest piece of contiguous I/O request that
- X * can be I/O'ed in one call. E.g., IBM PC = 31K.
- X * Note that this MUST be declared as a LONG literal.
- X */
- X#define BIGIO 32760L
- X
- X/* Set this to the smaller of BIGMEM and BIGIO
- X */
- X#define BIGBUF BIGIO
- X
- X/* Set this to the longest line reasonably returnable by the
- X * line-oriented I/O functions. I.e., this is the size of buffers
- X * allocated for GetLine and so on. This needn't be bigger that about 250.
- X */
- X#define BIGLINE 250
- X
- X/* Set this to 1 if you have structure assignment.
- X * Set this to 0 to use PLmemcpy.
- X * (note that PPL never passes structures by value)
- X */
- X#define STRUCT_ASSIGN 1
- X
- X/* Set this to 1 if you have prototype arguments for external functions.
- X * Set this to 0 to declare functions without prototype arguments.
- X */
- X#define PROTOTYPES 1
- X
- X/* Set this to 1 if you have ANSI-style function definition headings.
- X * Set this to 0 if you have PCC-style function definition headings.
- X */
- X#define ANSIHEADERS 1
- X
- X/* Set this to 1 if HIDDEN functions need prototype declarations.
- X * Set this to 0 if you don't want them.
- X */
- X#define HIDPROTS 1
- X
- X/* Set this to 1 if you want to check arguments to library functions.
- X * Set this to 0 once your programs are debugged.
- X */
- X#define CHKARGS 1
- X
- X
- X
- X
- X/*****************************************************************
- X *
- X * These parameters are utility macros. Do not change them!
- X *
- X */
- Xtypedef char * str; /* '\0' terminated string */
- X#define EOS '\0'
- X
- X#define loop while(1) /* like other langs */
- X
- X#define HIDDEN static /* hidden objects go away (can be changed to comment for stupid debuggers) */
- X
- X/* Use this macro to assign structures */
- X#if STRUCT_ASSIGN
- X#define SASGN(a, b) (a = b)
- X#else
- X#define SASGN(a, b) PLCopyMem(&a, &b, sizeof(a))
- X#endif
- X
- X/* Use this macro to declare arguments on function declarations */
- X#if PROTOTYPES
- X#define ARGS(a) a
- X#else
- X#define ARGS(a) ()
- X#endif
- X
- X/* Use this macro to define formals of function definitions */
- X#if ANSIHEADERS
- X#define ARGS0() ()
- X#define ARGS1(a,b) (a b)
- X#define ARGS2(a,b,c,d) (a b, c d)
- X#define ARGS3(a,b,c,d,e,f) (a b, c d, e f)
- X#define ARGS4(a,b,c,d,e,f,g,h) (a b, c d, e f, g h)
- X#define ARGS5(a,b,c,d,e,f,g,h,i,j) (a b, c d, e f, g h, i j)
- X#define ARGS6(a,b,c,d,e,f,g,h,i,j,k,l) (a b, c d, e f, g h, i j, k l)
- X#define ARGS7(a,b,c,d,e,f,g,h,i,j,k,l,m,n) (a b, c d, e f, g h, i j, k l, m n)
- X#define ARGS8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) (a b, c d, e f, g h, i j, k l, m n, o p)
- X#else
- X#define ARGS0() ()
- X#define ARGS1(a,b) (b)a b;
- X#define ARGS2(a,b,c,d) (b,d)a b; c d;
- X#define ARGS3(a,b,c,d,e,f) (b,d,f)a b;c d;e f;
- X#define ARGS4(a,b,c,d,e,f,g,h) (b,d,f,h)a b;c d;e f;g h;
- X#define ARGS5(a,b,c,d,e,f,g,h,i,j) (b,d,f,h,j)a b;c d;e f;g h;i j;
- X#define ARGS6(a,b,c,d,e,f,g,h,i,j,k,l) (b,d,f,h,j,l)a b;c d;e f;g h;i j;k l;
- X#define ARGS7(a,b,c,d,e,f,g,h,i,j,k,l,m,n) (b,d,f,h,j,l,n)a b;c d;e f;g h;i j;k l;m n;
- X#define ARGS8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) (b,d,f,h,j,l,n,p)a b;c d;e f;g h;i j;k l;m n;o p;
- X#endif
- X
- X/* This allows constant paramters passed to a short formal to by typecast
- X * easily. It is kind of like a trailing L on an integer. Use new ANSI
- X * stuff instead.
- X */
- X#define S (short)
- X
- X#define TRUE ((bool) 1)
- X#define FALSE ((bool) 0)
- X
- X
- X/*****************************************************************
- X *
- X * These declare the startup and termination routines.
- X * Do NOT change these!
- X *
- X */
- X
- X/* This is to be called by the main() of the host program.
- X * It returns the exit severity.
- X */
- Xextern short DoIt ARGS((void));
- X
- X/* This is called by the application when an unrecoverable error
- X * has occured. The severity is passed as the argument.
- X * The host should clean up if possible.
- X */
- Xextern void PLExit ARGS((short severity));
- X
- X/* These are the severities:
- X */
- X#define PLsev_normal 0 /* no error - just exit normally */
- X#define PLsev_badarg 1 /* command line arguments bad or wrong config */
- X#define PLsev_error 2 /* some other kind of error */
- X#define PLsev_userbreak 3 /* user requested unclean interrupt */
- X#define PLsev_oores 4 /* out of required resource */
- X#define PLsev_nfres 5 /* required resource not found at all */
- X#define PLsev_badform 6 /* input or file in wrong format */
- X#define PLsev_fault 7 /* user req to not recov from recov error */
- X#define PLsev_bomb 8 /* program detected unrecov error */
- X#define PLsev_assert 9 /* assertion failed */
- X#define PLsev_crash 10 /* program (and probably machine) crashed */
- X
- X
- X/*****************************************************************
- X *
- X * These declare the memory allocation / access primatives
- X *
- X */
- X
- X/* This allocates dynamic memory. The first argument is a LONG
- X * specifying how much memory (in bytes) needs to be allocated.
- X * The second is an INT containing various flags (two so far).
- X * If (flags & PLalloc_die) this will bomb("Out of Memory")
- X * if the allocation fails; otherwise it will return NULL if the
- X * allocation fails.
- X * You will fail the allocation or bomb("Memory request too large")
- X * if more memory than BIGMEM is requested. This retains the length
- X * for the PLfreemem function.
- X * If (flags & PLalloc_zero) this will clear the allocated memory to
- X * all binary zeros if the allocation succeeds; otherwise, the memory
- X * will be uninitialized.
- X */
- X#define PLalloc_die 1 /* bomb if out of memory */
- X#define PLalloc_zero 2 /* clear new mem to zeros */
- Xptr PLAllocMem ARGS((long size, int flags));
- X
- X/* This frees dynamic memory. The argument is a previously-allocated
- X * pointer to memory as returned by PLAllocMem(). The application is
- X * responsible for deallocating all memory it allocates before returning
- X * normally from DoIt(). If possible, the application should deallocate
- X * all memory before calling PLExit. The host programmer may wish to
- X * check that memory is freed exactly once.
- X */
- Xvoid PLFreeMem ARGS((ptr where));
- X
- X/* This allocates enough memory to hold the given string, then copies
- X * the string into that memory. It passes PLalloc_die=true to the
- X * PLallocmem call.
- X */
- Xstr PLStrDup ARGS((str s));
- X
- X/* This copies memory from src to dest for siz bytes. The host function
- X * will handle copying in the correct direction if the areas overlap.
- X * This should be as efficient as possible.
- X */
- Xvoid PLCopyMem ARGS((ptr to, ptr from, long siz));
- X
- X/* This assigns a constant byte to a region of memory.
- X * Again, this should be as efficient as possible.
- X */
- Xvoid PLFillMem ARGS((ptr where, long siz, char chr));
- X
- X/* This looks for a specific character within a range of memory.
- X * It returns NULL if not found, or a pointer to the matching character
- X * if found.
- X */
- Xptr PLFindMem ARGS((ptr where, long siz, char chr));
- X
- X
- X/*****************************************************************
- X *
- X * These declare the error routines
- X *
- X */
- X
- X/* This is the type of an error value
- X */
- Xtypedef short PLerr_enum;
- X#define PLerr_none 0 /* no error occured */
- X#define PLerr_opsysR 1 /* otherwise unknown error - retry */
- X#define PLerr_opsysW 2 /* otherwise unknown error - wait then retry */
- X#define PLerr_opsysU 3 /* otherwise unknown error - ask user to fix */
- X#define PLerr_opsysF 4 /* otherwise unknown error - unrecoverable failure */
- X#define PLerr_fault 5 /* program-detected error */
- X#define PLerr_eod 6 /* end of data (during read) */
- X#define PLerr_oores 7 /* out of some resource (during write/create) */
- X#define PLerr_again 8 /* multiple errors occured without being cleared */
- X#define PLerr_exist 9 /* access to non-existant item */
- X#define PLerr_already 10 /* can't create because item already there */
- X#define PLerr_permit 11 /* "owner" disallows that access to you */
- X#define PLerr_unsup 12 /* unsuported in this instance */
- X#define PLerr_busy 13 /* item exits but is busy */
- X#define PLerr_param 14 /* argument to function cannot be parsed */
- X#define PLerr_notyet 15 /* something not yet implemented */
- X#define PLerr_never 16 /* something that cannot be implemented */
- X#define PLerr_badarg 17 /* argument to function semantically invalid */
- X#define PLerr_overflow 18 /* overflow error */
- X#define PLerr_underflow 19 /* underflow error */
- X#define PLerr_userbreak 20 /* user break or interrupted system call */
- X#define PLerr_last 21 /* largest error number + 1 */
- X
- X/* The PL error number */
- Xextern PLerr_enum PLerr;
- X
- X/* The OS error number (whatever you need, if anything) */
- Xextern int OSerr; /* may be changed by HostPgrmr */
- X
- X/* The file and line of the last error (mainly for debugging) */
- Xextern str PLerr_file;
- Xextern long PLerr_line;
- X
- X/* This sets the error number.
- X */
- X#ifdef DEBUG
- X#define PLErrSet(e) ((PLerr_file=__FILE__),(PLerr_line=__LINE__),\
- XPLerr=((PLerr!=PLerr_none)?PLerr_again:(e)))
- X#else
- X#define PLErrSet(e) (PLerr = ((PLerr != PLerr_none) ? PLerr_again : (e)))
- X#endif
- X
- X/* This clears the error number.
- X * (This may be a void function if your compiler doesn't like empty args)
- X */
- X#define PLErrClr() (OSerr=0,PLerr=PLerr_none)
- X
- X/* This returns a string, suitable for user viewing, describing the
- X * most recent error as indicated by PLerr.
- X * The string should be static.
- X */
- Xstr PLErrText ARGS((void));
- X
- X/* This returns a string, suitable for user viewing, describing the
- X * most recent error in the HOST terminology. Used when PLopsys?
- X * returned or for additional information.
- X * The string should be static.
- X */
- Xstr PLOSErrText ARGS((void));
- X
- X/*****************************************************************
- X *
- X * These declare the status message routines
- X * (Note that delay and beep are included here only due to their
- X * typical usage.)
- X *
- X */
- X
- X/* This displays a status message for utilities. The display should
- X * be suppressed if PLstatuslevel <= level. PLstatuslevel should be
- X * initialized before calling DoIt(), and is intended to be
- X * changable by the user. It should default to a value of 6 (giving
- X * status messages in the range 0-6).
- X * level == 5 should be used for normal status messages, including
- X * initial copyright messages, final summaries, and so on;
- X * level == 6 should be used for progress reports;
- X * level == 7 should be used to echo parameters; level == 3 should be
- X * use for warnings and level == 2 should be used for non-fatal errors.
- X * Obviously, use level == 0 (which can't be disabled) for fatal errors.
- X */
- Xextern short PLstatuslevel;
- Xvoid PLStatus ARGS((short level, str message));
- X
- X/* This function will delay for the indicated number of seconds in the
- X * most efficient way possible. (Of course, on a single-tasking
- X * machine, you may wait as inefficiently as you like.)
- X */
- Xextern void PLDelay ARGS((short secs));
- X
- X/* This function is used to draw the user's attention to the computer.
- X * If passed a zero, it should make a quiet, pleasant beep or chime,
- X * or simply flash the screen if possible. This option will be used
- X * to indicate that a minor error (like an illegal keystroke) has
- X * occured.
- X * If passed a one, it should make an audible tone, loud enough to be
- X * heard even if not listened for. This should be used to indicate that
- X * a lengthy process (during which the user has started working on
- X * back paperwork or something) has completed. It should never be used
- X * to indicate that an error has occured.
- X * If passed a two or greater, it should give a rude audible indicator
- X * of problems. This will be used only when the user is about to do
- X * something that it is quite unlikely he wants to do.
- X */
- Xextern void PLBeep ARGS((short how));
- X
- X
- X/*****************************************************************
- X *
- X * These declare basic standard input/output functions
- X *
- X * Do not use these in sophisticated applications.
- X * Do not use these in place of the PLstatus routine.
- X */
- X
- X
- X/* This should return an integer from 0 to 255, representing the ASCII
- X * of the next character read from the "standard input" or -1 for EOF or
- X * -2 for some other I/O error. Newline must be returned as '\n', and
- X * space as ' ' and tab as '\t'. It is assumed that redirection might
- X * occur on this stream -- see also PLResetInput().
- X * This may be changed to a macro by the host programmer.
- X */
- Xextern int fgetc(FILE *);
- X#define PLGetChar() fgetc(stdin)
- X
- X/* This should send the indicated character to the "standard output".
- X * The output characters may include '\n' for newline. It is assumed
- X * that redirection may occur on this stream -- see also PLResetOutput().
- X * This may be changed to a macro by the host programmer.
- X */
- Xextern int fputc(char, FILE *);
- X#define PLPutChar(ch) ((void)(fputc((ch),stdout),fflush(stdout)))
- X
- X/* When this is called, further calls to PLgetchar() should take
- X * their input from the user terminal.
- X * This may be changed to a macro by the host programmer.
- X */
- X#define PLResetInput() ((void)freopen("/dev/tty", "r", stdin))
- X
- X/* When this is called, further calls to PLputchar() should send
- X * their output to the user terminal.
- X * This may be changed to a macro by the host programmer.
- X */
- X#define PLResetOutput() ((void)freopen("/dev/tty","a",stdout))
- X
- X /* For testing only! Do not call printf except while debugging! */
- X extern void printf(char *, ...);
- X
- X
- X/*****************************************************************
- X *
- X * These declare command-line argument functions
- X *
- X */
- X
- X/* This gives the name of the executable file, if available.
- X * Otherwise, this will be NULL.
- X */
- Xextern str PLcmdname;
- X
- X/* This gives the host-syntax filename for the executable file now running,
- X * if available.
- X * Otherwise, this will be NULL.
- X */
- Xextern str PLcmdfile;
- X
- X/* This tells how many command-line arguments there were, EXCLUDING
- X * the command name.
- X */
- Xextern short PLargcnt;
- X
- X/* This is the array of command-line argument strings, EXCLUDING the
- X * command name.
- X */
- Xextern str PLarglist[];
- X
- X/* These are the flags describing the command-line parameters.
- X */
- Xextern long PLargflags;
- X#define PLaf_hostwc 1 /* use host wildcards instead of portable wc's */
- X#define PLaf_hostex 2 /* host already has expanded wildcards */
- X
- X
- X/********** These are here because this assumes GCC with non-ANSI
- X header files (SunOS 4.1, to be precise) **********************/
- X
- X/* these should be in stdio.h for ANSI compilers, but aren't on the Sun */
- Xextern int fprintf ARGS((FILE *, char *, ...));
- Xextern void exit ARGS((int));
- Xextern void fflush ARGS((FILE *));
- X/* these should be in stdlib.h for ANSI compilers, but aren't on the Sun */
- Xextern void * malloc ARGS((long));
- Xextern void free ARGS((void *));
- X/* these should be in ctype.h for ANSI compilers (I think), but aren't on the Sun */
- Xextern int toupper ARGS((int));
- Xextern int tolower ARGS((int));
- X
- X
- X#endif /* PPL_h */
- X
- END_OF_FILE
- if test 17468 -ne `wc -c <'PPL/PPLUnix.h'`; then
- echo shar: \"'PPL/PPLUnix.h'\" unpacked with wrong size!
- fi
- # end of 'PPL/PPLUnix.h'
- fi
- echo shar: End of archive 8 \(of 9\).
- cp /dev/null ark8isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 9 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- --
- --- Darren New --- Grad Student --- CIS --- Univ. of Delaware ---
-
- exit 0 # Just in case...
- --
- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
- Use a domain-based address or give alternate paths, or you may lose out.
-