This commit is contained in:
Oliver Lehmann 1989-04-03 19:22:17 +00:00
parent 9a13de27d5
commit 33acf4a9ef
6 changed files with 477 additions and 0 deletions

View File

@ -0,0 +1,248 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "../h/catalog.h"
# include "../h/tree.h"
# include "../h/symbol.h"
# include "../h/access.h"
/*
** DISPLAY -- display query corresponding to view, permission,
** or intgerity declaration
**
** Defines:
** display() -- main function
** disp() -- routes VIEW, PERMIT, and INTEGRITY
** pr_def() -- print view definition
** pr_integrity() -- print out integrity contstraints on a rel
*/
extern FILE *Dbs_out;
extern int Standalone;
extern QTREE *gettree(); /* gets a tree from AA_TREE catalog [readtree.c] */
char *Resrel; /* Used in pr_tree() [pr_tree.c] */
static short Mode; /* 4 - View, 5 - permission, 6 - integrity
* query print
*/
/*
** DISPLAY -- display query
**
** Parameters:
** argc -- number of args in argv
** argv -- argv [i] == 4 for VIEW, 5 for PERMIT, 6 for INTEGRITY
** where i % 2 == 0
** argv [i] -- relation names for which argv[i-1] is Mode
** where i%2==1
**
** Returns:
** 0 -- total success
** err -- error number of last error
*/
display(argc, argv)
int argc;
char **argv;
{
register int ac;
register char **av;
extern DESC Treedes;
char err_array[MAXPARMS]; /* errors are coded
** this array for
** printing out
** at the end
*/
int err;
# ifdef xZTR1
if (AAtTfp(11, -1, "DISPLAY: "))
AAprargs(argc, argv);
# endif
err = 0;
if (argc % 2)
AAsyserr(11023, argc);
opencatalog(AA_TREE, 0);
for (ac = 0, av = argv; ac < argc; av++, ac++)
{
if (AA_atoi(*av, &Mode))
AAsyserr(11024, *av);
Resrel = *++av;
err_array[ac++] = 0;
err_array[ac] = disp(*av);
}
for (ac = 0, av = argv; ac < argc; av++, ac++)
{
if (err_array[ac])
err = error(5400 + err_array[ac], *av, (char *) 0);
}
return (err);
}
/*
** DISP -- display integrity, permit, or define query on a relation
**
** Finds a relation owned by the user or the DBA and passes
** the name and owner to the appropritae routine depending on
** Mode.
**
** Parameters:
** relation -- relation on which query is to be printed
**
** Returns:
** 0 -- success
** 1 -- no such relation, or none seeable by the user.
** 3 -- VIEW mode and relation not a view
** 4 -- PERMIT and no permissions on relation
** 5 -- INTEGRITY mode and no integrity constraints
*/
disp(relation)
char *relation;
{
DESC d;
register int i;
# ifdef xZTR1
AAtTfp(11, 8, "DISP: relation %s\n", relation);
# endif
if ((i = AArelopen(&d, -1, relation)) < 0)
AAsyserr(11025, relation, i);
if (i > 0 || !AAbequal(AAusercode, d.reldum.relowner, 2))
return (1);
switch (Mode)
{
case 4: /* View query */
if (d.reldum.relstat & S_VIEW)
pr_def(relation, d.reldum.relowner);
else
return (3);
break;
case 5:
if (pr_prot(&d))
return (4);
break;
case 6:
if (d.reldum.relstat & S_INTEG)
pr_integrity(relation, d.reldum.relowner);
else
return (5);
break;
default:
AAsyserr(11026, Mode);
}
return (0);
}
/*
** PR_DEF -- Print "define view" query of a view
**
** Parameters:
** relation -- relation in question
** owner -- relowner
**
** Side Effects:
** reads a tree, clears range table
*/
pr_def(relation, owner)
char *relation;
char *owner;
{
register QTREE *t;
# ifdef xZTR1
AAtTfp(11, 9, "pr_def(relation=\"%s\", owner=%s)\n", relation, owner);
# endif
if (!Standalone)
fprintf(Dbs_out, "View %s defined:\n\n", relation);
clrrange();
/* Treeid == 0 because views have only one definition */
t = gettree(relation, owner, mdVIEW, 0);
pr_range();
fprintf(Dbs_out, "define view ");
pr_tree(t);
}
/*
** PR_INTEGRITY -- print out integrity constraints on a relation
**
** Finds all integrity tuples for this unique relation, and
** calls pr_int() to print a query from them.
**
** Parameters:
** relid -- rel name
** relowner -- 2 byte owner id
*/
pr_integrity(relid, relowner)
char *relid;
char *relowner;
{
extern DESC Intdes;
struct tup_id hitid;
struct tup_id lotid;
struct integrity key;
struct integrity tuple;
register int i;
# ifdef xZTR1
AAtTfp(11, 9, "pr_integrity(relid =%s, relowner=%s)\n", relid, relowner);
# endif
if (!Standalone)
fprintf(Dbs_out, "Integrity constraints on %s are:\n\n", relid);
opencatalog(AA_INTEG, 0);
/* get AA_INTEG tuples for relid, relowner */
AAam_clearkeys(&Intdes);
AAam_setkey(&Intdes, &key, relid, INTRELID);
AAam_setkey(&Intdes, &key, relowner, INTRELOWNER);
if (i = AAam_find(&Intdes, EXACTKEY, &lotid, &hitid, &key))
AAsyserr(11027, i);
for ( ; ; )
{
if (i = AAam_get(&Intdes, &lotid, &hitid, &tuple, TRUE))
break;
if (!AAkcompare(&Intdes, &tuple, &key))
pr_int(&tuple);
}
if (i != 1)
AAsyserr(11028, i);
}
/*
** PR_INT -- print an integrity definition given a AA_INTEG tuple
**
** Parameters:
** g -- integrity tuple
*/
pr_int(g)
struct integrity *g;
{
register struct integrity *i;
register QTREE *t;
extern int Resultvar;
i = g;
clrrange();
t = gettree(i->intrelid, i->intrelowner, mdINTEG, i->inttree);
if (!Standalone)
fprintf(Dbs_out, "Integrity constraint %d -\n\n", i->inttree);
pr_range();
fprintf(Dbs_out, "define integrity on ");
pr_rv(Resultvar = ctoi(i->intresvar));
fprintf(Dbs_out, " is ");
pr_qual(t->right);
if (!Standalone)
fprintf(Dbs_out, "\n\n\n");
}

View File

@ -0,0 +1,82 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** INCLUDE FILE
**
** A file name, which must follow the \i, is read and inserted
** into the text stream at this location. It may include all of
** the standard control functions. Includes may be nested.
**
** If the parameter is 0, the file name is taken from the input;
** otherwise it is taken directly from the parameter. In this
** mode, errors are not printed.
**
** Prompts are turned off during the include.
*/
include(filename)
char *filename;
{
register char *f;
register FILE *b;
register int savendf;
register FILE *saveinp;
# ifdef SETBUF
char inpbuf[BUFSIZ];
# endif
extern char *getfilename();
if (!(f = filename))
f = getfilename();
if (AAsequal(f, "-")) /* read keyboard */
b = stdin;
else if (!*f)
{
/* back up one level (EOF on next read) */
Peekch = -1;
return;
}
else /* read file */
{
if (!(b = fopen(f, "r")))
{
if (!filename)
printf("%sopen INCLUDE file '%s'\n", ERROR, f);
return;
}
# ifdef SETBUF
setbuf(b, inpbuf);
# endif
}
/* check for too deep */
if (Idepth >= INC_DEPTH)
{
printf("%sMehr als %d INCLUDE's\n", ERROR, INC_DEPTH);
if (b && b != stdin)
fclose(b);
return;
}
Idepth++;
/* get input from alternate file */
savendf = Nodayfile;
if (b == stdin)
{
Nodayfile = Userdflag;
prompt(INPUT);
}
else
Nodayfile = -1;
saveinp = Input;
Input = b;
command();
/* done -- restore old file */
Input = saveinp;
Nodayfile = savendf;
Idepth--;
}

View File

@ -0,0 +1,17 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** CHANGE WORKING DIRECTORY
*/
newdirec()
{
register char *direc;
extern char *getfilename();
if (chdir(direc = getfilename()))
printf("%s? cd `%s'\n", ERROR, direc);
}

View File

@ -0,0 +1,36 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** OUTPUT PROMPT CHARACTER
**
** The prompt is output to the standard output. It will not be
** output if -ss mode is set or if we are not at a newline.
**
** The parameter is printed out if non-zero.
*/
prompt(msg)
register char *msg;
{
if (!Prompt || Peekch < 0)
return;
if (Nodayfile >= 0)
{
if (msg)
printf("\07%s\n", msg);
printf(PROMPT);
}
fflush(stdout);
}
/*
** PROMPT WITH CONTINUE OR GO
*/
cgprompt()
{
prompt(Notnull? FULL: EMPTY);
}

View File

@ -0,0 +1,25 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
# define HELPMSG "\t? %s\n\tVersuchen Sie %s\n"
/*
** SHORT (SYNTAX) ON-LINE HELP
*/
shorthelp(x)
register int x; /* x == 1: short help */
/* == 0: long help */
{
register char *help;
extern char *AAztack();
extern char *getfilename();
help = getfilename();
if (!*help)
help = "toc";
if (AAcat(AAztack(AAztack(AApath, x? "/sys/ref/": "/sys/man/"), help)))
printf(HELPMSG, help, x? "help": "HELP");
}

View File

@ -0,0 +1,69 @@
# include <stdio.h>
# include "gen.h"
# include "../h/dbs.h"
# include "../h/aux.h"
# include "monitor.h"
/*
** WAIT FOR PROCESS TO DIE
**
** Used in edit() and shell() to terminate the subprocess.
** Waits on pid "Xwaitpid". If this is zero, xwait() returns
** immediately.
**
** This is called by "catchsig()" so as to properly terminate
** on a rubout while in one of the subsystems.
*/
xwait()
{
register int i;
int status;
# ifdef MACRO
extern char *mcall();
# endif
# ifdef xMTR2
AAtTfp(15, 0, "XWAIT: [%u]\n", Xwaitpid);
# endif
if (!Xwaitpid)
{
cgprompt();
return;
}
while ((i = wait(&status)) != -1)
{
# ifdef xMTR2
AAtTfp(15, 1, "pid %u stat 0%o\n", i, status);
# endif
if (i == Xwaitpid)
break;
}
if (i < 0)
{
AAunlall();
fflush(stdout);
exit(status >> 8);
}
Xwaitpid = 0;
# ifdef MACRO
/* call execptionhandler EXECTRAP */
if (i = status >> 8)
{
macdefine(ERRORCOUNT, AA_iocv(i), TRUE);
mcall(EXECTRAP);
}
# endif
print(FALSE);
/* reopen query buffer */
if (!(Qryiop = fopen(Qbname, "a")))
AAsyserr(16026);
# ifdef SETBUF
setbuf(Qryiop, Qryxxx);
# endif
}