2a446ed0d69d2a846c4f990c6e577d2788c1b88e kent Tue Aug 13 11:54:35 2019 -0700 Making a little string calculator mostly just to test strex library module. diff --git src/utils/strexCalc/strexCalc.c src/utils/strexCalc/strexCalc.c new file mode 100644 index 0000000..7fc9852 --- /dev/null +++ src/utils/strexCalc/strexCalc.c @@ -0,0 +1,45 @@ +/* strexCalc - String expression calculator, mostly to test strex expression evaluator.. */ +#include "common.h" +#include "linefile.h" +#include "hash.h" +#include "options.h" +#include "verbose.h" +#include "strex.h" + +void usage() +/* Explain usage and exit. */ +{ +errAbort( + "strexCalc - String expression calculator, mostly to test strex expression evaluator.\n" + "usage:\n" + " strexCalc [variable assignments] expression\n" + "command options in strexCalc are used to seed variables so for instance the command\n" + " strexCalc a=12 b=13 c=xyz 'a + b + c'\n" + "ends up returning 1213xyz\n" + ); +} + +char *symLookup(void *symbols, char *key) +{ +return optionVal(key, NULL); +} + +void strexCalc(char *expression) +/* strexCalc - String expression calculator, mostly to test strex expression evaluator.. */ +{ +struct strexParse *parsed = strexParseString(expression, expression, 0); +if (verboseLevel() > 1) + strexParseDump(parsed, 0, stderr); +char *result = strexEvalAsString(parsed, NULL, symLookup); +printf("%s\n", result); +} + +int main(int argc, char *argv[]) +/* Process command line. */ +{ +optionInit(&argc, argv, NULL); +if (argc != 2) + usage(); +strexCalc(argv[1]); +return 0; +}