DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T g

⟦4d97d7921⟧ TextFile

    Length: 3301 (0xce5)
    Types: TextFile
    Names: »generate.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Abermud/generate.c« 

TextFile

/*
**  Utility program to build the data files.
*/
#include "kernel.h"
#ifdef	RCSID
static char RCS[] =
	"$Header: generate.c,v 1.1 89/03/13 09:36:24 rsalz Exp $";
#endif	/* RCSID */


static int	 blob[10000];


crapup(p)
    char	*p;
{
    perror(p);
    exit(1);
}


/*
**  Parse a flags line, a line like:
**	int1:int2:bits
**  and turn it into a four-byte int like:
**	bits:int1:int2
*/
static int
flags(buff)
    char		*buff;
{
    register char	*p;
    register int	 i;
    register int	 b;
    char		 save[120];

    (void)strcpy(save, buff);
    if (p = strchr(buff, ':')) {
	*p++ = '\0';
	i = atoi(buff) << 8;
	buff = p;
	if (p = strchr(buff, ':')) {
	    *p++ = '\0';
/*	    i |= atoi(p); */
	    i |= atoi(buff);
	    for (b = 0; *p && *p != '\n'; p++)
		b = (b << 1) | (*p == '0' ? 0 : 1);
	    return i | (b << 16);
	}
    }
    fprintf(stderr, "Badly-formed input line:\n\t%s\n", save);
    exit(1);
    /* NOTREACHED */
}
\f




/*
**  Open file to write or die trying.
*/
static FILE *
Xfopen(p)
    char	*p;
{
    FILE	*F;

    (void)unlink(p);
    if ((F = fopen(p, "w")) == NULL) {
	perror(p);
	(void)fprintf(stderr, "Unable to create new version.\n");
	exit(1);
    }
    return F;
}


/*
**  Create world file.
*/
static void
make_world(ac, av)
    int		 ac;
    char	*av[];
{
    register FILE	*F;
    register int	 b;
    int			 x[64];

    F = Xfopen(ac == 2 ? av[1] : UNIVERSE);
    x[0] = 1;
    x[1] = 1;
    sec_write(F, x, 0, sizeof x / sizeof x[0]);
    for (b = 0; b < sizeof x / sizeof x[0]; )
	x[b++] = 0;

    for (b = 1; b < 600; b++, x[0] = 0)
	sec_write(F, x, b, sizeof x / sizeof x[0]);
    (void)fclose(F);
    exit(0);
}


/*
**  Create the user activity file.
*/
static void
make_uaf(ac, av)
    int		 ac;
    char	*av[];
{
    FILE	*F;
    PERSONA	 P;

    F = Xfopen(ac == 2 ? av[1] : UAF_RAND);

    P.p_sex = 0;
    P.p_level = 10001;
    P.p_score = 0;
    P.p_strength = 100;
    (void)strcpy(P.p_name, "Root");
    (void)fwrite((char *)&P, 1, sizeof P, F);

    /* Not legal name as endmark ie 2 in it */
    (void)strcpy(P.p_name, "Debugger");
    (void)fwrite((char *)&P, 1, sizeof P, F);
    (void)fclose(F);

    exit(0);
}


/*
**  Make the data file that shows what starts where, and their states.
*/
static void
make_reset(ac, av)
    int			 ac;
    char		*av[];
{
    register FILE	*In;
    register FILE	*Out;
    register int	*ip;
    register int	 i;
    char		 buff[128];

    if (ac == 3) {
	if ((In = fopen(av[1], "r")) == NULL) {
	    perror(av[1]);
	    (void)fprintf(stderr, "Can't open input file.");
	}
	Out = Xfopen(av[2]);
    }

    for (ip = blob, i = 0; fgets(buff, sizeof buff, In); i++)
	*ip++ = ((i & 0x03) == 2) ? flags(buff) : (int) atoi(buff);
    sec_write(Out, blob, 0, ip - blob);
    (void)fclose(In);
    (void)fclose(Out);
    exit(0);
}


/*
**  Make the user file.
*/
static void
make_user(ac, av)
    int		 ac;
    char	*av[];
{
    (void)fclose(Xfopen(ac == 2 ? av[1] : PASSWORDFILE));
    exit(0);
}


main(ac, av)
    int		 ac;
    char	*av[];
{
    ac--;
    av++;

    if (EQ(*av, "world"))
	make_world(ac, av);
    if (EQ(*av, "uaf"))
	make_uaf(ac, av);
    if (EQ(*av, "reset"))
	make_reset(ac, av);
    if (EQ(*av, "userfile"))
	make_user(ac, av);

    (void)fprintf(stderr, "Usage error.\n");
    exit(1);
}