RPG table handling routines (1/2)
Flame Bait
joshua at athertn.Atherton.COM
Fri Dec 14 04:51:48 AEST 1990
The routines are designed to write character generation programs, but
should be useful for lots of other RPG type applications. There are
routines to read in tables, print them, free them, and use them in
several different ways. In addition there are some rolling routines
which take text strings like "2d4+2" or "1d100" and roll them. The
table routines are designed to be object oriented, so you can add new
types of tables, and new operations on tables fairly easily.
Finally, there are two simple applications, a computer buzzphase generator
and a cyberpunk style name generator.
I'm planning a 0.5 release to be followed by a 1.0 release, so please
email me any problems you have or improvements you make. If you use these
routines to write a program longer than 200 lines, please send me its source,
so I can include it in my regression testing, and also so I can get a feel
for how people are using this package. Thanks.
Joshua Levy (joshua at atherton.com) (408) 734-9822
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
# Makefile
# RANDOM
# README
# UPDATES
# doc
# apps
# This archive created: Fri Nov 30 12:07:14 1990
# By: Flame Bait ()
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Makefile'
then
echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X#
X# Makefile for the table and random utility packages
X# and some programs which use them.
X# by Joshua Levy
X#
X
Xsetup:
X cd src ; make libs
X cd src ; make execs
X cd tst ; make
X cd apps ; make
X
Xclean:
X cd src ; make clean
X cd apps ; make clean
X cd tst ; make clean
X cd doc ; make clean
X rm -f *~ "*/*~" core
X
Xshar: clean
X shar -p X [A-Z]* doc apps > tablea.shar
X shar -p Y src tst > tableb.shar
X
SHAR_EOF
fi
if test -f 'RANDOM'
then
echo shar: "will not over-write existing file 'RANDOM'"
else
sed 's/^X//' << \SHAR_EOF > 'RANDOM'
X
XThis is a very brief into to the random number routines. Version 0.3
XBy Joshua Levy
X
XNote that this is a "presentation layer" random number package.
XIt relies on random(3) to generate random number, but presents
Xthem to the user in a more useful way, as well as providing
Xlogging facilities.
X
XTo make the *.o file: cc -c random.c
XTo make a test executable: cc -DTEST -o rndtest random.c
X
XInclude the header file (random.h) in you programs.
X
XTo test the routines make rndtest and try these two UNIX commands:
X rndtest <rndtnorm.ts
X rndtest <rndtacid.ts
SHAR_EOF
fi
if test -f 'README'
then
echo shar: "will not over-write existing file 'README'"
else
sed 's/^X//' << \SHAR_EOF > 'README'
X
XREADME file for table: a package to manipulate tables (Version 0.3)
XBy Joshua Levy
X
XThis is a set of subroutines to handle tables, such as are commonly used in
XFRP and computer games. It also includes some random number routines.
X
XTo make this stuff, unshar the two files and run make. This should produce
Xseveral executables:
X in the apps directory, bw and cname
X in the src directory tbtest, rndtest, and tb2tbl
X
XTo use these routines in your own program, you must link with table.a
Xand random.o, which are in the src directory.
X
XThere is documentation in the doc directory, and testing shell scripts in
Xthe tst directory.
X
XRead the file called UPDATES for some change history, but it is not complete.
X
XIf you find these routine useful, please help me maintain them by doing one
Xof the following things:
X Write a new test suite, which tests stuff currently untested, or acid
X tests something.
X Add a new table type.
X Add a new message type, or a new option to the print message, (a print
X in LaTeX message would be great, so would pre loaded C code).
X Send me a sample application.
X Extend the random routines.
X
XThanks.
X
XJoshua Levy
X905 W. Middlefield Apt. 946
XMountain View, CA
X94043
X(408) 734-9822
Xjoshua at atherton.com
X
XLegal Stuff:
X
XThis package (source code and documentation) is covered by the GNU
XGENERAL AGREEMENT, commonly known as the "copyleft". If you want
Xto do something not allowed by the copyleft, contact the author
Xto arrange a seperate agreement.
X
X
X
SHAR_EOF
fi
if test -f 'UPDATES'
then
echo shar: "will not over-write existing file 'UPDATES'"
else
sed 's/^X//' << \SHAR_EOF > 'UPDATES'
X
XChanges to the Table and Random routines since version 0.1.
XListed newest changes to oldest.
XBy Joshua Levy
X
XKnown problems with 0.3:
X
XShould be able to put comments in table files (starting with '#')
X
XThe ra_roll routine needs to accept more types of dice rolls. For example,
X it should know about "discard the worst dice roll", "ignore rolls under N",
X and so on.
X
X
X
XChanges from 0.2 to 0.3:
X
XAdded new message tb_many, to roll many times on the same table, returing
Xdifferent answers each time.
X
XThere is now documenation specifically describing how to add new table types.
X
XAdded a new table type, the SimpleBig type.
X
XThe ra_random man page does documents the ra_logging and ra_float call.
X
XNeed an ra_query routine to return a roll's min, max, average, and legality.
X
XChanges from 0.1 to 0.2:
XAdded log/replace facility to random number generator.
XAdded crude floating point generator.
XRemoved some untested macros from the table.h file.
XCleaned and commented the code.
XFixed bugs in and improved the table.man manual page.
XReplaced the random number test program with a better one.
XStarted a test suite for the random number generator.
SHAR_EOF
fi
if test ! -d 'doc'
then
mkdir 'doc'
fi
cd 'doc'
if test -f 'random.man'
then
echo shar: "will not over-write existing file 'random.man'"
else
sed 's/^X//' << \SHAR_EOF > 'random.man'
X.ig XC
X% nroff -man random.man | more
X%n nroff -man random.man | lpr
X%t ptroff -man random.man -Plw
X.XC
X.TH RA_RANDOM 3 "November 1990"
X.SH NAME
Xra_random \- random number generation routines
X.SH SYNOPSIS
X.nf
X#include "random.h"
X
Xint ra_roll(str) char *str ;
X
Xchar *ra_card()
X
Xint ra_random(max) int max ;
X
Xint ra_seed(seed) int seed ;
X
Xdouble ra_float()
X
Xint ra_query(str,what) char *str ; int what ;
X
Xint ra_logging(state,filename) int state ; char *filename ;
X.fi
X.SH DESCRIPTION
X.IP ra_roll
XThis routine takes a text representation of a dice roll, and returns a
Xnumber rolled. Sample dice rolls are "1d10", "2d4", "3d10+2", or "4d4-1".
X.IP ra_card
XThis call returns a random card from a playing deck (minus jokers).
XThe returned pointer is to a static string containing a number and a lower
Xcase letter, for example "4s" or "12d" for the four of spades and queen
Xof diamonds, respectively.
X.IP ra_random
XTakes a number and returns a random number between 1 and the number passed
Xin.
X.IP ra_seed
XInitializes the random number stream. It's one argument is the new seed.
XUse a seed of zero for debugging (for reproducablity) but some other number
Xfor real use.
X.IP ra_float
XThis call returns a random floating point number between 0 and 1. I'm not
Xreally sure how random it is though; it is experimental.
X.IP ra_query
XThis function returns information about a dice roll. The roll you are
Xasking about is the first argument. The second argument controls what
Xis returned:
X.RS
X.IP RA_MAX
XReturns the largest number this roll can generate.
X.IP RA_MIN
XReturns the small number this roll can generate.
X.IP RA_AVE
XReturns the average number which this roll will generate.
X.IP RA_LEGAL
XReturns true (1) if the string passed in is a legal dice roll. Returns
Xfalse (0) if it is not.
X.RE
X.sp 1
X.IP ra_logging
XThis routine enables or disables logging an playback of random numbers.
XIt is designed help testing/debugging by recreating the same random number
Xstream over and over. The first argument is the command, the second is
Xa file name. The commands are in random.h:
X.RS
X.IP RA_NORMAL
XReturns to the normal state. Random number are generated on the fly and
Xnot logged. The second argument is ignored.
X.IP RA_PLAY
XRandom numbers are not generated, but read from the file passed in as the
Xsecond argument. By convention these files end in ".rl" for random log.
X.IP RA_LOG
XRandom number are generated on the fly and stored in a random log file
Xfor later playback. The log file name is the second command.
X.RE
X.sp 1
XIn theory, both play and log can be active at the same time, but this is
Xan untested configuration. Both play and log are turned off by normal.
X.IP ra_stddev
X<<NOT YET IMPLEMENTED>>
X.SH "EXAMPLES"
X.nf
XNot done yet. Look at random.c, tablesimple.c and tablemulti.c.
X.fi
X.SH "SEE ALSO"
X.PP
XThese routines use random(3) to generate random numbers.
X.SH "BUGS"
X.IP \(bu
XThese routines rely on the local C library to provide raw random numbers.
XThey should come with there own generator.
X.SH AUTHOR
X.PP
XThe random routines were written by Joshua Levy.
X.br
Xjoshua at atherton.com Home: (415) 968-3718 Work: (408) 734-9822
X.IP "\(co 1989 Joshua Levy"
XThis man page and the code it describes is covered by the GNU general
Xpublic license, commonly called the "copyleft". It can only be used or
Xredistributed under the terms of that agreement. Persons or corporations
Xwishing to use this code in ways not allowed by the GNU license should
Xcontact the author to discuss other licensing agreements.
X.br
SHAR_EOF
fi
if test -f 'tb-execs.man'
then
echo shar: "will not over-write existing file 'tb-execs.man'"
else
sed 's/^X//' << \SHAR_EOF > 'tb-execs.man'
X.ig XC
X% nroff -man tb-execs.man | more
X%n nroff -man tb-execs.man | lpr
X%t ptroff -man tb-execs.man -Plw
X.XC
X.TH TABLE-EXECS 1 "Dec 27th 1989"
X.SH NAME
Xtable-exec \- the executables shipped with table: table, tb2tbl, rndtest, bw
X.SH SYNOPSIS
X.nf
Xtable <table.file> <number>
Xtb2tbl <table.file>
Xrndtest
Xtbtest
Xbw <seed> <number>
X.fi
X.SH DESCRIPTION
X.IP table
XThis is a simple front end to the table routines, designed for testing.
XTable takes two arguments. The name of the file containing the table,
Xand the number of times to roll on that table. Neither of these arguments
Xare optional.
X.IP tb2tbl
XThis program takes one argument, a table file, which it translates
Xinto troff/tbl format and write to the standard output.
X.IP rndtest
XThis is a simple front end to the random number generation routines,
Xdesigned for testing. It takes no arguments, but interactively reads in
Xan executes commands, untill it reads a quit or an EOF. The commands it
Xaccepts are:
X.RS
X.IP "seed <new-seed>"
XThis calls the ra_seed routine, which changes the seed number used by the
Xunderlieing random number generator.
X.IP "roll <number> <dice>"
XThis calls the ra_roll routine <number> times. <Dice> is the dice roll to
Xuse.
X.IP "card <number>"
XThis calls the ra_card routine <number> times.
X.IP "log <what> <where>"
XThis calls the ra_logging routine.
X.RE
X.IP tbtest
XThis is a simple front end to the table routines, designed for testing.
XIt takes no arguments, but reads commands from a script. The commands
Xit knows about are:
X.RS
X.IP "read"
XReads in a table and makes it the current table. It takes one argument,
Xthe file to read in the table from.
X.IP "free"
XFrees the current table.
X.IP "use"
XUses the current table.
X.IP "many"
XUses the current table many times.
X.IP "back"
X.IP "print"
XPrints out the current table.
X.IP "help"
XPrints out some help.
X.IP "quit"
XTo exit from the program.
X.RE
X.IP bw
XA buzzphase generator. Its first argument is a random number seed,
Xand its second is the number of phrases it should generate. They
Xare written to the standard output, one per line.
X.SH EXAMPLES
X.nf
Xtable simp1.tab 10
Xtable multi1.tab 5
Xtb2tbl bw2.tab | tbl | nroff -me | col | more
Xbw 0 10
Xbw 10 10
X.fi
X.SH "SEE ALSO"
X.PP
Xra_random(3), table(3).
X.SH "BUGS"
X.SH AUTHOR
X.PP
XThese programs were written by Joshua Levy at Atherton Technology.
X.br
Xjoshua at atherton.com Home: (415) 968-3718 Work: (408) 734-9822
X.IP "\(co 1989 Joshua Levy"
XThis man page and the code it describes is covered by the GNU general
Xpublic license, commonly called the "copyleft". It can only be used or
Xredistributed under the terms of that agreement. Persons or corporations
Xwishing to use this code in ways not allowed by the GNU license should
Xcontact the author to discuss other licensing agreements.
X.br
SHAR_EOF
fi
if test -f 'Makefile'
then
echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X
Xclean:
X rm -f *~ *.bak #*#
SHAR_EOF
fi
if test -f 'table.man'
then
echo shar: "will not over-write existing file 'table.man'"
else
sed 's/^X//' << \SHAR_EOF > 'table.man'
X.ig XC
X% nroff -man table.man | more
X%n nroff -man table.man | lpr
X%t ptroff -man table.man -Plw
X.XC
X.TH TABLE 3 "Feb 22th 1990"
X.SH NAME
Xtable \- table handling routines for role playing and computer games
X.SH SYNOPSIS
X.nf
X#include "table.h"
X
Xint tb_read(filename,table) char *filename ; table_t **table ;
X
Xint tb_use(table,...,result) table_t *table ; ... char **result ;
X
Xint tb_print(table,filename,way) table_t *table ; char *filename ; int way ;
X
Xint tb_many(table,num,...,result) table_t *table ; int num ; ... char **result ;
Xint tb_free(table) table_t *table ;
X
Xint tb_query(table,query,result) table_t *table ; int query ; int *result ;
X.fi
X.SH DESCRIPTION
X.IP tb_read
XGiven a pointer to a pointer to a table, and the name of a file, this
Xroutine reads the text representation of a table into the table variable,
Xusing malloc(3) to allocate memory as needed.
X.IP tb_use
XGiven a poniter to a table, a pointer to a pointer to characters, and
X(optionally) other arguments, this routine uses the table and a random
Xnumber generator to "roll" on the table. The number and type of optional
Xarguments depends on the type of table being used. Simple tables
Xrequire no extra arguments, but multi and change tables require a
Xstring which determines which column on the table to use. For example:
X
X.nf
Xtable_t *foo ;
Xchar *result ;
Xtb_use(foo,&result) ; /* assumes foo is a simple table */
Xtb_use(foo,"column1",&result) ; /* assumes foo is a multi table */
Xtb_use(foo,"column1",&result) ; /* assumes foo is a change table */
X.fi
X
XNote that the result points at a static buffer, which must not be changed
Xand which may disappear during the next tb_use call.
X.IP tb_print
XGiven a pointer to a table and a file name, this routine prints out a
Xcopy of the file. The third argument determines the form the table is
Xprinted out in. Right now, 1 prints it out in troff/tbl format, and
X0 is reserved for future work. This routine is useful for debugging, as
Xwell as to generate documentation.
X.IP tb_many
XThis routine is similar to tb_use, execpt that it returns several rolls
Xfrom the table which are different. The extra argument ``num'' is the
Xnumber of rolls. The result should be an array of character pointers
Xlarge enough to hold all the answers.
X.IP tb_free
XGiven a pointer to a table, this routines frees the space associated
Xwith the table. After calling this routine the only function call which
Xis legal on the table is tb_read. This routine calls free(3).
X.IP tb_query
XGiven a pointer to a table, and a question about that table, result will
Xbe filled with the answer to the question. Currently supported queries
Xinclude:
X.RS
X.IP TB_Q_MAX
XReturns the largest roll which can be made on this table.
X.IP TB_Q_MIN
XReturns the smallest roll which can be made on this table.
X.IP TB_Q_AVE
XReturns the average roll made on this table.
X.RE
X.bp
X.SH "TABLE TYPES"
X.PP
XThis package support several different types of tables, and new types
Xcan be added with a recompile (see the man page on table-add). Here
Xis a description of all of the table types which are currently supported.
X.IP "Simple"
XThis is the simplest form of table. It is a list of rolls and the results
Xfor each roll. An example would be a table of possible races for NPCs, or
Xa list of possible home towns.
X.IP "Multiple"
XThese tables contain one column for the dice roll, but several columns
Xeach of which contains a result in different situations. An example
Xmight be a PC hight table, with different columns for each race. Or a
Xyearly income table, with different columns for each class. When using
Xthese tables, you must specify which column is important.
X.IP "SimpleBig"
XThis table is very similar to the simple table. The difference is in
Xformatting. This table is designed to return large chuncks of text,
Xlike sentences and paragraphs. The simple tables are designed to return
Xwords or lines.
X.bp
X.SH "FILE FORMATS"
X.PP
XThe files read by tb_read must be formatted correctly. The format for
Xeach type of table (simple, multi, etc.) is different, but the first
Xline is always the same: the name of the table followed by its type.
X.PP
XSimple tables have a line with the type of roll to make and the number
Xof rows in the table, seperated by a tab. The third line is the source
Xof the table. The fourth, and all following lines, are rows of the table,
Xeach row contains a number (or two numbers seperated by a dash) followed
Xby a tab, and the result.
X.PP
XMultiple tables are more complicated. Their second row is the roll, the
Xnumber of rows, and the number of columns; all separated by tabs. The number
Xof columns does not include the results column. The third line is the source
Xof the table. The fourth line are the column headers; each header is
Xseparated by a tab. The first column is used for the roll, so it is
Xuntitled. The fifth line, and all other rows are rows of the table; they
Xstart with the roll and then have each result. Each field is separated by
Xa tab.
X.bp
X.SH "EXAMPLE FILES"
X.LP
XHere is a sample simple table file (The `::' charaters are tabs):
X.nf
XPay-off results table::Simple
X2d6::9
Xp13 of The Complete Tavern
X2::Banker loses triple, passes dice
X3::Banker loses double, passes dice
X4::Banker loses double
X5::Banker loses
X6::Banker loses half of bet
X7::Stand off, rethrow
X8-9::Banker wins bet
X10-11::Banker double bet
X12::Banker triple bet
X.fi
X.LP
XHere is an example multiple table file ("::" are tabs):
X.nf
XBasic Test::Multiple
X2d6::6::4
Xmy mind
X-::Elf::Human::Dwarf::Troll
X2::e2::h2::d2::t2
X3::e3::h3::d3::t3
X4-7::e4::h4::d4::t4
X8-9::e8::h8::d8::t8
X10::e10::h10::d10::t10
X11-12::e11::h11::d11::t11
X.fi
X.bp
X.SH "EXAMPLE CODE"
X.nf
X/*
X * Routine to tralate a table stored in file infile into a troff/tbl
X * document, which is in outfile.
X */
Xtb2tbl(infile,outfile) char *infile ; char *outfile ;
X{
X table_t *tab ;
X int sts ;
X
X sts = tb_read(infile,&tab) ; assert(sts==TB_E_OK) ;
X sts = tb_print(tab,outfile,1) ; assert(sts==TB_E_OK) ;
X sts = tb_free(tab) ; assert(sts==TB_E_OK) ;
X}
X/*
X * Routine read in a table, and then rolls on it repeatedly, printing
X * the result of each roll to the screen.
X */
X
Xroll(tabfile,times) char *tabfile ; int times ;
X{
X table_t *tab ;
X char *str ;
X int sts ;
X int i ;
X
X sts = tb_read(infile,&tab) ; assert(sts==TB_E_OK) ;
X for(i=0 ; i<times ; i++) {
X sts = tb_use(tab,&str) ;
X printf("result %d was %s\\n",i+1,str) ;
X }
X sts = tb_free(tab) ; assert(sts==TB_E_OK) ;
X}
X.fi
X.bp
X.SH DIAGNOSTICS
X.TP 15
XTB_E_OK
XEverything worked fine.
X.TP 15
XTB_E_MISC
XGeneral purpose error message. Something went wrong.
X.TP 15
XTB_E_NOTYET
XFeature not yet implemented.
X.TP 15
XTB_E_NOFILE
XThe external table file you wanted to read does not exist.
X.TP 15
XTB_E_NO_COL
XNo column in the table iwth that name. For multiple column tables, you
Xmust pass a column name to tb_use or tb_choose, but your name does not
Xmatch one in the table.
X.TP 15
XTB_E_NOTYPE
XThe type of the table you passed to a tb_ routine is not a legal type.
XCurrently the legal types are 1 (Simple) and 2 (Multi). Either you are
Xexperimenting with new types, or (more likely) the table pointer you
Xpassed to a tb_routine points to garbage.
X.TP 15
XTB_E_TOOMANY
XYou have asked the tb_many routine for too many answers. The the table
Xonly contains 10 possible answers (for example) and you ask for 12,
Xyou will get this error. Since tb_many must return as many unique answers
Xas you ask for, it will return this error if there are not that many
Xunique answers in the table.
X.SH "SEE ALSO"
X.PP
XThese routines use ra_random(3) to generate random numbers.
X.SH "BUGS"
X.IP \(bu
XUsing strange file names to specify stdout and stderr in tb_print is
Xa sleezy hack. Also, there is no way to write this to a file descriptor
Xwhich is already open.
X.SH AUTHOR
X.PP
XThe table routines were written by Joshua Levy at Atherton Technology.
X.br
Xjoshua at atherton.com Home: (415) 968-3718 Work: (408) 734-9822
X.IP "\(co 1989 Joshua Levy"
XThis man page and the code it describes is covered by the GNU general
Xpublic license, commonly called the "copyleft". It can only be used or
Xredistributed under the terms of that agreement. Persons or corporations
Xwishing to use this code in ways not allowed by the GNU license should
Xcontact the author to discuss other licensing agreements.
X.br
X
X
SHAR_EOF
fi
if test -f 'tb-add.man'
then
echo shar: "will not over-write existing file 'tb-add.man'"
else
sed 's/^X//' << \SHAR_EOF > 'tb-add.man'
X.ig XC
X% nroff -man tb-add.man | more
X%n nroff -man tb-add.man | lpr
X%t ptroff -man tb-add.man -Plw
X.XC
X.TH TABLE-ADD 3 "Feb 22th 1990"
X.SH NAME
Xtable-add \- instructions for adding new table and messagte types to the table routines
X.SH SYNOPSIS
X.PP
XThis page describes how to add new table types to the table package.
XIt also discusses how to add new messages.
X(It is not really tested, but should give you a flavor of what to do.)
X.SH OVERVIEW
X.PP
XThe code in table.c is a very simple dispatch mechanism for a very
Xsimple object oriented system. To add a new table type you must
Xfirst tell the dispatch system about it, and then write the "message
Xhandling" or method routines, which the dispatcher will call for you.
X.PP
XThe most complicated of these routines is the read routine, which
Xreads the table from a disk file. This routine implicitly defines
Xthe text format used to store the new table type. The format is
Xvery important, since that is how tables are created and modified
Xby people.
X.SH DESCRIPTION
X.IP "Create a sample table file."
XI always start with the format of the table file. I
Xcreate a sample which will be used as the first test case. The cat
Xcommand with the -e and -t flags is great for making sure you put
Xtabs in all the right price. Here are the guidelines I use in designing
Xthese files:
X.RS
X.IP 1
XThe first line should contain the table's title and its type.
X.IP 2
XThe second line should contain the dice roll used on this tabel,
Xand all information about the size of the table. After reading
Xthe first two lines, the tb_read routine should have enough
Xinformation to allocate space for the table structure.
X.IP 3
XThe third line should contain the source of this table. A title and
Xpage number, or the person who came up with the table are fine here.
X.IP 4
XOther lines might contain other control type information.
X.IP 5
XFinally, the lines which describe the actual table. Ideally, the
Xfile should look like the table, so that it is as easy as possible
Xto copy tables from books and magazine articles.
X.RE
X.IP "Add a new type to the tba_type table."
XAbout a third of the way down the table.c file is an array of structures
Xcalled tba_type. Add a new structure to this array and the second to last
Xitem. The first field in the structure should be the (capitalized) name
Xof your new table type. The second field should be it's unique number.
XA sample new structure is "{"New",10}". The new list would like like this:
X{"Simple", 1}, {"Multiple",2}, {"New",3}, {NULL, 0}. The number you used
Xshould be one more than the number currently in use.
X.IP "Add new methods to the dispatch tables."
XRight after the tba_type array are the arrays used to dispatch messages.
XAdd your routines after the routines already there. If a given message
Xis legal, then put in illegal. Note that table type 0 does not exist,
Xso an message sent to 0 is illegal. That is why the first entry in each
Xarray is illegal.
X.IP "Create the new data structure."
XThis is pretty easy. Make sure the first field is an integer called
Xtype, so that the structure overlay code works correctly. They just
Xtranslate each field from you table file to be a field in your structure.
XWhere possible, try to have similar fields in other table structures
Xoverlay with fields in your structure. This data structure, as well
Xas the declarations for your new method functions should be put in a
Xfile called tablenew.h. Add this file to the other .h files included
Xin table.h. Your structure should be called tablenew_t.
X.IP "Naming Convensions"
X.PP
XThe file which contains your methods should be named tablenew.c, assuming
Xyour file type is called new. The any public functions which you write,
Xespecially method functions, should be named tb_new_ followed by the name
Xof the message (read, print, use, many, free).
X.IP "Write Methods"
X.RS
X.IP "read"
XThe first method I write is the read routine, since it is the most
Xdifficult, and required for all the other routines. <<<add>>>
X.IP
XThe interface for this program should look like this:
X.br
Xint tb_new_read(rt,fp,title) table_t **rt ; FILE *fp ; char *title ;
X.br
X.IP "tbl"
XThe second method I write is the tbl routine, since it tests the read
Xroutine and makes sure that all the data really is put into the table
Xstructure properly.
X.IP
XThe interface for this program should look like this:
X.br
Xint tb_new_tbl(tab,fp,way) table_t *tab ; FILE *fp ; int way ;
X.br
X.IP "use"
X.IP
XThe interface for this program should look like this:
X.br
Xint tb_new_use(tab,result) table_t *tab ; char **result ;
X.br
X.IP "free"
X.IP
XThe interface for this program should look like this:
X.br
Xint tb_new_free(rt) table_t *rt ;
X.br
X.RE
X.IP "Modify the tb_use routine."
X.IP "Add new table type to the test suite."
X<<When there is a test suite for tables:>>
X.SH "EXAMPLE CODE"
X.PP
XCurrently there are two table types, simple and multi. Both other these
Xcan be used as sample code, to help you understand how all the pieces fit
Xtogether.
X.SH DIAGNOSTICS
X.PP
XAll tb_ functions return a negative integer to show that an error
Xhas occured. This error codes are listed in table.h, and should be
Xused by your code as much as possible. If you need to add an new
Xerror code follow these steps:
X.IP 1
XAdd the code to table.h using the same format as the error codes already
Xthere.
X.IP 2
XModify the tb_error routine to print out a useful error message
Xwhen the new error occures.
X.SH "ADDING MESSAGES"
X.PP
XTo add a new message to the table routines, you should follow the following
Xsteps. <example>
X.IP "Add new handler routine."
X.IP "Add new message array."
X.IP "Add declarations to each table types's .h file"
X.IP "Add message handlers to old table types."
X.SH REPORTING
X.PP
XIf you implement a new useful table type, please email it to me, so that
XI can integrate it with future releases of the table subroutine package.
XThis is imporant, since otherwise, if I add a new type, and you add a
Xnew type, they will likely have the same table type number, and cause
Xall sorts of problems. The same is true of new error numbers.
X.SH AUTHOR
X.PP
XThe table routines were written by Joshua Levy at Atherton Technology.
X.br
Xjoshua at atherton.com Home: (415) 968-3718 Work: (408) 734-9822
X.IP "\(co 1989 Joshua Levy"
XThis man page and the code it describes is covered by the GNU general
Xpublic license, commonly called the "copyleft". It can only be used or
Xredistributed under the terms of that agreement. Persons or corporations
Xwishing to use this code in ways not allowed by the GNU license should
Xcontact the author to discuss other licensing agreements.
X.br
SHAR_EOF
fi
if test -f 'tb-script.man'
then
echo shar: "will not over-write existing file 'tb-script.man'"
else
sed 's/^X//' << \SHAR_EOF > 'tb-script.man'
X.ig XC
X% nroff -man table-script.man | more
X%n nroff -man table-script.man | lpr
X%t ptroff -man table-script.man -Plw
X.XC
X.TH TABLE-SCRIPT 1 "DEC 1st 1989"
X.SH NAME
Xtb-script \- the script language to manipulate tables.
X.SH SYNOPSIS
X.nf
Xtbscript <script.file> [<executable>]
X.fi
X.SH DESCRIPTION
X.PP
XThis man page describes a piece of software which is not finished
Xyet. If you would like it, email me.
X.PP
X.SH EXAMPLES
X.LP
XHere is a sample script file.
X.nf
XSTART
X TABLE(one) ;
X RESULT(res) ;
X
X READ("simp1.tab",one) ;
X USE(one,res) ;
X PRINT(res) ;
XEND
X.fi
X.SH "SEE ALSO"
X.PP
Xra_random(3), table(3), *.ts for examples
X.SH "BUGS"
X.SH AUTHOR
X.PP
XThese programs were written by Joshua Levy at Atherton Technology.
X.br
Xjoshua at atherton.com Home: (415) 968-3718 Work: (408) 734-9822
X.IP "\(co 1989 Joshua Levy"
XThis man page and the code it describes is covered by the GNU general
Xpublic license, commonly called the "copyleft". It can only be used or
Xredistributed under the terms of that agreement. Persons or corporations
Xwishing to use this code in ways not allowed by the GNU license should
Xcontact the author to discuss other licensing agreements.
X.br
SHAR_EOF
fi
cd ..
if test ! -d 'apps'
then
mkdir 'apps'
fi
cd 'apps'
if test -f 'bw.c'
then
echo shar: "will not over-write existing file 'bw.c'"
else
sed 's/^X//' << \SHAR_EOF > 'bw.c'
X/*
X * BW.C
X * Computer Buzzword Generator
X * By Joshua Levy
X * From specification by .
X */
X
X#include <stdio.h>
X#include <assert.h>
X#include <string.h>
X#include <ctype.h>
X
X#include "random.h"
X#include "table.h"
X
Xmain(argc,argv) int argc ; char *argv[] ;
X{
X table_t *first, *second, *third ;
X char *result1, *result2, *result3 ;
X long seed=0 ;
X int count=1 ;
X int i ;
X int sts ;
X
X /* parse the command line arguments */
X if (argc<=1) {
X printf("usage: bw <seed> <number>\n") ;
X printf("This will cause generation of <number> of buzzwords.\n") ;
X printf("Using <seed> and a random number seed.\n") ;
X printf("Seed defaults to 0, count to 1. Buzzword example:\n\n");
X }
X if (argc>=2)
X seed = atol(argv[1]) ;
X if (argc>=3)
X count = atoi(argv[2]) ;
X
X /*
X * Initialize the random number generater and the three tables.
X */
X ra_seed(seed) ;
X sts = tb_read("bw1.tab",&first) ; assert(sts==TB_OK) ;
X sts = tb_read("bw2.tab",&second) ; assert(sts==TB_OK) ;
X sts = tb_read("bw3.tab",&third) ; assert(sts==TB_OK) ;
X
X /*
X * Print out the three tables (mostly for debugging).
X sts = tb_tbl(first,"",0) ; assert(sts==TB_OK) ;
X sts = tb_tbl(second,"",0) ; assert(sts==TB_OK) ;
X sts = tb_tbl(third,"",0) ; assert(sts==TB_OK) ;
X */
X
X for(i=0 ; i<count ; i++) {
X sts = tb_use(first,&result1) ; assert(sts==TB_OK) ;
X sts = tb_use(second,&result2) ; assert(sts==TB_OK) ;
X sts = tb_use(third,&result3) ; assert(sts==TB_OK) ;
X printf("%s %s %s\n",result1,result2,result3) ;
X }
X
X /* these three frees are not really needed, since the program will end */
X sts = tb_free(first) ; assert(sts==TB_OK) ;
X sts = tb_free(second) ; assert(sts==TB_OK) ;
X sts = tb_free(third) ; assert(sts==TB_OK) ;
X}
X
X
SHAR_EOF
fi
if test -f 'Makefile'
then
echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
XI=-I../src
XS=../src
X
Xall: cname bw
X
Xcname: cname.c
X cc -o cname cname.c $I $S/random.o $S/table.a -lm
X
Xbw: bw.c
X cc -o bw bw.c $I $S/random.o $S/table.a -lm
X
Xclean:
X rm -f bw cname *~ #*# core
X
SHAR_EOF
fi
if test -f 'APPS'
then
echo shar: "will not over-write existing file 'APPS'"
else
sed 's/^X//' << \SHAR_EOF > 'APPS'
X
XThis directory contains some sample applications programs
Xwhich have been built on top of the table routines. More
Xcomplex examples will be put in subdirectories.
X
XThe first two examples are pretty trivial (and right now there are no others).
X
Xbw: Computer buzzphrase generator
X This is an example of the simple table type.
X
Xcname: Cyberpunk style name generator
X This is an example of the multi table type.
X
SHAR_EOF
fi
if test -f 'buzzwords'
then
echo shar: "will not over-write existing file 'buzzwords'"
else
sed 's/^X//' << \SHAR_EOF > 'buzzwords'
XFrom athertn!hpda!hplabs!hpfcso!hpldola!hp-lsd!oldcolo!weekley Tue Nov 7 12:33:35 PST 1989
XArticle 5316 of comp.misc:
XPath: athertn!hpda!hplabs!hpfcso!hpldola!hp-lsd!oldcolo!weekley
X>From: weekley at oldcolo.UUCP (Bob Weekley)
XNewsgroups: comp.misc
XSubject: COMPUTER BUZZWORD GENERATOR
XKeywords: computer buzzword generator
XMessage-ID: <[41]comp.misc at oldcolo.UUCP>
XDate: 5 Nov 89 13:10:04 GMT
XLines: 51
X
X
X EXPANDED "COMPUTER BUZZWORD" GENERATOR
X
X The microcomputer revolution has created new words that are as
Xincomprehensible as they are sophisticated. We have recently updated a
Xtechnique developed in the 1960's called the "Instant Buzzword Generator"
Xto help you master this obscure jargon. With it you can create an almost
Xendless variety of intelligent-sounding technical terms.
X
XINSTRUCTIONS: Simply select a number from each of the three columns below
Xand combine the words into your own computer buzzword phrases. For example,
Xselect "10," "16," and "5" and you generate
X "Ergonomic Transitional Capability"
Xan expression bound to command instant respect...and confusion!
X WATCH YOUR LANGUAGE!
X
X EXPANDED "COMPUTER BUZZWORD" GENERATOR
X 1. Integrated 1. Digital 1. Language
X 2. Synchronous 2. Logical 2. Compatability
X 3. Sectore 3. Memory 3. Management
X 4. On-line 4. Random 4. Options
X 5. Batched 5. Default 5. Capability
X 6. Relational 6. Third-Generation 6. Network
X 7. Dynamic 7. Incremental 7. Parameters
X 8. Parallel 8. Interpretive 8. Self-test
X 9. Responsive 9. Floppy 9. Matrix
X 10. Ergonomic 10. De-bugged 10. Hardware
X 11. Alphanumeric 11. Password 11. Device
X 12. Optical 12. Protocol 12. Refresh
X 13. Functional 13. Run-time 13. Compiler
X 14. Formatted 14. Analog 14. Controller
X 15. Mnemonic 15. Pixel 15. Flexability
X 16. Acknowledged 16. Transitional 16. Contingency
X 17. User-friendly 17. Intelligent 17. Duplex
X 18. Addressable 18. Virtual 18. Eprom
X 19. Enhanced 19. Buffered 19. Subroutine
X 20. Monitored 20. Vertical 20. Access
X
XNote: This all came from a very clever, beautifuly executed, two sided
Xfolding
Xwhatsoever with LBM. Their card is so fantastic, I thought everyone might
Xenjoy it.
X ----------------------
XRobert R. Weekley @ oldcolo.UUCP
X THE OLD COLORADO CITY ELECTRONIC COTTAGE
X | Standard | 2502 W. Colorado Ave. #203; C.S., CO 80904
X |Disclaimer| (719) 632-3391 [8-N-1]; 632-4848 [voice]
X
X "Freedom is the opportunity for self dicipline" -Dwight D. Eisenhower
X-----------------------------------------------------------------------------
X-
X
X
SHAR_EOF
fi
if test -f 'bw1.tab'
then
echo shar: "will not over-write existing file 'bw1.tab'"
else
sed 's/^X//' << \SHAR_EOF > 'bw1.tab'
XEXPANDED "COMPUTER BUZZWORD" GENERATOR (Table 1) Simple
X1d20 20
XBusiness Card by LONG BEACH MICRO; L.B. Calif.
X1 Integrated
X2 Synchronous
X3 Sectore
X4 On-line
X5 Batched
X6 Relational
X7 Dynamic
X8 Parallel
X9 Responsive
X10 Ergonomic
X11 Alphanumeric
X12 Optical
X13 Functional
X14 Formatted
X15 Mnemonic
X16 Acknowledged
X17 User-friendly
X18 Addressable
X19 Enhanced
X20 Monitored
X
SHAR_EOF
fi
if test -f 'bw2.tab'
then
echo shar: "will not over-write existing file 'bw2.tab'"
else
sed 's/^X//' << \SHAR_EOF > 'bw2.tab'
XEXPANDED "COMPUTER BUZZWORD" GENERATOR (Table 1) Simple
X1d20 20
XBusiness Card by LONG BEACH MICRO; L.B Calif
X1 Digital
X2 Logical
X3 Memory
X4 Random
X5 Default
X6 Third-Generation
X7 Incremental
X8 Interpretive
X9 Floppy
X10 De-bugged
X11 Password
X12 Protocol
X13 Run-time
X14 Analog
X15 Pixel
X16 Transitional
X17 Intelligent
X18 Virtual
X19 Buffered
X20 Vertical
X
X
SHAR_EOF
fi
if test -f 'bw3.tab'
then
echo shar: "will not over-write existing file 'bw3.tab'"
else
sed 's/^X//' << \SHAR_EOF > 'bw3.tab'
XEXPANDED "COMPUTER BUZZWORD" GENERATOR (Table 1) Simple
X1d20 20
XBusiness Card by LONG BEACH MICRO; L.B Calif
X1 Language
X2 Compatability
X3 Management
X4 Options
X5 Capability
X6 Network
X7 Parameters
X8 Self-test
X9 Matrix
X10 Hardware
X11 Device
X12 Refresh
X13 Compiler
X14 Controller
X15 Flexability
X16 Contingency
X17 Duplex
X18 Eprom
X19 Subroutine
X20 Access
SHAR_EOF
fi
if test -f 'cname.c'
then
echo shar: "will not over-write existing file 'cname.c'"
else
sed 's/^X//' << \SHAR_EOF > 'cname.c'
X/*
X * CNAME.C
X * A Cyberpunk style name generator.
X * By Joshua levy
X *
X% cc -g -I.. -o cname cname.c ../table.a ../random.o
X */
X
X#include <stdio.h>
X#include <string.h>
X#include <ctype.h>
X#include <assert.h>
X
X#include "random.h"
X#include "table.h"
X
Xextern char *optarg ;
X
Xmain(argc,argv) int argc ; char *argv[] ;
X{
X table_t *table1 ;
X char *result1 ;
X char *result2 ;
X int count=1, i ;
X int sts=0 ;
X int seed=0 ;
X int ch ;
X
X if (argc<=1) {
X printf("usage: cname -r <rand> -c <count>\nAn example result is:\n") ;
X }
X while ((ch=getopt(argc,argv,"c:r:")) != -1) {
X switch (ch) {
X case 'c': count = atoi(optarg) ; break ;
X case 'r': seed = atoi(optarg) ; break ;
X }
X }
X ra_seed(seed) ;
X tb_read("cname.tab",&table1) ;
X assert(sts==TB_OK) ;
X
X for(i=0 ; i<count ; i++) {
X sts = tb_use(table1,"1",&result1) ;
X assert(sts==TB_OK) ;
X sts = tb_use(table1,"2",&result2) ;
X assert(sts==TB_OK) ;
X printf("%s%s\n",result1,result2) ;
X }
X
X sts = tb_free(table1) ;
X assert(sts==TB_OK) ;
X}
X
X
SHAR_EOF
fi
if test -f 'cname.tab'
then
echo shar: "will not over-write existing file 'cname.tab'"
else
sed 's/^X//' << \SHAR_EOF > 'cname.tab'
XCyberpunk Style Name Generator Multiple
X1d13 13 2
Xmy mind
X- 1 2
X1 Live Wire
X2 Jack Up
X3 Cool Hand
X4 Silver Lake
X5 Black Ball
X6 Jump Down
X7 Flash Life
X8 Lazer Burn
X9 Quick Silver
X10 Soft War
X11 Low Heat
X12 Cyber Punk
X13 Comp Sci
SHAR_EOF
fi
cd ..
exit 0
# End of shell archive
More information about the Alt.sources
mailing list