summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Stensgård <mastensg@mastensg.net>2025-07-08 23:21:23 +0200
committerMartin Stensgård <mastensg@mastensg.net>2025-07-08 23:21:23 +0200
commit131e9525be948dab3446026d8d0f5602bcd5bba3 (patch)
treebfd73fc1ef41591a1d230cef4ed21159035fe664
parent7a567665cfb08169c140ff714cf46488183f831a (diff)
generic import_booking -> update
-rw-r--r--.gitignore2
-rw-r--r--Makefile10
-rw-r--r--update.c (renamed from import_booking.c)32
3 files changed, 21 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 035286d..ff3310f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,8 +3,8 @@
/check_ical
/check_ical_out.txt
/events.ical
-/import_booking
/opplysning
/select_booking
/sqlite3
+/update
core
diff --git a/Makefile b/Makefile
index 607e8c7..48ddd20 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ LIBS = -lraylib -lm -lpthread -lGLESv2 -lEGL \
-lical -licalss -licalvcal \
$$([ `uname -m` = aarch64 ] && echo '-lvcos -lvchiq_arm -lgbm -ldrm')
-all: check_ical import_booking opplysning select_booking
+all: check_ical opplysning select_booking update
check: all
./check_ical < check_ical_in.ical > check_ical_out.txt
@@ -13,20 +13,17 @@ check: all
clean:
rm -f check_ical check_ical_out.txt
- rm -f import_booking
rm -f opplysning
rm -f select_booking
rm -f sqlite.o
rm -f sqlite3
+ rm -f update
.PHONY: all check clean
check_ical: check_ical.c
$(CC) $(CFLAGS) -o $@ check_ical.c $(LIBS)
-import_booking: import_booking.c sqlite.o
- $(CC) $(CFLAGS) -o $@ import_booking.c sqlite.o -lical -licalss -licalvcal
-
opplysning: opplysning.c sqlite.o
$(CC) $(CFLAGS) -o $@ opplysning.c sqlite.o $(LIBS)
@@ -38,3 +35,6 @@ sqlite.o: sqlite/sqlite3.c
sqlite3: sqlite/shell.c sqlite/sqlite3.c
$(CC) $(CFLAGS) -o sqlite3 sqlite/shell.c sqlite/sqlite3.c -lm
+
+update: update.c sqlite.o
+ $(CC) $(CFLAGS) -o $@ update.c sqlite.o -lical -licalss -licalvcal
diff --git a/import_booking.c b/update.c
index 4fbb046..2686943 100644
--- a/import_booking.c
+++ b/update.c
@@ -6,8 +6,6 @@
#include "sqlite/sqlite3.h"
-static const char *DATABASE = "booking.db";
-
static char *SCHEMA = "CREATE TABLE event ("
" start TIMESTAMP,"
" end TIMESTAMP,"
@@ -49,34 +47,34 @@ component(sqlite3 *db, icalcomponent *c)
}
int
-main(void)
+main(int argc, const char *argv[static argc])
{
- sqlite3 *db;
- char *errmsg = NULL;
- if (sqlite3_open(DATABASE, &db))
- errx(1, "sqlite3_open: %s", errmsg);
-
- if (sqlite3_exec(db, SCHEMA, NULL, NULL, &errmsg))
- errx(1, "sqlite3_exec: %s", errmsg);
+ if (2 != argc)
+ errx(1, "usage: %s dbfile < icalfile", argv[0]);
icalparser *parser = icalparser_new();
assert(parser);
-
FILE *stream = stdin;
assert(stream);
+ icalparser_set_gen_data(parser, stream);
+ sqlite3 *db;
+ char *errmsg = NULL;
+ if (sqlite3_open(argv[1], &db))
+ errx(1, "sqlite3_open: %s", errmsg);
if (sqlite3_exec(db, "BEGIN", NULL, NULL, &errmsg))
errx(1, "sqlite3_exec: %s", errmsg);
- icalparser_set_gen_data(parser, stream);
+ if (sqlite3_exec(db, "DROP TABLE IF EXISTS event", NULL, NULL, &errmsg))
+ errx(1, "sqlite3_exec: %s", errmsg);
+ if (sqlite3_exec(db, SCHEMA, NULL, NULL, &errmsg))
+ errx(1, "sqlite3_exec: %s", errmsg);
for (;;) {
char *line = icalparser_get_line(parser, read_stream);
- if (!line) {
+ if (!line)
break;
- }
icalcomponent *c = icalparser_add_line(parser, line);
- if (!c) {
+ if (!c)
continue;
- }
for (icalcompiter i = icalcomponent_begin_component(
c, ICAL_VEVENT_COMPONENT);
icalcompiter_deref(&i); icalcompiter_next(&i)) {
@@ -87,7 +85,7 @@ main(void)
}
if (sqlite3_exec(db, "COMMIT", NULL, NULL, &errmsg))
errx(1, "sqlite3_exec: %s", errmsg);
+ sqlite3_close(db);
icalparser_free(parser);
- sqlite3_close(db);
}