From a73a9f7ebe6c82a9210e63700481b0b2dfcb0b4b Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 2 Feb 2019 22:56:02 +0100 Subject: First attempt to sort for unifications --- src/postprocess/sort_plz.c | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/postprocess/sort_plz.c (limited to 'src') diff --git a/src/postprocess/sort_plz.c b/src/postprocess/sort_plz.c new file mode 100644 index 0000000..f44cec7 --- /dev/null +++ b/src/postprocess/sort_plz.c @@ -0,0 +1,132 @@ +/* + target is in current directory: + entries_single/ entries_multi/ + is either [0-9_]{5} or _____ or brken + opens files in source directory: + 01_Flags 02_Nachname 03_Vorname 04_Zusaetze 07_Strasse 08_Hausnummer 09_Verweise 10_Postleitzahl + 11_Ort 12_Vorwahl 13_Rufnummer 16_Koordinaten + appends to all of the above dirs plus + 00_Jahr +*/ + +#include +#include +#include +#include +#include +#include + +enum { F_00, F_01, F_10, F_02, F_03, F_04, F_07, F_08, F_09, F_11, F_12, F_13, F_16, F_COUNT }; + +static char *g_filenames[] = { + "00_Jahr", "01_Flags", "10_Postleitzahl", "02_Nachname", "03_Vorname", "04_Zusaetze", "07_Strasse", "08_Hausnummer", "09_Verweise", "11_Ort", "12_Vorwahl", "13_Rufnummer", "16_Koordinaten" }; + +FILE * fopen_prefix(char *prefix, int file_id, int readonly) { + char filename[1024]; + snprintf( filename, sizeof(filename), "%s/%s", prefix, g_filenames[file_id]); + return fopen(filename, readonly ? "r" : "a"); +} + +int main(int argc, char **args) { + FILE * in_handles[F_COUNT] = { NULL }; + FILE * out_handles[F_COUNT] = { NULL }; + char flags[4]; + int i, in_multi = 0; + char *input = malloc(1024); + size_t input_size = 1024; + + /* First open all input files */ + for (i=F_01; i '9') && input[i] != '.') { + broken = 1; + break; + } + dest[i] = input[i]; + if (dest[i] == '.') dest[i] = '_'; + } + dest[5] = 0; + if (broken) + strcpy(out_dir, in_multi ? "multi/broken" : "single/broken"); + } else + strcpy(out_dir, in_multi ? "multi/broken" : "single/broken"); + + if (mkdir(out_dir, 0755) == -1 && errno != EEXIST) + errx( 1, "Couldn't create directory %s %d\n", out_dir, errno); + + for (i=F_00; i