/*-------------------------------------*/
|
/*-------------------------------------*/
|
/* frmstr.c */
|
/* frmstr.c */
|
/* Last change : 14.10.94 */
|
/* Last change : 14.10.94 */
|
/*-------------------------------------*/
|
/*-------------------------------------*/
|
/*
|
/*
|
* $Id: frmstr.c,v 1.2 2001-09-27 11:59:59 chris Exp $
|
* $Id: frmstr.c,v 1.2 2001-09-27 11:59:59 chris Exp $
|
*/
|
*/
|
|
|
#include "frmstr.h"
|
#include "frmstr.h"
|
/*-------------------------------------*/
|
/*-------------------------------------*/
|
/* How to treat the rest.
|
/* How to treat the rest.
|
*/
|
*/
|
#define FOR_CONSOLE 1
|
#define FOR_CONSOLE 1
|
#define DO_LONG 1
|
#define DO_LONG 1
|
|
|
/* To Store a byte.
|
/* To Store a byte.
|
*/
|
*/
|
#ifdef _STORE_BYTE
|
#ifdef _STORE_BYTE
|
# define STORE_BYTE(a, b) (store_byte(a, b))
|
# define STORE_BYTE(a, b) (store_byte(a, b))
|
long store_byte(void);
|
long store_byte(void);
|
#else
|
#else
|
# define STORE_BYTE(a, b) (* (a) = (b))
|
# define STORE_BYTE(a, b) (* (a) = (b))
|
#endif
|
#endif
|
/* Some decalrations.
|
/* Some decalrations.
|
*/
|
*/
|
static void geta(ArgType *, int);
|
static void geta(ArgType *, int);
|
static const char * gnum(const char *, ArgType * );
|
static const char * gnum(const char *, ArgType * );
|
static char * i_compute(unsigned val, int, char *);
|
static char * i_compute(unsigned val, int, char *);
|
#ifdef DO_LONG
|
#ifdef DO_LONG
|
static char * l_compute(long, int, char *);
|
static char * l_compute(long, int, char *);
|
#endif
|
#endif
|
static ArgType * nextarg;
|
static ArgType * nextarg;
|
/* And macros.
|
/* And macros.
|
*/
|
*/
|
#define wsize(par) ((sizeof par) / sizeof(ArgType))
|
#define wsize(par) ((sizeof par) / sizeof(ArgType))
|
#define signbit(par) (1L<<(sizeof par * 8 - 1))
|
#define signbit(par) (1L<<(sizeof par * 8 - 1))
|
|
|
int format_string(const char * fmt, ArgType * args, char * buffer)
|
int format_string(const char * fmt, ArgType * args, char * buffer)
|
{
|
{
|
char * s;
|
char * s;
|
# ifdef DO_LONG
|
# ifdef DO_LONG
|
long l;
|
long l;
|
int lflag;
|
int lflag;
|
# else
|
# else
|
# define lflag 0
|
# define lflag 0
|
# endif
|
# endif
|
# ifdef DO_FLOAT
|
# ifdef DO_FLOAT
|
double dbl;
|
double dbl;
|
# endif
|
# endif
|
ArgType inte;
|
ArgType inte;
|
ArgType_U uint;
|
ArgType_U uint;
|
ArgType width, ndigit;
|
ArgType width, ndigit;
|
int i, j, c, rjust, ndfnd, zfill;
|
int i, j, c, rjust, ndfnd, zfill;
|
const char * oldfmt;
|
const char * oldfmt;
|
char * s1, buf[64];
|
char * s1, buf[64];
|
|
|
nextarg = args;
|
nextarg = args;
|
while (c = * fmt ++) {
|
while (c = * fmt ++) {
|
if (c != '%') {
|
if (c != '%') {
|
# ifdef FOR_CONSOLE
|
# ifdef FOR_CONSOLE
|
if (c == '\n') STORE_BYTE(buffer ++, '\r');
|
if (c == '\n') STORE_BYTE(buffer ++, '\r');
|
# endif
|
# endif
|
STORE_BYTE(buffer ++, c);
|
STORE_BYTE(buffer ++, c);
|
continue;
|
continue;
|
}
|
}
|
# ifdef DO_LONG
|
# ifdef DO_LONG
|
lflag = 0 ;
|
lflag = 0 ;
|
# endif
|
# endif
|
j = 10 ;
|
j = 10 ;
|
rjust = 0;
|
rjust = 0;
|
if (* fmt == '-') {
|
if (* fmt == '-') {
|
fmt ++;
|
fmt ++;
|
rjust ++;
|
rjust ++;
|
}
|
}
|
zfill = ' ';
|
zfill = ' ';
|
if (* fmt == '0') {
|
if (* fmt == '0') {
|
fmt ++;
|
fmt ++;
|
zfill = '0';
|
zfill = '0';
|
}
|
}
|
fmt = gnum(fmt, & width);
|
fmt = gnum(fmt, & width);
|
ndigit = 0; ndfnd = 0;
|
ndigit = 0; ndfnd = 0;
|
if (* fmt == '.') {
|
if (* fmt == '.') {
|
fmt ++; oldfmt = fmt;
|
fmt ++; oldfmt = fmt;
|
fmt = gnum(fmt, & ndigit);
|
fmt = gnum(fmt, & ndigit);
|
ndfnd = (int)(fmt != oldfmt);
|
ndfnd = (int)(fmt != oldfmt);
|
}
|
}
|
s = s1 = buf;
|
s = s1 = buf;
|
# ifdef DO_LONG
|
# ifdef DO_LONG
|
if (* fmt == 'l' || * fmt == 'L') {
|
if (* fmt == 'l' || * fmt == 'L') {
|
fmt ++; lflag ++;
|
fmt ++; lflag ++;
|
}
|
}
|
# endif
|
# endif
|
switch (c = * fmt ++) {
|
switch (c = * fmt ++) {
|
default:
|
default:
|
# ifdef FOR_CONSOLE
|
# ifdef FOR_CONSOLE
|
if (c == '\n') STORE_BYTE(buffer ++, '\r');
|
if (c == '\n') STORE_BYTE(buffer ++, '\r');
|
# endif
|
# endif
|
STORE_BYTE(buffer ++, c);
|
STORE_BYTE(buffer ++, c);
|
continue;
|
continue;
|
case 's':
|
case 's':
|
geta((ArgType *) & s1, wsize(s1));
|
geta((ArgType *) & s1, wsize(s1));
|
s = s1;
|
s = s1;
|
do {
|
do {
|
if (s == 0) break;
|
if (s == 0) break;
|
if (* s == 0)
|
if (* s == 0)
|
break;
|
break;
|
s ++;
|
s ++;
|
} while (-- ndigit);
|
} while (-- ndigit);
|
break;
|
break;
|
case 'b':
|
case 'b':
|
j = 2;
|
j = 2;
|
case 'u':
|
case 'u':
|
getu:
|
getu:
|
|
|
if (! lflag) {
|
if (! lflag) {
|
geta(& inte, wsize(inte));
|
geta(& inte, wsize(inte));
|
goto i_unsignd;
|
goto i_unsignd;
|
}
|
}
|
# ifdef DO_LONG
|
# ifdef DO_LONG
|
case 'U':
|
case 'U':
|
getlu:
|
getlu:
|
|
|
geta((ArgType *) & l, wsize(l));
|
geta((ArgType *) & l, wsize(l));
|
goto l_unsignd;
|
goto l_unsignd;
|
case 'B':
|
case 'B':
|
j = 2 ;
|
j = 2 ;
|
goto getlu;
|
goto getlu;
|
case 'X':
|
case 'X':
|
j = 16;
|
j = 16;
|
goto getlu;
|
goto getlu;
|
case 'O':
|
case 'O':
|
j = 8;
|
j = 8;
|
goto getlu ;
|
goto getlu ;
|
case 'D':
|
case 'D':
|
l_signed:
|
l_signed:
|
|
|
geta((ArgType *) & l, wsize(l));
|
geta((ArgType *) & l, wsize(l));
|
if (l < 0) {
|
if (l < 0) {
|
STORE_BYTE(s ++, '-');
|
STORE_BYTE(s ++, '-');
|
l = -l;
|
l = -l;
|
}
|
}
|
goto do_l;
|
goto do_l;
|
|
|
l_unsignd:
|
l_unsignd:
|
|
|
if (l && ndigit)
|
if (l && ndigit)
|
STORE_BYTE(s ++, '0');
|
STORE_BYTE(s ++, '0');
|
|
|
do_l:
|
do_l:
|
|
|
s = l_compute(l, j, s);
|
s = l_compute(l, j, s);
|
break;
|
break;
|
# endif
|
# endif
|
case 'x':
|
case 'x':
|
j = 16;
|
j = 16;
|
goto getu;
|
goto getu;
|
case 'o':
|
case 'o':
|
j = 8;
|
j = 8;
|
goto getu;
|
goto getu;
|
case 'd':
|
case 'd':
|
if (lflag) goto l_signed;
|
if (lflag) goto l_signed;
|
geta(& inte, wsize(inte));
|
geta(& inte, wsize(inte));
|
if (inte < 0) {
|
if (inte < 0) {
|
STORE_BYTE(s ++, '-');
|
STORE_BYTE(s ++, '-');
|
inte = - inte;
|
inte = - inte;
|
}
|
}
|
goto do_i;
|
goto do_i;
|
|
|
i_unsignd:
|
i_unsignd:
|
|
|
if (inte && ndigit)
|
if (inte && ndigit)
|
STORE_BYTE(s ++, '0');
|
STORE_BYTE(s ++, '0');
|
|
|
do_i:
|
do_i:
|
|
|
s = i_compute(inte, j, s);
|
s = i_compute(inte, j, s);
|
break;
|
break;
|
case 'c':
|
case 'c':
|
geta ((ArgType *) & uint, wsize(uint));
|
geta ((ArgType *) & uint, wsize(uint));
|
for (i = sizeof uint - 1; i >= 0; i --) {
|
for (i = sizeof uint - 1; i >= 0; i --) {
|
if (STORE_BYTE(s, uint % 256)) s ++;
|
if (STORE_BYTE(s, uint % 256)) s ++;
|
uint /= 256 ;
|
uint /= 256 ;
|
}
|
}
|
break;
|
break;
|
# ifdef DO_FLOAT
|
# ifdef DO_FLOAT
|
case 'e':
|
case 'e':
|
geta((ArgType *) & dbl, wsize(dbl));
|
geta((ArgType *) & dbl, wsize(dbl));
|
s = _pscien(dbl, s, ndigit, ndfnd);
|
s = _pscien(dbl, s, ndigit, ndfnd);
|
break;
|
break;
|
case 'f':
|
case 'f':
|
geta((ArgType *) &dbl,wsize(dbl));
|
geta((ArgType *) &dbl,wsize(dbl));
|
s = _pfloat(dbl, s, ndigit, ndfnd);
|
s = _pfloat(dbl, s, ndigit, ndfnd);
|
break;
|
break;
|
# endif
|
# endif
|
case 'r':
|
case 'r':
|
geta((ArgType *) & nextarg, wsize(nextarg));
|
geta((ArgType *) & nextarg, wsize(nextarg));
|
geta((ArgType *) & oldfmt, wsize(fmt));
|
geta((ArgType *) & oldfmt, wsize(fmt));
|
fmt = oldfmt;
|
fmt = oldfmt;
|
continue;
|
continue;
|
}
|
}
|
j = s - s1;
|
j = s - s1;
|
if ((c = width - j) > 0) {
|
if ((c = width - j) > 0) {
|
if (rjust == 0) {
|
if (rjust == 0) {
|
do STORE_BYTE(buffer ++, zfill);
|
do STORE_BYTE(buffer ++, zfill);
|
while (-- c);
|
while (-- c);
|
}
|
}
|
}
|
}
|
while (-- j >= 0)
|
while (-- j >= 0)
|
STORE_BYTE(buffer ++, * s1 ++);
|
STORE_BYTE(buffer ++, * s1 ++);
|
while (-- c >= 0)
|
while (-- c >= 0)
|
STORE_BYTE(buffer ++, zfill);
|
STORE_BYTE(buffer ++, zfill);
|
}
|
}
|
STORE_BYTE(buffer, 0);
|
STORE_BYTE(buffer, 0);
|
return 0;
|
return 0;
|
}
|
}
|
static void geta(ArgType * p, int size)
|
static void geta(ArgType * p, int size)
|
{
|
{
|
if ((ArgType *) & p - (ArgType *) & size > 0) {
|
if ((ArgType *) & p - (ArgType *) & size > 0) {
|
p += size;
|
p += size;
|
while (size --) {
|
while (size --) {
|
* -- p = * nextarg --;
|
* -- p = * nextarg --;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
while (size --) {
|
while (size --) {
|
* p ++ = * nextarg ++ ;
|
* p ++ = * nextarg ++ ;
|
}
|
}
|
}
|
}
|
}
|
}
|
static const char * gnum(const char * f, ArgType * ip)
|
static const char * gnum(const char * f, ArgType * ip)
|
{
|
{
|
ArgType i;
|
ArgType i;
|
int c;
|
int c;
|
|
|
if (* f == '*') {
|
if (* f == '*') {
|
geta(ip, wsize(i)) ;
|
geta(ip, wsize(i)) ;
|
f ++;
|
f ++;
|
}
|
}
|
else {
|
else {
|
i = 0;
|
i = 0;
|
while ((c = * f - '0') >= 0 && c <= 9) {
|
while ((c = * f - '0') >= 0 && c <= 9) {
|
i = i * 10 + c;
|
i = i * 10 + c;
|
f ++;
|
f ++;
|
}
|
}
|
* ip = i;
|
* ip = i;
|
}
|
}
|
return f;
|
return f;
|
}
|
}
|
static char * i_compute(unsigned int val, int base, char * s)
|
static char * i_compute(unsigned int val, int base, char * s)
|
{
|
{
|
int c;
|
int c;
|
|
|
c = val % base;
|
c = val % base;
|
val /= base;
|
val /= base;
|
if (val)
|
if (val)
|
s = i_compute(val, base, s);
|
s = i_compute(val, base, s);
|
STORE_BYTE(s ++, c>9 ? c-10+'a' : c+'0');
|
STORE_BYTE(s ++, c>9 ? c-10+'a' : c+'0');
|
return s;
|
return s;
|
}
|
}
|
#ifdef DO_LONG
|
#ifdef DO_LONG
|
static char *l_compute(long l1,int d, char * s)
|
static char *l_compute(long l1,int d, char * s)
|
{
|
{
|
int c;
|
int c;
|
long l2;
|
long l2;
|
|
|
if (l1 < 0) {
|
if (l1 < 0) {
|
c = l1 & 1;
|
c = l1 & 1;
|
l2 = ((l1>>1) & ~signbit(l1));
|
l2 = ((l1>>1) & ~signbit(l1));
|
l1 = l2 / (d>>1);
|
l1 = l2 / (d>>1);
|
c += (l2%(d>>1))<<1;
|
c += (l2%(d>>1))<<1;
|
}
|
}
|
else {
|
else {
|
c = l1 % d;
|
c = l1 % d;
|
l1 = l1 / d;
|
l1 = l1 / d;
|
}
|
}
|
if (l1)
|
if (l1)
|
s = l_compute(l1, d, s);
|
s = l_compute(l1, d, s);
|
STORE_BYTE(s ++, c>9 ? c-10+'A' : c+'0');
|
STORE_BYTE(s ++, c>9 ? c-10+'A' : c+'0');
|
return s;
|
return s;
|
}
|
}
|
#endif
|
#endif
|
#ifdef _STORE_BYTE
|
#ifdef _STORE_BYTE
|
long store_byte(char * cp, long c)
|
long store_byte(char * cp, long c)
|
{
|
{
|
long shift, reg, * ptr;
|
long shift, reg, * ptr;
|
|
|
shift = ((long) cp & 3) * 8;
|
shift = ((long) cp & 3) * 8;
|
ptr = (long *) ((long) cp & ~3);
|
ptr = (long *) ((long) cp & ~3);
|
reg = * ptr;
|
reg = * ptr;
|
reg &= ~(0xff << shift);
|
reg &= ~(0xff << shift);
|
reg |= c << shift;
|
reg |= c << shift;
|
* ptr = reg;
|
* ptr = reg;
|
|
|
return c;
|
return c;
|
}
|
}
|
#endif
|
#endif
|
|
|
#define SPC 01
|
#define SPC 01
|
#define STP 02
|
#define STP 02
|
|
|
#define NULL 0
|
#define NULL 0
|
#define EOF 0
|
#define EOF 0
|
#define SHORT 0
|
#define SHORT 0
|
#define REGULAR 1
|
#define REGULAR 1
|
#define LONG 2
|
#define LONG 2
|
#define INT 0
|
#define INT 0
|
#define FLOAT 1
|
#define FLOAT 1
|
|
|
static int new_c(void);
|
static int new_c(void);
|
static void unnew_c(char);
|
static void unnew_c(char);
|
static int _innum(int ** ptr, int type, int len, int size, int * eofptr);
|
static int _innum(int ** ptr, int type, int len, int size, int * eofptr);
|
static int _instr(char * ptr, int type, int len, int * eofptr);
|
static int _instr(char * ptr, int type, int len, int * eofptr);
|
static const char * _getccl(const char *);
|
static const char * _getccl(const char *);
|
static int vme_isupper(char);
|
static int vme_isupper(char);
|
static int vme_tolower(char);
|
static int vme_tolower(char);
|
static int vme_isdigit(char);
|
static int vme_isdigit(char);
|
|
|
static char _sctab[128] = {
|
static char _sctab[128] = {
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,SPC,SPC,0,0,0,0,0,
|
0,SPC,SPC,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
SPC,0,0,0,0,0,0,0,
|
SPC,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,
|
};
|
};
|
static const char * line;
|
static const char * line;
|
static char * linep;
|
static char * linep;
|
|
|
int unformat_string(const char * fmt, int ** argp, const char * buffer)
|
int unformat_string(const char * fmt, int ** argp, const char * buffer)
|
{
|
{
|
int ch;
|
int ch;
|
int nmatch, len, ch1;
|
int nmatch, len, ch1;
|
int ** ptr, fileended, size;
|
int ** ptr, fileended, size;
|
|
|
line = buffer;
|
line = buffer;
|
linep = (char*)line;
|
linep = (char*)line;
|
|
|
nmatch = 0;
|
nmatch = 0;
|
fileended = 0;
|
fileended = 0;
|
for (;;) switch (ch = * fmt ++) {
|
for (;;) switch (ch = * fmt ++) {
|
case '\0':
|
case '\0':
|
return (nmatch);
|
return (nmatch);
|
case '%':
|
case '%':
|
if ((ch = * fmt ++) == '%')
|
if ((ch = * fmt ++) == '%')
|
goto def;
|
goto def;
|
ptr = 0;
|
ptr = 0;
|
if (ch != '*')
|
if (ch != '*')
|
ptr = argp ++;
|
ptr = argp ++;
|
else
|
else
|
ch = * fmt ++;
|
ch = * fmt ++;
|
len = 0;
|
len = 0;
|
size = REGULAR;
|
size = REGULAR;
|
while (vme_isdigit(ch)) {
|
while (vme_isdigit(ch)) {
|
len = len*10 + ch - '0';
|
len = len*10 + ch - '0';
|
ch = * fmt ++;
|
ch = * fmt ++;
|
}
|
}
|
if (len == 0)
|
if (len == 0)
|
len = 30000;
|
len = 30000;
|
if (ch == 'l') {
|
if (ch == 'l') {
|
ch = * fmt ++;
|
ch = * fmt ++;
|
size = LONG;
|
size = LONG;
|
}
|
}
|
else if (ch == 'h') {
|
else if (ch == 'h') {
|
size = SHORT;
|
size = SHORT;
|
ch = * fmt ++;
|
ch = * fmt ++;
|
}
|
}
|
else if (ch=='[')
|
else if (ch=='[')
|
fmt = _getccl(fmt);
|
fmt = _getccl(fmt);
|
if (vme_isupper(ch)) {
|
if (vme_isupper(ch)) {
|
ch = vme_tolower(ch);
|
ch = vme_tolower(ch);
|
size = LONG;
|
size = LONG;
|
}
|
}
|
if (ch == '\0')
|
if (ch == '\0')
|
return -1;
|
return -1;
|
if (_innum(ptr, ch, len, size, & fileended) && ptr)
|
if (_innum(ptr, ch, len, size, & fileended) && ptr)
|
nmatch ++;
|
nmatch ++;
|
if (fileended)
|
if (fileended)
|
return nmatch? nmatch: -1;
|
return nmatch? nmatch: -1;
|
break;
|
break;
|
case ' ':
|
case ' ':
|
case '\n':
|
case '\n':
|
case '\t':
|
case '\t':
|
while ((ch1 = new_c())==' ' || ch1=='\t' || ch1=='\n')
|
while ((ch1 = new_c())==' ' || ch1=='\t' || ch1=='\n')
|
;
|
;
|
if (ch1 != EOF)
|
if (ch1 != EOF)
|
unnew_c(ch1);
|
unnew_c(ch1);
|
break;
|
break;
|
default:
|
default:
|
|
|
def:
|
def:
|
|
|
ch1 = new_c();
|
ch1 = new_c();
|
if (ch1 != ch) {
|
if (ch1 != ch) {
|
if (ch1==EOF)
|
if (ch1==EOF)
|
return -1 ;
|
return -1 ;
|
unnew_c(ch1);
|
unnew_c(ch1);
|
return nmatch;
|
return nmatch;
|
}
|
}
|
}
|
}
|
}
|
}
|
static int new_c()
|
static int new_c()
|
{
|
{
|
char c;
|
char c;
|
|
|
if (linep) {
|
if (linep) {
|
c = * linep ++;
|
c = * linep ++;
|
return c;
|
return c;
|
}
|
}
|
else {
|
else {
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
static void unnew_c(char ch)
|
static void unnew_c(char ch)
|
{
|
{
|
if (linep > line)
|
if (linep > line)
|
* (-- linep) = ch;
|
* (-- linep) = ch;
|
}
|
}
|
static int _innum(int ** ptr, int type, int len, int size, int * eofptr)
|
static int _innum(int ** ptr, int type, int len, int size, int * eofptr)
|
{
|
{
|
# ifdef DO_FLOAT
|
# ifdef DO_FLOAT
|
extern double atof();
|
extern double atof();
|
# endif
|
# endif
|
char * np;
|
char * np;
|
char numbuf[64];
|
char numbuf[64];
|
int c, base;
|
int c, base;
|
int expseen, scale, negflg, c1, ndigit;
|
int expseen, scale, negflg, c1, ndigit;
|
long lcval;
|
long lcval;
|
|
|
if (type=='c' || type=='s' || type=='[')
|
if (type=='c' || type=='s' || type=='[')
|
return _instr(ptr? * (char **) ptr: (char *) NULL, type, len, eofptr);
|
return _instr(ptr? * (char **) ptr: (char *) NULL, type, len, eofptr);
|
lcval = 0;
|
lcval = 0;
|
ndigit = 0;
|
ndigit = 0;
|
scale = INT;
|
scale = INT;
|
if (type=='e'||type=='f')
|
if (type=='e'||type=='f')
|
scale = FLOAT;
|
scale = FLOAT;
|
base = 10;
|
base = 10;
|
if (type=='o')
|
if (type=='o')
|
base = 8;
|
base = 8;
|
else if (type=='x')
|
else if (type=='x')
|
base = 16;
|
base = 16;
|
np = numbuf;
|
np = numbuf;
|
expseen = 0;
|
expseen = 0;
|
negflg = 0;
|
negflg = 0;
|
while ((c = new_c())==' ' || c=='\t' || c=='\n');
|
while ((c = new_c())==' ' || c=='\t' || c=='\n');
|
if (c=='-') {
|
if (c=='-') {
|
negflg ++;
|
negflg ++;
|
* np ++ = c;
|
* np ++ = c;
|
c = new_c();
|
c = new_c();
|
len --;
|
len --;
|
}
|
}
|
else if (c=='+') {
|
else if (c=='+') {
|
len --;
|
len --;
|
c = new_c();
|
c = new_c();
|
}
|
}
|
for ( ; -- len >= 0; * np ++ = c, c = new_c()) {
|
for ( ; -- len >= 0; * np ++ = c, c = new_c()) {
|
if (vme_isdigit(c)
|
if (vme_isdigit(c)
|
|| base==16 && ('a'<=c && c<='f' || 'A'<=c && c<='F')) {
|
|| base==16 && ('a'<=c && c<='f' || 'A'<=c && c<='F')) {
|
ndigit ++;
|
ndigit ++;
|
if (base==8)
|
if (base==8)
|
lcval <<=3;
|
lcval <<=3;
|
else if (base==10)
|
else if (base==10)
|
lcval = ((lcval<<2) + lcval)<<1;
|
lcval = ((lcval<<2) + lcval)<<1;
|
else
|
else
|
lcval <<= 4;
|
lcval <<= 4;
|
c1 = c;
|
c1 = c;
|
if ('0'<=c && c<='9')
|
if ('0'<=c && c<='9')
|
c -= '0';
|
c -= '0';
|
else if ('a'<=c && c<='f')
|
else if ('a'<=c && c<='f')
|
c -= 'a'-10;
|
c -= 'a'-10;
|
else
|
else
|
c -= 'A'-10;
|
c -= 'A'-10;
|
lcval += c;
|
lcval += c;
|
c = c1;
|
c = c1;
|
continue;
|
continue;
|
}
|
}
|
else if (c=='.') {
|
else if (c=='.') {
|
if (base!=10 || scale==INT)
|
if (base!=10 || scale==INT)
|
break;
|
break;
|
ndigit ++;
|
ndigit ++;
|
continue;
|
continue;
|
}
|
}
|
else if ((c=='e'||c=='E') && expseen==0) {
|
else if ((c=='e'||c=='E') && expseen==0) {
|
if (base!=10 || scale==INT || ndigit==0)
|
if (base!=10 || scale==INT || ndigit==0)
|
break;
|
break;
|
expseen ++;
|
expseen ++;
|
* np ++ = c;
|
* np ++ = c;
|
c = new_c();
|
c = new_c();
|
if (c!='+'&&c!='-'&&('0'>c||c>'9'))
|
if (c!='+'&&c!='-'&&('0'>c||c>'9'))
|
break;
|
break;
|
}
|
}
|
else
|
else
|
break;
|
break;
|
}
|
}
|
if (negflg)
|
if (negflg)
|
lcval = -lcval;
|
lcval = -lcval;
|
if (c != EOF) {
|
if (c != EOF) {
|
unnew_c(c);
|
unnew_c(c);
|
* eofptr = 0;
|
* eofptr = 0;
|
}
|
}
|
else
|
else
|
* eofptr = 1;
|
* eofptr = 1;
|
if (ptr==NULL || np==numbuf)
|
if (ptr==NULL || np==numbuf)
|
return 0;
|
return 0;
|
* np ++ = 0;
|
* np ++ = 0;
|
switch ((scale<<4) | size) {
|
switch ((scale<<4) | size) {
|
# ifdef DO_FLOAT
|
# ifdef DO_FLOAT
|
|
|
case (FLOAT<<4) | SHORT:
|
case (FLOAT<<4) | SHORT:
|
case (FLOAT<<4) | REGULAR:
|
case (FLOAT<<4) | REGULAR:
|
** (float **) ptr = atof(numbuf);
|
** (float **) ptr = atof(numbuf);
|
break;
|
break;
|
|
|
case (FLOAT<<4) | LONG:
|
case (FLOAT<<4) | LONG:
|
** (double **) ptr = atof(numbuf);
|
** (double **) ptr = atof(numbuf);
|
break;
|
break;
|
# endif
|
# endif
|
case (INT<<4) | SHORT:
|
case (INT<<4) | SHORT:
|
** (short **) ptr = lcval;
|
** (short **) ptr = lcval;
|
break;
|
break;
|
|
|
case (INT<<4) | REGULAR:
|
case (INT<<4) | REGULAR:
|
** (int **) ptr = lcval;
|
** (int **) ptr = lcval;
|
break;
|
break;
|
|
|
case (INT<<4) | LONG:
|
case (INT<<4) | LONG:
|
** (long **) ptr = lcval;
|
** (long **) ptr = lcval;
|
break;
|
break;
|
}
|
}
|
return 1;
|
return 1;
|
}
|
}
|
static int _instr(char * ptr, int type, int len, int * eofptr)
|
static int _instr(char * ptr, int type, int len, int * eofptr)
|
{
|
{
|
int ch;
|
int ch;
|
char * optr;
|
char * optr;
|
int ignstp;
|
int ignstp;
|
|
|
* eofptr = 0;
|
* eofptr = 0;
|
optr = ptr;
|
optr = ptr;
|
if (type=='c' && len==30000)
|
if (type=='c' && len==30000)
|
len = 1;
|
len = 1;
|
ignstp = 0;
|
ignstp = 0;
|
if (type=='s')
|
if (type=='s')
|
ignstp = SPC;
|
ignstp = SPC;
|
while (_sctab[ch = new_c()] & ignstp)
|
while (_sctab[ch = new_c()] & ignstp)
|
if (ch==EOF)
|
if (ch==EOF)
|
break;
|
break;
|
ignstp = SPC;
|
ignstp = SPC;
|
if (type=='c')
|
if (type=='c')
|
ignstp = 0;
|
ignstp = 0;
|
else if (type=='[')
|
else if (type=='[')
|
ignstp = STP;
|
ignstp = STP;
|
while (ch!=EOF && (_sctab[ch]&ignstp)==0) {
|
while (ch!=EOF && (_sctab[ch]&ignstp)==0) {
|
if (ptr)
|
if (ptr)
|
* ptr ++ = ch;
|
* ptr ++ = ch;
|
if (-- len <= 0)
|
if (-- len <= 0)
|
break;
|
break;
|
ch = new_c();
|
ch = new_c();
|
}
|
}
|
if (ch != EOF) {
|
if (ch != EOF) {
|
if (len > 0)
|
if (len > 0)
|
unnew_c(ch);
|
unnew_c(ch);
|
* eofptr = 0;
|
* eofptr = 0;
|
}
|
}
|
else
|
else
|
* eofptr = 1;
|
* eofptr = 1;
|
if (ptr && ptr!=optr) {
|
if (ptr && ptr!=optr) {
|
if (type!='c')
|
if (type!='c')
|
* ptr ++ = '\0';
|
* ptr ++ = '\0';
|
return 1;
|
return 1;
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
static const char * _getccl(const char * s)
|
static const char * _getccl(const char * s)
|
{
|
{
|
int c, t;
|
int c, t;
|
|
|
t = 0;
|
t = 0;
|
if (* s == '^') {
|
if (* s == '^') {
|
t ++;
|
t ++;
|
s ++;
|
s ++;
|
}
|
}
|
for (c = 0; c < 128; c++)
|
for (c = 0; c < 128; c++)
|
if (t)
|
if (t)
|
_sctab[c] &= ~STP;
|
_sctab[c] &= ~STP;
|
else
|
else
|
_sctab[c] |= STP;
|
_sctab[c] |= STP;
|
while (((c = * s ++)&0177) != ']') {
|
while (((c = * s ++)&0177) != ']') {
|
if (t)
|
if (t)
|
_sctab[c++] |= STP;
|
_sctab[c++] |= STP;
|
else
|
else
|
_sctab[c++] &= ~STP;
|
_sctab[c++] &= ~STP;
|
if (c==0)
|
if (c==0)
|
return -- s;
|
return -- s;
|
}
|
}
|
return s;
|
return s;
|
}
|
}
|
static int vme_isupper(char ch)
|
static int vme_isupper(char ch)
|
{
|
{
|
if( ch >= 'A' & ch <= 'Z')
|
if( ch >= 'A' & ch <= 'Z')
|
return 1;
|
return 1;
|
else
|
else
|
return 0;
|
return 0;
|
}
|
}
|
static int vme_tolower(char ch)
|
static int vme_tolower(char ch)
|
{
|
{
|
return 'a' + 'A' - ch;
|
return 'a' + 'A' - ch;
|
}
|
}
|
static vme_isdigit(char ch)
|
static vme_isdigit(char ch)
|
{
|
{
|
if (ch >= '0' & ch <= '9')
|
if (ch >= '0' & ch <= '9')
|
return 1;
|
return 1;
|
else
|
else
|
return 0;
|
return 0;
|
}
|
}
|
/*-------------*/
|
/*-------------*/
|
/* End of file */
|
/* End of file */
|
/*-------------*/
|
/*-------------*/
|
|
|
|
|