1985-02-04 22:18:16 +00:00
|
|
|
#include "bc_string.h"
|
|
|
|
#include "bc_io.h"
|
1984-11-29 14:22:02 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1984-11-29 14:22:02 +00:00
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void _readln(void)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
1985-01-21 23:53:41 +00:00
|
|
|
register int c;
|
2016-12-12 20:16:32 +00:00
|
|
|
while ((c = fgetc(_chanrd)) != EOF && c != '\n')
|
1984-11-29 14:22:02 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void readskip(void)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
1985-01-21 23:53:41 +00:00
|
|
|
register int c;
|
1984-11-29 14:22:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("readskip\n");
|
|
|
|
#endif
|
2016-12-12 20:16:32 +00:00
|
|
|
while ((c = fgetc(_chanrd)) != EOF && c != ',' && c != '\n')
|
1984-11-29 14:22:02 +00:00
|
|
|
;
|
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _readint(int* addr)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
2016-12-12 20:16:32 +00:00
|
|
|
char buf[1024];
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf("read int from %d\n", _chann);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
|
|
|
_asschn();
|
2016-12-12 20:16:32 +00:00
|
|
|
if (fscanf(_chanrd, "%d", &i) != 1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
if (ferror(_chanrd))
|
|
|
|
error(29);
|
|
|
|
if (feof(_chanrd))
|
|
|
|
error(2);
|
|
|
|
if (_chann == -1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
_asschn(); /* may be closed by now */
|
|
|
|
fgets(buf, 1024, _chanrd);
|
1984-11-29 14:22:02 +00:00
|
|
|
printf("?Redo ");
|
|
|
|
_readint(addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error(40);
|
2016-12-12 20:16:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
readskip();
|
|
|
|
*addr = i;
|
|
|
|
}
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _readflt(double* addr)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
double f;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf("read flt from %d\n", _chann);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
|
|
|
_asschn();
|
2016-12-12 20:16:32 +00:00
|
|
|
if (fscanf(_chanrd, "%lf", &f) != 1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
if (ferror(_chanrd))
|
|
|
|
error(29);
|
|
|
|
if (feof(_chanrd))
|
|
|
|
error(2);
|
|
|
|
if (_chann == -1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
fgets(buf, 1024, _chanrd);
|
1984-11-29 14:22:02 +00:00
|
|
|
printf("?Redo ");
|
|
|
|
_readflt(addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error(40);
|
2016-12-12 20:16:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
readskip();
|
|
|
|
*addr = f;
|
|
|
|
}
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _readstr(String** s)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
char buffer[1024];
|
2016-12-12 20:16:32 +00:00
|
|
|
register int kar;
|
|
|
|
char* c;
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf("read str from %d\n", _chann);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
|
|
|
_asschn();
|
2016-12-12 20:16:32 +00:00
|
|
|
c = buffer;
|
|
|
|
kar = fgetc(_chanrd);
|
|
|
|
while (isspace(kar) && kar != EOF)
|
|
|
|
kar = fgetc(_chanrd);
|
|
|
|
*c = kar;
|
|
|
|
if (kar == '"')
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
/* read quoted string */
|
1984-11-29 14:22:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("qouted string\n");
|
|
|
|
#endif
|
2016-12-12 20:16:32 +00:00
|
|
|
while ((kar = fgetc(_chanrd)) != EOF && kar != '"')
|
|
|
|
*c++ = kar;
|
|
|
|
ungetc(kar, _chanrd);
|
|
|
|
*c = 0;
|
|
|
|
}
|
|
|
|
else if (isalpha(*c))
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
/* read normal string */
|
|
|
|
c++;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("non-qouted string\n");
|
|
|
|
#endif
|
2016-12-12 20:16:32 +00:00
|
|
|
while ((kar = fgetc(_chanrd)) != ',' && kar != EOF && !isspace(kar) && kar != '\n')
|
|
|
|
*c++ = kar;
|
|
|
|
ungetc(kar, _chanrd);
|
|
|
|
*c = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ferror(_chanrd))
|
|
|
|
error(29);
|
|
|
|
if (feof(_chanrd))
|
|
|
|
error(2);
|
|
|
|
if (_chann == -1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
fgets(buffer, 1024, _chanrd);
|
1984-11-29 14:22:02 +00:00
|
|
|
printf("?Redo ");
|
|
|
|
_rdline(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error(40);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf("string read: %s\n", buffer);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
|
|
|
readskip();
|
|
|
|
/* save value read */
|
|
|
|
_decstr(*s);
|
2016-12-12 20:16:32 +00:00
|
|
|
*s = (String*)_newstr(buffer);
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
|
|
|
|
1985-01-21 12:37:26 +00:00
|
|
|
extern int _seektab[];
|
1984-11-29 14:22:02 +00:00
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void _restore(int line)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
int nr;
|
|
|
|
char buffer[1024];
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf("seek to %d", line);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
2016-12-12 20:16:32 +00:00
|
|
|
fseek(_chanrd, 0l, 0);
|
|
|
|
if (line)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
/* search number of lines to skip */
|
2016-12-12 20:16:32 +00:00
|
|
|
for (nr = 0; _seektab[nr] && _seektab[nr] < line; nr += 2)
|
1984-11-29 14:22:02 +00:00
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf("test %d %d\n", _seektab[nr], _seektab[nr + 1]);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
|
|
|
;
|
|
|
|
nr /= 2;
|
|
|
|
#ifdef DEBUG
|
2016-12-12 20:16:32 +00:00
|
|
|
printf(" %d lines to skip\n", nr);
|
1984-11-29 14:22:02 +00:00
|
|
|
#endif
|
2016-12-12 20:16:32 +00:00
|
|
|
while (nr-- > 0)
|
|
|
|
fgets(buffer, 1024, _chanrd);
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _rdline(String** s)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
char buffer[1024];
|
2016-12-12 20:16:32 +00:00
|
|
|
if (fgets(buffer, 1024, _chanrd) == 0)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
if (_chann == -1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
printf("?Redo ");
|
|
|
|
_rdline(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error(40);
|
|
|
|
}
|
|
|
|
_decstr(*s);
|
2016-12-12 20:16:32 +00:00
|
|
|
*s = (String*)_newstr(buffer);
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|