This commit is contained in:
Oliver Lehmann 1989-08-30 12:48:26 +00:00
parent 1e4ac310c6
commit d37f3fc9b0
5 changed files with 651 additions and 0 deletions

View File

@ -0,0 +1,99 @@
/*
** --- RG_DOM.C -------- DOMAIN HANDLING ------------------------------------
**
** Version: @(#)rg_dom.c 4.0 02/05/89
**
*/
# include <stdio.h>
# include "rg_int.h"
# define FRMT tos->sy_frmt
# define FRML tos->sy_frml
rg_push_dom(tos, tup, from, to)
register SYMBOL *tos;
register char *tup;
int from;
int to;
{
register DESC_T *d;
register union anytype *any;
int len;
extern DESC_T *ck_dom();
extern char *AAbmove();
d = ck_dom(R_val);
tup += d->domoff;
len = ctou(d->domfrml);
if (d->domfrmt == CHAR)
{
from = ck_len(&len, from, to);
tup += from;
push_str(tos, tup, len);
# ifdef RG_TRACE
if (TR_PUSH)
{
printf("PUSH-DOM CHAR len=%d |", len);
while (len--)
{
putchar(*tup);
tup++;
}
printf("|\n");
}
# endif
return;
}
/* d->domfrmt == INT | FLOAT */
FRMT = FLOAT;
FRML = sizeof (double);
any = &tos->sy_val;
AAbmove(tup, any->c0type, len);
/* now convert to double */
switch (len)
{
case sizeof (char): /* must be INT */
any->f8type = ctoi(any->i1type);
break;
case sizeof (short): /* must be INT */
any->f8type = any->i2type;
break;
case sizeof (long):
if (d->domfrmt == INT)
any->f8type = any->i4type;
# ifndef NO_F4
else
any->f8type = any->f4type;
# endif
}
# ifdef RG_TRACE
if (TR_PUSH)
printf("PUSH-DOM FLOAT %10.3f\n", any->f8type);
# endif
}
rg_pr_dom(tup)
register char *tup;
{
register DESC_T *d;
register SYMBOL *tos;
register union anytype *any;
extern char *AAbmove();
extern DESC_T *ck_dom();
d = ck_dom(R_val);
tup += d->domoff;
tos = Print;
FRML = ctou(d->domfrml);
any = &tos->sy_val;
if ((FRMT = d->domfrmt) == CHAR)
any->cptype = tup;
else
AAbmove(tup, any->c0type, ctou(FRML));
}

View File

@ -0,0 +1,177 @@
/*
** --- RG_LINE.C ------- LINE EXCEPTIONS ------------------------------------
**
** Version: @(#)rg_line.c 4.0 02/05/89
**
*/
# include "rg.h"
static char Ovfline[MAX_LINE];
static char *SYS_ovfl = Ovfline;
line_begin()
{
register int save;
# ifdef RG_TRACE
if (TR_LINE)
printf("#LINE\t%d\n", SYS_line);
# endif
SYS_line++; /* new line */
SYS_col = Line;
if (ONb_line)
/* ==========--------------- */
/* | HEADER | Text[R_cols] | */
/* ==========--------------- */
{
Col_begin = Line;
Col_end = &Line[MAX_LINE - R_cols];
save = Line_begin;
Line_begin = 1;
exception(&RUNline, ONb_line, FALSE);
Line_begin = save;
}
/* ---------================ */
/* | HEADER | Text[R_cols] | */
/* ---------================ */
Col_begin = SYS_col;
Col_end = Col_begin + R_cols;
}
line_end()
{
register int save;
extern char *AApad();
# ifdef RG_TRACE
if (TR_LINE)
printf("LINE#\t%d\n", SYS_line);
# endif
if (!ONe_line)
return;
if ((save = Col_end - SYS_col) > 0)
SYS_col = AApad(SYS_col, save);
Col_begin = Line;
Col_end = &Line[MAX_LINE];
save = Line_begin;
Line_begin = 1;
exception(&RUNline, ONe_line, FALSE);
Line_begin = save;
}
set_line(line)
register int line;
{
# ifdef RG_TRACE
if (TR_LINE)
printf("SET\tline %d to %d\n", SYS_line, line);
# endif
if (RUNline)
{
RUN++;
return;
}
/* set to line begin */
if (SYS_col != Col_begin)
new_line();
/* check for valid line count */
if (line <= 0 || line > R_lines)
line = 0;
else
--line;
while (line != SYS_line - Line_begin)
{
new_line();
if (RUN)
return;
}
}
new_line()
{
register char *p;
register int c;
register int l;
int len;
# ifdef RG_TRACE
if (TR_LINE)
printf("NEW\tline %d\n", SYS_line);
# endif
if (!SYS_line)
page_header();
line_end();
if ((len = l = SYS_col - (p = Line)) > 0)
{
for ( ; l; --l)
{
if ((c = *p) < ' ')
*p = ' ';
else if (R_big && ((c >= 'a'
# ifdef EBCDIC
&& c <= 'i') || (c >= 'j'
&& c <= 'r') || (c >= 's'
# endif
&& c <= 'z')))
*p = c + 'A' - 'a';
# ifndef EBCDIC
*p &= ASCII_MASK;
# endif
p++;
}
}
*p = '\n';
rg_report(Line, ++len);
line_begin();
if (SYS_line >= Line_end)
page_end();
batch_line();
}
check_line()
{
register char *from;
register char *to;
register int len;
register int count;
extern char *AAbmove();
while (SYS_col > (from = Col_end))
{
if (RUNline)
{ /* abort exception */
SYS_col = from;
RUN++;
return;
}
len = SYS_col - from;
SYS_ovfl = AAbmove(SYS_col = from, to = SYS_ovfl, len);
count = batch_count(0);
new_line();
batch_count(count);
SYS_col = AAbmove(SYS_ovfl = to, SYS_col, len);
}
}

View File

@ -0,0 +1,110 @@
/*
** --- RG_PAGE.C ------- PAGE EXCEPTIONS ------------------------------------
**
** Version: @(#)rg_page.c 4.0 02/05/89
**
*/
# include "rg.h"
page_header()
{
register int len;
char save[MAX_LINE];
extern char *AAbmove();
# ifdef RG_TRACE
if (TR_PAGE)
printf("HEADER\tpage=%d\n", SYS_page);
# endif
len = SYS_col - Line;
/* save line */
AAbmove(Line, save, len);
line_begin();
page_begin();
/* restore line */
SYS_col = AAbmove(save, SYS_col, len);
}
page_begin()
{
register int page;
# ifdef RG_TRACE
if (TR_PAGE)
printf("#PAGE\t%d\n", SYS_page);
# endif
page = ++SYS_page; /* new page */
SYS_line = 1;
RUNoutput = page < R_first_page || page > R_last_page;
if (ONb_page)
{
Line_begin = 1;
Line_end = MAX_I2;
exception(&RUNpage, ONb_page, TRUE);
}
Line_begin = SYS_line;
Line_end = Line_begin + R_lines;
}
page_end()
{
register int i;
# ifdef RG_TRACE
if (TR_PAGE)
printf("PAGE#\t%d\n", SYS_page);
# endif
if (ONe_page)
{
Line_begin = 1;
Line_end = MAX_I2;
exception(&RUNpage, ONe_page, TRUE);
}
/* check for too long page */
i = R_all_lines - SYS_line + 1;
while (i < 0)
{
i += R_all_lines;
if (!i)
i = R_all_lines;
}
for ( ; i; --i)
rg_report("\n", 1); /* empty lines */
SYS_line = 0;
SYS_col = Col_begin = Line;
Col_end = Col_begin + R_cols;
}
new_page()
{
register int i;
# ifdef RG_TRACE
if (TR_PAGE)
printf("NEW\tpage%d\n", SYS_page);
# endif
if (SYS_col != Col_begin)
new_line();
if (!SYS_line)
return;
for (i = Line_end - SYS_line; i > 0; --i)
new_line();
}

View File

@ -0,0 +1,124 @@
/*
** --- RG_REP.C -------- REPORT OUTPUT --------------------------------------
**
** Version: @(#)rg_rep.c 4.0 02/05/89
**
*/
# include <stdio.h>
# include "rg_file.h"
static char ibuf[MAX_FIELD];
static char obuf[BUFSIZ];
static char *bp = obuf;
static char PROMPT[] = "> \007";
rg_report(b, olen)
register char *b;
int olen;
{
register int len;
register char *p;
# ifdef RG_TRACE
register int c;
if (TR_REPORT)
{
printf("REPORT RUN %d\tlen=%d, `", RUNoutput, len = olen);
for (p = b; len; --len)
{
if ((c = *p++) == '\n')
printf("\\n");
else
putchar(c);
if (c == ' ')
{
while (*p == ' ')
{
p++;
--len;
}
}
}
printf("'\n");
}
# endif
if (RUNoutput)
return; /* nothing to print */
if ((len = &obuf[BUFSIZ] - (p = bp)) > olen)
len = olen;
olen -= len;
while (--len >= 0)
*p++ = *b++;
bp = p;
if (olen)
{
rg_flush(); /* flush the buffer */
rg_report(b, olen); /* write the rest */
}
}
rg_flush()
{
register FILETYPE *f;
register int len;
extern int errno;
len = bp - obuf;
# ifdef RG_TRACE
if (TR_REPORT)
printf("FLUSH\tlen=%d\n", len);
# endif
if (!len)
goto done; /* nothing to print */
if (!(f = &Rg_file[F_REPORT - 1])->rf_open)
{ /* report not open, what can we do ? */
rg_error("REPORT NOT OPEN");
rg_exit(EXIT_OPEN);
}
errno = 0;
if (write(f->rf_fd, obuf, len) != len)
{
rg_error("REPORT WRITE ERROR");
rg_exit(EXIT_WRITE);
}
done:
bp = obuf;
}
rg_input(output, input)
char *output;
char **input;
{
register char *b;
register int len;
register int c;
write(2, output, R_val);
write(2, PROMPT, sizeof PROMPT - 1);
*input = b = ibuf;
len = 0;
/* no test for ibuf overflowe werde made */
while ((c = getchar()) > 0)
{
if (c == '\n')
break;
*b++ = c;
len++;
}
return (len);
}

View File

@ -0,0 +1,141 @@
/*
** --- RG_UTIL.C ------- UTILITIES ------------------------------------------
**
** CMOVE() pad with some char's
** SEPERATE() find last blank for string batching
** PAD() pad string out with blanks
** CONVERT() convert anything to double
**
** Version: @(#)rg_util.c 4.0 02/05/89
**
*/
# include "rg_int.h"
char *cmove(b, l, c)
register char *b;
register int l;
register int c;
{
while (--l >= 0)
*b++ = c;
return (b);
}
seperate(b, l)
register char *b;
register int l;
{
register char *p;
b = p = &b[l];
while (--l && *(--p) != ' ')
continue;
if (l)
return (l);
return (b - p + 1);
}
char *AApad(s, l)
register char *s;
register int l;
{
register int c;
c = ' ';
while (--l >= 0)
*s++ = c;
return (s);
}
convert(s)
register SYMBOL *s;
{
register int len;
register union anytype *any;
register char *p;
register int i;
char save;
extern char *print_type();
len = ctou(s->sy_frml);
any = &s->sy_val;
# ifdef RG_TRACE
if (TR_FORMAT)
printf("CONVERT\t%s%d\n", print_type(s->sy_frmt), len);
# endif
switch (s->sy_frmt)
/* assume correct types: "c..", "i1", "i2", "i4", "f4", "f8" */
{
case CHAR: /* try to convert */
p = &any->cptype[len];
save = *p;
*p = 0;
i = AA_atof(any->cptype, &any->f8type);
*p = save;
if (i)
return (TRUE);
break;
case INT:
switch (len)
{
case sizeof (char):
any->f8type = ctoi(any->i1type);
break;
case sizeof (short):
any->f8type = any->i2type;
break;
case sizeof (long):
any->f8type = any->i4type;
break;
}
break;
# ifndef NO_F4
case FLOAT:
if (len == sizeof (float))
any->f8type = any->f4type;
# endif
}
s->sy_frmt = FLOAT;
s->sy_frml = sizeof (double);
return (FALSE);
}
char *print_type(type)
register int type;
{
static char buf[2];
switch (type)
{
case INT:
return ("i");
case CHAR:
return ("c");
case FLOAT:
return ("f");
}
buf[0] = type + 'A';
buf[1] = 0;
return (buf);
}