GetNumArg and misc other cleanups from Lucho

git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@944 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2004-05-23 16:21:14 +00:00
parent 24d27f2f9b
commit c97bc20bf2

View File

@ -206,11 +206,10 @@ STATIC VOID CfgMenuDefault(BYTE * pLine);
STATIC BYTE * skipwh(BYTE * s); STATIC BYTE * skipwh(BYTE * s);
STATIC BYTE * scan(BYTE * s, BYTE * d); STATIC BYTE * scan(BYTE * s, BYTE * d);
STATIC BOOL isnum(char ch); STATIC BOOL isnum(char ch);
STATIC char * GetNumber(REG const char *p, int *num);
#if 0 #if 0
STATIC COUNT tolower(COUNT c); STATIC COUNT tolower(COUNT c);
#endif #endif
STATIC unsigned char toupper(unsigned char c); STATIC char toupper(char c);
STATIC VOID strupr(char *s); STATIC VOID strupr(char *s);
STATIC VOID mcb_init(UCOUNT seg, UWORD size, BYTE type); STATIC VOID mcb_init(UCOUNT seg, UWORD size, BYTE type);
STATIC VOID mumcb_init(UCOUNT seg, UWORD size); STATIC VOID mumcb_init(UCOUNT seg, UWORD size);
@ -865,16 +864,43 @@ STATIC BOOL SkipLine(char *pLine)
} }
STATIC BYTE * GetNumArg(BYTE * pLine, COUNT * pnArg) /* JPP - changed so will accept hex number. */
/* ea - changed to accept hex digits in hex numbers */
STATIC char *GetNumArg(char *p, int *num)
{ {
static char digits[] = "0123456789ABCDEF";
unsigned char base = 10;
int sign = 1;
int n = 0;
/* look for NUMBER */ /* look for NUMBER */
pLine = skipwh(pLine); p = skipwh(p);
if (!isnum(*pLine) && *pLine != '-') if (*p == '-')
{ {
CfgFailure(pLine); p++;
return (BYTE *) 0; sign = -1;
} }
return (BYTE *)GetNumber(pLine, pnArg); else if (!isnum(*p))
{
CfgFailure(p);
return NULL;
}
for( ; *p; p++)
{
char ch = toupper(*p);
if (ch == 'X')
base = 16;
else
{
char *q = strchr(digits, ch);
if (q == NULL)
break;
n = n * base + (q - digits);
}
}
*num = n * sign;
return p;
} }
BYTE *GetStringArg(BYTE * pLine, BYTE * pszString) BYTE *GetStringArg(BYTE * pLine, BYTE * pszString)
@ -974,16 +1000,16 @@ STATIC VOID CfgLastdrive(BYTE * pLine)
BYTE drv; BYTE drv;
pLine = skipwh(pLine); pLine = skipwh(pLine);
drv = *pLine & ~0x20; drv = toupper(*pLine);
if (drv < 'A' || drv > 'Z') if (drv < 'A' || drv > 'Z')
{ {
CfgFailure(pLine); CfgFailure(pLine);
return; return;
} }
drv -= 'A'; drv -= 'A' - 1; /* Make real number */
drv++; /* Make real number */ if (drv > Config.cfgLastdrive)
Config.cfgLastdrive = max(Config.cfgLastdrive, drv); Config.cfgLastdrive = drv;
Config.cfgLastdriveHigh = 0; Config.cfgLastdriveHigh = 0;
} }
@ -1569,51 +1595,11 @@ STATIC BOOL isnum(char ch)
return (ch >= '0' && ch <= '9'); return (ch >= '0' && ch <= '9');
} }
/* JPP - changed so will accept hex number. */
/* ea - changed to accept hex digits in hex numbers */
STATIC char * GetNumber(REG const char *p, int *num)
{
unsigned char base = 10;
int sign = 1;
int n = 0;
if (*p == '-')
{
p++;
sign = -1;
}
for(;;p++)
{
unsigned char ch = toupper(*p);
if (ch == 'X')
{
base = 16;
continue;
}
if (isnum(ch))
{
n = n * base + ch - '0';
}
else if (base == 16 && (ch<='F') && (ch>='A'))
{
n = n * base + 10 + ch - 'A';
}
else
{
break;
}
}
*num = n * sign;
return (char *)p;
}
/* Yet another change for true portability (PJV) */ /* Yet another change for true portability (PJV) */
STATIC unsigned char toupper(unsigned char c) STATIC char toupper(char c)
{ {
if (c >= 'a' && c <= 'z') if (c >= 'a' && c <= 'z')
return (c - ('a' - 'A')); c -= 'a' - 'A';
else
return c; return c;
} }