ftp.nice.ch/pub/next/database/plz/NXplz.1.1.NI.s.tar.gz#/NXplz-1.1/parse.c

This is parse.c in view mode; [Download] [Up]

/* $Id: parse.c,v 2.7 1993/06/04 14:46:52 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 <string.h>

#include "parse.h"
#include "utils.h"




void ParseStrasse (char *string, char **strasse, char **hausnummer, 
		   char **postfach)
{
    char word[100];
    char *s = string;
    char *r;

    *strasse = (char *) malloc (100);
    *hausnummer = (char *) malloc (100);
    *postfach = (char *) malloc (100);
    (*strasse)[0] = (*hausnummer)[0] = (*postfach)[0] = word[0] = '\0';
    *word = '\0';

    s = string;
    while (*s)
    {
	int last;
	for (; *s && isspace ((unsigned char) *s); s++)
	    ;
        for (r = s; *r && !isspace ((unsigned char) *r) ; r++)
	    ;
	last = strlen (word);
        strncat (word, s, (int) (r - s));
	last += r - s;
        word[last] = '\0';
	for (s = r; *s && isspace ((unsigned char) *s); s++)
	    ;
	/* Falls das aktuelle Wort nicht zu einer Haus- oder Postfachnummer
	   gehört, hängen wir es an den Straßennamen an. */
	if (!(isdigit (word[0]))
	&& word[last - 1] != '-')
	{
	    if (**strasse)
		strcat (*strasse, " ");
	    strcat (*strasse, word);
	    *word = '\0';
	}
    }
    if (isdigit (*word))
	strcpy (*hausnummer, word);
    else
    {
	if (**strasse && *word)
	    strcat (*strasse, " ");
	strcat (*strasse, word);
    }
    if (IbmIsoCStringCompare (*strasse, "Postfach") == 0)
    {
	strcpy (*postfach, *hausnummer);
	(*strasse)[0] = (*hausnummer)[0] = '\0';
    }
}




void ParseOrt (char *string, char **plz_alt, char **ort, char **postanstalt, 
	       char **ortsteil)
{
    char *s = string;
    char *r;

    *plz_alt = (char *) malloc (100);
    *ort = (char *) malloc (100);
    *postanstalt = (char *) malloc (100);
    *ortsteil = (char *) malloc (100);

    **plz_alt = **ort = **postanstalt = **ortsteil = '\0';


    /* Postleitzahl: */

    for (s = r = string; *s && isspace ((unsigned char) *s); s++)
	;
    if (*s == 'W' || *s == 'O' || *s == 'w' || *s == 'o')
    {
	if (*(s+1) == '-' || isdigit (*(s+1)))
	    for (r = s; !isspace (*r); r++)
		;
    }
    else if (isdigit (*s))
	for (r = s; *r != ' '; r++)
	    ;
    if (r > s)
    {
	strncpy (*plz_alt, s, (int) (r - s));
	(*plz_alt)[r - s] = '\0';
    }


    /* Ort: */

    for (s = r; *s && isspace ((unsigned char) *s); s++)
	;
    /* Wortweise weiter bis Ziffer (Postanstalt) oder '(' (Ortsteil) */
    r = s;
    while (*r && !isdigit (*r) && *r != '(')
    {
	while (*r && *r != ' ')
	    r++;
	if (*r == ' ')
	    r++;
    }
    if (*(r-1) == ' ')
	r--;
    strncpy (*ort, s, (int) (r - s));
    (*ort)[r - s] = '\0';


    /* Postanstalt: */

    for (s = r; isspace (*s); s++)
	;
    for (r = s; *r && isdigit (*r); r++)
	;
    strncpy (*postanstalt, s, (int) (r - s));
    (*postanstalt)[r - s] = '\0';


    /* Ortsteil: */

    for (s = r; isspace (*s); s++)
	;
    if (*s == '(')
    {
	for (r = ++s; *r && *r != ')'; r++)
	    ;
	strncpy (*ortsteil, s, (int) (r - s));
	(*ortsteil)[r - s] = '\0';
    }
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.