#include #include /********************************************************************* * GEMATRIA TABLES * * DESCRIPTION: standard tables of letter values * * NOTES: * *********************************************************************/ static short ac_sum, as_sum, gd_sum, ld_sum, st_sum, en_sum; /* gematria registers */ /* this table is loadable at run time */ static short ld_gematria[26]; /* this table is derived from Aleister Crowley */ 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 }; /* this table is derived from the Aurum Solis */ 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 }; /* this table is derived from the Golden Dawn */ 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 }; /* this table is derived from character frequencies in James' Enochian Keys */ static short st_gematria[] = { /* A B C D E F G H I J K L M N O */ 544, 117, 122, 120, 100, 36, 106, 97, 360, 0, 0, 225, 151, 187, 369, /* P Q R S T U V W X Y Z */ 135, 22, 210, 153, 106, 0, 107, 0, 35, 0, 97 }; /* this table is the English cabala from Equinox VII, #1 */ static short en_gematria[] = { /* A B C D E F G H I J K L M N O */ 1, 20, 13, 6, 25, 18, 11, 4, 23, 16, 9, 2, 21, 14, 7, /* P Q R S T U V W X Y Z */ 26, 19, 12, 5, 24, 17, 10, 3, 22, 15, 8 }; /********************************************************************* * DATA DEFINITIONS * * DESCRIPTION: data definitions used by the gematria code * * NOTES: * *********************************************************************/ /* maximum filename length */ #define NAMELEN 80 /* maximum separator length */ #define SEPLEN 32 /* 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 { ALL_OPT, AC_OPT, AS_OPT, GD_OPT, ST_OPT, EN_OPT, LOAD_OPT, ZERO_OPT, SEP_OPT, HELP_OPT, LAST_OPT } COMMAND_ARG; static OPTION all_option = {"-all", NULL, 3, 0, FALSE, FALSE }; 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 st_option = {"-st", NULL, 3, 0, FALSE, FALSE }; static OPTION en_option = {"-en", 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[] = { &all_option, &ac_option, &as_option, &gd_option, &st_option, &en_option, &load_option, &zero_option, &sep_option, &help_option, &nul_option }; /********************************************************************* * GETOPTS * * DESCRIPTION: acquires and stores command-line options * * NOTES: * *********************************************************************/ static short getopts(int argc, char **argv) { int 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]); } /********************************************************************* * COMPUTE GEMATRIA * * DESCRIPTION: computes the gematria value of a string * * NOTES: * *********************************************************************/ static void compute_gematria(char *bfr) { int len, i, j, tmp; char dstr[16]; len = strlen(bfr); for (ac_sum = as_sum = gd_sum = st_sum = en_sum = ld_sum = i = 0;i < len;i++) { if (isupper(toupper(bfr[i]))) { gd_sum += gd_gematria[toupper(bfr[i]) - 0x41]; as_sum += as_gematria[toupper(bfr[i]) - 0x41]; ac_sum += ac_gematria[toupper(bfr[i]) - 0x41]; st_sum += st_gematria[toupper(bfr[i]) - 0x41]; en_sum += en_gematria[toupper(bfr[i]) - 0x41]; ld_sum += ld_gematria[toupper(bfr[i]) - 0x41]; } else { if (isdigit(bfr[i])) { for (j=0; isdigit(bfr[i]); i++, j++) { dstr[j] = bfr[i]; } dstr[j] = 0; tmp = atoi(dstr); gd_sum += tmp; as_sum += tmp; ac_sum += tmp; st_sum += tmp; en_sum += tmp; ld_sum += tmp; } } } } /********************************************************************* * PRINT VALUE * * DESCRIPTION: prints computed gematria value of a string * * NOTES: * *********************************************************************/ static void print_value(char *bfr) { compute_gematria(bfr); if (get_arg(ALL_OPT)->present) { if (get_arg(LOAD_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s%04d%s%04d%s%04d%s%04d%s%04d%s%s" : "%4d%s%4d%s%4d%s%4d%s%4d%s%s"), ld_sum, separator, ac_sum, separator, as_sum, separator, gd_sum, separator, st_sum, separator, en_sum, separator, bfr); else printf((get_arg(ZERO_OPT)->present ? "%04d%s%04d%s%04d%s%04d%s%04d%s%s" : "%4d%s%4d%s%4d%s%4d%s%s"), ac_sum, separator, as_sum, separator, gd_sum, separator, st_sum, separator, en_sum, separator, bfr); } else { if (get_arg(GD_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s" : "%4d%s"), gd_sum, separator); if (get_arg(AS_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s" : "%4d%s"), as_sum, separator); if (get_arg(AC_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s" : "%4d%s"), ac_sum, separator); if (get_arg(ST_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s" : "%4d%s"), st_sum, separator); if (get_arg(EN_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s" : "%4d%s"), en_sum, separator); if (get_arg(LOAD_OPT)->present) printf((get_arg(ZERO_OPT)->present ? "%04d%s" : "%4d%s"), ld_sum, separator); printf("%s", 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; int 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) { char bfr[BFRSIZ+1]; getopts(argc, argv); if (!get_arg(HELP_OPT)->present) { if (get_arg(LOAD_OPT)->present) { if (load_gematria()) while (fgets(bfr, BFRSIZ, stdin) != NULL) print_value(bfr); } else { if (get_arg(ALL_OPT)->present) fprintf(stderr, "*** Using All Gematria Values ***\n"); else { if (get_arg(GD_OPT)->present) fprintf(stderr, "*** Using Golden Dawn Gematria Values ***\n"); if (get_arg(AS_OPT)->present) fprintf(stderr, "*** Using Aurum Solis Gematria Values ***\n"); if (get_arg(AC_OPT)->present) fprintf(stderr, "*** Using Aleister Crowley's Gematria Values ***\n"); if (get_arg(ST_OPT)->present) fprintf(stderr, "*** Using Statistical Gematria Values ***\n"); if (get_arg(EN_OPT)->present) fprintf(stderr, "*** Using English Gematria Values ***\n"); } while (fgets(bfr, BFRSIZ, stdin) != NULL) print_value(bfr); } } else { fprintf(stderr, "Usage: %s [options...]\n", argv[0]); fprintf(stderr, "Options: -gd - use Golden Dawn gematria values\n"); fprintf(stderr, "Options: -as - use Aurum Solis gematria values\n"); fprintf(stderr, "Options: -ac - use the Beast's gematria values\n"); fprintf(stderr, "Options: -st - use statistical gematria values\n"); fprintf(stderr, "Options: -en - use English gematria values\n"); fprintf(stderr, "Options: -al[l] - use all[gd as ac st en] gematria tables\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(s)\n"); fprintf(stderr, "Options: -h[elp] - prints this message\n"); fprintf(stderr, "Example: %s -load wombat -zero calcs\n", argv[0]); } return(0); }