Source code for Zhodani word generator...

By Dave Boddie ·

TML message #2427From bundle 201

Here is the source for the Zhodani word generator...Like I said earlier, it is
shar'ed just like the Vargr program source...save this into a file, cut out the
header, and follow the shar instructions to uncompress it....

Hope ya like it!
Dave


#---------------------------------- cut here ----------------------------------
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Dave (Unix Hero) [email removed] on Mon Jun 10 16:12:32 1991
#
# This archive contains:
#       zcon1.c         zcon2.c         zhodani.c       zhodani.doc
#       zmain.c         zvow.c
#

LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH

echo x - zcon1.c
cat >zcon1.c <<'@EOF'
/* this is the initial consonant table listing. */

extern char *init1[6][6] =      {
                                { "b","b","b","b","b","bl" },
                                { "bl","bl","br","br","br","br" },
                                { "br","ch","ch","ch","ch","ch" },
                                { "ch","ch","ch","ch","ch","ch" },
                                { "ch","cht","cht","cht","cht","cht" },
                                { "cht","cht","d","d","d","d" },
                                };

extern char *init2[6][6] =      {
                                { "d","d","d","d","d","dl" },
                                { "dl","dl","dl","dl","dl","dl" },
                                { "dr","dr","dr","dr","dr","f" },
                                { "f","f","f","f","fl","fl" },
                                { "fl","fr","fr","fr","j","j" },
                                { "j","j","j","j","j","jd" },
                                };

extern char *init3[6][6] =      {
                                { "jd","jd","jd","jd","k","k" },
                                { "k","k","k","kl","kl","kr" },
                                { "kr","l","l","l","m","m" },
                                { "n","n","n","n","n","n" },
                                { "n","n","p","p","p","p" },
                                { "p","p","p","pl","pl","pl" },
                                };

extern char *init4[6][6] =      {
                                { "pl","pl","pl","pl","pr","pr" },
                                { "pr","q","q","ql","ql","qr" },
                                { "qr","r","r","r","r","r" },
                                { "s","s","s","s","s","s" },
                                { "s","sh","sh","sh","sh","sh" },
                                { "sh","sh","sht","sht","sht","sht" },
                                };

extern char *init5[6][6] =      {
                                { "sht","sht","sht","t","t","t" },
                                { "t","t","st","st","st","st" },
                                { "st","st","st","tl","tl","tl" },
                                { "tl","tl","tl","tl","tl","tl" },
                                { "tl","ts","ts","ts","v","v" },
                                { "v","v","v","vl","vl","vr" },
                                };

extern char *init6[6][6] =      {
                                { "vr","y","y","y","z","z" },
                                { "z","z","z","zd","zd","zd" },
                                { "zd","zd","zd","zd","zd","zd" },
                                { "zd","zh","zh","zh","zh","zh" },
                                { "zh","zh","zhd","zhd","zhd","zhd" },
                                { "zhd","zhd","zhd","zhd","zhd","zhd" },
                                };

/* end of initial consonant initialization */
@EOF

chmod 644 zcon1.c

echo x - zcon2.c
cat >zcon2.c <<'@EOF'
/* this file contains the final consonant letters for the random word */
/* generator.                                                         */

extern char *final1[6][6] =     {
                                { "b","b","bl","bl","bl","bl" },
                                { "bl","bl","bl","br","br","br" },
                                { "br","br","br","br","ch","ch" },
                                { "ch","ch","ch","d","d","d" },
                                { "d","dl","dl","dl","dl","dl" },
                                };

extern char *final2[6][6] =     {
                                { "dr","dr","dr","f","f","f" },
                                { "f","f","fl","fl","fl","fl" },
                                { "fl","fr","fr","fr","fr","fr" },
                                { "j","j","j","j","k","k" },
                                { "kl","kl","kl","kl","kr","kr" },
                                { "l","l","l","l","l","l" },
                                };

extern char *final3[6][6] =     {
                                { "l","l","l","l","l","l" },
                                { "m","m","n","n","nch","nch" },
                                { "nch","nch","nch","nch","nch","nj" },
                                { "nj","nj","nj","nj","ns","ns" },
                                { "ns","ns","ns","nsh","nsh","nsh" },
                                { "nsh","nsh","nsh","nsh","nt","nt" },
                                };

extern char *final4[6][6] =     {
                                { "nt","nt","nts","nts","nts","nts" },
                                { "nz","nz","nz","nz","nz","nzh" },
                                { "nzh","nzh","nzh","nzh","nzh","nzh" },
                                { "p","p","pl","pl","pl","pl" },
                                { "pl","pl","pl","pr","pr","pr" },
                                { "pr","pr","pr","pr","q","q" },
                                };

extern char *final5[6][6] =     {
                                { "ql","ql","qr","qr","r","r" },
                                { "r","r","r","sh","sh","sh" },
                                { "sh","sh","sh","sh","t","t" },
                                { "t","t","ts","ts","ts","ts" },
                                { "ts","ts","ts","tl","tl","tl" },
                                { "tl","tl","tl","tl","tl","tl" },
                                };

extern char *final6[6][6] =     {
                                { "v","v","v","v","v","vl" },
                                { "vl","vl","vl","vr","vr","vr" },
                                { "vr","vr","z","z","z","z" },
                                { "z","z","z","z","z","zh" },
                                { "zh","zh","zh","zh","zh","zh" },
                                { "'","'","'","'","'","'" },
                                };

/* end of final consonant initialization */
@EOF

chmod 644 zcon2.c

echo x - zhodani.c
cat >zhodani.c <<'@EOF'
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "zmain.c"
#include "zcon1.c"
#include "zvow.c"
#include "zcon2.c"

#define DIE     6
#define CONS    'C'
#define VOW     'V'

char *string[6], *wordstring;
char rc, *ptr;
int syllen;
int Random();
char *GetICons();
char *GetFCons();
char *GetVow();

main(argc,argv)
int argc;
char *argv[];
{
        int red, white, i, j, count, maxsyl;
        static int syllables;

        if(argc >= 2)   {
                srand(time(0L));
                for(count=0;count<atoi(argv[1]);count++)        {
                        syllables = (int) Random(DIE);
                        if(argv[2] != NULL)
                                maxsyl = atoi(argv[2]);
                        if(maxsyl > 0 && maxsyl <= 6)
                                syllables = maxsyl;
                        for (i=0; i<syllables; i++)     {
                                red = Random(DIE) - 1;
                                white = Random(DIE) - 1;
                                if(i != 0)
                                        rc = *(string[i-1]+strlen(string[i-1])-1);
                                if(i==0 || rc == CONS) {
                                        string[i] = basic[red][white];
                                        }
                                else    {
                                        string[i] = alt[red][white];
                                        }
                        } /* End of Loop */
                        string[i] = '\0';
                        wordstring = malloc((syllables * 9)+1);
                        *wordstring = '\0';
                        for(i=0;i<syllables;i++)        {
                                syllen = strlen(string[i]);
                                for(j=0;j<syllen;j++)   {
                                        rc = *(string[i]+j);
                                        if(j==0 && rc == CONS)  {
                                                red = Random(DIE);
                                                ptr = GetICons(red);
                                                strcat(wordstring,ptr);
                                        }
                                        else if(j != 0 && rc == CONS)   {
                                                red = Random(DIE);
                                                ptr = GetFCons(red);
                                                strcat(wordstring,ptr);
                                        }
                                        if(rc == VOW)   {
                                                red = Random(DIE);
                                                ptr = GetVow(red);
                                                strcat(wordstring,ptr);
                                        }
                                }
                        }
                        printf("%s\n",wordstring);
                        *wordstring = '\0';
                }
        }
        else    {
                printf("Usage: zhodani number-of-names [maximum syllables]\n");
                }
} /* End of Main */

int Random(max)
int max;
{
        int die;

        die = ((int)(rand()%max)+1);
        return(die);
} /* End of Random */

char *GetICons(num)
int num;
{
        int r, w;
        char *grab;

        r = Random(DIE) - 1;
        w = Random(DIE) - 1;
        switch(num)     {
                case 1: grab = init1[r][w];
                        break;
                case 2: grab = init2[r][w];
                        break;
                case 3: grab = init3[r][w];
                        break;
                case 4: grab = init4[r][w];
                        break;
                case 5: grab = init5[r][w];
                        break;
                case 6: grab = init6[r][w];
                        break;
        }
        return(grab);
} /* End of GetICons */

char *GetFCons(num)
int num;
{
        int r, w;
        char *grab;

        r = Random(DIE) - 1;
        w = Random(DIE) - 1;
        switch(num)     {
                case 1: grab = final1[r][w];
                        break;
                case 2: grab = final2[r][w];
                        break;
                case 3: grab = final3[r][w];
                        break;
                case 4: grab = final4[r][w];
                        break;
                case 5: grab = final5[r][w];
                        break;
                case 6: grab = final6[r][w];
                        break;
        }
        return(grab);
} /* End of GetFCons */

char *GetVow(num)
int num;
{
        int r, w;
        char *grab;

        r = Random(DIE) - 1;
        w = Random(DIE) - 1;
        switch(num)     {
                case 1: grab = vow1[r][w];
                        break;
                case 2: grab = vow2[r][w];
                        break;
                case 3: grab = vow3[r][w];
                        break;
                case 4: grab = vow4[r][w];
                        break;
                case 5: grab = vow5[r][w];
                        break;
                case 6: grab = vow6[r][w];
                        break;
        }
        return(grab);
} /* End of GetVow */
@EOF

chmod 644 zhodani.c

echo x - zhodani.doc
cat >zhodani.doc <<'@EOF'
^L               The Zhodani word generator was created to speed
                up creating words and names in the Vargr lang-
                uage using the tables found in Alien Module #4
                for the Traveller Role Playing Game. This code
                is copyright by me, David Courney Boddie on
                May of 1991, and I give express concent to any
                one who wishes to copy and/or change the code
                at will, but if you wish to sell the code, I
                would request that you contact me first. This is
                my first batch of C code that actually works
                that does more than prints "Hello World", and
                I am pretty proud of it. This code is public
                domain, but if you distribute it, keep all the
                parts together.

                Compiling this program is simple...There is no
                makefile, and the only file that you need to
                compile is ZHODANI.C, which will call all the
                remaining C files. An example command to com-
                pile for a Unix machine would be:

                        cc -o zhodani zhodani.c

                For Turbo C, you can just type the following:

                        tcc zhodani.c

                which will create an executible with the same
                name as the C program. You can also use the IDE
                to generate an executible file. Any errors generated
                by the code should be sent back to [email removed].

^L               Once you have generated an executible, you can execute
                the program with the following parameters (square brack-
                ets [] represent optional parameters):

                        zhodani number-of-words [maximum syllables]

                The number of names (whether 1 or a million) must be
                specified. I haven't updated the code yet to take any
                number of arguements, so I had to stick this restriction
                on it. Since this word/name generator can generate up to
                6 syllables, and each syllable can have up to 10 char-
                acters each...so that can be a lot. So I have entered a
                parameter that allows you to set the maximum number of
                syllables. Neither of these numbers can be 0 or negative.

                Well, there you have it...If you have any questions about
                the code or have patches, please submit them to me. I
                would like to see what you can do with this if you want.
                I believe this code is somewhat bug free, but I have
                heard that the executibles may crash some PCs. This
                program is simple, and you shouldn't have any problems
                with it....but you still might...

                Standard Disclaimer: Since this is my first written
                piece of code, I will disclaim that I will not be res-
                ponsible for any harmful effects of this code. If you
                are a programmer of C, or can understand C somewhat,
                you should inspect this code before installing it on
                your machine. For those who aren't adept at C, all I
                can give you is my word that this code is harmless.

========================Greetings from the Flux==========================
: Dave Boddie                                          ___________      :
: Computer Operator I / Lab Consultant                 |+         |_    :
: University of Arkansas, Fayetteville                 | NorthWest /    :
: Bitnet: [email removed]                              | Arkansas |     :
: Internet: [email removed]                            |_ U of A /      :
:                                                        |______|       :
:    "Strive for exellence, struggle for power, grieve for losing."     :
=========================================================================
@EOF

chmod 644 zhodani.doc

echo x - zmain.c
cat >zmain.c <<'@EOF'
/* The file ZMAIN.C contains the basic and alternate tables for the */
/* random word generation program. These provide vowel (V) and cons */
/* onant (C) values for the syllable string.                        */

extern char *basic[6][6] =      {
                                { "V","V","V","V","CV","CV"             },
                                { "VC","VC","VC","VC","VC","VC"         },
                                { "VC","VC","VC","CVC","CVC","CVC"      },
                                { "CVC","CVC","CVC","CVC","CVC","CVC"   },
                                { "CVC","CVC","CVC","CVC","CVC","CVC"   },
                                { "CVC","CVC","CVC","CVC","CVC","CVC"   }
                                };

extern char *alt[6][6] =        {
                                { "V","V","V","V","V","V"               },
                                { "CV","CV","CV","CV","CV","CV"         },
                                { "VC","VC","VC","VC","VC","VC"         },
                                { "CVC","CVC","CVC","CVC","CVC","CVC"   },
                                { "CVC","CVC","CVC","CVC","CVC","CVC"   },
                                { "CVC","CVC","CVC","CVC","CVC","CVC"   },
                                };

/* End of the Basic Tables */
@EOF

chmod 644 zmain.c

echo x - zvow.c
cat >zvow.c <<'@EOF'
/* this file contains all the vowel tables required with the random word */
/* generator.                                                            */

extern char *vow1[6][6] =       {
                                { "a","a","a","a","a","a" },
                                { "a","a","a","a","a","a" },
                                { "a","a","a","a","a","a" },
                                { "a","a","a","a","a","a" },
                                { "a","a","a","a","a","a" },
                                { "a","a","a","a","a","a" },
                                };

extern char *vow2[6][6] =       {
                                { "a","a","a","a","a","a" },
                                { "a","a","a","a","a","a" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                };

extern char *vow3[6][6] =       {
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","e","e","e" },
                                { "e","e","e","i","i","i" },
                                };

extern char *vow4[6][6] =       {
                                { "i","i","i","i","i","i" },
                                { "i","i","i","i","i","i" },
                                { "i","i","i","i","i","i" },
                                { "i","i","i","i","i","i" },
                                { "i","i","i","i","i","i" },
                                { "i","i","ia","ia","ia","ia" },
                                };

extern char *vow5[6][6] =       {
                                { "ia","ia","ia","ia","ia","ia" },
                                { "ia","ia","ia","ia","ia","ia" },
                                { "ia","ia","ia","ia","ia","ia" },
                                { "ia","ia","ia","ia","ia","ia" },
                                { "ie","ie","ie","ie","ie","ie" },
                                { "ie","ie","ie","ie","ie","ie" },
                                };

extern char *vow6[6][6] =       {
                                { "ie","ie","ie","ie","ie","ie" },
                                { "ie","ie","ie","ie","ie","ie" },
                                { "ie","ie","ie","ie","o","o" },
                                { "o","o","o","o","o","o" },
                                { "o","o","o","o","o","o" },
                                { "r","r","r","r","r","r" },
                                };

/* end of vowel initialization */
@EOF

chmod 644 zvow.c

exit 0