From 9f637857c883b04cb61a2d644f0357bb112024af Mon Sep 17 00:00:00 2001 From: hummypkg Date: Fri, 3 Jun 2011 00:13:37 +0000 Subject: [PATCH] add now and brief mode --- lint.h | 1 + main.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lint.h b/lint.h index c6dc81c..c1eb415 100644 --- a/lint.h +++ b/lint.h @@ -4,6 +4,7 @@ #include "util.h" #define SYSOPT_PARSABLE 0x1 +#define SYSOPT_BRIEF 0x2 extern int debug; extern const char *version; diff --git a/main.c b/main.c index fc7ddd5..bc7d766 100644 --- a/main.c +++ b/main.c @@ -28,15 +28,17 @@ syntax() "Syntax: epg [options] ...\n"); fprintf(stderr, " Options:\n" - " -d[level] Set debug level.\n" - " -f Specify alternate EPG data file.\n" - " -h Show help text.\n" + " -b Brief output.\n" + " -d[level] Set debug level.\n" + " -f Specify alternate EPG data file.\n" + " -h Show help text.\n" " -p Parsable output.\n" ); fprintf(stderr, "\n"); fprintf(stderr, " Commands:\n" " dump Show a parsed summary of the EPG.\n" + " now Show what is currently on.\n" " search Search programme names for text.\n" " searchall " "Search programme names/descriptions for text.\n" @@ -56,6 +58,33 @@ dump(struct epg *epg __attribute__((unused)), printf("----------------------------------------------------------\n"); + if (sysopts & SYSOPT_BRIEF) + { + safeprintf("%d/%d: %s+%d\n", + s->service_id, d->event_id, ctime_nl(&tm), + d->dur_hour * 3600 + d->dur_min * 60 + d->dur_sec); + if (ds[PARSER_SHORT_EVENT]) + { + struct descriptor *d77 = ds[PARSER_SHORT_EVENT]; + + safeprintf("Name:%.*s\n", + d77->content.d77.namelen, d77->content.d77.name); + safeprintf("Text:%.*s\n", + d77->content.d77.textlen, d77->content.d77.text); + } + + if (ds[PARSER_USER_DEFINED]) + { + struct descriptor *d137 = ds[PARSER_USER_DEFINED]; + + safeprintf("Warning:%.*s\n", + d137->content.d137.warninglen, + d137->content.d137.warning); + } + + return; + } + if (sysopts & SYSOPT_PARSABLE) { printf("ServiceID:%d\n", s->service_id); @@ -172,6 +201,24 @@ searchall(struct epg *epg __attribute__((unused)), dump(epg, s, d, ds, NULL); } +void +now(struct epg *epg __attribute__((unused)), + struct section *s, struct data *d, struct descriptor **ds, + void *var __attribute__((unused))) +{ + static time_t now = 0; + time_t tm, etm; + + if (!now) + time(&now); + + tm = mjd(d->start_date, d->start_hour, d->start_min, d->start_sec); + etm = tm + d->dur_hour * 3600 + d->dur_min * 60 + d->dur_sec; + + if (tm < now && etm > now) + dump(epg, s, d, ds, NULL); +} + int main(int argc, char **argv) { @@ -185,6 +232,10 @@ main(int argc, char **argv) { switch (*cp) { + case 'b': + sysopts |= SYSOPT_BRIEF; + break; + case 'd': if (*++cp == '\0') debug = 1; @@ -225,6 +276,8 @@ nextopt: if (!strcmp(argv[0], "dump")) parse(epgpath, dump, NULL); + if (!strcmp(argv[0], "now")) + parse(epgpath, now, NULL); else if (!strcmp(argv[0], "search") && argc > 1) parse(epgpath, search, (void *)argv[1]); else if (!strcmp(argv[0], "searchall") && argc > 1)