ack/modules/src/string/str2long.c

42 lines
668 B
C
Raw Normal View History

1994-06-24 11:31:16 +00:00
/* $Id$ */
1987-03-09 15:15:03 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1987-01-06 11:41:50 +00:00
/* str2long()
*/
1993-11-10 12:09:49 +00:00
#include "ack_string.h"
1987-01-06 11:41:50 +00:00
value(c, b)
char c;
int b;
{
1987-03-25 17:54:24 +00:00
register int ch;
ch = c - '0';
if ((unsigned) ch <= 9) return ch;
ch = c - 'A';
if ((unsigned) ch <= 5) return ch + 10;
ch = c - 'a';
if ((unsigned) ch <= 5) return ch + 10;
1987-01-06 11:41:50 +00:00
return b;
}
long
str2long(str, base)
register char *str;
int base;
{
int minus = 0, d;
long l = 0;
if (*str == '-') {
minus++;
str++;
}
while ((d = value(*str++, base)) < base)
l = base * l + d;
return minus ? -l : l;
}