ack/lang/basic/lib/print.c

90 lines
1.2 KiB
C
Raw Permalink Normal View History

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "bc_io.h"
#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
{
char buffer[40];
1984-11-29 14:22:02 +00:00
_asschn();
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
{
register char* c = buffer;
int eformat = 0;
if (f >= 0)
{
if (f > 1.0e8)
{
eformat = 1;
sprintf(buffer, " %e", f);
}
else
sprintf(buffer, " %f", f);
1984-11-29 14:22:02 +00:00
c++;
}
else
{
if (-f > 1.0e8)
{
eformat = 1;
sprintf(buffer, "-%e", -f);
}
else
sprintf(buffer, "-%f", -f);
1984-11-29 14:22:02 +00:00
}
if (!eformat)
{
for (; *c && *c != ' '; c++)
;
c--;
while (c > buffer && *c == '0')
{
*c = 0;
c--;
}
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 */
char buffer[100];
char* c;
1984-11-29 14:22:02 +00:00
_asschn();
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();
if (str == 0)
_out("<null>");
else
_out(str->strval);
1984-11-29 14:22:02 +00:00
}