1985-02-04 22:18:16 +00:00
|
|
|
#include "bc_io.h"
|
2018-06-23 22:35:51 +00:00
|
|
|
#include "lib.h"
|
1984-11-29 14:22:02 +00:00
|
|
|
|
2013-05-14 15:11:29 +00:00
|
|
|
/* dtrg --- this originally used sgtty.h to do clever tty manipulation.
|
|
|
|
* Strictly this should be converted to use termios, but for simplicity
|
|
|
|
* we're going to stick with plain stdio for now. */
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
/* BASIC has some nasty io characteristics */
|
|
|
|
|
|
|
|
#define MAXWIDTH 255
|
|
|
|
|
2016-12-12 20:16:32 +00:00
|
|
|
int _width = 75, _pos = 0, _zonewidth = 15;
|
1984-11-29 14:22:02 +00:00
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void _out(char* str)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
2016-12-12 20:16:32 +00:00
|
|
|
if (_chann == -1)
|
|
|
|
pos = _pos;
|
|
|
|
else
|
|
|
|
pos = _fdtable[_chann].pos;
|
|
|
|
while (*str)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
if (pos >= _width)
|
|
|
|
{
|
|
|
|
_outnl();
|
|
|
|
pos = 0;
|
|
|
|
}
|
1984-11-29 14:22:02 +00:00
|
|
|
fputc(*str++, _chanwr);
|
|
|
|
pos++;
|
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
if (_chann == -1)
|
|
|
|
_pos = pos;
|
|
|
|
else
|
|
|
|
_fdtable[_chann].pos = pos;
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void _outnl(void)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
fputc('\n', _chanwr);
|
|
|
|
if (_chann == -1)
|
|
|
|
_pos = 0;
|
1984-11-29 14:22:02 +00:00
|
|
|
else
|
2016-12-12 20:16:32 +00:00
|
|
|
_fdtable[_chann].pos = 0;
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _zone(void)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
/* go to next zone */
|
|
|
|
int pos;
|
2016-12-12 20:16:32 +00:00
|
|
|
if (_chann == -1)
|
|
|
|
pos = _pos;
|
|
|
|
else
|
|
|
|
pos = _fdtable[_chann].pos;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fputc(' ', _chanwr);
|
1984-11-29 14:22:02 +00:00
|
|
|
pos++;
|
2016-12-12 20:16:32 +00:00
|
|
|
if (pos == _width)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
_outnl();
|
2016-12-12 20:16:32 +00:00
|
|
|
pos = 0;
|
1984-11-29 14:22:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
} while (pos % _zonewidth != 0);
|
|
|
|
if (_chann == -1)
|
|
|
|
_pos = pos;
|
|
|
|
else
|
|
|
|
_fdtable[_chann].pos = pos;
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _in(char* buf)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
register int holder;
|
|
|
|
char* c;
|
1984-11-29 14:22:02 +00:00
|
|
|
int pos;
|
2016-12-12 20:16:32 +00:00
|
|
|
if (_chann == -1)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
pos = _pos;
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
else
|
|
|
|
pos = _fdtable[_chann].pos;
|
|
|
|
c = buf;
|
|
|
|
while ((holder = fgetc(_chanrd)) != EOF && holder != '\n')
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
*c = holder;
|
|
|
|
if (_chann == -1)
|
|
|
|
putchar(holder);
|
|
|
|
c++;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
*c = 0;
|
|
|
|
if (_chann == -1)
|
|
|
|
{
|
|
|
|
_pos = pos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_fdtable[_chann].pos = pos;
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _tab(int x)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
if (x > _width)
|
|
|
|
error(3);
|
|
|
|
if (x < _pos)
|
|
|
|
_outnl();
|
|
|
|
_spc(x - _pos);
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _spc(int x)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
while (x-- > 0)
|
|
|
|
_out(" ");
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|