diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
commit | c8bf38e5fb717d40635a2a89b22ed71b0de4266b (patch) | |
tree | 63751b2f5497c6f99e1c6a78f23a8e6e5c49833f /tests/emit_keys.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/emit_keys.c')
-rw-r--r-- | tests/emit_keys.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/emit_keys.c b/tests/emit_keys.c new file mode 100644 index 000000000..0b98689eb --- /dev/null +++ b/tests/emit_keys.c @@ -0,0 +1,48 @@ +#include <stdlib.h> /* malloc */ +#include <errno.h> /* perror */ +#include <stdio.h> /* printf */ +#include <unistd.h> /* write */ + +/* this define must precede uthash.h */ +#define HASH_EMIT_KEYS 1 +#include "uthash.h" + +#define BUFLEN 30 + +typedef struct name_rec { + char boy_name[BUFLEN]; + UT_hash_handle hh; +} name_rec; + +int main(int argc,char *argv[]) +{ + name_rec *name, *names=NULL; + char linebuf[BUFLEN]; + FILE *file; + int i=0; + + if (argc != 2) { + fprintf(stderr,"usage: %s file\n", argv[0]); + exit(-1); + } + + if ( (file = fopen( argv[1], "r" )) == NULL ) { + perror("can't open: "); + exit(-1); + } + + while (fgets(linebuf,BUFLEN,file) != NULL) { + name = (name_rec*)malloc(sizeof(name_rec)); + if (name == NULL) { + exit(-1); + } + strcpy(name->boy_name, linebuf); + HASH_ADD_STR(names,boy_name,name); + i++; + } + + fprintf(stderr,"%d keys emitted.\n", i); + fclose(file); + return 0; +} + |