ftp.nice.ch/pub/next/database/plz/NXplz.1.1.NIHS.bs.tar.gz#/NXplz-1.1/pofada.c

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

/* $Id: pofada.c,v 3.1 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.
 *
 */

#ifdef __NeXT__
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include <memory.h>
#include <stdio.h>
#include <string.h>

#include "xplz.h"
#include "message.h"
#include "plzfile.h"
#include "pofada.h"




static PlzFile pofada = {(FILE *) 0, 0, 0, 0};



PofadaSet *PostfaecherAndPostanstalt (PofadaSet *pofadaSet, char *postanstalt)
{
    PofadaSet *result = (PofadaSet *) malloc (sizeof (PofadaSet));
    Pofada *r;
    int i;
    int nrPostanstalt = atoi (postanstalt);

    if (result == (PofadaSet *) 0)
    {
	OutOfMemory ("PostfaecherAndPostanstalt");
	return result;
    }
    result->list = (Pofada *) calloc (pofadaSet->entries, sizeof (Pofada));
    if (result->list == (Pofada *) 0)
    {
	OutOfMemory ("PostfaecherAndPostanstalt");
	free (result);
	return (PofadaSet *) 0;
    }

    r = result->list;
    for (i = 0; i < pofadaSet->entries; i++)
    {
	if (strntoi (pofadaSet->list[i].npanst, 
		     sizeof (pofadaSet->list[i].npanst)) == nrPostanstalt)
	    memcpy ((char *) r++, (char *) &(pofadaSet->list[i]), 
		    sizeof (Pofada));
    }
    result->entries = r - result->list;
    return result;
}




PofadaSet *PostfaecherAndPlz (PofadaSet *pofadaSet, char *plz)
{
    PofadaSet *result = (PofadaSet *) malloc (sizeof (PofadaSet));
    Pofada *r;
    int i;

    if (result == (PofadaSet *) 0)
    {
	OutOfMemory ("PostfaecherAndPostanstalt");
	return result;
    }
    result->list = (Pofada *) calloc (pofadaSet->entries, sizeof (Pofada));
    if (result->list == (Pofada *) 0)
    {
	OutOfMemory ("PostfaecherAndPostanstalt");
	free (result);
	return (PofadaSet *) 0;
    }

    r = result->list;
    for (i = 0; i < pofadaSet->entries; i++)
    {
	if (strncmp (pofadaSet->list[i].plz_w_o, plz, 
		     sizeof (((Pofada *) 0)->plz_w_o)) == 0 
	&& strncmp (pofadaSet->list[i].plzalt,
		    plz + sizeof (((Pofada *) 0)->plz_w_o),
		    sizeof (((Pofada *) 0)->plzalt)) == 0)
	    memcpy ((char *) r++, (char *) &(pofadaSet->list[i]), 
		    sizeof (Pofada));
    }
    result->entries = r - result->list;
    return result;
}




PofadaSet *SuchePostfach (char *alort, char *pobox)
{
    Range *foundEntries;
    PofadaSet *result = (PofadaSet *) malloc (sizeof (PofadaSet));
    Pofada *r;
    long pos;
    int i;
    int number;
    int entries;
    int from, to;

    if (result == (PofadaSet *) 0)
    {
	OutOfMemory ("SuchePostfach");
	return result;
    }

    OpenPlzFile (&pofada, "pofada");
    if (pofada.f == (FILE *) 0)
	return (PofadaSet *) 0;

    foundEntries = BinarySearchAll (pofada.f, pofada.recordLength, 0L,
				    pofada.entries, 
				    ((Pofada *) 0)->alort - 
				    ((Pofada *) 0)->alort, 
				    sizeof (((Pofada *) 0)->alort),
				    alort, -1,
				    userInterfaceMethods.PofadaRecordRead,
				    &pofada);
    if (foundEntries->first == -1 && foundEntries->last == -1)
	result->entries = 0;
    else
	result->entries = foundEntries->last - foundEntries->first + 1;
    if (result->entries == 0)
    {
	free (foundEntries);
	result->list = (Pofada *) 0;
	return result;
    }
    else
	result->list = (Pofada *) malloc ((unsigned int) (result->entries * 
					sizeof (Pofada) + 2));

    if (result->list == (Pofada *) 0)
    {
	free (foundEntries);
	OutOfMemory ("SearchForPobox");
	return (PofadaSet *) 0;
    }

    Note ("\n");
    number = atoi (pobox);

    pos = foundEntries->first;
    entries = 0;
    for (r = result->list, i = 0; i < result->entries; i++, r++)
    {
        fgetr (r, pos++, &pofada);
	from = strntoi (r->pfnrvon, sizeof (r->pfnrvon));
	to = strntoi (r->pfnrbis, sizeof (r->pfnrbis));
	if (from <= number && number <= to)
	    entries++;
	else
	    r--;
    }
    free (foundEntries);
    result->entries = entries;
    return result;
}




PofadaSet *SearchForZA (PofadaSet *pofadaSet, char *plzalt, char *zustellamt)
{
    Pofada *p, *p1;
    PofadaSet *new = (PofadaSet *) malloc (sizeof (PofadaSet *));
    int i;
    int number = atoi (zustellamt);

    if (new == (PofadaSet *) 0)
    {
	OutOfMemory ("SearchForZA");
	return (PofadaSet *) 0;
    }
    new->list = (Pofada *) calloc (pofadaSet->entries, sizeof (Pofada));
    if (new == (PofadaSet *) 0)
    {
	OutOfMemory ("SearchForZA");
	free (new);
	return (PofadaSet *) 0;
    }
    p = pofadaSet->list;
    p1 = new->list;
    for (i = 0; i < pofadaSet->entries; i++, p++)
	if (strntoi (p->npanst, sizeof (p->npanst)) == number 
	&& strncmp (plzalt, p->plz_w_o, 5) == 0)
	    memcpy (p1++, p, sizeof (Pofada));
    new->entries = p1 - new->list;
    return new;
}




Boolean UniquePostbox (PofadaSet *pofadaSet)
{
    return pofadaSet->entries == 1;
}

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