This is umsda.c in view mode; [Download] [Up]
/* $Id: umsda.c,v 3.2 1993/06/28 09:31:07 klute Exp klute $ */ /* * Copyright 1993 Rainer Klute <klute@irb.informatik.uni-dortmund.de> * * Permission to use, copy, modify, distribute, and sell this software and * its documentation for any purpose is hereby granted without fee, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation. The author makes no representations about the suitability * of this software for any purpose. It is provided "as is" without express * or implied warranty. * */ #include <ctype.h> #ifdef __NeXT__ #include <stdlib.h> #else #include <malloc.h> #endif #include <stdio.h> #include <string.h> #include "message.h" #include "plzfile.h" #include "umsda.h" static PlzFile umsda = {(FILE *) 0, 0, 0, 0}; static Shortcut abk[] = { {"St.", "Sankt"}, {"st.", "sankt"}, {"ST.", "SANKT"}, {"St ", "Sankt "}, {"st ", "sankt "}, {"ST ", "SANKT "}, {(char *) 0, (char *) 0}, }; UmsdaSet *UmsdaSetSucheOrt (UmsdaSet *list, char *ortsname) { UmsdaSet *result = (UmsdaSet *) malloc (sizeof (UmsdaSet)); Umsda *l; Umsda *r; int i; char *e_ortsname; char *help; if (result == (UmsdaSet *) 0) { OutOfMemory ("RematchPlace"); return result; } result->list = (Umsda *) malloc ((unsigned int) (list->entries * sizeof (Umsda) + 2)); if (result->list == (Umsda *) 0) { OutOfMemory ("RematchPlace"); return (UmsdaSet *) 0; } result->entries = 0; e_ortsname = AbkuerzungenExpandieren (ortsname, abk); help = IsoToCapitals (e_ortsname); free (e_ortsname); e_ortsname = CStringToFixed (help, sizeof (((Umsda *) 0)->oname_sort_a)); free (help); for (l = list->list, r = result->list, i = 0; i < list->entries; i++, l++) { if (strncmp (l->oname_sort_a, e_ortsname, sizeof (l->oname_sort_a)) == 0) { strncpy ((char *)r++, (char *)l, sizeof (Umsda)); result->entries++; } } free (e_ortsname); return result; } UmsdaSet *UmsdaSucheOrt (char *ortsname) { long i; long pos; long entries; Range *foundEntries; Umsda searchKeys; UmsdaSet *result = (UmsdaSet *) malloc (sizeof (UmsdaSet)); Umsda *r; char *help1, *help2; char *e_ortsname; int max; unsigned char *c; if (result == (UmsdaSet *) 0) { OutOfMemory ("SearchForPlace"); return result; } OpenPlzFile (&umsda, "umsda"); if (umsda.f == (FILE *) 0) return (UmsdaSet *) 0; e_ortsname = AbkuerzungenExpandieren (ortsname, abk); help1 = IsoToCapitals (e_ortsname); help2 = CStringToFixed (help1, sizeof (((Umsda *) 0)->oname_sort_a)); strncpy (searchKeys.oname_sort_a, help2, sizeof (searchKeys.oname_sort_a)); free (help1); free (help2); /* Auf Grund von Sortierfehlern in der Datei "umsda" dürfen wir nur nach * dem ersten Teil des Ortsnamens suchen. Beispiel: "Mülheim-Kärlich" -> * suche "Mülheim". Die Variable "max" enthält die signifikante Länge. */ i = 0; for (c = (unsigned char *) e_ortsname; *c && !ispunct (*c); c++) if (*c == ISO_Ae || *c == ISO_Oe || *c == ISO_Ue || *c == ISO_ae || *c == ISO_oe || *c == ISO_ue || *c == ISO_ss || *c == IBM_Ae || *c == IBM_Oe || *c == IBM_Ue || *c == IBM_ae || *c == IBM_oe || *c == IBM_ue || *c == IBM_ss) i++; if (ispunct (*c)) { while ((ispunct (*(c-1)) || isspace (*(c-1))) && (int) c >= (int) e_ortsname) c--; max = (char *) c - e_ortsname + i; } else max = sizeof (((Umsda *) 0)->oname_sort_a); free (e_ortsname); if (max == 0) { result->entries = 0; return result; } foundEntries = BinarySearchAll (umsda.f, umsda.recordLength, 0L, umsda.entries, (int) (((Umsda *) 0)->oname_sort_a - ((Umsda *) 0)->ala), max, searchKeys.oname_sort_a, (int) (((Umsda *) 0)->ortname_a - ((Umsda *) 0)->ala), userInterfaceMethods.UmsdaRecordRead, &umsda); if (foundEntries->first == -1 && foundEntries->last == -1) result->entries = 0; else result->entries = foundEntries->last - foundEntries->first + 1; Note ("\n"); if (result->entries == 0) { free (foundEntries); /* ??? */ result->list = (Umsda *) 0; return result; } else result->list = (Umsda *) malloc ((unsigned int) (result->entries * sizeof (Umsda) + 2)); if (result->list == (Umsda *) 0) { free (foundEntries); OutOfMemory ("SearchForPlace"); return (UmsdaSet *) 0; } pos = foundEntries->first; entries = 0; for (r = result->list, i = 0; i < result->entries; i++, r++) { fgetr (r, pos++, &umsda); entries++; } free (foundEntries); result->entries = entries; return result; } UmsdaSet *UmsdaSetSuchePlzAlt (UmsdaSet *list, char *plzalt, char verkehrsgebiet) { UmsdaSet *result = (UmsdaSet *) malloc (sizeof (UmsdaSet)); Umsda searchKeys; Umsda *l; Umsda *r; char *help1; int i; if (result == (UmsdaSet *) 0) { OutOfMemory ("SearchForPlace"); return result; } result->list = (Umsda *) malloc ((unsigned int) (list->entries * sizeof (Umsda) + 2)); if (result->list == (Umsda *) 0) { OutOfMemory ("SearchForPlace"); return (UmsdaSet *) 0; } result->entries = 0; help1 = OldPlz (plzalt, verkehrsgebiet); searchKeys.plz_w_o[0] = *help1; strncpy (searchKeys.plzalt, help1 + 1, 4); for (l = list->list, r = result->list, i = 0; i < list->entries; i++, l++) { if (searchKeys.plz_w_o[0] == (l->plz_w_o)[0] && (strncmp (searchKeys.plzalt, l->plzalt, sizeof (l->plzalt)) == 0)) { strncpy ((char *)r++, (char *)l, sizeof (Umsda)); result->entries++; } } return result; } UmsdaSet *UmsdaSetSuchePostanstalt (UmsdaSet *list, char *postanstalt) { UmsdaSet *result = (UmsdaSet *) malloc (sizeof (UmsdaSet)); char fPostanstalt[sizeof (((Umsda *) 0)->npanst_a)]; Umsda *l; Umsda *r; int i; if (result == (UmsdaSet *) 0) { OutOfMemory ("SuchePostanstalt"); return result; } result->list = (Umsda *) malloc ((unsigned int) (list->entries * sizeof (Umsda) + 2)); if (result->list == (Umsda *) 0) { OutOfMemory ("SuchePostanstalt"); return (UmsdaSet *) 0; } result->entries = 0; for (i = 0; i < sizeof (fPostanstalt) && *postanstalt; i++) fPostanstalt[i] = *postanstalt++; for (; i < sizeof (fPostanstalt); i++) fPostanstalt[i] = ' '; for (l = list->list, r = result->list, i = 0; i < list->entries; i++, l++) { if (strncmp (l->npanst_a, fPostanstalt, sizeof (fPostanstalt)) == 0) { strncpy ((char *)r++, (char *)l, sizeof (Umsda)); result->entries++; } } return result; } #define IsMultipleNewStreetPlz(u) (IsMultipleNewPlz (u->nplzo_z)) #define IsMultipleNewPoboxPlz(u) (IsMultipleNewPlz (u->nplzo_p)) char *UmsdaSetOrtEindeutig (UmsdaSet *umsdaSet) { int i; static char alort[sizeof (((Umsda *) 0)->alort) + 1]; Umsda *u; Boolean unique = True; if (umsdaSet->entries > 0) { u = umsdaSet->list; strncpy (alort, u->alort, sizeof (u->alort)); alort[sizeof (alort) - 1] = '\0'; } else return ""; for (i = 1, u++; i < umsdaSet->entries && unique; i++, u++) if (strncmp (alort, u->alort, sizeof (u->alort)) != 0) unique = False; if (unique) return alort; else return ""; } char *UmsdaSetPlzAltEindeutig (UmsdaSet *umsdaSet) { int i; static char plz[6]; Umsda *u; Boolean unique = True; if (umsdaSet->entries > 0) { u = umsdaSet->list; strncpy (plz, u->plz_w_o, 5); plz[5] = '\0'; } else return ""; for (i = 1, u++; i < umsdaSet->entries && unique; i++, u++) if (strncmp (plz, u->plz_w_o, 5) != 0) unique = False; if (unique) return plz; else return ""; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.