|
|
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: 3473 (0xd91)
Types: TextFile
Names: »util.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
└─⟦34cc4e2f7⟧ »./UNRELEASED/xgdb3.2.tar.Z«
└─⟦80fac5d7c⟧
└─⟦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(va_alist)
va_dcl
{
char *fmt;
va_list ap;
va_start(ap);
fprintf(stderr, "%s: (%s) ", program_name, _Curr_rtn);
fmt = va_arg(ap, char *);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputc('\n', stderr);
}
/*
* Puke, then die.
*/
/* VARARGS */
void puke_and_die(va_alist)
va_dcl
{
char *fmt;
va_list ap;
va_start(ap);
fprintf(stderr, "%s: FATAL ERROR in %s, ", program_name, _Curr_rtn);
fmt = va_arg(ap, char *);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputc('\n', stderr);
exit(1);
}
/*
* Output a debugging message.
*/
/* VARARGS */
debug(va_alist)
va_dcl
{
va_list ap;
static FILE *dbug = NULL;
char *fmt;
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);
}
fmt = va_arg(ap, char *);
fprintf(dbug, "debug: (%s): ", _Curr_rtn);
vfprintf(dbug, fmt, ap);
fputc('\n', dbug);
va_end(ap);
}
/*
* 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 && !strcomp(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);
}