home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume15
/
dmake-3.6
/
part24
< prev
next >
Wrap
Text File
|
1990-10-14
|
40KB
|
1,621 lines
Newsgroups: comp.sources.misc
X-UNIX-From: dvadura@watdragon.waterloo.edu
subject: v15i076: dmake version 3.6 (part 24/25)
from: Dennis Vadura <dvadura@watdragon.waterloo.edu>
Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Posting-number: Volume 15, Issue 76
Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu>
Archive-name: dmake-3.6/part24
#!/bin/sh
# this is part 24 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file common/dbug.c continued
#
CurArch=24
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file common/dbug.c"
sed 's/^X//' << 'SHAR_EOF' >> common/dbug.c
X if (discard != NULL && discard -> next_state != NULL) {
X stack = discard -> next_state;
X _db_fp_ = stack -> out_file;
X _db_pfp_ = stack -> prof_file;
X if (discard -> keywords != NULL) {
X FreeList (discard -> keywords);
X }
X if (discard -> functions != NULL) {
X FreeList (discard -> functions);
X }
X if (discard -> processes != NULL) {
X FreeList (discard -> processes);
X }
X if (discard -> p_functions != NULL) {
X FreeList (discard -> p_functions);
X }
X CloseFile (discard -> out_file);
X CloseFile (discard -> prof_file);
X free ((char *) discard);
X }
X}
X
X
X/*
X * FUNCTION
X *
X * _db_enter_ process entry point to user function
X *
X * SYNOPSIS
X *
X * VOID _db_enter_ (_func_, _file_, _line_, _sfunc_, _sfile_, _slevel_)
X * char *_func_; points to current function name
X * char *_file_; points to current file name
X * int _line_; called from source line number
X * char **_sfunc_; save previous _func_
X * char **_sfile_; save previous _file_
X * int *_slevel_; save previous nesting level
X *
X * DESCRIPTION
X *
X * Called at the beginning of each user function to tell
X * the debugger that a new function has been entered.
X * Note that the pointers to the previous user function
X * name and previous user file name are stored on the
X * caller's stack (this is why the ENTER macro must be
X * the first "executable" code in a function, since it
X * allocates these storage locations). The previous nesting
X * level is also stored on the callers stack for internal
X * self consistency checks.
X *
X * Also prints a trace line if tracing is enabled and
X * increments the current function nesting depth.
X *
X * Note that this mechanism allows the debugger to know
X * what the current user function is at all times, without
X * maintaining an internal stack for the function names.
X *
X */
X
XVOID _db_enter_ (_func_, _file_, _line_, _sfunc_, _sfile_, _slevel_)
Xchar *_func_;
Xchar *_file_;
Xint _line_;
Xchar **_sfunc_;
Xchar **_sfile_;
Xint *_slevel_;
X{
X if (!init_done) {
X _db_push_ ("");
X }
X *_sfunc_ = func;
X *_sfile_ = file;
X func = _func_;
X file = BaseName (_file_);
X stack -> level++;
X *_slevel_ = stack -> level;
X if (DoProfile ()) {
X (VOID) fprintf (_db_pfp_, "%s\tE\t%ld\n",func, Clock());
X (VOID) fflush (_db_pfp_);
X }
X if (DoTrace ()) {
X DoPrefix (_line_);
X Indent (stack -> level);
X (VOID) fprintf (_db_fp_, ">%s\n", func);
X (VOID) fflush (_db_fp_);
X (VOID) XDelay (stack -> delay);
X }
X}
X
X
X/*
X * FUNCTION
X *
X * _db_return_ process exit from user function
X *
X * SYNOPSIS
X *
X * VOID _db_return_ (_line_, _sfunc_, _sfile_, _slevel_)
X * int _line_; current source line number
X * char **_sfunc_; where previous _func_ is to be retrieved
X * char **_sfile_; where previous _file_ is to be retrieved
X * int *_slevel_; where previous level was stashed
X *
X * DESCRIPTION
X *
X * Called just before user function executes an explicit or implicit
X * return. Prints a trace line if trace is enabled, decrements
X * the current nesting level, and restores the current function and
X * file names from the defunct function's stack.
X *
X */
X
XVOID _db_return_ (_line_, _sfunc_, _sfile_, _slevel_)
Xint _line_;
Xchar **_sfunc_;
Xchar **_sfile_;
Xint *_slevel_;
X{
X if (!init_done) {
X _db_push_ ("");
X }
X if (stack -> level != *_slevel_ && (TRACING || DEBUGGING || PROFILING)) {
X (VOID) fprintf (_db_fp_, ERR_MISSING_RETURN, _db_process_, func);
X (VOID) XDelay (stack -> delay);
X } else if (DoProfile ()) {
X (VOID) fprintf (_db_pfp_, "%s\tX\t%ld\n", func, Clock());
X (VOID) XDelay (stack -> delay);
X } else if (DoTrace ()) {
X DoPrefix (_line_);
X Indent (stack -> level);
X (VOID) fprintf (_db_fp_, "<%s\n", func);
X (VOID) XDelay (stack -> delay);
X }
X (VOID) fflush (_db_fp_);
X stack -> level = *_slevel_ - 1;
X func = *_sfunc_;
X file = *_sfile_;
X}
X
X
X/*
X * FUNCTION
X *
X * _db_pargs_ log arguments for subsequent use by _db_doprnt_()
X *
X * SYNOPSIS
X *
X * VOID _db_pargs_ (_line_, keyword)
X * int _line_;
X * char *keyword;
X *
X * DESCRIPTION
X *
X * The new universal printing macro DBUG_PRINT, which replaces
X * all forms of the DBUG_N macros, needs two calls to runtime
X * support routines. The first, this function, remembers arguments
X * that are used by the subsequent call to _db_doprnt_().
X*
X */
X
XVOID _db_pargs_ (_line_, keyword)
Xint _line_;
Xchar *keyword;
X{
X u_line = _line_;
X u_keyword = keyword;
X}
X
X
X/*
X * FUNCTION
X *
X * _db_doprnt_ handle print of debug lines
X *
X * SYNOPSIS
X *
X * VOID _db_doprnt_ (format, ARGLIST)
X * char *format;
X * long ARGLIST;
X *
X * DESCRIPTION
X *
X * When invoked via one of the DBUG macros, tests the current keyword
X * set by calling _db_pargs_() to see if that macro has been selected
X * for processing via the debugger control string, and if so, handles
X * printing of the arguments via the format string. The line number
X * of the DBUG macro in the source is found in u_line.
X *
X * Note that the format string SHOULD NOT include a terminating
X * newline, this is supplied automatically.
X *
X * NOTES
X *
X * This runtime support routine replaces the older _db_printf_()
X * routine which is temporarily kept around for compatibility.
X *
X * The rather ugly argument declaration is to handle some
X * magic with respect to the number of arguments passed
X * via the DBUG macros. The current maximum is 3 arguments
X * (not including the keyword and format strings).
X *
X * The new <varargs.h> facility is not yet common enough to
X * convert to it quite yet...
X *
X */
X
X/*VARARGS1*/
XVOID _db_doprnt_ (format, ARGLIST)
Xchar *format;
Xlong ARGLIST;
X{
X if (_db_keyword_ (u_keyword)) {
X DoPrefix (u_line);
X if (TRACING) {
X Indent (stack -> level + 1);
X } else {
X (VOID) fprintf (_db_fp_, "%s: ", func);
X }
X (VOID) fprintf (_db_fp_, "%s: ", u_keyword);
X (VOID) fprintf (_db_fp_, format, ARGLIST);
X (VOID) fprintf (_db_fp_, "\n");
X (VOID) fflush (_db_fp_);
X (VOID) XDelay (stack -> delay);
X }
X}
X
X/*
X * The following routine is kept around temporarily for compatibility
X * with older objects that were compiled with the DBUG_N macro form
X * of the print routine. It will print a warning message on first
X * usage. It will go away in subsequent releases...
X */
X
X/*VARARGS3*/
XVOID _db_printf_ (_line_, keyword, format, ARGLIST)
Xint _line_;
Xchar *keyword, *format;
Xlong ARGLIST;
X{
X static BOOLEAN firsttime = TRUE;
X
X if (firsttime) {
X (VOID) fprintf (stderr, ERR_PRINTF, _db_process_, file);
X firsttime = FALSE;
X }
X _db_pargs_ (_line_, keyword);
X _db_doprnt_ (format, ARGLIST);
X}
X
X
X/*
X * FUNCTION
X *
X * ListParse parse list of modifiers in debug control string
X *
X * SYNOPSIS
X *
X * LOCAL struct link *ListParse (ctlp)
X * char *ctlp;
X *
X * DESCRIPTION
X *
X * Given pointer to a comma separated list of strings in "cltp",
X * parses the list, building a list and returning a pointer to it.
X * The original comma separated list is destroyed in the process of
X * building the linked list, thus it had better be a duplicate
X * if it is important.
X *
X * Note that since each link is added at the head of the list,
X * the final list will be in "reverse order", which is not
X * significant for our usage here.
X *
X */
X
XLOCAL struct link *ListParse (ctlp)
Xchar *ctlp;
X{
X REGISTER char *start;
X REGISTER struct link *new;
X REGISTER struct link *head;
X
X head = NULL;
X while (*ctlp != EOS) {
X start = ctlp;
X while (*ctlp != EOS && *ctlp != ',') {
X ctlp++;
X }
X if (*ctlp == ',') {
X *ctlp++ = EOS;
X }
X new = (struct link *) DbugMalloc (sizeof (struct link));
X new -> string = StrDup (start);
X new -> next_link = head;
X head = new;
X }
X return (head);
X}
X
X
X/*
X * FUNCTION
X *
X * InList test a given string for member of a given list
X *
X * SYNOPSIS
X *
X * LOCAL BOOLEAN InList (linkp, cp)
X * struct link *linkp;
X * char *cp;
X *
X * DESCRIPTION
X *
X * Tests the string pointed to by "cp" to determine if it is in
X * the list pointed to by "linkp". Linkp points to the first
X * link in the list. If linkp is NULL then the string is treated
X * as if it is in the list (I.E all strings are in the null list).
X * This may seem rather strange at first but leads to the desired
X * operation if no list is given. The net effect is that all
X * strings will be accepted when there is no list, and when there
X * is a list, only those strings in the list will be accepted.
X *
X */
X
XLOCAL BOOLEAN InList (linkp, cp)
Xstruct link *linkp;
Xchar *cp;
X{
X REGISTER struct link *scan;
X REGISTER BOOLEAN accept;
X
X if (linkp == NULL) {
X accept = TRUE;
X } else {
X accept = FALSE;
X for (scan = linkp; scan != NULL; scan = scan -> next_link) {
X if (STREQ (scan -> string, cp)) {
X accept = TRUE;
X break;
X }
X }
X }
X return (accept);
X}
X
X
X/*
X * FUNCTION
X *
X * PushState push current state onto stack and set up new one
X *
X * SYNOPSIS
X *
X * LOCAL VOID PushState ()
X *
X * DESCRIPTION
X *
X * Pushes the current state on the state stack, and initializes
X * a new state. The only parameter inherited from the previous
X * state is the function nesting level. This action can be
X * inhibited if desired, via the "r" flag.
X *
X * The state stack is a linked list of states, with the new
X * state added at the head. This allows the stack to grow
X * to the limits of memory if necessary.
X *
X */
X
XLOCAL VOID PushState ()
X{
X REGISTER struct state *new;
X
X new = (struct state *) DbugMalloc (sizeof (struct state));
X new -> flags = 0;
X new -> delay = 0;
X new -> maxdepth = MAXDEPTH;
X if (stack != NULL) {
X new -> level = stack -> level;
X } else {
X new -> level = 0;
X }
X new -> out_file = stderr;
X new -> functions = NULL;
X new -> p_functions = NULL;
X new -> keywords = NULL;
X new -> processes = NULL;
X new -> next_state = stack;
X stack = new;
X init_done = TRUE;
X}
X
X
X/*
X * FUNCTION
X *
X * DoTrace check to see if tracing is current enabled
X *
X * SYNOPSIS
X *
X * LOCAL BOOLEAN DoTrace ()
X *
X * DESCRIPTION
X *
X * Checks to see if tracing is enabled based on whether the
X * user has specified tracing, the maximum trace depth has
X * not yet been reached, the current function is selected,
X * and the current process is selected. Returns TRUE if
X * tracing is enabled, FALSE otherwise.
X *
X */
X
XLOCAL BOOLEAN DoTrace ()
X{
X REGISTER BOOLEAN trace;
X
X trace = FALSE;
X if (TRACING) {
X if (stack -> level <= stack -> maxdepth) {
X if (InList (stack -> functions, func)) {
X if (InList (stack -> processes, _db_process_)) {
X trace = TRUE;
X }
X }
X }
X }
X return (trace);
X}
X
X
X/*
X * FUNCTION
X *
X * DoProfile check to see if profiling is current enabled
X *
X * SYNOPSIS
X *
X * LOCAL BOOLEAN DoProfile ()
X *
X * DESCRIPTION
X *
X * Checks to see if profiling is enabled based on whether the
X * user has specified profiling, the maximum trace depth has
X * not yet been reached, the current function is selected,
X * and the current process is selected. Returns TRUE if
X * profiling is enabled, FALSE otherwise.
X *
X */
X
XLOCAL BOOLEAN DoProfile ()
X{
X REGISTER BOOLEAN profile;
X
X profile = FALSE;
X if (PROFILING) {
X if (stack -> level <= stack -> maxdepth) {
X if (InList (stack -> p_functions, func)) {
X if (InList (stack -> processes, _db_process_)) {
X profile = TRUE;
X }
X }
X }
X }
X return (profile);
X}
X
X
X/*
X * FUNCTION
X *
X * _db_keyword_ test keyword for member of keyword list
X *
X * SYNOPSIS
X *
X * BOOLEAN _db_keyword_ (keyword)
X * char *keyword;
X *
X * DESCRIPTION
X *
X * Test a keyword to determine if it is in the currently active
X * keyword list. As with the function list, a keyword is accepted
X * if the list is null, otherwise it must match one of the list
X * members. When debugging is not on, no keywords are accepted.
X * After the maximum trace level is exceeded, no keywords are
X * accepted (this behavior subject to change). Additionally,
X * the current function and process must be accepted based on
X * their respective lists.
X *
X * Returns TRUE if keyword accepted, FALSE otherwise.
X *
X */
X
XBOOLEAN _db_keyword_ (keyword)
Xchar *keyword;
X{
X REGISTER BOOLEAN accept;
X
X if (!init_done) {
X _db_push_ ("");
X }
X accept = FALSE;
X if (DEBUGGING) {
X if (stack -> level <= stack -> maxdepth) {
X if (InList (stack -> functions, func)) {
X if (InList (stack -> keywords, keyword)) {
X if (InList (stack -> processes, _db_process_)) {
X accept = TRUE;
X }
X }
X }
X }
X }
X return (accept);
X}
X
X
X/*
X * FUNCTION
X *
X * Indent indent a line to the given indentation level
X *
X * SYNOPSIS
X *
X * LOCAL VOID Indent (indent)
X * int indent;
X *
X * DESCRIPTION
X *
X * Indent a line to the given level. Note that this is
X * a simple minded but portable implementation.
X * There are better ways.
X *
X * Also, the indent must be scaled by the compile time option
X * of character positions per nesting level.
X *
X */
X
XLOCAL VOID Indent (indent)
Xint indent;
X{
X REGISTER int count;
X AUTO char buffer[PRINTBUF];
X
X indent *= INDENT;
X for (count = 0; (count < (indent - INDENT)) && (count < (PRINTBUF - 1)); count++) {
X if ((count % INDENT) == 0) {
X buffer[count] = '|';
X } else {
X buffer[count] = ' ';
X }
X }
X buffer[count] = EOS;
X (VOID) fprintf (_db_fp_, buffer);
X (VOID) fflush (_db_fp_);
X}
X
X
X/*
X * FUNCTION
X *
X * FreeList free all memory associated with a linked list
X *
X * SYNOPSIS
X *
X * LOCAL VOID FreeList (linkp)
X * struct link *linkp;
X *
X * DESCRIPTION
X *
X * Given pointer to the head of a linked list, frees all
X * memory held by the list and the members of the list.
X *
X */
X
XLOCAL VOID FreeList (linkp)
Xstruct link *linkp;
X{
X REGISTER struct link *old;
X
X while (linkp != NULL) {
X old = linkp;
X linkp = linkp -> next_link;
X if (old -> string != NULL) {
X free (old -> string);
X }
X free ((char *) old);
X }
X}
X
X
X/*
X * FUNCTION
X *
X * StrDup make a duplicate of a string in new memory
X *
X * SYNOPSIS
X *
X * LOCAL char *StrDup (string)
X * char *string;
X *
X * DESCRIPTION
X *
X * Given pointer to a string, allocates sufficient memory to make
X * a duplicate copy, and copies the string to the newly allocated
X * memory. Failure to allocated sufficient memory is immediately
X * fatal.
X *
X */
X
X
XLOCAL char *StrDup (string)
Xchar *string;
X{
X REGISTER char *new;
X
X new = DbugMalloc (strlen (string) + 1);
X (VOID) strcpy (new, string);
X return (new);
X}
X
X
X/*
X * FUNCTION
X *
X * DoPrefix print debugger line prefix prior to indentation
X *
X * SYNOPSIS
X *
X * LOCAL VOID DoPrefix (_line_)
X * int _line_;
X *
X * DESCRIPTION
X *
X * Print prefix common to all debugger output lines, prior to
X * doing indentation if necessary. Print such information as
X * current process name, current source file name and line number,
X * and current function nesting depth.
X *
X */
X
X
XLOCAL VOID DoPrefix (_line_)
Xint _line_;
X{
X lineno++;
X if (stack -> flags & NUMBER_ON) {
X (VOID) fprintf (_db_fp_, "%5d: ", lineno);
X }
X if (stack -> flags & PROCESS_ON) {
X (VOID) fprintf (_db_fp_, "%s: ", _db_process_);
X }
X if (stack -> flags & FILE_ON) {
X (VOID) fprintf (_db_fp_, "%14s: ", file);
X }
X if (stack -> flags & LINE_ON) {
X (VOID) fprintf (_db_fp_, "%5d: ", _line_);
X }
X if (stack -> flags & DEPTH_ON) {
X (VOID) fprintf (_db_fp_, "%4d: ", stack -> level);
X }
X (VOID) fflush (_db_fp_);
X}
X
X
X/*
X * FUNCTION
X *
X * OpenFile open new output stream for debugger output
X *
X * SYNOPSIS
X *
X * LOCAL VOID OpenFile (name)
X * char *name;
X *
X * DESCRIPTION
X *
X * Given name of a new file (or "-" for stdout) opens the file
X * and sets the output stream to the new file.
X *
X */
X
XLOCAL VOID OpenFile (name)
Xchar *name;
X{
X REGISTER FILE *fp;
X REGISTER BOOLEAN newfile;
X
X if (name != NULL) {
X if (strcmp (name, "-") == 0) {
X _db_fp_ = stdout;
X stack -> out_file = _db_fp_;
X } else {
X if (!Writable (name)) {
X (VOID) fprintf (_db_fp_, ERR_OPEN, _db_process_, name);
X perror ("");
X (VOID) fflush (_db_fp_);
X (VOID) XDelay (stack -> delay);
X } else {
X if (EXISTS (name)) {
X newfile = FALSE;
X } else {
X newfile = TRUE;
X }
X fp = fopen (name, "a");
X if (fp == NULL) {
X (VOID) fprintf (_db_fp_, ERR_OPEN, _db_process_, name);
X perror ("");
X (VOID) fflush (_db_fp_);
X (VOID) XDelay (stack -> delay);
X } else {
X _db_fp_ = fp;
X stack -> out_file = fp;
X if (newfile) {
X ChangeOwner (name);
X }
X }
X }
X }
X }
X}
X
X
X/*
X * FUNCTION
X *
X * OpenProfile open new output stream for profiler output
X *
X * SYNOPSIS
X *
X * LOCAL VOID OpenProfile (name)
X * char *name;
X *
X * DESCRIPTION
X *
X * Given name of a new file, opens the file
X * and sets the profiler output stream to the new file.
X *
X * It is currently unclear whether the prefered behavior is
X * to truncate any existing file, or simply append to it.
X * The latter behavior would be desirable for collecting
X * accumulated runtime history over a number of separate
X * runs. It might take some changes to the analyzer program
X * though, and the notes that Binayak sent with the profiling
X * diffs indicated that append was the normal mode, but this
X * does not appear to agree with the actual code. I haven't
X * investigated at this time [fnf; 24-Jul-87].
X */
X
XLOCAL VOID OpenProfile (name)
Xchar *name;
X{
X REGISTER FILE *fp;
X REGISTER BOOLEAN newfile;
X
X if (name != NULL) {
X if (!Writable (name)) {
X (VOID) fprintf (_db_fp_, ERR_OPEN, _db_process_, name);
X perror ("");
X (VOID) fflush (_db_fp_);
X (VOID) XDelay (stack -> delay);
X } else {
X if (EXISTS (name)) {
X newfile = FALSE;
X } else {
X newfile = TRUE;
X }
X fp = fopen (name, "w");
X if (fp == NULL) {
X (VOID) fprintf (_db_fp_, ERR_OPEN, _db_process_, name);
X perror ("");
X (VOID) fflush (_db_fp_);
X (VOID) XDelay (stack -> delay);
X } else {
X _db_pfp_ = fp;
X stack -> prof_file = fp;
X if (newfile) {
X ChangeOwner (name);
X }
X }
X }
X }
X}
X
X
X/*
X * FUNCTION
X *
X * CloseFile close the debug output stream
X *
X * SYNOPSIS
X *
X * LOCAL VOID CloseFile (fp)
X * FILE *fp;
X *
X * DESCRIPTION
X *
X * Closes the debug output stream unless it is standard output
X * or standard error.
X *
X */
X
XLOCAL VOID CloseFile (fp)
XFILE *fp;
X{
X if (fp != stderr && fp != stdout) {
X if (fclose (fp) == EOF) {
X (VOID) fprintf (stderr, ERR_CLOSE, _db_process_);
X perror ("");
X (VOID) fflush (stderr);
X (VOID) XDelay (stack -> delay);
X }
X }
X}
X
X
X/*
X * FUNCTION
X *
X * DbugExit print error message and exit
X *
X * SYNOPSIS
X *
X * LOCAL VOID DbugExit (why)
X * char *why;
X *
X * DESCRIPTION
X *
X * Prints error message using current process name, the reason for
X * aborting (typically out of memory), and exits with status 1.
X * This should probably be changed to use a status code
X * defined in the user's debugger include file.
X *
X */
X
XLOCAL VOID DbugExit (why)
Xchar *why;
X{
X (VOID) fprintf (stderr, ERR_ABORT, _db_process_, why);
X (VOID) fflush (stderr);
X (VOID) XDelay (stack -> delay);
X exit (1);
X}
X
X
X/*
X * FUNCTION
X *
X * DbugMalloc allocate memory for debugger runtime support
X *
X * SYNOPSIS
X *
X * LOCAL char *DbugMalloc (size)
X * int size;
X *
X * DESCRIPTION
X *
X * Allocate more memory for debugger runtime support functions.
X * Failure to to allocate the requested number of bytes is
X * immediately fatal to the current process. This may be
X * rather unfriendly behavior. It might be better to simply
X * print a warning message, freeze the current debugger state,
X * and continue execution.
X *
X */
X
XLOCAL char *DbugMalloc (size)
Xint size;
X{
X register char *new;
X
X new = malloc ( size );
X if (new == NULL) {
X DbugExit ("out of memory");
X }
X return (new);
X}
X
X
X/*
X * This function may be eliminated when strtok is available
X * in the runtime environment (missing from BSD4.1).
X */
X
XLOCAL char *strtok (s1, s2)
Xchar *s1, *s2;
X{
X static char *end = NULL;
X REGISTER char *rtnval;
X
X rtnval = NULL;
X if (s2 != NULL) {
X if (s1 != NULL) {
X end = s1;
X rtnval = strtok ((char *) NULL, s2);
X } else if (end != NULL) {
X if (*end != EOS) {
X rtnval = end;
X while (*end != *s2 && *end != EOS) {end++;}
X if (*end != EOS) {
X *end++ = EOS;
X }
X }
X }
X }
X return (rtnval);
X}
X
X
X/*
X * FUNCTION
X *
X * BaseName strip leading pathname components from name
X *
X * SYNOPSIS
X *
X * LOCAL char *BaseName (pathname)
X * char *pathname;
X *
X * DESCRIPTION
X *
X * Given pointer to a complete pathname, locates the base file
X * name at the end of the pathname and returns a pointer to
X * it.
X *
X */
X
XLOCAL char *BaseName (pathname)
Xchar *pathname;
X{
X register char *base;
X
X base = strrchr (pathname, '/');
X if (base++ == NULL) {
X base = pathname;
X }
X return (base);
X}
X
X
X/*
X * FUNCTION
X *
X * Writable test to see if a pathname is writable/creatable
X *
X * SYNOPSIS
X *
X * LOCAL BOOLEAN Writable (pathname)
X * char *pathname;
X *
X * DESCRIPTION
X *
X * Because the debugger might be linked in with a program that
X * runs with the set-uid-bit (suid) set, we have to be careful
X * about opening a user named file for debug output. This consists
X * of checking the file for write access with the real user id,
X * or checking the directory where the file will be created.
X *
X * Returns TRUE if the user would normally be allowed write or
X * create access to the named file. Returns FALSE otherwise.
X *
X */
X
XLOCAL BOOLEAN Writable (pathname)
Xchar *pathname;
X{
X REGISTER BOOLEAN granted;
X#ifdef unix
X REGISTER char *lastslash;
X#endif
X
X#ifndef unix
X granted = TRUE;
X#else
X granted = FALSE;
X if (EXISTS (pathname)) {
X if (WRITABLE (pathname)) {
X granted = TRUE;
X }
X } else {
X lastslash = strrchr (pathname, '/');
X if (lastslash != NULL) {
X *lastslash = EOS;
X } else {
X pathname = ".";
X }
X if (WRITABLE (pathname)) {
X granted = TRUE;
X }
X if (lastslash != NULL) {
X *lastslash = '/';
X }
X }
X#endif
X return (granted);
X}
X
X
X/*
X * This function may be eliminated when strrchr is available
X * in the runtime environment (missing from BSD4.1).
X * Alternately, you can use rindex() on BSD systems.
X */
X
XLOCAL char *strrchr (s, c)
Xchar *s;
Xchar c;
X{
X REGISTER char *scan;
X
X for (scan = s; *scan != EOS; scan++) {;}
X while (scan > s && *--scan != c) {;}
X if (*scan != c) {
X scan = NULL;
X }
X return (scan);
X}
X
X
X/*
X * FUNCTION
X *
X * ChangeOwner change owner to real user for suid programs
X *
X * SYNOPSIS
X *
X * LOCAL VOID ChangeOwner (pathname)
X *
X * DESCRIPTION
X *
X * For unix systems, change the owner of the newly created debug
X * file to the real owner. This is strictly for the benefit of
X * programs that are running with the set-user-id bit set.
X *
X * Note that at this point, the fact that pathname represents
X * a newly created file has already been established. If the
X * program that the debugger is linked to is not running with
X * the suid bit set, then this operation is redundant (but
X * harmless).
X *
X */
X
XLOCAL VOID ChangeOwner (pathname)
Xchar *pathname;
X{
X#ifdef unix
X if (chown (pathname, getuid (), getgid ()) == -1) {
X (VOID) fprintf (stderr, ERR_CHOWN, _db_process_, pathname);
X perror ("");
X (VOID) fflush (stderr);
X (VOID) XDelay (stack -> delay);
X }
X#endif
X}
X
X
X/*
X * FUNCTION
X *
X * _db_setjmp_ save debugger environment
X *
X * SYNOPSIS
X *
X * VOID _db_setjmp_ ()
X *
X * DESCRIPTION
X *
X * Invoked as part of the user's DBUG_SETJMP macro to save
X * the debugger environment in parallel with saving the user's
X * environment.
X *
X */
X
XVOID _db_setjmp_ ()
X{
X jmplevel = stack -> level;
X jmpfunc = func;
X jmpfile = file;
X}
X
X
X/*
X * FUNCTION
X *
X * _db_longjmp_ restore previously saved debugger environment
X *
X * SYNOPSIS
X *
X * VOID _db_longjmp_ ()
X *
X * DESCRIPTION
X *
X * Invoked as part of the user's DBUG_LONGJMP macro to restore
X * the debugger environment in parallel with restoring the user's
X * previously saved environment.
X *
X */
X
XVOID _db_longjmp_ ()
X{
X stack -> level = jmplevel;
X if (jmpfunc) {
X func = jmpfunc;
X }
X if (jmpfile) {
X file = jmpfile;
X }
X}
X
X
X/*
X * FUNCTION
X *
X * DelayArg convert D flag argument to appropriate value
X *
X * SYNOPSIS
X *
X * LOCAL int DelayArg (value)
X * int value;
X *
X * DESCRIPTION
X *
X * Converts delay argument, given in tenths of a second, to the
X * appropriate numerical argument used by the system to delay
X * that that many tenths of a second. For example, on the
X * AMIGA, there is a system call "Delay()" which takes an
X * argument in ticks (50 per second). On unix, the sleep
X * command takes seconds. Thus a value of "10", for one
X * second of delay, gets converted to 50 on the amiga, and 1
X * on unix. Other systems will need to use a timing loop.
X *
X */
X
XLOCAL int DelayArg (value)
Xint value;
X{
X int delayarg = 0;
X
X#ifdef unix
X delayarg = value / 10; /* Delay is in seconds for sleep () */
X#endif
X#ifdef AMIGA
X delayarg = (HZ * value) / 10; /* Delay in ticks for XDelay () */
X#endif
X return (delayarg);
X}
X
X
X/*
X * A dummy delay stub for systems that do not support delays.
X * With a little work, this can be turned into a timing loop.
X */
X
X#ifndef unix
X#ifndef AMIGA
XXDelay ()
X{
X}
X#endif
X#endif
X
X
X/*
X * FUNCTION
X *
X * perror perror simulation for systems that don't have it
X *
X * SYNOPSIS
X *
X * LOCAL VOID perror (s)
X * char *s;
X *
X * DESCRIPTION
X *
X * Perror produces a message on the standard error stream which
X * provides more information about the library or system error
X * just encountered. The argument string s is printed, followed
X * by a ':', a blank, and then a message and a newline.
X *
X * An undocumented feature of the unix perror is that if the string
X * 's' is a null string (NOT a NULL pointer!), then the ':' and
X * blank are not printed.
X *
X * This version just complains about an "unknown system error".
X *
X */
X
X#if !unix && !(AMIGA && LATTICE)
XLOCAL VOID perror (s)
X#ifdef __STDC__
Xconst char *s;
X#else
Xchar *s;
X#endif
X{
X if (s && *s != EOS) {
X (VOID) fprintf (stderr, "%s: ", s);
X }
X (VOID) fprintf (stderr, "<unknown system error>\n");
X}
X#endif /* !unix && !(AMIGA && LATTICE) */
X
X/*
X * Here we need the definitions of the clock routine. Add your
X * own for whatever system that you have.
X */
X
X#if unix
X
X# include <sys/param.h>
X# if BSD4_3 || sun
X
X/*
X * Definition of the Clock() routine for 4.3 BSD.
X */
X
X#include <sys/time.h>
X#include <sys/resource.h>
X
X/*
X * Returns the user time in milliseconds used by this process so
X * far.
X */
X
XLOCAL unsigned long Clock ()
X{
X struct rusage ru;
X
X (VOID) getrusage (RUSAGE_SELF, &ru);
X return ((ru.ru_utime.tv_sec * 1000) + (ru.ru_utime.tv_usec / 1000));
X}
X
X#else
X
XLOCAL unsigned long Clock ()
X{
X return (0);
X}
X
X# endif
X
X#else
X
X#if AMIGA
X
Xstruct DateStamp { /* Yes, this is a hack, but doing it right */
X long ds_Days; /* is incredibly ugly without splitting this */
X long ds_Minute; /* off into a separate file */
X long ds_Tick;
X};
X
Xstatic int first_clock = TRUE;
Xstatic struct DateStamp begin;
Xstatic struct DateStamp elapsed;
X
XLOCAL unsigned long Clock ()
X{
X register struct DateStamp *now;
X register unsigned long millisec = 0;
X extern VOID *AllocMem ();
X
X now = (struct DateStamp *) AllocMem ((long) sizeof (struct DateStamp), 0L);
X if (now != NULL) {
X if (first_clock == TRUE) {
X first_clock = FALSE;
X (VOID) DateStamp (now);
X begin = *now;
X }
X (VOID) DateStamp (now);
X millisec = 24 * 3600 * (1000 / HZ) * (now -> ds_Days - begin.ds_Days);
X millisec += 60 * (1000 / HZ) * (now -> ds_Minute - begin.ds_Minute);
X millisec += (1000 / HZ) * (now -> ds_Tick - begin.ds_Tick);
X (VOID) FreeMem (now, (long) sizeof (struct DateStamp));
X }
X return (millisec);
X}
X
X#else
X
XLOCAL unsigned long Clock ()
X{
X return (0);
X}
X
X#endif /* AMIGA */
X
X#endif /* unix */
X
X#ifdef AMIGA
XXDelay(x)
Xint x;
X{
X if (x) Delay(x); /* fix Delay bug in AmigaDOS */
X}
X#endif
X
SHAR_EOF
echo "File common/dbug.c is complete"
chmod 0440 common/dbug.c || echo "restore of common/dbug.c fails"
echo "x - extracting common/db.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > common/db.h &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/common/RCS/db.h,v 1.1 90/10/06 12:04:41 dvadura Exp $
X-- SYNOPSIS -- front end to DBUG macros.
X--
X-- DESCRIPTION
X-- This is a front end to Fred Fish's DBUG macros. The intent was
X-- to provide an interface so that if you don't have the DBUG code
X-- you can still compile dmake, by undefining DBUG, if you do have
X-- the code then you can use Fred Fish's DBUG package. Originally
X-- the DBUG stuff was copyrighted, it is now in the public domain
X-- so the need for this is not as apparent.
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: db.h,v $
X * Revision 1.1 90/10/06 12:04:41 dvadura
X * dmake Release, Version 3.6
X *
X*/
X
X#ifndef DB_h
X#define DB_h
X
X#ifdef DBUG
X
X# include <stdio.h>
X# include <dbug.h>
X
X# define DB_ENTER(a1) DBUG_ENTER(a1)
X# define DB_RETURN(a1) DBUG_RETURN(a1)
X# define DB_VOID_RETURN DBUG_VOID_RETURN
X# define DB_EXECUTE(keyword, a1) DBUG_EXECUTE(keyword,a1)
X# define DB_PRINT(keyword,arglist) DBUG_PRINT(keyword,arglist)
X# define DB_PUSH(a1) DBUG_PUSH(a1)
X# define DB_POP() DBUG_POP()
X# define DB_PROCESS(a1) DBUG_PROCESS(a1)
X# define DB_FILE (stderr) DBUG_FILE(stderr)
X# define DB_SETJMP DBUG_SETJMP
X# define DB_LONGJMP DBUG_LONGJMP
X
X#else
X
X# define DB_ENTER(a1)
X# define DB_RETURN(a1) return (a1)
X# define DB_VOID_RETURN return
X# define DB_EXECUTE(keyword, a1)
X# define DB_PRINT(keyword,arglist)
X# define DB_PUSH(a1)
X# define DB_POP()
X# define DB_PROCESS(a1)
X# define DB_FILE(stderr)
X# define DB_SETJMP setjmp
X# define DB_LONGJMP longjmp
X
X#endif
X#endif
X
SHAR_EOF
chmod 0440 common/db.h || echo "restore of common/db.h fails"
echo "x - extracting common/alloc.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > common/alloc.h &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/common/RCS/alloc.h,v 1.1 90/10/06 12:04:39 dvadura Exp $
X-- SYNOPSIS -- macros for allocating memory.
X--
X-- DESCRIPTION
X-- A somewhat nicer interface to malloc and calloc.
X-- Here we standardise the calling convention with a common macro
X-- interface.
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: alloc.h,v $
X * Revision 1.1 90/10/06 12:04:39 dvadura
X * dmake Release, Version 3.6
X *
X*/
X
X#ifndef ALLOC_h
X#define ALLOC_h
X
X/* DO NOT CHANGE these! These are the definitions that the make source
X * uses for allocating memory. They must be defined for make to compile
X * properly.
X */
X
X#if !defined(_TYPES_) && !defined(M_XENIX)
X#if defined(MSDOS) || defined(__MSDOS__)
Xtypedef unsigned size_t;
X#else
Xtypedef long size_t;
X#endif
X#endif
X
X#define usizeof(t) (size_t)sizeof(t)
X
X#ifdef DBUG
X#define FREE(p) My_free((char*)(p), __FILE__, __LINE__)
X#define MALLOC(n, t) (t*) My_malloc((n)*usizeof(t), __FILE__, __LINE__)
X#define CALLOC(n, t) (t*) My_calloc((n), usizeof(t), __FILE__, __LINE__)
X#else
X#define FREE(p) free((char*)(p))
X#define MALLOC(n, t) (t*) malloc((unsigned int)(n)*usizeof(t))
X#define CALLOC(n, t) (t*) calloc((unsigned int)(n), usizeof(t))
X#endif
X
X#define TALLOC(p, n, t) if ((p = CALLOC(n, t)) == (t*)0) {No_ram();}
X
X#endif
X
SHAR_EOF
chmod 0440 common/alloc.h || echo "restore of common/alloc.h fails"
echo "x - extracting basename.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > basename.c &&
X/* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/basename.c,v 1.1 90/10/06 12:03:31 dvadura Exp $
X-- SYNOPSIS -- return pointer to last pathname component
X--
X-- DESCRIPTION
X-- take a file name like /fred/foo/hoe/mary.k, and return the 'mary.k'
X-- portion
X--
X-- AUTHOR
X-- Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X-- CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X-- Copyright (c) 1990 by Dennis Vadura. All rights reserved.
X--
X-- This program is free software; you can redistribute it and/or
X-- modify it under the terms of the GNU General Public License
X-- (version 1), as published by the Free Software Foundation, and
X-- found in the file 'LICENSE' included with this distribution.
X--
X-- This program is distributed in the hope that it will be useful,
X-- but WITHOUT ANY WARRANTY; without even the implied warrant of
X-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X-- GNU General Public License for more details.
X--
X-- You should have received a copy of the GNU General Public License
X-- along with this program; if not, write to the Free Software
X-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X-- $Log: basename.c,v $
X * Revision 1.1 90/10/06 12:03:31 dvadura
X * dmake Release, Version 3.6
X *
X*/
X
X#include <string.h>
X#include "extern.h"
X
Xchar*
Xbasename( path )
Xchar *path;
X{
X char *p;
X char *q;
X
X if( *(q = path) ) {
X for(; *(p=_strpbrk(q, DirBrkStr)) != '\0'; q = p+1 );
X if( !*q ) {
X for( p=q-1; p != path; --p )
X if( strchr( DirBrkStr, *p ) == NIL(char) ) return( p+1 );
X return( strchr(DirBrkStr, *p)?path:(p+1) );
X }
X path = q;
X }
X return( path );
X}
SHAR_EOF
chmod 0440 basename.c || echo "restore of basename.c fails"
echo "x - extracting _updctl (Text)"
sed 's/^X//' << 'SHAR_EOF' > _updctl &&
SHAR_EOF
chmod 0640 _updctl || echo "restore of _updctl fails"
echo "x - extracting _install (Text)"
sed 's/^X//' << 'SHAR_EOF' > _install &&
XINSTALLATION INSTRUCTIONS
X
XThis file contains the instructions required to install and create the
Xappropriate version of dmake.
X
X
XMAKING THE PROPER VERSION
X
XIn order to use dmake you must first make the correct version. As shipped
Xthere exist several versions that you can make:
X
X bsd43 - Generic BSD 4.3 (eg, true BSD, apollo, sun OS4, SGI etc)
X bsd43uw - Generic BSD 4.3 at U of Waterloo
X bsd43vf - Generic BSD with no vfprintf in its library (use this
X target if you are missing vfprintf function in your
X C library)
X sysvr3 - Generic SysV R3 UNIX
X sysvr1 - Generic SysV R1 UNIX
X 386ix - 386/ix (SysV R3), not tested
X dynix - Sequent Symmetry dynix
X ultrix - Ultrix 3.0 system
X mips - Any MIPS box
X tcc - DOS with tcc 2.0"
X tccswp - swapping DOS version with tcc 2.0"
X msc - DOS with MSC 4.0 to 5.1"
X msc60 - DOS with MSC 6.0"
X mscswp - swapping DOS version with MSC 4.0 to 5.1"
X msc60swp - swapping DOS version with MSC 6.0"
X
XThe file 'makefile' understands these targets and runs the appropriate script
Xto create the correct version.
X
XThe source code is organized as follows:
X
X dmake [source for all common functions]
X |
X |
X -----------
X | |
X unix msdos [source for OS specific functions]
X | |
X ---------------------- -------------
X | | | | |
X386ix bsd43 sysvr3 tccdos mscdos [source for OSRELEASE specific
X | functions]
X --------
X | |
X uw vf
X
X
XEach of the directories (eg. bsd43, mscdos, tccdos, and sysvr3) contain source
Xthat is specific to that release of the OS (and possibly C-library)
XTo make the apropriate versions of dmake, simply type the command
X
X 'make system'
X
Xwhere system is one of the supplied possibilities. For a complete list
Xof the versions you can make, see the comments in the file 'makefile', or
Xtype 'make'.
X
XThe bootstrapping of dmake is accomplished by running a shell script with the
Xappropriate compile commands hard coded.
X
X(NOTE: If you are using MSDOS then, you will actually be using the make.bat
X scriptfile to make the correct version of dmake for MSDOS. If you
X are running a SHELL other than command.com, you may have to perform
X some extra work to invoke the batch file.
X
X Make sure you read the _readme.dos file before attempting to make the
X MSDOS version, as it contains important configuration and limitation
X information.)
X
XThe making of dmake, echoes the commands being executed, and should proceed
SHAR_EOF
echo "End of part 24"
echo "File _install is continued in part 25"
echo "25" > s2_seq_.tmp
exit 0