aboutsummaryrefslogtreecommitdiff
path: root/tgeb/anbieter.c
diff options
context:
space:
mode:
Diffstat (limited to 'tgeb/anbieter.c')
-rw-r--r--tgeb/anbieter.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/tgeb/anbieter.c b/tgeb/anbieter.c
new file mode 100644
index 0000000..575ed03
--- /dev/null
+++ b/tgeb/anbieter.c
@@ -0,0 +1,124 @@
+/* $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 <err.h>
+#include "tgebdat.h"
+
+static void rhdr_an(struct an *, FILE *); /* read header */
+static void rent_an(struct an *, FILE *); /* read entries */
+static void resort_an(struct an *);
+
+struct an *
+tgeb_read_an(char *file)
+{
+ struct an *an;
+ FILE *fd;
+
+ if (!(fd = fopen(file, "r")))
+ err(1, "fopen %s", file);
+
+ if (!(an = (struct an *) malloc(sizeof(struct an))))
+ err(1, "malloc");
+
+ rhdr_an(an, fd);
+ rent_an(an, fd);
+
+ fclose(fd);
+ return an;
+}
+
+void
+rhdr_an(struct an * an, FILE * fd)
+{
+ int i;
+
+ fread(&an->q, sizeof(an->q), 1, fd);
+ if (!(an->h = (struct an_hdr *) calloc(an->q, sizeof(struct an_hdr))))
+ err(1, "malloc");
+
+ fseek(fd, 2, SEEK_SET);
+ for (i = 0; i < an->q; i++) {
+ _tgeb_sread(&an->h[i].name, fd);
+ _tgeb_sread(&an->h[i].mail, fd);
+ _tgeb_sread(&an->h[i].url, fd);
+ fread(&an->h[i].off, sizeof(an->h[i].off), 1, fd);
+ an->h[i].off--;
+ }
+ return;
+}
+
+void
+rent_an(struct an * an, FILE * fd)
+{
+ int i, j;
+
+ an->e_q = 0;
+ for (i = 0; i < an->q; i++) {
+ fseek(fd, an->h[i].off, SEEK_SET);
+ fread(&an->h[i].q, sizeof(an->h[i].q), 1, fd);
+ if (!(an->h[i].d = (struct an_d *)
+ calloc(an->h[i].q, sizeof(struct an_d))))
+ err(1, "malloc");
+ for (j = 0; j < an->h[i].q; j++) {
+ an->h[i].d[j].h = &an->h[i];
+ _tgeb_sread(&an->h[i].d[j].serv, fd);
+ _tgeb_sread(&an->h[i].d[j].pref, fd);
+ fread(&an->h[i].d[j].id,
+ sizeof(an->h[i].d[j].id), 1, fd);
+ if (an->h[i].d[j].id > an->e_q)
+ an->e_q = an->h[i].d[j].id;
+ _tgeb_sread(&an->h[i].d[j].valf, fd);
+ _tgeb_sread(&an->h[i].d[j].valt, fd);
+ fread(&an->h[i].d[j].type,
+ sizeof(an->h[i].d[j].type), 1, fd);
+ fread(&an->h[i].d[j].mvol,
+ sizeof(an->h[i].d[j].mvol), 1, fd);
+ fread(&an->h[i].d[j].bfee,
+ sizeof(an->h[i].d[j].bfee), 1, fd);
+ fread(&an->h[i].d[j].afee,
+ sizeof(an->h[i].d[j].afee), 1, fd);
+ _tgeb_sread(&an->h[i].d[j].url, fd);
+ _tgeb_sread(&an->h[i].d[j].url2, fd);
+ _tgeb_sread(&an->h[i].d[j].phone, fd);
+ _tgeb_sread(&an->h[i].d[j].mail, fd);
+ _tgeb_sread(&an->h[i].d[j].x, fd);
+ fread(&an->h[i].d[j].reg,
+ sizeof(an->h[i].d[j].reg), 1, fd);
+ _tgeb_sread(&an->h[i].d[j].rurl, fd);
+ _tgeb_sread(&an->h[i].d[j].rfax, fd);
+ }
+ }
+ resort_an(an);
+ return;
+}
+
+void
+resort_an(struct an * an)
+{
+ int i, j;
+
+ if (!(an->e = (struct an_d *) calloc(an->e_q, sizeof(struct an_d))))
+ err(1, "malloc");
+ for (i = 0; i < an->e_q; i++) {
+ for (j = 0; j < an->h[i].q; j++) {
+ an->e[an->h[i].d[j].id - 1] = an->h[i].d[j];
+ }
+ }
+ return;
+}