zone-1.10

This commit is contained in:
akool 1999-06-22 16:30:10 +00:00
parent f6fe20a597
commit 43d546bcd0
11 changed files with 81 additions and 64 deletions

View File

@ -8,7 +8,7 @@ U:%.3f DM
#
# (C) Copyright 1999 by Andreas Kool (akool@isdn4linux.de)
#
# $Id: rate-de.dat,v 1.23 1999/06/21 19:32:14 akool Exp $
# $Id: rate-de.dat,v 1.24 1999/06/22 16:30:10 akool Exp $
#
# Zonenzuordnung für Deutschland
#

View File

@ -1,4 +1,4 @@
/* $Id: zone.c,v 1.5 1999/06/21 19:35:04 akool Exp $
/* $Id: zone.c,v 1.6 1999/06/22 16:31:15 akool Exp $
*
* Zonenberechnung
*
@ -19,11 +19,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: zone.c,v $
* Revision 1.5 1999/06/21 19:35:04 akool
* isdnlog Version 3.35
* zone data for .nl (many thanks to Paul!)
*
* WARNING: This version of isdnlog dont even compile! *EXPERIMENTAL*!!
* Revision 1.6 1999/06/22 16:31:15 akool
* zone-1.10
*
* Revision 1.4 1999/06/18 12:41:57 akool
* zone V1.0
@ -350,8 +347,8 @@ static int _initZone(int provider, char *path, char **msg, bool area_only)
for (p++,n=0,q=dversion; n<6 && *p != ' '; n++)
*q++ = *p++;
*q = '\0';
if (*dversion != *version) {
if (msg)
if (memcmp(dversion, version, 3)) {
if (msg)
snprintf (message, LENGTH,
"Zone V%s: Error: Provider %d File '%s': incompatible Dataversion %s",
version, provider, path, dversion);
@ -373,11 +370,11 @@ static int _initZone(int provider, char *path, char **msg, bool area_only)
p++;
tsize = strtol(p, &p, 10);
break;
case 'O' :
case 'O' :
p++;
sthp[ocount].oz = strtol(p, &p, 10);
break;
case 'L' :
case 'L' :
p++;
sthp[ocount].numlen = strtol(p, &p, 10);
break;
@ -465,7 +462,7 @@ static int _getZ(struct sth *sthp, char *from, char *sto) {
char *temp;
int res;
if ((res=strcmp(from, sto)) == 0)
if ((res=strcmp(from, sto)) == 0)
return sthp->oz;
else if (res > 0) {
temp=from;
@ -475,10 +472,10 @@ static int _getZ(struct sth *sthp, char *from, char *sto) {
strncpy(newfrom, from, LENGTH-1);
while (strlen(newfrom)) {
UL lifrom = (UL) atol(newfrom); /* keys could be long */
US ifrom = (US) lifrom;
US ifrom = (US) lifrom;
if (sthp->pack_key == 2) {
key.dptr = (char *) &ifrom;
key.dsize = sizeof(US);
key.dptr = (char *) &ifrom;
key.dsize = sizeof(US);
}
else {
key.dptr = (char *) &lifrom;
@ -492,8 +489,8 @@ static int _getZ(struct sth *sthp, char *from, char *sto) {
int ito;
unsigned char z=0;
if (sthp->cc) /* if areacodes */
/* here is since 1.00 a zero-terminated strring */
while (*p++);
/* here is since 1.00 a zero-terminated strring */
while (*p++);
count = *((US*)p)++;
while (count--) {
bool ind = true;
@ -552,16 +549,20 @@ static int _getAreacode(struct sth *sthp, char *from, char **text) {
newfrom[sthp->numlen] = '\0';
while ((len=strlen(newfrom))) {
UL lifrom = (UL) atol(newfrom); /* keys could be long */
US ifrom = (US) lifrom;
US ifrom = (US) lifrom;
if (sthp->pack_key == 2) {
if (lifrom >= 0x10000) { /* can't be, so cut a digit */
newfrom[strlen(newfrom) - 1] = '\0';
continue;
} /* if */
if (lifrom >= 0x10000) { /* can't be, so cut a dig */
newfrom[strlen(newfrom)-1] = '\0';
continue;
}
key.dptr = (char *) &ifrom;
key.dsize = sizeof(US);
}
else {
if (lifrom >= 0x10000000L) { /* can't be, so cut a dig */
newfrom[strlen(newfrom)-1] = '\0';
continue;
}
key.dptr = (char *) &lifrom;
key.dsize = sizeof(UL);
}
@ -571,29 +572,28 @@ static int _getAreacode(struct sth *sthp, char *from, char **text) {
if (*dbv == 'G') /* GDBM has a malloced string in dptr */
free(value.dptr);
return UNKNOWN;
}
}
if (*dbv == 'G') /* GDBM has a malloced string in dptr */
*text = value.dptr;
else
else
*text = strdup(value.dptr);
return len;
} /* if dptr */
newfrom[strlen(newfrom)-1] = '\0';
}
return UNKNOWN;
}
}
int getAreacode(int provider, char *from, char **text)
int getAreacode(int country, char *from, char **text)
{
int i;
char *path=NULL;
for (i=0; i<count; i++)
if (sthp[i].provider == provider) {
path = sthp[i].path ? sthp[i].path : sthp[sthp[i].real].path;
if (sthp[i].cc == country) {
if (sthp[i].fh == 0)
return UNKNOWN;
return _getAreacode(&sthp[i], from, text);
}
return _getAreacode(&sthp[i], from, text);
}
return UNKNOWN;
}
#ifdef STANDALONE
@ -678,11 +678,11 @@ static int checkArea(char *df, int cc, char *from, int verbose) {
printf("%s\n", msg);
ret = getAreacode(cc, from, &text);
if(ret != UNKNOWN) {
printf("%s:%d '%s'\n", from, ret, text);
printf("%s:%d '%s'\n", from, ret, text);
free(text);
}
else
printf("%s - UNKNOWN\n", from);
printf("%s - UNKNOWN\n", from);
exitZone(1);
return ret;
}
@ -721,9 +721,9 @@ int main (int argc, char *argv[])
}
if (df && (zf || (num1 && num2)))
return checkZone(zf, df, num1, num2, verbose);
if (df && num1)
return checkArea(df, snum1, verbose);
fprintf(stderr, "Usage:\n%s -d DBfile -v -V { -z Zonefile | num1 num2 }\n", basename(argv[0]));
if (df && num1 && cc)
return checkArea(df, cc, snum1, verbose);
fprintf(stderr, "Usage:\n%s -d DBfile -v -V { -z Zonefile | num1 num2 | -a cc num}\n", basename(argv[0]));
fprintf(stderr, "\t-d DBfile -v -V num1\n");
return 0;
}

View File

@ -4,9 +4,8 @@
# (C) 1999 l.toetsch <lt@toetsch.at>
#
BZIP2 = @BZIP2@
BZIP2 = @BZIP2@
SHELL = /bin/sh
CFLAGS = -Wall -O2
CFLAGS = -Wall -g
INCLUDES =
LDFLAGS = @DBMLIB@
DBEXT = @DBEXT@
@ -70,24 +69,37 @@ clean:
rm -f *.o *~ $(PROGRAM) *.db *.gdbm zone
distclean: clean
rm -f config.h config.status config.cache config.log *.man Makefile
rm -f config.h config.status config.cache config.log *.man Makefile configure
test:
./$(PROGRAM) -d zone-at-pta$(DBEXT) -r at/pta/zred.pta -c at/code -v
./$(PROGRAM) -d zone-at-pta$(DBEXT) -r at/pta/zred.pta -c at/code -a43 -v
$(BZIP2) -d at/pta/zred.pta.bz2
$(BZIP2) -d at/pta/zoneall.pta.bz2
./zone -d zone-at-pta$(RDBEXT) -z at/pta/zoneall.pta -v
$(BZIP2) -9 at/pta/zred.pta
$(BZIP2) -9 at/pta/zoneall.pta
zonefiles:
#
# ATTENTION:
# zonedatabasefilenames must be zone-CC-*
#
zonefiles: AT DE NL
AT:
./$(PROGRAM) -d ../../zone-at-1012$(DBEXT) -r at/1012/zred-at-1012 -c at/code -v -l4
$(BZIP2) -d at/uta/zred.uta.bz2
./$(PROGRAM) -d ../../zone-at-uta$(DBEXT) -r at/uta/zred.uta -c at/code -v
./$(PROGRAM) -d ../../zone-at-uta$(DBEXT) -r at/uta/zred.uta -c at/code -v
$(BZIP2) -9 at/uta/zred.uta
$(BZIP2) -d at/pta/zred.pta.bz2
./$(PROGRAM) -d ../../zone-at-pta$(DBEXT) -r at/pta/zred.pta -c at/code -v
./$(PROGRAM) -d ../../zone-at-pta$(DBEXT) -r at/pta/zred.pta -c at/code -a43 -v
$(BZIP2) -9 at/pta/zred.pta
DE:
$(BZIP2) -d de/01033/zred.dtag.bz2
./$(PROGRAM) -d ../../zone-de-dtag$(DBEXT) -r de/01033/zred.dtag -c de/code -v
./$(PROGRAM) -d ../../zone-de-dtag$(DBEXT) -r de/01033/zred.dtag -c de/code -a49 -v
$(BZIP2) -9 de/01033/zred.dtag
NL:
$(BZIP2) -d nl/kpn/zred.bz2
./$(PROGRAM) -d ../../zone-nl-kpn$(DBEXT) -r nl/kpn/zred -c nl/code -a31 -v -o3
$(BZIP2) -9 nl/kpn/zred

View File

@ -126,9 +126,9 @@ sub read_compact {
my($temp) = unpack($pack_key, $key);
next if( $temp !~ /\d/);
if ($cc) {
my($ind);
my($ort) = substr($value,0, $ind=index($value, "\x0"));
$value = substr($value, $ind+1);
my($ind);
my($ort) = substr($value,0, $ind=index($value, "\x0"));
$value = substr($value, $ind+1);
}
my($count) = unpack('S', $value);
$value=substr($value, 2); # past count

View File

@ -64,10 +64,10 @@ sub read_compact {
my($temp) = unpack($pack_key, $key);
next if( $temp !~ /\d/);
if ($cc) {
my($ind);
my($ort) = substr($value,0, $ind=index($value, "\x0"));
print "$temp $ort\n";
$value = substr($value, $ind+1);
my($ind);
my($ort) = substr($value,0, $ind=index($value, "\x0"));
print "$temp $ort\n";
$value = substr($value, $ind+1);
}
my($count) = unpack('S', $value);
$value=substr($value, 2); # past count

View File

@ -22,9 +22,8 @@
*
*/
static char progversion[] = "1.01";
/* first char must match dataversion */
static char progversion[] = "1.10";
/* first 3 chars must match dataversion */
#define STANDALONE
@ -53,7 +52,7 @@ extern const char *basename (const char *name);
void usage(char *argv[]) {
fprintf(stderr, "%s: -r RedZonefile -c Code -d Database [ -v ] [ -V ] [ -o Localzone ] [ -l Len ]\n",
fprintf(stderr, "%s: -r RedZonefile -d Database -c Code [-a CC] [ -v ] [ -V ] [ -o Localzone ] [ -l Len ]\n",
basename(argv[0]));
exit(EXIT_FAILURE);
}
@ -72,11 +71,12 @@ static code_t *codes = 0;
static int nc;
static int ortszone=1;
static int numlen;
static int country=0;
static void read_codefile(char *cf) {
FILE *fp;
char *p;
auto char line[BUFSIZ];
auto char line[BUFSIZ];
nc = 0;
if (verbose)
@ -288,7 +288,8 @@ static void write_db(char * df) {
int i, j;
char version[80];
qsort(codes, nc, sizeof(code_t), comp_func);
if (country)
qsort(codes, nc, sizeof(code_t), comp_func);
if (verbose)
printf("Writing\n");
if((db=OPEN(df,WRITE)) == 0) {
@ -303,9 +304,9 @@ static void write_db(char * df) {
/* write version & table */
key.dptr = "vErSiO";
key.dsize = 7;
sprintf(version,"V1.00 K%c C%c N%d T%d O%d L%d",
sprintf(version,"V1.10 K%c C%c N%d T%d O%d L%d A%d",
keylen==2?'S':'L',tablelen==1?'C':tablelen==2?'S':'L',
nn,n, ortszone, numlen?numlen:keydigs);
nn,n, ortszone, numlen?numlen:keydigs, country);
value.dptr = version;
value.dsize = strlen(version)+1;
if(STORE(db, key, value)) {
@ -351,7 +352,8 @@ static void write_db(char * df) {
*((US*)val) = count;
value.dptr = val;
value.dsize = vlen;
insert_code(&value, ofrom);
if (country)
insert_code(&value, ofrom);
if(STORE(db, key, value)) {
fprintf(stderr, "Error storing key '%d' - %s\n",ofrom,GET_ERR);
exit(EXIT_FAILURE);
@ -407,10 +409,12 @@ static void write_db(char * df) {
*((US*)val) = count;
value.dptr = val;
value.dsize = vlen;
insert_code(&value, ofrom);
if (country)
insert_code(&value, ofrom);
STORE(db, key, value);
free(value.dptr);
write_remaining_codes(db);
if (country)
write_remaining_codes(db);
CLOSE(db);
free(zones);
free(df);
@ -428,7 +432,7 @@ int main (int argc, char *argv[])
if (argc < 2)
usage(argv);
while ( (c=getopt(argc, argv, "vVr:d:c:o:l:")) != EOF) {
while ( (c=getopt(argc, argv, "vVr:d:c:o:l:a:")) != EOF) {
switch (c) {
case 'v' : verbose = true; break;
case 'V' : printf("%s: V%s Db=%s\n",
@ -438,6 +442,7 @@ int main (int argc, char *argv[])
case 'c' : cf = strdup(optarg); break;
case 'o' : ortszone = atoi(optarg); break;
case 'l' : numlen = atoi(optarg); break;
case 'a' : country = atoi(optarg); break;
}
}
read_codefile(cf);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
isdnlog/zone-nl-kpn.gdbm Normal file

Binary file not shown.