|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 5149 (0x141d)
Types: TextFile
Names: »util.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
└─⟦e10a7c8ba⟧ »./UNRELEASED/xgdb.tar.Z«
└─⟦ae30648b5⟧
└─⟦this⟧ »./util.c«
#ifndef lint
\f
static char rcsid[] = "$Header: util.c,v 1.1 89/07/05 15:36:57 hubbard Exp $";
#endif
/*
*
* Copyright 1988, 1989
* PCS Computer Systeme, GmbH
* Munich, West Germany
*
* All rights reserved.
*
* This is unsupported software and is subject to change without notice.
* PCS makes no representations about the suitability of this software
* for any purpose. It is supplied "as is" without express or implied
* warranty.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of PCS Computer Systeme not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
*/
/*
* Author: Jordan K. Hubbard
* For: PCS Computer Systems, GmbH.
* When: February 10th, 1989.
*
* $Log: util.c,v $
* Revision 1.1 89/07/05 15:36:57 hubbard
* Initial revision
*
*
*/
/*
* General utility routines. Some stuff for printing arbitrary error
* messages. Nothing in here should be xgdb specific though the existance
* of a few initialized globals (like program_name) is assumed.
*/
#include <varargs.h>
#include "xgdb.h"
/*
* Puke out an error message. Assumes that the global char* "program_name"
* is pointing to something meaningful.
*/
/* VARARGS */
int puke(fmt, va_alist)
String fmt;
va_dcl
{
void ctrl();
va_list ap;
va_start(ap);
fprintf(stderr, "%s: ", program_name);
_output(stderr, fmt, ap);
va_end(ap);
}
/*
* Puke, then die.
*/
/* VARARGS */
void puke_and_die(fmt, va_alist)
String fmt;
va_dcl
{
va_list ap;
va_start(ap);
_output(stderr, fmt, ap);
exit(1);
}
/*
* Output a debugging message.
*/
/* VARARGS */
debug(fmt, va_alist)
String fmt;
va_dcl
{
va_list ap;
static FILE *dbug = NULL;
va_start(ap);
if (!dbug) {
char template[18];
char *tmp;
strcpy(template, "/tmp/xgdbXXXXXX");
tmp = (char *)mktemp(template);
dbug = fopen(tmp, "w");
if (!dbug)
puke_and_die("debug: Can't open logging file '%s'", tmp);
}
_output(dbug, fmt, ap);
}
/*
* Allows for variable length error messages. A pity to have to
* replicate most of printf's work, but there's no other way to do
* this easily. Right now, only simple integers, strings, characters
* and floats are supported. No widths, no padding or filling. Such
* features make little sense for a simple error message utility anyway.
* An additional control '%p' is implemented for printing the name
* of the current function. Since _output isn't called directly, we assume
* that the address of the parameters has already been initialized properly
* by the calling function (thus we don't call va_start()).
*/
int _output(file, fmt, ap)
FILE *file;
String fmt;
va_list ap;
{
register String cp;
register char ch;
void ctrl();
ctrl(cp = fmt); /* backslash interpretation of fmt string */
/*
* Scan format string for conversion specifications.
*/
while (*cp) {
while ((ch = *cp++) != '%') {
if (ch == 0)
goto cleanup;
fputc(ch, file);
}
switch (*cp) {
case 'd':
case 'u':
case 'i':
case 'l':
fprintf(file, "%d", va_arg(ap, int));
break;
case 'o':
fprintf(file, "%o", va_arg(ap, int));
break;
case 'x':
case 'X':
fprintf(file, "%x", va_arg(ap, int));
break;
case 's':
fputs(va_arg(ap, char *), file);
break;
case 'f':
case 'g':
case 'G':
fprintf(file, "%f", va_arg(ap, float));
break;
case 'c':
fputc(va_arg(ap, char), file);
break;
case 'p':
fprintf(file, "%s", _Curr_rtn);
break;
case '%':
fputc('%', file); /* that's easy.. */
break;
default:
fprintf(file, "(output error!) What the heck is a '%c'?\n",
cp);
break;
}
cp++;
}
cleanup:
va_end(ap);
fputc('\n', file);
fflush(file);
return(0);
}
/*
* Search for a file along a path, opening it if found.
*/
FILE *find_and_open(path, name, mode)
String path, name, mode;
{
FILE *tmp = NULL;
String cp = path;
Boolean more_path = TRUE;
char dir[MAXPATHLEN];
Entry("find_and_open");
/* First try to open in place */
tmp = fopen(name, mode);
if (path && !strcmp(path, INITIAL))
more_path = FALSE;
while (!tmp && more_path) {
if ((cp = index(path, ':')) != NULL) {
CPYN(dir, cp, cp - path);
strcat(dir, "/");
path = cp + 1;
}
else {
strcpy(dir, path);
strcat(dir, "/");
more_path = FALSE;
}
strcat(dir, name);
tmp = fopen(dir, mode);
}
Leave(tmp);
}