[net.games.frp] Players Handbook Database Interpretor

tgm@ukc.UUCP (T.Murphy) (03/30/85)

Well here are the programs to translate the database. I really didn't think the
database was all that unreadable. The only tricky bit was figuring that spell
components made a three digit bianary number that fit nicely into one byte.
I am afraid the code is mostly uncommented but it should be fairly straight-
forward. Two output routines are here: inout.c and inout.c.old . I am sure
that better ones can be devised since they were only secondary to the rest
of the program which reads in and translates the spells. It would be nice
if somebody wrote a routine to search for a spell by whatever and print out
the entire spell (other than putting in a readable file and using grep -r).
I have actually lost the PRFILE that is used in inout.c.old but you should
be able to recreate it easially. It just conatains the prompts to print before
the data, i.e. Name:, Class:, Duration:, ... . If you could post all errors in
both the database and program to me and not to the newsnet I will compile them
all and post the corrections in about a months time.
				Good Hacking

		{decvax,seismo,philabs}!mcvax!ukc!tcdmath!jaymin
Joe Jaquinta; c/o D.U. Mats Society, 39.16 Trinity College Dublin, Ireland


---------------------------- Cut Here -------------------------------------
/*###### File : makefile                       ######*/

all:	sp.o vsm.o init.o time.o type.o class.o inout.o special.o
	ld -X /lib/crt0.o sp.o vsm.o init.o time.o type.o class.o inout.o special.o -lc -o sp

/*###### File : sp.h                           ######*/

#include <stdio.h>
#include <ctype.h>

#define MAXSTR 50
#define ARGS 10
#define PRFILE "/usr/user/system/jaymin/d+d/s.prmt"
#define SEPCHAR '@'
#define CLASS 0
#define NAME 1
#define TYPE 2
#define LEVEL 3
#define RANGE 4
#define DURAT 5
#define AOE 6
#define COM 7
#define TIME 8
#define SAVE 9

char    tome[ARGS][MAXSTR];
char	promt[ARGS][MAXSTR];
char	buff[MAXSTR];

/*###### File : class.c                        ######*/

#include "sp.h"

class(clss)
char clss[];
{       switch(clss[0])
        {       case 'c':
                        strcpy(clss ,"Cleric");
                        break;
                case 'd':
                        strcpy(clss ,"Druid");
                        break;
                case 'm':
                        strcpy(clss ,"Magic user");
                        break;
                case 'i':
                        strcpy(clss ,"Illusionist");
                        break;
        }
}

name(namestr)
char    namestr[];
{       if ((namestr[strlen(namestr)-1] == 'r') && (namestr[strlen(namestr)-2] == ' '))
        {       namestr[strlen(namestr)-1] = '\0';
                strcat(namestr,"(Reversible)");
        }
}

/*###### File : init.c                         ######*/

#include "sp.h"

blnkstr(string)
char	string[];
{	register int	i;

	for (i = 0; i<MAXSTR; i++)
		string[i] = '\0';
}

init()
{       FILE    *prmt;
        register int    i,j;

        if ((prmt = fopen(PRFILE, "r")) == NULL)
        {       fprintf(stderr,"Cannot open prompt file.\n");
                exit(1);
        }
        fgets(promt[0],MAXSTR,prmt); /* Eliminates first number */
        for (i = 0; i<=10; i++)
        {       fgets(promt[i],MAXSTR,prmt);
                for (j = 0; promt[i][j] != '\n'; ++j);
                promt[i][j] = '\t';
        }
}

/*###### File : inout.c                        ######*/

#include "sp.h"

readspell(stream)
FILE *stream;

{       register int    i;

        for (i = 0; i<ARGS; i++)
                getnext(tome[i],stream);
        fgetc(stream);
}

getnext(string,stream)
char    string[];
FILE    *stream;

{       register int i;

        for (i=0; ((string[i] = fgetc(stream)) != SEPCHAR) && (i<=MAXSTR); i++);
        string[i] = '\0';
}

writespell()
{
	char	outbuf[171];
	int	ptr;

	for (ptr = 0; ptr < 171; ptr++)
		outbuf[ptr] = ' ';
	copy(0, tome[NAME], outbuf);
	copy(30, tome[LEVEL], outbuf);
	copy(34, tome[RANGE], outbuf);
	copy(55, tome[DURAT], outbuf);
	copy(88, tome[AOE], outbuf);
	copy(138, tome[COM], outbuf);
	copy(144, tome[TIME], outbuf);
	copy(164, tome[SAVE], outbuf);
/*	printf("%s\n", outbuf); */
write(1, outbuf, 171);
write(1, "\n", 1);
}

copy(start, insert, string)
int	start;
char	*insert,*string;
{
	char	*c;

	for(c = string + start; *insert; insert++, c++)
		if ((*insert != '\n') || (*insert != '\0'))
			*c = *insert;
}

/*###### File : sp.c                           ######*/

#include "sp.h"

main(argc,argv)
int     argc;
char    **argv;

{       FILE *stream;

        if ((stream = fopen(*++argv, "r")) == NULL)
        {       fprintf(stderr,"Can't open %s\n",*argv);
                exit(1);
        }
        else
        {       init();
		ungetc(getc(stream), stream); /* to flag eof */
                while (!feof(stream))
                {       readspell(stream);
			class(tome[CLASS]);
/*                        name(tome[NAME]); */
                        type(tome[TYPE]);
                        level(tome[RANGE]);
                        level(tome[DURAT]);
			level(tome[AOE]);
			time(tome[DURAT]);
			time(tome[TIME]);
			vsm(tome[COM]);
			aoe(tome[AOE]);
			special(tome[AOE]);
			special(tome[TIME]);
			special(tome[DURAT]);
			special(tome[RANGE]);
			special(tome[SAVE]);
			save(tome[SAVE]);
			writespell();
			ungetc(getc(stream), stream);/* do dah, do dah */
                }
        }
}

/*###### File : special.c                      ######*/

#include "sp.h"

special(str)
char	str[];
{	register char	*ptr;

	blnkstr(buff);
	for (ptr = str; *ptr; ptr++)
		if (*ptr == 'X')
			strcat(buff, "special");
		else
			strncat(buff, ptr, 1);
	strcpy(str, buff);
}

save(str)
char	str[];
{	switch(str[0])
	{	case 'H':
			strcpy(str, "half");
			break;
		case 'N':
			strcpy(str, "negates");
			break;
		case 'M':
			strcpy(str, "none");
			break;
	}
}

level(str)
char    str[];
{       register char   *ptr;

	blnkstr(buff);
	for (ptr = str; *ptr != '\0'; ptr++)
        	if (*ptr == 'L')
			strcat(buff, "Level");
		else if (*ptr == '+')
			strcat(buff, " + ");
			else
				strncat(buff, ptr, 1);
	strcpy(str, buff);
}

/*###### File : time.c                         ######*/

#include "sp.h"

time(str)
char	str[];
{	register char	*ptr;

	blnkstr(buff);
	buff[0] = str[0];
	ptr = str;
	for (ptr++; *ptr != '\0'; ptr++)
	{	if (!isalpha(*(ptr-1)) && !isalpha(*(ptr+1)))
			switch(*ptr)
			{	case 'r':
					strcat(buff," round");
					if (*(ptr-1) != '1')
						strncat(buff,"s",1);
					break;
				case 's':
					strcat(buff," segment");
					if (*(ptr-1) != '1')
						strncat(buff,"s",1);
					break;
				case 't':
					strcat(buff," turn");
					if (*(ptr-1) != '1')
						strncat(buff,"s",1);
					break;
				default:
					strncat(buff,ptr,1);
			}
		else
			switch(*ptr)
			{	case '+':
					strcat(buff," + ");
					break;
				default:
					strncat(buff,ptr,1);
			}
		}
	strcpy(str,buff);
}

/*###### File : type.c                         ######*/

#include "sp.h"

type(typestr)
char    typestr[];
{        register char	*ptr;

	blnkstr(buff);
	for (ptr = typestr; *ptr != '\0'; ptr++)
               switch(*ptr)
                {       case 'e':
                                if (*(ptr + 1) == 'n')
                                {       strcat(buff,"Enchantment");
                                        ptr++;
                                }
                                else
                                if (*(ptr + 1) == 'v')
                                {       strcat(buff,"Evocation");
                                        ptr++;
                                }
                                break;
                       case 'a':
                                if (*(ptr + 1) == 'l')
                                {       strcat(buff,"Alteration");
                                        ptr++;
                                }
                                else
                                if (*(ptr + 1) == 'b')
                                {       strcat(buff,"Abjuration");
                                        ptr++;
                                }
                                break;
                       case 'i':
                                if (*(ptr + 1) == 'l')
                                {       strcat(buff,"Illusion");
                                        ptr++;
                                }
				else
                                if (*(ptr + 1) == 'n')
                                {       strcat(buff,"Invocation");
                                        ptr++;
                                }
                                break;
                       case 'p':
                                if (*(ptr + 1) == 'h')
                                {       strcat(buff,"Phantasm");
                                        ptr++;
                                }
                                else
                                if (*(ptr + 1) == 'o')
                                {       strcat(buff,"Posession");
                                        ptr++;
                                }
                                break;
                       case 's':
                                if (*(ptr + 1) == 'u')
                                {       strcat(buff,"Summoning");
                                        ptr++;
                                }
                                break;
                       case 'n':
                                if (*(ptr + 1) == 'e')
                                {       strcat(buff,"Necromantic");
                                        ptr++;
                                }
                                break;
                       case 'd':
                                if (*(ptr + 1) == 'i')
                                {       strcat(buff,"Divination");
                                        ptr++;
                                }
                                break;
                       case 'c':
                                if (*(ptr + 1) == 'o')
                                {       strcat(buff,"Conjuration");
                                        ptr++;
                                }
                                else
                                if (*(ptr + 1) == 'h')
                                {       strcat(buff,"Charm");
                                        ptr++;
                                }
                                break;
                        case '/':
                                strcat(buff,"/");
                                break;
                        case '-':
                        case ',':
                                strcat(buff,",");
                                break;
                }
        strcpy(typestr, buff);
}

/*###### File : vsm.c                          ######*/

#include "sp.h"

vsm(type)
char	type[];
{	register int	x;

	x = type[0] - '0';
	type[0] = '\0';
	if (x & 4)
	{	strcat(type, "V");
		if (x > 4)
			strcat(type, ",");
	}
	if (x & 2)
	{	strcat(type, "S");
		if (x & 1)
			strcat(type, ",");
	}
	if (x & 1)
		strcat(type, "M");
}

aoe(str)
char	str[];
{	char	*ptr;

	blnkstr(buff);
	for (ptr = str; *ptr; ptr++)
		switch(*ptr)
		{	case 'R':
				strcat(buff, "radius");
				break;
			case 'S':
				strcat(buff, "sphere");
				break;
			case 'D':
				strcat(buff, "diameter");
				break;
			case 'Q':
				strcat(buff, "square");
				break;
			default:
				strncat(buff, ptr, 1);
		}
	strcpy(str, buff);
}

/*###### File : inout.c.old                    ######*/

#include "sp.h"

readspell(stream)
FILE *stream;

{       register int    i;

        for (i = 0; i<ARGS; i++)
                getnext(tome[i],stream);
        fgetc(stream);
}

getnext(string,stream)
char    string[];
FILE    *stream;

{       register int i;

        for (i=0; ((string[i] = fgetc(stream)) != SEPCHAR) && (i<=MAXSTR); i++);
        string[i] = '\0';
}

writespell()
{       printf("%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n\n",
                promt[0],tome[0],
                promt[1],tome[1],
                promt[2],tome[2],
                promt[3],tome[3],
                promt[4],tome[4],
                promt[5],tome[5],
                promt[6],tome[6],
                promt[7],tome[7],
                promt[8],tome[8],
                promt[9],tome[9]);
}