aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2004-05-10 15:22:29 +0000
committerDimitri Sokolyuk <demon@dim13.org>2004-05-10 15:22:29 +0000
commit99d84ecc0e6630fb736e9090f6570eb8abc473ed (patch)
tree7962649b5ea9d65b63a010cceef5ea60a1ee684c
parent65a6c5505b29a946faa06fd55929238280176d32 (diff)
version 0.3
homedir added minor changes
-rw-r--r--README4
-rw-r--r--include/tgeb.h1
-rw-r--r--lib/common.c18
-rw-r--r--lib/update.c10
-rw-r--r--src/main.c82
5 files changed, 96 insertions, 19 deletions
diff --git a/README b/README
index f0edfcc..9b6e52b 100644
--- a/README
+++ b/README
@@ -10,14 +10,14 @@ Install:
make install
Usage:
- tgeb [-CRP9nrfo12O] [-h <hour>] [-q <quantity>] [-u] [-?]
+ tgeb [-CRP9n5fo12O] [-h <hour>] [-q <quantity>] [-u] [-?]
-C Call-by-Call (default)
-R Call-by-Call with registration
-P Preselect
-9 with 0190 (default - without)
-n Nah
- -r Reg. 50km
+ -5 Region 50km
-f Fern (default)
-o Ort
-1 D1
diff --git a/include/tgeb.h b/include/tgeb.h
index c0a3dfd..9cfff56 100644
--- a/include/tgeb.h
+++ b/include/tgeb.h
@@ -166,3 +166,4 @@ void _tgeb_sread(char **, FILE *); /* read string */
SORTED *tgeb_select(TA *, AN *, int reg, int flags, int time);
void tgeb_free_mem(AN *, AU *, TA *);
void tgeb_free_sd(SORTED *);
+char *tgeb_read_date(char *file);
diff --git a/lib/common.c b/lib/common.c
index 56f7fd1..f1eac05 100644
--- a/lib/common.c
+++ b/lib/common.c
@@ -117,3 +117,21 @@ tgeb_free_sd(SORTED * sd)
free(sd->data);
free(sd);
}
+
+char *
+tgeb_read_date(char *file)
+{
+ FILE *fd;
+ char *datum;
+
+ if (!(datum = calloc(20, sizeof(char))))
+ err(1, "malloc");;
+
+ if(!(fd = fopen(file, "r")))
+ err(1, "fopen %s", file);
+
+ fread(datum, sizeof(char), 19, fd);
+
+ fclose(fd);
+ return(datum);
+}
diff --git a/lib/update.c b/lib/update.c
index f510861..6dd14d2 100644
--- a/lib/update.c
+++ b/lib/update.c
@@ -36,6 +36,7 @@
const char *TGebURL = "www.billiger-telefonieren.de";
const char *TGebGET = "GET /downloads/tgeb/tarife_%.4i%.2i%.2i.zip HTTP/1.0\n\n";
+extern char *__progname;
static void unzip(void);
@@ -52,6 +53,9 @@ tgeb_update(struct tm * tm)
int filelen;
int offset = 0;
+ printf("%s: updating database ", __progname);
+ fflush(stdout);
+
if (!(he = gethostbyname(TGebURL)))
err(1, "gethostbyname");
@@ -85,7 +89,10 @@ tgeb_update(struct tm * tm)
offset += block;
if (!(buf = realloc(buf, offset + BUF_SIZ)))
err(1, "malloc");
+ putchar('.');
+ fflush(stdout);
}
+ putchar('\n');
close(sockfd);
file = strstr(buf, "\r\n\r\n") + 4;
filelen = offset + buf - file;
@@ -120,6 +127,8 @@ unzip(void)
for (i = 0; i < gi.number_entry; i++) {
unzGetCurrentFileInfo(unzfd, &fi, FileName, sizeof(FileName),
NULL, 0, NULL, 0);
+ printf("extract %s ...", FileName);
+ fflush(stdout);
unzOpenCurrentFile(unzfd);
if (!(fd = fopen(FileName, "wb")))
err(1, "fopen %s", FileName);
@@ -127,6 +136,7 @@ unzip(void)
fwrite(buf, len, 1, fd);
}
fclose(fd);
+ printf(" done\n");
unzGoToNextFile(unzfd);
}
free(buf);
diff --git a/src/main.c b/src/main.c
index 631ca6e..1a0802c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,7 +17,11 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <pwd.h>
#include <time.h>
#include <strings.h>
#include <err.h>
@@ -25,11 +29,12 @@
#include <tgebup.h>
extern char *__progname;
-const char *copyright = "TGeb parasite 0.2 - " \
- "Copyright (c) 2004 demon <demon@vhost.dyndns.org>";
+const char *copyright = "TGeb parasite 0.3 - "
+ "Copyright (c) 2004 demon <demon@vhost.dyndns.org>";
void usage(void);
void prdt(AN_D *, TA_D *);
+void print_reg(int);
int
main(int argc, char **argv)
@@ -39,18 +44,32 @@ main(int argc, char **argv)
AU *au;
SORTED *sd;
char ch;
- int reg = 0;
+ char *datum;
+ int reg = FERN_W;
int flags = 0;
time_t tval = time(NULL);
struct tm *tm = localtime(&tval);
int time = tm->tm_hour;
int quant = 3;
int i;
+ struct passwd *pw;
+ char *home;
+
+ home = calloc(_POSIX_PATH_MAX, sizeof(char));
+ pw = getpwnam(getlogin());
+ snprintf(home, _POSIX_PATH_MAX, "%s/.tgeb", pw->pw_dir);
+ if (chdir(home) < NULL) {
+ if (mkdir(home, 0755) < NULL)
+ err(1, "%s", home);
+ if (chdir(home) < NULL)
+ err(1, "%s", home);
+ tgeb_update(tm);
+ }
+ free(home);
- while ((ch = getopt(argc, argv, "CRP9nrfo12eONE?h:q:u")) != -1)
+ while ((ch = getopt(argc, argv, "CRP9n5fo12eONE?h:q:u")) != -1)
switch (ch) {
case 'u': /* update */
- printf("%s: updating database...\n", __progname);
tgeb_update(tm);
exit(0);
break;
@@ -77,7 +96,7 @@ main(int argc, char **argv)
case 'n': /* Nah */
reg = NAH_W;
break;
- case 'r': /* Reg 50km */
+ case '5': /* Reg 50km */
reg = REG_W;
break;
case 'f': /* Fern */
@@ -98,7 +117,6 @@ main(int argc, char **argv)
case 'O': /* o2 */
reg = O2_W;
break;
-/*
case 'N': // Now
if ((tm->tm_wday == 0) || (tm->tm_wday == 6))
reg++;
@@ -106,7 +124,6 @@ main(int argc, char **argv)
case 'E': // Wochenende
reg++;
break;
-*/
case '?':
default:
usage();
@@ -120,6 +137,7 @@ main(int argc, char **argv)
if ((tm->tm_wday == 0) || (tm->tm_wday == 6))
reg++;
+ datum = tgeb_read_date("datum.dat");
an = tgeb_read_an("anbieter.dat");
au = tgeb_read_au("ausland.dat");
ta = tgeb_read_ta("tarife.dat", au);
@@ -129,14 +147,17 @@ main(int argc, char **argv)
}
sd = tgeb_select(ta, an, reg, flags, time);
+ printf("\nDB\t%s\n\n", datum);
+ print_reg(reg);
+
for (i = 0; i < sd->q; i++) {
prdt(&an->e[sd->id[i]], sd->data[i]);
if ((i + 1) >= quant)
break;
}
+ free(datum);
tgeb_free_sd(sd);
-
tgeb_free_ta(ta);
tgeb_free_au(au);
tgeb_free_an(an);
@@ -148,19 +169,21 @@ main(int argc, char **argv)
void
prdt(AN_D * an_d, TA_D * ta_d)
{
- printf("(%.2u)\tPrefix:\t%s\n"
- "\tName:\t%s"
+#ifdef DEBUG
+ printf("ID\t%.2u\n", an_d->id);
+#endif
+ printf("Prefix\t%s\n"
+ "Name\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",
+ printf("Valid\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"
+ printf("Fee:\t%.2f ct/min"
" + %.2f ct\n"
- "\tTiming:\t%u/%u s\n",
+ "Timing\t%u/%u s\n",
ta_d->fee * 100,
ta_d->dfee * 100,
ta_d->t1,
@@ -170,16 +193,41 @@ prdt(AN_D * an_d, TA_D * ta_d)
}
void
+print_reg(int reg)
+{
+ char *regions[] = {
+ "Nah", "Nah Wochenende",
+ "50km", "50km Wochenende",
+ "Fern", "Fern Wochenende",
+ "Ort", "Ort Wochenende",
+ "D1", "D1 Wochenende",
+ "D2", "D2 Wochenende",
+ "E+", "E+ Wochenende",
+ "o2", "o2 Wochenende",
+ NULL };
+
+ if (reg < 0x00 || reg > 0xFF)
+#ifdef DEBUG
+ errx(1, "wrong region: 0x%.2x", reg);
+#else
+ return;
+#endif
+
+ printf("Region\t%s\n\n", regions[reg]);
+ return;
+}
+
+void
usage()
{
printf("%s\n", copyright);
- printf("Usage: %s [-CRP9nrfo12O] [-h <hour>] [-q <quantity>] [-u] [-?]\n", __progname);
+ printf("Usage: %s [-CRP9n5fo12O] [-h <hour>] [-q <quantity>] [-u] [-?]\n", __progname);
printf(" -C Call-by-Call (default)\n" \
" -R Call-by-Call with registration\n" \
" -P Preselect\n" \
" -9 with 0190 (default - without)\n" \
" -n Nah\n" \
- " -r Reg. 50km\n" \
+ " -5 Region 50km\n" \
" -f Fern (default)\n" \
" -o Ort\n" \
" -1 D1\n" \