2013-05-14 15:11:29 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2018-06-23 22:35:51 +00:00
|
|
|
#include <string.h>
|
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
|
|
|
|
|
|
|
/* Here all routine to generate terminal oriented output is located */
|
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void _qstmark(void)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
/* prompt for terminal input */
|
|
|
|
putchar('?');
|
|
|
|
}
|
|
|
|
|
2016-12-12 20:15:25 +00:00
|
|
|
void _nl(void)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
_asschn();
|
|
|
|
_outnl();
|
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _prinum(int i)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
char buffer[40];
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
_asschn();
|
2016-12-12 20:16:32 +00:00
|
|
|
if (i >= 0)
|
|
|
|
sprintf(buffer, " %d ", i);
|
|
|
|
else
|
|
|
|
sprintf(buffer, "-%d ", -i);
|
1984-11-29 14:22:02 +00:00
|
|
|
_out(buffer);
|
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _str(double f, char* buffer)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
register char* c = buffer;
|
1987-02-11 12:47:45 +00:00
|
|
|
int eformat = 0;
|
2016-12-12 20:16:32 +00:00
|
|
|
if (f >= 0)
|
|
|
|
{
|
|
|
|
if (f > 1.0e8)
|
|
|
|
{
|
1987-02-11 12:47:45 +00:00
|
|
|
eformat = 1;
|
2016-12-12 20:16:32 +00:00
|
|
|
sprintf(buffer, " %e", f);
|
1987-02-11 12:47:45 +00:00
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
else
|
|
|
|
sprintf(buffer, " %f", f);
|
1984-11-29 14:22:02 +00:00
|
|
|
c++;
|
2016-12-12 20:16:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (-f > 1.0e8)
|
|
|
|
{
|
1987-02-11 12:47:45 +00:00
|
|
|
eformat = 1;
|
2016-12-12 20:16:32 +00:00
|
|
|
sprintf(buffer, "-%e", -f);
|
1987-02-11 12:47:45 +00:00
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
else
|
|
|
|
sprintf(buffer, "-%f", -f);
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
if (!eformat)
|
|
|
|
{
|
|
|
|
for (; *c && *c != ' '; c++)
|
|
|
|
;
|
1987-02-11 12:47:45 +00:00
|
|
|
c--;
|
2016-12-12 20:16:32 +00:00
|
|
|
while (c > buffer && *c == '0')
|
1987-02-11 12:47:45 +00:00
|
|
|
{
|
2016-12-12 20:16:32 +00:00
|
|
|
*c = 0;
|
|
|
|
c--;
|
1987-02-11 12:47:45 +00:00
|
|
|
}
|
2016-12-12 20:16:32 +00:00
|
|
|
if (*c == '.')
|
|
|
|
*c = 0;
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _prfnum(double f)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
/* BASIC strings trailing zeroes */
|
2016-12-12 20:16:32 +00:00
|
|
|
char buffer[100];
|
|
|
|
char* c;
|
1984-11-29 14:22:02 +00:00
|
|
|
|
|
|
|
_asschn();
|
2016-12-12 20:16:32 +00:00
|
|
|
c = buffer;
|
|
|
|
_str(f, c);
|
|
|
|
strcat(buffer, " ");
|
1984-11-29 14:22:02 +00:00
|
|
|
_out(buffer);
|
|
|
|
}
|
2016-12-12 20:15:25 +00:00
|
|
|
void _prstr(String* str)
|
1984-11-29 14:22:02 +00:00
|
|
|
{
|
|
|
|
_asschn();
|
2016-12-12 20:16:32 +00:00
|
|
|
if (str == 0)
|
|
|
|
_out("<null>");
|
|
|
|
else
|
|
|
|
_out(str->strval);
|
1984-11-29 14:22:02 +00:00
|
|
|
}
|