|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T a
Length: 5905 (0x1711)
Types: TextFile
Names: »aetbuild.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
└─⟦eba4602b1⟧ »./isode-5.0.tar.Z«
└─⟦d3ac74d73⟧
└─⟦this⟧ »isode-5.0/support/aetbuild.c«
/* aetbuild.c - build/print the isoentities database for -ldbm access */
#ifndef lint
static char *rcsid = "$Header: /f/osi/support/RCS/aetbuild.c,v 6.0 89/03/18 23:44:20 mrose Rel $";
#endif
/*
* $Header: /f/osi/support/RCS/aetbuild.c,v 6.0 89/03/18 23:44:20 mrose Rel $
*
*
* $Log: aetbuild.c,v $
* Revision 6.0 89/03/18 23:44:20 mrose
* Release 5.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
#include <dbm.h>
#undef NULL
#include <stdio.h>
#include <varargs.h>
#include "psap.h"
#include "isoaddrs.h"
#include "tailor.h"
/* \f
DATA */
struct dbm_entry {
struct isoentity dbm_entity;
unsigned int dbm_elements[NELEM + 1];
};
static char *isoentities = "isoentities";
static char *myname = "aetbuild";
static int buildsw = 0;
static int printsw = 0;
static int verbose = 0;
static char dirfile[BUFSIZ];
static char pagfile[BUFSIZ];
void adios (), advise ();
/* \f
MAIN */
/* ARGSUSED */
main (argc, argv, envp)
int argc;
char **argv,
**envp;
{
arginit (argv);
if (buildsw)
build_db ();
if (printsw)
print_db ();
exit (0);
}
/* \f
BUILD */
static build_db ()
{
int fd;
char *cp,
buffer[BUFSIZ];
register struct isoentity *ie;
struct dbm_entry entry;
datum key,
value,
test;
cp = isodefile (myname);
(void) sprintf (dirfile, "%s.dir", cp);
(void) sprintf (pagfile, "%s.pag", cp);
if (access (dirfile, 0x00) != NOTOK || access (pagfile, 0x00) != NOTOK)
adios (NULLCP, "%s already exists!", cp);
if ((fd = creat (dirfile, 0644)) == NOTOK)
adios (dirfile, "unable to create");
(void) close (fd);
if ((fd = creat (pagfile, 0644)) == NOTOK) {
advise (pagfile, "unable to create");
goto out1;
}
(void) close (fd);
if (dbminit (cp) < 0) {
advise (cp, "unable to initialize database");
goto out2;
}
while (ie = getisoentity ()) {
entry.dbm_entity = *ie; /* struct copy */
bcopy ((char *) ie -> ie_identifier.oid_elements,
(char *) entry.dbm_elements, sizeof entry.dbm_elements);
key.dsize = strlen (key.dptr = ie -> ie_descriptor) + 1;
test = fetch (key);
if (test.dptr) {
if (verbose)
advise (NULLCP, "skipping duplicate entry for \"%s\"",
key.dptr);
continue;
}
value.dptr = (char *) &entry, value.dsize = sizeof entry;
if (store (key, value) < 0)
adios (cp, "store failed on");
if (verbose)
advise (NULLCP, "storing entry for \"%s\"", key.dptr);
}
#ifdef sun
if (dbmclose () < 0) {
advise (cp, "dmbclose failed on");
goto out2;
}
#endif
cp = isodefile (isoentities);
(void) sprintf (buffer, "%s.pag", cp);
if (rename (pagfile, buffer) == NOTOK) {
advise (buffer, "unable to rename %s to", pagfile);
goto out2;
}
(void) sprintf (buffer, "%s.dir", cp);
if (rename (dirfile, buffer) == NOTOK)
adios (buffer, "unable to rename %s to", dirfile);
return;
out2: ;
(void) unlink (pagfile);
out1: ;
(void) unlink (dirfile);
exit (1);
}
/* \f
PRINT */
static print_db ()
{
char *cp;
struct dbm_entry *entry;
register struct isoentity *ie;
AEI aei;
datum key,
value;
if (dbminit (cp = isodefile (isoentities)) < 0)
adios (cp, "unable to initialize");
for (key = firstkey (); key.dptr; key = nextkey (key)) {
value = fetch (key);
if ((entry = (struct dbm_entry *) value.dptr) == NULL) {
advise (NULLCP, "unable to find value for key %s", key.dptr);
continue;
}
if (value.dsize != sizeof *entry)
adios (NULLCP, "%s dbm corrupt!", cp);
ie = &entry -> dbm_entity;
ie -> ie_identifier.oid_elements = entry -> dbm_elements;
ie -> ie_descriptor = key.dptr;
printf ("Entity: %s (%s)\n", ie -> ie_descriptor,
oid2ode (&ie -> ie_identifier));
if (aei = oid2aei (&ie -> ie_identifier))
printf ("AE info: %s\n", sprintaei (aei));
printf ("Address: %s\n\n", paddr2str (&ie -> ie_addr, NULLNA));
}
#ifdef sun
if (dbmclose () < 0)
adios (cp, "dmbclose failed on");
#endif
}
/* \f
ARGINIT */
static arginit (vec)
char **vec;
{
register char *ap;
if (myname = rindex (*vec, '/'))
myname++;
if (myname == NULL || *myname == NULL)
myname = *vec;
isodetailor (myname, 1);
for (vec++; ap = *vec; vec++) {
if (*ap == '-')
switch (*++ap) {
case 'b':
buildsw++;
continue;
case 'p':
printsw++;
continue;
case 'v':
verbose++;
continue;
default:
adios (NULLCP, "-%s: unknown switch", ap);
}
adios (NULLCP, "usage: %s [switches]", myname);
}
(void) umask (0022);
if (buildsw == 0 && printsw == 0)
buildsw++;
}
/* \f
DSAP */
#ifdef DSAP
/* ARGSUSED */
AEI str2aei_dse (designator, qualifier)
char *designator,
*qualifier;
{
return NULLAEI;
}
/* ARGSUSED */
struct PSAPaddr *aei2addr_dse (aei)
AEI aei;
{
return NULLPA;
}
#endif
/* \f
ERRORS */
#ifndef lint
void _advise ();
void adios (va_alist)
va_dcl
{
va_list ap;
va_start (ap);
_advise (ap);
va_end (ap);
_exit (1);
}
#else
/* VARARGS */
void adios (what, fmt)
char *what,
*fmt;
{
adios (what, fmt);
}
#endif
#ifndef lint
void advise (va_alist)
va_dcl
{
va_list ap;
va_start (ap);
_advise (ap);
va_end (ap);
}
static void _advise (ap)
va_list ap;
{
char buffer[BUFSIZ];
asprintf (buffer, ap);
(void) fflush (stdout);
fprintf (stderr, "%s: ", myname);
(void) fputs (buffer, stderr);
(void) fputc ('\n', stderr);
(void) fflush (stderr);
}
#else
/* VARARGS */
void advise (what, fmt)
char *what,
*fmt;
{
advise (what, fmt);
}
#endif