/* * Routines extracted from unhunk.c because they are also used in * the dl program. Fred Fish 4-May-86 */ #include #include "convert.h" #ifdef DBUG #include #else #include "dbugstubs.h" #endif /* * Convert char string to long * prefixes understood: 0x (hex), 0 (octal), otherwise decimal * leading '-' means 2's complement */ long getnum(str) char *str; { long num; char *foo; int negflag; extern long strtol(); DBUG_ENTER("getnum"); if (*str == '-') { DBUG_3("args", "minus sign: '%s'", str); negflag = 1; str++; } else negflag = 0; DBUG_3("args", "string is: '%s'", str); #if 0 /**** this sucks! strtol() causes an address error guru med! ****/ DBUG_4("args", "about to call strtol: str='%s', &foo=0x%x", str, &foo); num = strtol(str, &foo, 0); DBUG_4("args", "got back from strtol, got num=%ld (0x%lx)", num, num); #else 0 if (*str == '0') { str++; if(*str == 'x' || *str == 'X') stch_i(++str, &num); else panic("Can't handle octal args"); } else stcd_i(str, &num); #endif 0 if (negflag) num = (long) (0 - (int) num); DBUG_4("args", "conversion returns %ld (0x%lx)", num, num); DBUG_RETURN(num); } /* * Panic and give up. */ panic(s) char *s; { DBUG_ENTER("panic"); printf("unhunk disaster: %s\nGiving up...\n", s); exit(10); /* NOTREACHED */ DBUG_RETURN(0); }