00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 char *start[] =
00015   { "You", "1", "5", ".", "May", "13", ".", "With", "the", "19", "of", "18",
00016 ",", "may", "13", "."
00017 };
00018 char startLoc[] = { 3, 0, 4, 7, 16 };
00019 char *adj[] = { "3", "4", "2", ",", "1" };
00020 char adjLoc[] = { 3, 0, 1, 2, 5 };
00021 char *adj3[] = { "3", "4" };
00022 char adj3Loc[] = { 2, 0, 1, 2 };
00023 char *adj1[] =
00024   { "lame", "dried", "up", "par-broiled", "bloated", "half-baked", "spiteful",
00025 "egotistical", "ungrateful", "stupid", "moronic", "fat", "ugly", "puny", "pitiful",
00026 "insignificant", "blithering", "repulsive", "worthless", "blundering", "retarded",
00027 "useless", "obnoxious", "low-budget", "assinine", "neurotic", "subhuman", "crochety",
00028 "indescribable", "contemptible", "unspeakable", "sick", "lazy", "good-for-nothing",
00029 "slutty", "mentally-deficient", "creepy", "sloppy", "dismal", "pompous", "pathetic",
00030 "friendless", "revolting", "slovenly", "cantankerous", "uncultured", "insufferable",
00031 "gross", "unkempt", "defective", "crumby"
00032 };
00033 char adj1Loc[] =
00034   { 50, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
00035 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
00036 43, 44, 45, 46, 47, 48, 49, 50, 51 };
00037 char *adj2[] =
00038   { "putrefied", "festering", "funky", "moldy", "leprous", "curdled", "fetid",
00039 "slimy", "crusty", "sweaty", "damp", "deranged", "smelly", "stenchy", "malignant",
00040 "noxious", "grimy", "reeky", "nasty", "mutilated", "sloppy", "gruesome", "grisly",
00041 "sloshy", "wormy", "mealy", "spoiled", "contaminated", "rancid", "musty",
00042 "fly-covered", "moth-eaten", "decaying", "decomposed", "freeze-dried", "defective",
00043 "petrified", "rotting", "scabrous", "hirsute"
00044 };
00045 char adj2Loc[] =
00046   { 40, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
00047 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
00048 char *name[] =
00049   { "10", ",", "bad", "excuse", "for", "6", ",", "6", "for", "brains", ",",
00050 "4", "11", "8", "for", "brains", "offspring", "of", "a", "motherless", "10", "7", "6",
00051 "7", "4", "11", "8"
00052 };
00053 char nameLoc[] = { 7, 0, 1, 6, 10, 16, 21, 23, 27 };
00054 char *stuff[] =
00055   { "shit", "toe", "jam", "filth", "puss", "earwax", "leaf", "clippings",
00056 "bat", "guano", "mucus", "fungus", "mung", "refuse", "earwax", "spittoon", "spittle",
00057 "phlegm"
00058 };
00059 char stuffLoc[] = { 14, 0, 1, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 17, 18 };
00060 char *noun_and_prep[] =
00061   { "bit", "of", "piece", "of", "vat", "of", "lump", "of", "crock", "of",
00062 "ball", "of", "tub", "of", "load", "of", "bucket", "of", "mound", "of", "glob", "of", "bag",
00063 "of", "heap", "of", "mountain", "of", "load", "of", "barrel", "of", "sack", "of", "blob", "of",
00064 "pile", "of", "truckload", "of", "vat", "of"
00065 };
00066 char noun_and_prepLoc[] =
00067   { 21, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36,
00068 38, 40, 42 };
00069 char *organics[] =
00070   { "droppings", "mung", "zits", "puckies", "tumors", "cysts", "tumors",
00071 "livers", "froth", "parts", "scabs", "guts", "entrails", "blubber", "carcuses", "gizards",
00072 "9"
00073 };
00074 char organicsLoc[] =
00075   { 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
00076 char *body_parts[] =
00077   { "kidneys", "genitals", "buttocks", "earlobes", "innards", "feet"
00078 };
00079 char body_partsLoc[] = { 6, 0, 1, 2, 3, 4, 5, 6 };
00080 char *noun[] =
00081   { "pop", "tart", "warthog", "twinkie", "barnacle", "fondue", "pot",
00082 "cretin", "fuckwad", "moron", "ass", "neanderthal", "nincompoop", "simpleton", "11"
00083 };
00084 char nounLoc[] = { 13, 0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
00085 char *animal[] =
00086   { "donkey", "llama", "dingo", "lizard", "gekko", "lemur", "moose", "camel",
00087 "goat", "eel"
00088 };
00089 char animalLoc[] = { 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
00090 char *good_verb[] =
00091   { "love", "cuddle", "fondle", "adore", "smooch", "hug", "caress", "worship",
00092 "look", "at", "touch"
00093 };
00094 char good_verbLoc[] = { 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 };
00095 char *curse[] =
00096   { "14", "20", "23", "14", "17", "20", "23", "14", "find", "your", "9",
00097 "suddenly", "delectable", "14", "and", "14", "seek", "a", "battleground", "23"
00098 };
00099 char curseLoc[] = { 4, 0, 3, 7, 13, 20 };
00100 char *afflictors[] =
00101   { "15", "21", "15", "21", "15", "21", "15", "21", "a", "22", "Rush",
00102 "Limbaugh", "the", "hosts", "of", "Hades"
00103 };
00104 char afflictorsLoc[] = { 6, 0, 2, 4, 6, 8, 12, 16 };
00105 char *quantity[] =
00106   { "a", "4", "hoard", "of", "a", "4", "pack", "of", "a", "truckload", "of",
00107 "a", "swarm", "of", "many", "an", "army", "of", "a", "4", "heard", "of", "a", "4",
00108 "platoon", "of", "a", "4", "and", "4", "group", "of", "16"
00109 };
00110 char quantityLoc[] = { 10, 0, 4, 8, 11, 14, 15, 18, 22, 26, 32, 33 };
00111 char *numbers[] =
00112   { "a", "thousand", "three", "million", "ninty-nine", "nine-hundred,",
00113 "ninty-nine", "forty-two", "a", "gazillion", "sixty-eight", "times", "thirty-three"
00114 };
00115 char numbersLoc[] = { 7, 0, 2, 4, 5, 7, 8, 10, 13 };
00116 char *adv[] =
00117   { "viciously", "manicly", "merrily", "happily", ",", "with", "the", "19",
00118 "of", "18", ",", "gleefully", ",", "with", "much", "ritualistic", "celebration", ",",
00119 "franticly"
00120 };
00121 char advLoc[] = { 8, 0, 1, 2, 3, 4, 11, 12, 18, 19 };
00122 char *metaphor[] =
00123   { "an", "irate", "manticore", "Thor's", "belch", "Alah's", "fist", "16",
00124 "titans", "a", "particularly", "vicious", "she-bear", "in", "the", "midst", "of", "her",
00125 "menstrual", "cycle", "a", "pissed-off", "Jabberwock"
00126 };
00127 char metaphorLoc[] = { 6, 0, 3, 5, 7, 9, 20, 23 };
00128 char *force[] = { "force", "fury", "power", "rage" };
00129 char forceLoc[] = { 4, 0, 1, 2, 3, 4 };
00130 char *bad_action[] =
00131   { "spit", "shimmy", "slobber", "find", "refuge", "find", "shelter", "dance",
00132 "retch", "vomit", "defecate", "erect", "a", "strip", "mall", "build", "a", "26", "have", "a",
00133 "religious", "experience", "discharge", "bodily", "waste", "fart", "dance", "drool",
00134 "lambada", "spill", "16", "rusty", "tacks", "bite", "you", "sneeze", "sing", "16",
00135 "campfire", "songs", "smite", "you", "16", "times", "construct", "a", "new", "home", "throw",
00136 "a", "party", "procreate"
00137 };
00138 char bad_actionLoc[] =
00139   { 25, 0, 1, 2, 3, 5, 7, 8, 9, 10, 11, 15, 18, 22, 25, 26, 27, 28, 29, 33,
00140 35, 36, 40, 44, 48, 51, 52 };
00141 char *beasties[] =
00142   { "yaks", "22", "maggots", "22", "cockroaches", "stinging", "scorpions",
00143 "fleas", "22", "weasels", "22", "gnats", "South", "American", "killer", "bees", "spiders",
00144 "4", "monkeys", "22", "wiener-dogs", "22", "rats", "22", "wolverines", "4", ",", "22",
00145 "pit-fiends"
00146 };
00147 char beastiesLoc[] =
00148   { 14, 0, 1, 3, 5, 7, 8, 10, 12, 16, 17, 19, 21, 23, 25, 29 };
00149 char *condition[] =
00150   { "frothing", "manic", "crazed", "plague-ridden", "disease-carrying",
00151 "biting", "rabid", "blood-thirsty", "ravaging", "slavering"
00152 };
00153 char conditionLoc[] = { 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
00154 char *place[] =
00155   { "in", "24", "25", "upon", "your", "mother's", "grave", "on", "24", "best",
00156 "rug", "in", "the", "26", "you", "call", "home", "upon", "your", "heinie"
00157 };
00158 char placeLoc[] = { 5, 0, 3, 7, 11, 17, 20 };
00159 char *relation[] =
00160   { "your", "your", "your", "your", "father's", "your", "mother's", "your",
00161 "grandma's"
00162 };
00163 char relationLoc[] = { 6, 0, 1, 2, 3, 5, 7, 9 };
00164 char *in_something[] =
00165   { "entrails", "anal", "cavity", "shoes", "house", "pantry", "general",
00166 "direction", "pants", "bed"
00167 };
00168 char in_somethingLoc[] = { 8, 0, 1, 3, 4, 5, 6, 8, 9, 10 };
00169 char *bad_place[] =
00170   { "rat", "hole", "sewer", "toxic", "dump", "oil", "refinery", "landfill",
00171 "porto-pottie"
00172 };
00173 char bad_placeLoc[] = { 6, 0, 2, 3, 5, 7, 8, 9 };
00174 char **daGrammar[27];
00175 char *daGLoc[27];
00176 
00177 static void
00178 init_grammar (void)
00179 {
00180   daGrammar[0] = start;
00181   daGLoc[0] = startLoc;
00182   daGrammar[1] = adj;
00183   daGLoc[1] = adjLoc;
00184   daGrammar[2] = adj3;
00185   daGLoc[2] = adj3Loc;
00186   daGrammar[3] = adj1;
00187   daGLoc[3] = adj1Loc;
00188   daGrammar[4] = adj2;
00189   daGLoc[4] = adj2Loc;
00190   daGrammar[5] = name;
00191   daGLoc[5] = nameLoc;
00192   daGrammar[6] = stuff;
00193   daGLoc[6] = stuffLoc;
00194   daGrammar[7] = noun_and_prep;
00195   daGLoc[7] = noun_and_prepLoc;
00196   daGrammar[8] = organics;
00197   daGLoc[8] = organicsLoc;
00198   daGrammar[9] = body_parts;
00199   daGLoc[9] = body_partsLoc;
00200   daGrammar[10] = noun;
00201   daGLoc[10] = nounLoc;
00202   daGrammar[11] = animal;
00203   daGLoc[11] = animalLoc;
00204   daGrammar[12] = good_verb;
00205   daGLoc[12] = good_verbLoc;
00206   daGrammar[13] = curse;
00207   daGLoc[13] = curseLoc;
00208   daGrammar[14] = afflictors;
00209   daGLoc[14] = afflictorsLoc;
00210   daGrammar[15] = quantity;
00211   daGLoc[15] = quantityLoc;
00212   daGrammar[16] = numbers;
00213   daGLoc[16] = numbersLoc;
00214   daGrammar[17] = adv;
00215   daGLoc[17] = advLoc;
00216   daGrammar[18] = metaphor;
00217   daGLoc[18] = metaphorLoc;
00218   daGrammar[19] = force;
00219   daGLoc[19] = forceLoc;
00220   daGrammar[20] = bad_action;
00221   daGLoc[20] = bad_actionLoc;
00222   daGrammar[21] = beasties;
00223   daGLoc[21] = beastiesLoc;
00224   daGrammar[22] = condition;
00225   daGLoc[22] = conditionLoc;
00226   daGrammar[23] = place;
00227   daGLoc[23] = placeLoc;
00228   daGrammar[24] = relation;
00229   daGLoc[24] = relationLoc;
00230   daGrammar[25] = in_something;
00231   daGLoc[25] = in_somethingLoc;
00232   daGrammar[26] = bad_place;
00233   daGLoc[26] = bad_placeLoc;
00234 }
00235 
00236 #include <ctype.h>
00237 #include <debug.h>
00238 #include <random.h>
00239 #include <stdio.h>
00240 #include <stdlib.h>
00241 #include <string.h>
00242 #include <syscall.h>
00243 
00244 void expand (int num, char **grammar[], char *location[], int handle);
00245 
00246 static void
00247 usage (int ret_code, const char *message, ...) PRINTF_FORMAT (2, 3);
00248 
00249 static void
00250 usage (int ret_code, const char *message, ...)
00251 {
00252   va_list args;
00253 
00254   if (message != NULL) 
00255     {
00256       va_start (args, message);
00257       vprintf (message, args);
00258       va_end (args);
00259     }
00260   
00261   printf ("\n"
00262           "Usage: insult [OPTION]...\n"
00263           "Prints random insults to screen.\n\n"
00264           "  -h:               this help message\n"
00265           "  -s <integer>:     set the random seed (default 4951)\n"
00266           "  -n <integer>:     choose number of insults (default 4)\n"
00267           "  -f <file>:        redirect output to <file>\n");
00268 
00269   exit (ret_code);
00270 }
00271 
00272 int
00273 main (int argc, char *argv[])
00274 {
00275   int sentence_cnt, new_seed, i, file_flag, sent_flag, seed_flag;
00276   int handle;
00277   
00278   new_seed = 4951;
00279   sentence_cnt = 4;
00280   file_flag = 0;
00281   seed_flag = 0;
00282   sent_flag = 0;
00283   handle = STDOUT_FILENO;
00284 
00285   for (i = 1; i < argc; i++)
00286     {
00287       if (strcmp (argv[1], "-h") == 0)
00288         usage (0, NULL);
00289       else if (strcmp (argv[i], "-s") == 0)
00290         {
00291           if (seed_flag++)
00292             usage (-1, "Can't have more than one seed");
00293           if (++i >= argc)
00294             usage (-1, "Missing value for -s");
00295           new_seed = atoi (argv[i]);
00296         }
00297       else if (strcmp (argv[i], "-n") == 0)
00298         {
00299           if (sent_flag++)
00300             usage (-1, "Can't have more than one sentence option");
00301           if (++i >= argc)
00302             usage (-1, "Missing value for -n");
00303           sentence_cnt = atoi (argv[i]);
00304           if (sentence_cnt < 1)
00305             usage (-1, "Must have at least one sentence");
00306         }
00307       else if (strcmp (argv[i], "-f") == 0)
00308         {
00309           if (file_flag++)
00310             usage (-1, "Can't have more than one output file");
00311           if (++i >= argc)
00312             usage (-1, "Missing value for -f");
00313 
00314           
00315 
00316 
00317 
00318           create (argv[i], 0);
00319           handle = open (argv[i]);
00320           if (handle < 0)
00321             {
00322               printf ("%s: open failed\n", argv[i]);
00323               return EXIT_FAILURE;
00324             }
00325         }
00326       else
00327         usage (-1, "Unrecognized flag");
00328     }
00329 
00330   init_grammar ();
00331 
00332   random_init (new_seed);
00333   hprintf (handle, "\n");
00334 
00335   for (i = 0; i < sentence_cnt; i++)
00336     {
00337       hprintf (handle, "\n");
00338       expand (0, daGrammar, daGLoc, handle);
00339       hprintf (handle, "\n\n");
00340     }
00341   
00342   if (file_flag)
00343     close (handle);
00344 
00345   return EXIT_SUCCESS;
00346 }
00347 
00348 void
00349 expand (int num, char **grammar[], char *location[], int handle)
00350 {
00351   char *word;
00352   int i, which, listStart, listEnd;
00353 
00354   which = random_ulong () % location[num][0] + 1;
00355   listStart = location[num][which];
00356   listEnd = location[num][which + 1];
00357   for (i = listStart; i < listEnd; i++)
00358     {
00359       word = grammar[num][i];
00360       if (!isdigit (*word))
00361         {
00362           if (!ispunct (*word))
00363             hprintf (handle, " ");
00364           hprintf (handle, "%s", word);
00365         }
00366       else
00367         expand (atoi (word), grammar, location, handle);
00368     }
00369 
00370 }