/ Copyright (C) 1992 by R. Franklin Buchanan Permission is granted to any individual or in

---
Master Index Current Directory Index Go to SkepticTank Go to Human Rights activist Keith Henson Go to Scientology cult

Skeptic Tank!

/* Copyright (C) 1992 by R. Franklin Buchanan Permission is granted to any individual or institution to use, copy, or redistribute this software so long as all of the original files are included unmodified, that it is not sold for profit, and that this copyright notice is retained. --------------------------------------------------------------------- CHANGE HISTORY: 1.0 8 August 1992 - RFB - Initial Release --------------------------------------------------------------------- */ #include #include #define VERSION "1.0" /********************************************************************* * GEMATRIA TABLES * * DESCRIPTION: standard tables of letter values * * NOTES: * *********************************************************************/ static short ld_gematria[26]; /* loadable gematria table */ static short ac_gematria[] = { /* A B C D E F G H I J K L M N O */ 6, 5, 300, 4, 7, 300, 9, 1, 60, 0, 0, 40, 90, 50, 30, /* P Q R S T U V W X Y Z */ 8, 40, 100, 10, 400, 0, 70, 0, 400, 0, 1 }; static short as_gematria[] = { /* A B C D E F G H I J K L M N O */ 6, 1, 2, 4, 7, 5, 3, 10, 9, 0, 0, 20, 8, 50, 70, /* P Q R S T U V W X Y Z */ 30, 40, 80, 200, 300, 0, 100, 0, 60, 0, 90 }; static short gd_gematria[] = { /* A B C D E F G H I J K L M N O */ 1, 2, 20, 4, 5, 6, 3, 8, 10, 0, 0, 30, 40, 50, 70, /* P Q R S T U V W X Y Z */ 80, 90, 100, 200, 300, 0, 400, 0, 60, 0, 7 }; /********************************************************************* * DATA DEFINITIONS * * DESCRIPTION: data definitions used by the gematria code * * NOTES: * *********************************************************************/ /* maximum filename length */ #define NAMELEN 64 /* maximum separator length */ #define SEPLEN 64 /* maximum line buffer size */ #define BFRSIZ 512 typedef enum { FALSE, TRUE, } boolean; typedef struct option { char *keyword; char *opt; short match_len; short copy_len; boolean requires_parameter; boolean present; } OPTION; /********************************************************************* * OPTIONS * * DESCRIPTION: command-line options * * NOTES: * *********************************************************************/ static char filename[NAMELEN+1]; static char separator[SEPLEN+1] = {"\t"}; typedef enum { AC_OPT, AS_OPT, GD_OPT, LOAD_OPT, ZERO_OPT, SEP_OPT, HELP_OPT, LAST_OPT } COMMAND_ARG; static OPTION ac_option = {"-ac", NULL, 3, 0, FALSE, FALSE }; static OPTION as_option = {"-as", NULL, 3, 0, FALSE, FALSE }; static OPTION gd_option = {"-gd", NULL, 3, 0, FALSE, FALSE }; static OPTION load_option = {"-load", filename, 3, NAMELEN, TRUE, FALSE }; static OPTION zero_option = {"-zero", NULL, 3, 0, FALSE, FALSE }; static OPTION sep_option = {"-separator", separator, 3, SEPLEN, TRUE, FALSE }; static OPTION help_option = {"-help", NULL, 2, 0, FALSE, FALSE }; static OPTION nul_option = {NULL, NULL, 0, 0, FALSE, FALSE }; static OPTION *parameter_array[] = { &ac_option, &as_option, &gd_option, &load_option, &zero_option, &sep_option, &help_option, &nul_option }; /********************************************************************* * MIN * * DESCRIPTION: returns the smaller of two integer values * * NOTES: * *********************************************************************/ static short min(short a, short b) { if (b < a) return(b); else return(a); } /********************************************************************* * GETOPTS * * DESCRIPTION: acquires and stores command-line options * * NOTES: * *********************************************************************/ static short getopts(int argc, char **argv) { short optind, a, args; for (args = 0, optind = 1;(optind < argc) && (argv[optind][0] == '-');optind++) { for (a = 0;parameter_array[a]->keyword;a++) { if (!strncmp(parameter_array[a]->keyword, argv[optind], parameter_array[a]->match_len) && (parameter_array[a]->present == FALSE) ) { if (parameter_array[a]->requires_parameter) { strncpy(parameter_array[a]->opt, argv[optind+1], parameter_array[a]->copy_len); ++optind; } parameter_array[a]->present = TRUE; ++args; break; } } } return(args); } /********************************************************************* * GET ARG * * DESCRIPTION: returns a pointer to the specified option block * * NOTES: * *********************************************************************/ static OPTION *get_arg(COMMAND_ARG arg) { return(parameter_array[arg]); } /********************************************************************* * STRUPPER * * DESCRIPTION: uppercases a string * * NOTES: * *********************************************************************/ static char *strupper(char *wrk) { char* str; str = wrk; while(*str) { *str = toupper(*str); ++str; } return(wrk); } /********************************************************************* * COMPUTE GEMATRIA * * DESCRIPTION: computes the gematria value of a string * * NOTES: * *********************************************************************/ static short compute_gematria(char *bfr, short *gematria) { char tmp[BFRSIZ+1]; short sum, len, i; strupper(strncpy(tmp, bfr, (len = min(strlen(bfr), BFRSIZ)))); for (sum = i = 0;i < len;i++) { if (isupper(tmp[i])) sum += gematria[tmp[i] - 0x41]; } return(sum); } /********************************************************************* * PRINT VALUE * * DESCRIPTION: prints computed gematria value of a string * * NOTES: * *********************************************************************/ static void print_value(boolean zero, char *bfr, short *gematria) { if (zero) printf("%04d%s%s", compute_gematria(bfr, gematria), separator, bfr); else printf("%4d%s%s", compute_gematria(bfr, gematria), separator, bfr); } /********************************************************************* * LOAD GEMATRIA * * DESCRIPTION: loads the reference Gematria Table from disk * * NOTES: * *********************************************************************/ static boolean load_gematria(void) { FILE *fd; char *fn, bfr[BFRSIZ+1]; boolean status; short i; status = FALSE; if ((fd = fopen((fn = get_arg(LOAD_OPT)->opt), "r")) != NULL) { status = TRUE; for (i = 0;i < 26;i++) { fgets(bfr, BFRSIZ, fd); ld_gematria[i] = atoi(bfr); } fclose(fd); fprintf(stderr, "*** Loaded Gematria Table from %s ***\n", fn); } else fprintf(stderr, "*** Unable to Load Gematria Table from %s ***\n", fn); return(status); } /********************************************************************* * MAIN * * DESCRIPTION: program main entry point * * NOTES: * *********************************************************************/ main(int argc, char **argv) { boolean zero; char bfr[BFRSIZ+1]; short *gematria; fprintf(stderr, "%s - Release %s\n", argv[0], VERSION); getopts(argc, argv); if (!get_arg(HELP_OPT)->present) { if (get_arg(LOAD_OPT)->present) { if (load_gematria() == TRUE) gematria = ld_gematria; else gematria = NULL; } else { if (get_arg(AC_OPT)->present) { gematria = ac_gematria; fprintf(stderr, "*** Using Aleister Crowley's Gematria Values ***\n"); } else if (get_arg(AS_OPT)->present) { gematria = as_gematria; fprintf(stderr, "*** Using Aurum Solis Gematria Values ***\n"); } else if (get_arg(GD_OPT)->present) { gematria = gd_gematria; fprintf(stderr, "*** Using Golden Dawn Gematria Values ***\n"); } else gematria = NULL; } if (!gematria) { gematria = ac_gematria; fprintf(stderr, "*** Using Aleister Crowley's Gematria Values ***\n"); } zero = get_arg(ZERO_OPT)->present; while (fgets(bfr, BFRSIZ, stdin) != NULL) { print_value(zero, bfr, gematria); } } else { fprintf(stderr, "Usage: %s [options...]\n", argv[0]); fprintf(stderr, "Options: -ac (DEFAULT) - use the Beast's gematria values\n"); fprintf(stderr, "Options: -as - use Aurum Solis gematria values\n"); fprintf(stderr, "Options: -gd - use Golden Dawn gematria values\n"); fprintf(stderr, "Options: -lo[ad] {file} - load gematria values from file\n"); fprintf(stderr, "Options: -ze[ro] - zero-fill printed values\n"); fprintf(stderr, "Options: -se[parator] {string} - print between name and value\n"); fprintf(stderr, "Options: -h[elp] - prints this message\n"); fprintf(stderr, "Example: %s -load wombat -zero calcs\n", argv[0]); } return(0); }

---

E-Mail Fredric L. Rice / The Skeptic Tank