From 27d3cf31609704bc4428d6c4487e1bef1eaa9d95 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 27 Mar 2004 04:35:47 +0000 Subject: initial import 0.1-alpha --- src/Makefile | 9 ++++ src/main.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 src/Makefile create mode 100644 src/main.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..318328e --- /dev/null +++ b/src/Makefile @@ -0,0 +1,9 @@ +# $Id$ + +PROG= tgeb +SRCS= main.c +CFLAGS+= -Wall -I.. +LDADD+= -L../tgeb -ltgeb -lz +NOMAN= + +. include diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f7fc417 --- /dev/null +++ b/src/main.c @@ -0,0 +1,172 @@ +/* $Id$ */ +/* + * Copyright (c) 2004 demon + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +extern char *__progname; +const char *copyright = "$ TGeb parasite 0.1 -" \ + " Copyright (c) 2004 demon $"; + +void usage(void); +void prdt(struct an_d *, struct ta_d *); + +int +main(int argc, char **argv) +{ + struct an *an; + struct ta *ta; + struct au *au; + struct sorted sd; + char ch; + int reg = 0; + int flags = 0; + time_t tval = time(NULL); + struct tm *tm = localtime(&tval); + int time = tm->tm_hour; + int quant = 3; + int i; + + while ((ch = getopt(argc, argv, "CRP9nrfo12eONE?h:q:u")) != -1) + switch (ch) { + case 'u': /* update */ + printf("%s: updating database...\n", __progname); + tgeb_update(tm); + exit(0); + break; + case 'h': /* time hour */ + time = atoi(optarg); + if (time >= 24) + errx(1, "wrong time"); + break; + case 'q': /* time hour */ + quant = atoi(optarg); + break; + case 'C': /* Call by Call */ + flags ^= T_CBC; + break; + case 'R': /* Call by Call with reg. */ + flags ^= T_CBCR; + break; + case 'P': /* Preselect */ + flags ^= T_PRES; + break; + case '9': /* 0190 */ + flags ^= T_0190; + break; + case 'n': /* Nah */ + reg = NAH_W; + break; + case 'r': /* Reg 50km */ + reg = REG_W; + break; + case 'f': /* Fern */ + reg = FERN_W; + break; + case 'o': /* Ort */ + reg = ORT_W; + break; + case '1': /* D1 */ + reg = D1_W; + break; + case '2': /* D2 */ + reg = D2_W; + break; + case 'e': /* E+ */ + reg = EP_W; + break; + case 'O': /* o2 */ + reg = O2_W; + break; +/* + case 'N': // Now + if ((tm->tm_wday == 0) || (tm->tm_wday == 6)) + reg++; + break; + case 'E': // Wochenende + reg++; + break; +*/ + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (!(flags & ~T_0190)) /* default T_CBC, ignore T_0190 */ + flags ^= T_CBC; + + if ((tm->tm_wday == 0) || (tm->tm_wday == 6)) + reg++; + + an = tgeb_read_an("anbieter.dat"); + au = tgeb_read_au("ausland.dat"); + ta = tgeb_read_ta("tarife.dat", au); + + if (an->e_q != ta->q) + errx(1, "database missmatch - obtain new files"); + + sd = tgeb_select(ta, an, reg, flags, time); + + for (i = 0; i < sd.q; i++) { + prdt(&an->e[sd.id[i]], sd.data[i]); + if ((i + 1) >= quant) + break; + } + + exit(0); + return 0; +} + +void +prdt(struct an_d * an_d, struct ta_d * ta_d) +{ + printf("(%.2u)\tPrefix:\t%s\n" + "\tName:\t%s" + " (%s)\n", + an_d->id, + an_d->pref, + an_d->h->name, + an_d->serv); + printf("\tValid:\t%.2u:00 - %.2u:00 h\n", + ta_d->prev ? ta_d->prev->time : (char)NULL, + ta_d->time); + printf("\tFee:\t%.2f ct/min" + " + %.2f ct\n" + "\tTiming:\t%u/%u s\n", + ta_d->fee * 100, + ta_d->dfee * 100, + ta_d->t1, + ta_d->t2); + printf("\n"); + return; +} + +void +usage() +{ + printf("Usage: %s [-nrfo12eO] [-NWE]\n", __progname); + exit(1); + return; +} -- cgit v1.2.3