diff options
author | epoch <epoch@hack.thebackupbox.net> | 2021-08-11 00:02:42 +0000 |
---|---|---|
committer | epoch <epoch@hack.thebackupbox.net> | 2021-08-11 00:02:42 +0000 |
commit | af16af8af42e41f470f44fcd174babda8b52dfc7 (patch) | |
tree | dfea626733a38203a4cb3bdd93c95bdcc854da02 | |
parent | 4c0e3f77d79a31d07f7af220ed752dc12424c58c (diff) | |
download | libhashtable-af16af8af42e41f470f44fcd174babda8b52dfc7.tar.gz libhashtable-af16af8af42e41f470f44fcd174babda8b52dfc7.zip |
-rw-r--r-- | examples/Makefile | 9 | ||||
-rwxr-xr-x | examples/wordtr | bin | 0 -> 8288 bytes | |||
-rw-r--r-- | examples/wordtr.c | 45 |
3 files changed, 54 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..508f0e6 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,9 @@ +PREFIX:=/usr/local + +all: wordtr + +wordtr: LDLIBS=-lhashtable -lgcc_s +wordtr: wordtr.c + +install: wordtr + install -t $(PREFIX)/bin/ wordtr diff --git a/examples/wordtr b/examples/wordtr Binary files differnew file mode 100755 index 0000000..dc0996e --- /dev/null +++ b/examples/wordtr diff --git a/examples/wordtr.c b/examples/wordtr.c new file mode 100644 index 0000000..464450f --- /dev/null +++ b/examples/wordtr.c @@ -0,0 +1,45 @@ +#include <hashtable.h> +#include <string.h> +#include <stdio.h> + +/* + +Checking the hashtable before loading the arguments is just in case all of the stdin +is stuff that can be translated without needing to load all the arguments into the hashtable. +Which should make the program go faster, right? + +If it isn't in the hashtable, it loads the translations from arguments until it finds the one +it needs for the current line is has read from stdin, prints the replacement, and reads another +line from stdin. + +If all of that fails, it will have loaded all of the arguments, gives up by just printing the +line it got from stdin. + +*/ + +int main(int argc,char *argv[]) { + char line[1024]; + char *p; + struct hashtable ht; + inittable(&ht,512); + argc--; + argv++; +super_continue: + while(fgets(line,sizeof(line),stdin)) { + if((p=strchr(line,'\n'))) *p=0; + if((p=ht_getvalue(&ht,line))) { + printf("%s\n",p); + continue; + } + for(;argc > 1;argv+=2,argc-=2) { + ht_setkey(&ht,argv[0],argv[1]); +// printf("%s %s\n",argv[0],argv[1]); //to see how stuff is loading ofc. + if(!strcmp(argv[0],line)) { + printf("%s\n",argv[1]); + goto super_continue; + } + } + printf("%s\n",line); + } + return 0; +} |