Corrected inside_out()
[sigilutils.git] / sigutils.c
blob588f3051e18aeaeb43cb80cdd1465f2e64dec8e6
2 #include "basics.h"
3 #include "numbers.h"
4 #include "squares.h"
5 #include <unistd.h>
7 #define VERSION 0.01
9 char name[] = "Sigil Utilities, version";
10 char contact[] = "(C) 2020 theblaqcksquid <theblacksquid@subvertising.org>\n";
11 char license[] = "Licensed under GNU GPL v3\n";
13 char help0[] = "usage: sigutils [options] <STATEMENT OF INTENT>\n";
14 char help1[] = "-h Print this message and quit.\n";
15 char help2[] = "-v Print the version and license info, then quit.\n";
16 char help3[] = "-n Append the numerical and root values to the result.\n";
18 int main(int argc, char** argv)
20 int numeric_flag = 0;
21 int version_flag = 0;
22 int help_flag = 0;
23 int word_flag = 0;
24 int c;
26 while ((c = getopt(argc, argv, "nvhw")) != -1)
27 switch (c)
29 case 'n': numeric_flag = 1;
30 break;
32 case 'v': version_flag = 1;
33 break;
35 case 'h': help_flag = 1;
36 break;
38 case 'w': word_flag = 1;
39 break;
43 if (version_flag)
45 printf("%s %.2f\n%s%s", name, VERSION, contact, license);
46 return 0;
49 else if (help_flag)
51 printf("%s%s%s%s", help0, help1, help2, help3);
52 return 0;
55 char* raw = absorb_words(argc, argv, optind);
56 char* result = string_process(raw);
58 printf("%s", result);
60 if (numeric_flag)
62 int value = string_value(result, LETTERS);
63 int root = digital_root(value, 10);
64 printf(" %d %d", value, root);
67 if (word_flag)
69 printf("\n\n%s", inside_out(result));
72 printf("\n");
74 free(result);
75 free(raw);
76 return 0;