aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c172
1 files changed, 172 insertions, 0 deletions
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 <demon@vhost.dyndns.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <time.h>
+#include <strings.h>
+#include <err.h>
+#include <tgeb/tgebdat.h>
+#include <tgeb/tgebup.h>
+
+extern char *__progname;
+const char *copyright = "$ TGeb parasite 0.1 -" \
+ " Copyright (c) 2004 demon <demon@vhost.dyndns.org> $";
+
+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;
+}