ING_DB
This commit is contained in:
parent
9f30ec29eb
commit
6d2490fb13
|
|
@ -0,0 +1,242 @@
|
||||||
|
# include <stdio.h>
|
||||||
|
# include "gen.h"
|
||||||
|
# include "../h/dbs.h"
|
||||||
|
# include "../h/aux.h"
|
||||||
|
# include "../h/access.h"
|
||||||
|
# include "../h/lock.h"
|
||||||
|
# include "../h/bs.h"
|
||||||
|
|
||||||
|
# ifdef P8000
|
||||||
|
ret_buf AAjmp_buf;
|
||||||
|
# else
|
||||||
|
jmp_buf AAjmp_buf;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
FILE *Dbs_out = stdout;
|
||||||
|
extern int AAdbstat;
|
||||||
|
|
||||||
|
main(argc, argv)
|
||||||
|
int argc;
|
||||||
|
char *argv[];
|
||||||
|
{
|
||||||
|
register char **av;
|
||||||
|
register char *q;
|
||||||
|
register char *p;
|
||||||
|
register int i;
|
||||||
|
register int badf;
|
||||||
|
register int mode;
|
||||||
|
register int nc;
|
||||||
|
char style;
|
||||||
|
char stdbuf[BUFSIZ];
|
||||||
|
extern struct out_arg AAout_arg;
|
||||||
|
extern char *Parmvect[];
|
||||||
|
extern char *Flagvect[];
|
||||||
|
extern char *AAdbpath;
|
||||||
|
extern char *AAproc_name;
|
||||||
|
|
||||||
|
AAproc_name = "PRINTR";
|
||||||
|
|
||||||
|
# ifdef xSTR1
|
||||||
|
AAtTrace(&argc, argv, 'X');
|
||||||
|
# endif
|
||||||
|
|
||||||
|
mode = -1;
|
||||||
|
badf = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Scan the argument vector and otherwise initialize.
|
||||||
|
*/
|
||||||
|
switch (i = initucode(argc, argv, TRUE, (char *) 0, M_SHARE))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 5:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
case 6:
|
||||||
|
AAsyserr(0, "Die Datenbank '%s' existiert nicht", Parmvect[0]);
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
AAsyserr(0, "Sie duerfen auf die Datenbank '%s' nicht zugreifen", Parmvect[0]);
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
AAsyserr(0, "Sie sind kein eingetragener DBS-Nutzer");
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
printf("Sie haben keinen Datenbanknamen angegeben\n");
|
||||||
|
badf++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
AAsyserr(22200, AAproc_name, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (av = Flagvect; p = *av; av++)
|
||||||
|
{
|
||||||
|
if (p[0] != '-')
|
||||||
|
goto badflag;
|
||||||
|
switch (p[1])
|
||||||
|
{
|
||||||
|
case 'H':
|
||||||
|
case 'h': /* do headers on each page */
|
||||||
|
mode = -2;
|
||||||
|
if (!p[2])
|
||||||
|
break;
|
||||||
|
if (AA_atoi(&p[2], &AAout_arg.linesperpage))
|
||||||
|
goto badflag;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
case 's': /* supress headers and footers */
|
||||||
|
mode = -3;
|
||||||
|
if (p[2])
|
||||||
|
goto badflag;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'C':
|
||||||
|
case 'c': /* set cNwidth */
|
||||||
|
if (AA_atoi(&p[2], &AAout_arg.c0width))
|
||||||
|
{
|
||||||
|
badflag:
|
||||||
|
printf("Unbekanntes Flag '%s'\n", p);
|
||||||
|
badf++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'I':
|
||||||
|
case 'i': /* set iNwidth */
|
||||||
|
switch (p[2])
|
||||||
|
{
|
||||||
|
case '1':
|
||||||
|
if (AA_atoi(&p[3], &AAout_arg.i1width))
|
||||||
|
goto badflag;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '2':
|
||||||
|
if (AA_atoi(&p[3], &AAout_arg.i2width))
|
||||||
|
goto badflag;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '4':
|
||||||
|
if (AA_atoi(&p[3], &AAout_arg.i4width))
|
||||||
|
goto badflag;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto badflag;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'F':
|
||||||
|
case 'f': /* set fNwidth */
|
||||||
|
style = p[3];
|
||||||
|
switch (style)
|
||||||
|
{
|
||||||
|
case 'E':
|
||||||
|
case 'e':
|
||||||
|
case 'F':
|
||||||
|
case 'f':
|
||||||
|
case 'G':
|
||||||
|
case 'g':
|
||||||
|
case 'N':
|
||||||
|
case 'n':
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto badflag;
|
||||||
|
}
|
||||||
|
for (q = &p[4]; *q != '.'; q++)
|
||||||
|
if (!*q)
|
||||||
|
goto badflag;
|
||||||
|
*q++ = 0;
|
||||||
|
switch (p[2])
|
||||||
|
{
|
||||||
|
case '4':
|
||||||
|
# ifndef NO_F4
|
||||||
|
if (AA_atoi(&p[4], &AAout_arg.f4width))
|
||||||
|
goto badflag;
|
||||||
|
if (AA_atoi(q, &AAout_arg.f4prec))
|
||||||
|
goto badflag;
|
||||||
|
AAout_arg.f4style = style;
|
||||||
|
break;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
case '8':
|
||||||
|
if (AA_atoi(&p[4], &AAout_arg.f8width))
|
||||||
|
goto badflag;
|
||||||
|
if (AA_atoi(q, &AAout_arg.f8prec))
|
||||||
|
goto badflag;
|
||||||
|
AAout_arg.f8style = style;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto badflag;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'V':
|
||||||
|
case 'v':
|
||||||
|
if (!p[2] || p[3])
|
||||||
|
goto badflag;
|
||||||
|
AAout_arg.coldelim = p[2];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'L':
|
||||||
|
case 'l':
|
||||||
|
if (!p[2] || p[3])
|
||||||
|
goto badflag;
|
||||||
|
AAout_arg.linedelim = p[2];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto badflag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Find end of Parmvect and store mode there
|
||||||
|
*/
|
||||||
|
for (nc = 1; Parmvect[nc]; nc++)
|
||||||
|
continue;
|
||||||
|
Parmvect[nc] = (char *) mode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Check for usage errors.
|
||||||
|
*/
|
||||||
|
if (nc < 2)
|
||||||
|
{
|
||||||
|
badf++;
|
||||||
|
printf("HINWEIS: printr [flags] db_name {relation}\n");
|
||||||
|
}
|
||||||
|
if (badf)
|
||||||
|
{
|
||||||
|
AAunlall();
|
||||||
|
fflush(stdout);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = Parmvect[0]; /* data base is first parameter */
|
||||||
|
if (chdir(AAdbpath) < 0)
|
||||||
|
AAsyserr(22201, AAproc_name, p);
|
||||||
|
|
||||||
|
# ifdef SETBUF
|
||||||
|
setbuf(stdout, stdbuf);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* initialize access methods (and AAdmin struct) for user_ovrd test */
|
||||||
|
AAam_start();
|
||||||
|
|
||||||
|
print(nc - 1, &Parmvect[1]);
|
||||||
|
AAunldb();
|
||||||
|
fflush(stdout);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rubproc()
|
||||||
|
{
|
||||||
|
AAunlall();
|
||||||
|
fflush(stdout);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,280 @@
|
||||||
|
# include <stdio.h>
|
||||||
|
# include "gen.h"
|
||||||
|
# include "../h/dbs.h"
|
||||||
|
# include "../h/aux.h"
|
||||||
|
# include "../h/lock.h"
|
||||||
|
# include "../h/bs.h"
|
||||||
|
|
||||||
|
# ifdef P8000
|
||||||
|
ret_buf AAjmp_buf;
|
||||||
|
# else
|
||||||
|
jmp_buf AAjmp_buf;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
char All;
|
||||||
|
char Superuser;
|
||||||
|
char Ask;
|
||||||
|
char Purge;
|
||||||
|
char Clean;
|
||||||
|
extern int Wait_action;
|
||||||
|
extern int AAdbstat;
|
||||||
|
extern char *AAusercode;
|
||||||
|
long Today;
|
||||||
|
char SYSNAME[] = "_SYS";
|
||||||
|
int s_SYSNAME = sizeof SYSNAME - 1;
|
||||||
|
extern DESC Reldes;
|
||||||
|
|
||||||
|
struct directory
|
||||||
|
{
|
||||||
|
short inumber;
|
||||||
|
char fname[14];
|
||||||
|
char null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
** PURGE DATABASE
|
||||||
|
**
|
||||||
|
** This stand-alone routine cleans up a database. This includes:
|
||||||
|
**
|
||||||
|
** - Destroy temporary relations, i.e., relations with names
|
||||||
|
** beginning with SYSNAME.
|
||||||
|
** - Destroy expired relations
|
||||||
|
** - Clean out junk files, such as core, etc.
|
||||||
|
** - As a suggested future expansion, reformat relations which
|
||||||
|
** have many overflow pages, or heaps with lots of old
|
||||||
|
** deleted tuples, etc.
|
||||||
|
**
|
||||||
|
** It may be called by the DBS superuser or by the dba of
|
||||||
|
** a database. There are two modes. The first is where databases
|
||||||
|
** to be purged are explicitly named. If none are named, then
|
||||||
|
** all databases owned by the particular user (or all databases
|
||||||
|
** if the DBS superuser) are purged.
|
||||||
|
**
|
||||||
|
** Flags:
|
||||||
|
** -p enable the purge feature, i.e., clean out expired
|
||||||
|
** relations as well as temporary relations.
|
||||||
|
** -s attempt to run in superuser mode. The user must be
|
||||||
|
** login USERDBS for this to succeed.
|
||||||
|
** -a ask the user before each database.
|
||||||
|
** -f clean out rather than report junk files.
|
||||||
|
*/
|
||||||
|
main(argc, argv)
|
||||||
|
int argc;
|
||||||
|
char *argv[];
|
||||||
|
{
|
||||||
|
register char *db;
|
||||||
|
register int ret;
|
||||||
|
extern char *getnxtdb();
|
||||||
|
|
||||||
|
# ifdef xSTR1
|
||||||
|
AAtTrace(&argc, argv, 'X');
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* set up arguments and operating modes */
|
||||||
|
initialize(argc, argv);
|
||||||
|
time(&Today);
|
||||||
|
# ifdef xSTR2
|
||||||
|
AAtTfp(10, 2, "AAusercode: %.2s\n", AAusercode);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
while (db = getnxtdb())
|
||||||
|
ret += purgedb(db);
|
||||||
|
fflush(stdout);
|
||||||
|
exit(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rubproc()
|
||||||
|
{
|
||||||
|
AAunlall();
|
||||||
|
fflush(stdout);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** PURGE DATABASE
|
||||||
|
**
|
||||||
|
** The database is purged of temporaries, expired relations, and
|
||||||
|
** junk.
|
||||||
|
*/
|
||||||
|
purgedb(db)
|
||||||
|
register char *db;
|
||||||
|
{
|
||||||
|
struct relation rel;
|
||||||
|
struct relation key;
|
||||||
|
struct tup_id rtid;
|
||||||
|
struct tup_id rlimtid;
|
||||||
|
register int i;
|
||||||
|
# ifdef NON_V7_FS
|
||||||
|
extern char *read_dir();
|
||||||
|
register char *direc;
|
||||||
|
# else
|
||||||
|
struct directory direc;
|
||||||
|
register int fd;
|
||||||
|
extern long lseek();
|
||||||
|
# endif
|
||||||
|
int ret;
|
||||||
|
char *pv[2];
|
||||||
|
char pbuff[MAXNAME + 3];
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
# ifdef xSTR2
|
||||||
|
AAtTfp(11, 0, "entered purgedb(%s)\n", db);
|
||||||
|
# endif
|
||||||
|
printf("Datenbank %s\n", db);
|
||||||
|
AAam_start();
|
||||||
|
|
||||||
|
/* set exclusive lock on data base */
|
||||||
|
# ifdef xSTR2
|
||||||
|
AAtTfp(11, 1, "calling db_lock(%d)\n", M_EXCL);
|
||||||
|
# endif
|
||||||
|
db_lock(M_EXCL);
|
||||||
|
|
||||||
|
/* open the relation relation for read-write */
|
||||||
|
opencatalog(AA_REL, 2);
|
||||||
|
|
||||||
|
if (AAam_find(&Reldes, NOKEY, &rtid, &rlimtid))
|
||||||
|
{
|
||||||
|
printf("Datenbank %s: Fehler beim Eroeffnen des Katalogs \"relation\"\n", db);
|
||||||
|
ret++;
|
||||||
|
goto go_away;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!AAam_get(&Reldes, &rtid, &rlimtid, &rel, 1))
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
/* check for temp rel */
|
||||||
|
if (AAbequal(rel.relid, SYSNAME, s_SYSNAME))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
/* check for expired */
|
||||||
|
else if (rel.relsave < Today && rel.relsave)
|
||||||
|
{
|
||||||
|
printf("**\t\tRelation %.14s: verfallen\n", rel.relid);
|
||||||
|
if (Purge)
|
||||||
|
if (ask("Relation loeschen"))
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if this relation should be purged -- call destroy */
|
||||||
|
if (i)
|
||||||
|
{
|
||||||
|
printf("**\t\t purging %.14s\n", rel.relid);
|
||||||
|
|
||||||
|
/* set up parameter vector for destroy */
|
||||||
|
AAbmove(rel.relid, pbuff, MAXNAME + 2);
|
||||||
|
pbuff[MAXNAME + 2] = '\0';
|
||||||
|
pv[0] = pbuff;
|
||||||
|
pv[1] = (char *) -1;
|
||||||
|
if (destroy(1, pv))
|
||||||
|
AAsyserr(21079, pv[0]);
|
||||||
|
closecatalog(FALSE); /* to flush */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* open the directory to check for extra files */
|
||||||
|
# ifdef NON_V7_FS
|
||||||
|
if (!open_dir("."))
|
||||||
|
{
|
||||||
|
printf("Fehler beim Eroeffnen des directory %s/.\n");
|
||||||
|
ret++;
|
||||||
|
goto go_away;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* scan the directory */
|
||||||
|
while (direc = read_dir())
|
||||||
|
{
|
||||||
|
/* throw out legitimate files */
|
||||||
|
if (AAsequal(direc, ".") || AAsequal(direc, "..") || AAsequal(direc, AA_ADMIN))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* always purge SYSNAME files */
|
||||||
|
if (!AAbequal(direc, SYSNAME, s_SYSNAME))
|
||||||
|
{
|
||||||
|
/* it might be a relation */
|
||||||
|
AAam_clearkeys(&Reldes);
|
||||||
|
AAam_setkey(&Reldes, &key, direc, RELID);
|
||||||
|
AAam_setkey(&Reldes, &key, &direc[MAXNAME], RELOWNER);
|
||||||
|
if (AAgetequal(&Reldes, &key, &rel, &rtid) <= 0)
|
||||||
|
{
|
||||||
|
/* it is a relation (or should be saved) */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* it is a funny file!!! */
|
||||||
|
printf("**\t\tfile\t %s\n", direc);
|
||||||
|
if (!Clean)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* purge the file */
|
||||||
|
if (ask("file loeschen") && unlink(direc))
|
||||||
|
printf("**\t\tFehler beim Loeschen des file %s\n", direc);
|
||||||
|
}
|
||||||
|
close_dir();
|
||||||
|
# else
|
||||||
|
if ((fd = open(".", 0)) < 0)
|
||||||
|
{
|
||||||
|
printf("Fehler beim Eroeffnen des directory %s/.\n");
|
||||||
|
ret++;
|
||||||
|
goto go_away;
|
||||||
|
}
|
||||||
|
direc.null = 0;
|
||||||
|
lseek(fd, 32L, 0);
|
||||||
|
|
||||||
|
/* scan the directory */
|
||||||
|
while (read(fd, &direc, 16) == 16)
|
||||||
|
{
|
||||||
|
/* throw out null entries */
|
||||||
|
if (!direc.inumber)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* throw out legitimate files */
|
||||||
|
if (AAsequal(direc.fname, AA_ADMIN))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* always purge SYSNAME files */
|
||||||
|
if (!AAbequal(direc.fname, SYSNAME, s_SYSNAME))
|
||||||
|
{
|
||||||
|
if (direc.fname[13])
|
||||||
|
{
|
||||||
|
# ifdef VENIX
|
||||||
|
AAbmove(direc.fname, pbuff, MAXNAME + 3);
|
||||||
|
for (i = 0; i < MAXNAME + 2; i++)
|
||||||
|
if (direc.fname[i] == '#')
|
||||||
|
direc.fname[i] = ' ';
|
||||||
|
# endif
|
||||||
|
/* it might be a relation */
|
||||||
|
AAam_clearkeys(&Reldes);
|
||||||
|
AAam_setkey(&Reldes, &key, direc.fname, RELID);
|
||||||
|
AAam_setkey(&Reldes, &key, &direc.fname[MAXNAME], RELOWNER);
|
||||||
|
if (AAgetequal(&Reldes, &key, &rel, &rtid) <= 0)
|
||||||
|
/* it is a relation (or should be saved) */
|
||||||
|
continue;
|
||||||
|
# ifdef VENIX
|
||||||
|
AAbmove(pbuff, direc.fname, MAXNAME + 3);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* it is a funny file!!! */
|
||||||
|
printf("**\t\tfile\t %s\n", direc.fname);
|
||||||
|
if (!Clean)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* purge the file */
|
||||||
|
if (ask("file loeschen") && unlink(direc.fname))
|
||||||
|
printf("**\t\tFehler beim Loeschen des file %s\n",
|
||||||
|
direc.fname);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
# endif
|
||||||
|
go_away:
|
||||||
|
closecatalog(TRUE); /* close catalogs */
|
||||||
|
AAunlall(); /* unlock the database */
|
||||||
|
AAam_exit();
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue