home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
bmd-1.0beta.tar.Z
/
bmd-1.0beta.tar
/
bmd-1.0beta
/
app
/
omtd
/
util.c
< prev
Wrap
C/C++ Source or Header
|
1991-01-22
|
3KB
|
118 lines
/*
* Copyright (c) 1988-1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char rcsid[] =
"@(#) $Header: util.c,v 1.3 91/01/21 21:32:49 mccanne Exp $ (LBL)";
#endif
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <sys/types.h>
#include <ctype.h>
#include <varargs.h>
#include <sys/file.h>
#include <sys/stat.h>
/* Hex digit to integer. */
static inline int
xdtoi(c)
{
if (isdigit(c))
return c - '0';
else if (islower(c))
return c - 'a' + 10;
else
return c - 'A' + 10;
}
/*
* Convert string to integer. Just like atoi(), but checks for
* preceding 0x or 0 and uses hex or octal instead of decimal.
*/
int
stoi(s)
char *s;
{
int base = 10;
int n = 0;
if (*s == '0') {
if (s[1] == 'x' || s[1] == 'X') {
s += 2;
base = 16;
}
else {
base = 8;
s += 1;
}
}
while (*s)
n = n * base + xdtoi(*s++);
return n;
}
/* VARARGS */
void
error(va_alist)
va_dcl
{
register char *cp;
va_list ap;
va_start(ap);
cp = va_arg(ap, char *);
(void)vfprintf(stderr, cp, ap);
va_end(ap);
if (*cp) {
cp += strlen(cp);
if (cp[-1] != '\n')
(void)fputc('\n', stderr);
}
}
/* VARARGS */
void
fatal(va_alist)
va_dcl
{
register char *cp;
va_list ap;
(void)fprintf(stderr, "mtd: ");
va_start(ap);
cp = va_arg(ap, char *);
(void)vfprintf(stderr, cp, ap);
va_end(ap);
if (*cp) {
cp += strlen(cp);
if (cp[-1] != '\n')
(void)fputc('\n', stderr);
}
exit(1);
/* NOTREACHED */
}