This commit is contained in:
Oliver Lehmann 1989-05-26 13:49:45 +00:00
parent f376daca1a
commit 0abad3c194
3 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** Clear query buffer
** Flag f is set if called explicitly (with \q) and is
** clear if called automatically.
*/
clear(f)
register int f;
{
Autoclear = 0;
/* TRUNCATE FILE & RETURN */
if (!freopen(Qbname, "w", Qryiop))
AAsyserr(16001);
if (Nodayfile >= 0 && f)
prompt(EMPTY);
if (f)
clrline(TRUE);
Notnull = 0;
}

View File

@ -0,0 +1,73 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** DO MACRO EVALUATION OF QUERY BUFFER
**
** The logical query buffer is read and passed through the macro
** processor. The main purpose of this is to evaluate {define}'s.
** If the 'pr' flag is set, the result is printed on the terminal,
** and so becomes a post-evaluation version of print.
*/
eval(pr)
register int pr;
{
register FILE *tfile;
register int c;
# ifdef SETBUF
char tbuf[BUFSIZ];
# endif
char tfilename[QRYNAME];
extern int fgetc();
Autoclear = 0;
clrline(TRUE);
/* open temp file and rewind query buffer */
if (!pr)
{
Notnull = 0;
AAconcat(QRYTBUF, Fileset, tfilename);
if (!(tfile = fopen(tfilename, "w")))
AAsyserr(16004, tfilename);
# ifdef SETBUF
setbuf(tfile, tbuf);
# endif
}
if (!freopen(Qbname, "r", Qryiop))
AAsyserr(16005);
/* COPY FILE */
macinit(fgetc, Qryiop, FALSE);
while ((c = macgetch()) > 0)
{
if (pr)
putchar(c);
else
{
if (c != ' ' && c != '\n' && c != '\t')
Notnull++;
if (putc(c, tfile) == EOF)
AAsyserr(16006);
}
}
if (!pr)
{
/* link temp file back to query buffer */
fclose(tfile);
unlink(Qbname);
if (link(tfilename, Qbname))
AAsyserr(16007);
unlink(tfilename);
}
/* reopen query buffer (now evaluated) */
if (!(Qryiop = freopen(Qbname, "a", Qryiop)))
AAsyserr(16008);
cgprompt();
}

View File

@ -0,0 +1,49 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** PRINT QUERY BUFFER
**
** The logical query buffer is printed on the terminal regardless
** of the "Nodayfile" mode. Autoclear is reset, so the query
** may be rerun.
*/
print(pr)
register int pr;
{
register int c;
register FILE *iop;
# ifdef SETBUF
char iop_buf[BUFSIZ];
# endif
if (pr)
{
/* BACK UP FILE & UPDATE LAST PAGE */
Autoclear = 0;
clrline(TRUE);
fflush(Qryiop);
}
if (!(iop = fopen(Qbname, "r")))
AAsyserr(16021, Qbname);
# ifdef SETBUF
setbuf(iop, iop_buf);
# endif
/* list file on standard output */
Notnull = 0;
while ((c = getc(iop)) > 0)
{
if (pr)
putchar(c);
if (c != ' ' && c != '\n' && c != '\t')
Notnull++;
}
fclose(iop);
cgprompt();
}