Introduction
Introduction Statistics Contact Development Disclaimer Help
tsv2agenda: show everything by default - ics2txt - convert icalendar .ics file …
git clone git://bitreich.org/ics2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws…
Log
Files
Refs
Tags
README
---
commit 44e416da284ed08d3ed7b47f2d70a333433930f4
parent d1604d44d1926ce38a94073ad8d55b2c8a99d172
Author: Josuah Demangeon <[email protected]>
Date: Fri, 25 Jun 2021 22:46:59 +0200
tsv2agenda: show everything by default
Diffstat:
M tsv2agenda.1 | 2 +-
M tsv2agenda.c | 46 ++++++++++++++++-------------…
2 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/tsv2agenda.1 b/tsv2agenda.1
@@ -31,7 +31,7 @@ the output (if not empty).
.It Fl f Ar fromdate
Show only events starting from
.Ar fromdate .
-By default the current time: showing all future events.
+By default show everything from the beggining.
.
.It Fl t Ar todate
Show only events up to
diff --git a/tsv2agenda.c b/tsv2agenda.c
@@ -185,26 +185,26 @@ print(AgendaCtx *ctx, char **fields)
}
static void
-tsv_to_agenda(AgendaCtx *ctx, FILE *fp)
+tsv2agenda(FILE *fp)
{
- char *ln1 = NULL, *ln2 = NULL;
+ AgendaCtx ctx = {0};
+ char *line = NULL;
size_t sz1 = 0, sz2 = 0;
- if (ctx->linenum == 0) {
+ if (ctx.linenum == 0) {
char *fields[FIELD_MAX];
- ctx->linenum++;
- getline(&ln1, &sz1, fp);
+ ctx.linenum++;
+ getline(&line, &sz1, fp);
if (ferror(fp))
err(1, "reading stdin: %s", strerror(errno));
if (feof(fp))
err(1, "empty input");
-
- strchomp(ln1);
- ctx->fieldnum = strsplit(ln1, fields, FIELD_MAX, "\t");
- if (ctx->fieldnum == FIELD_MAX)
+ strchomp(line);
+ ctx.fieldnum = strsplit(line, fields, FIELD_MAX, "\t");
+ if (ctx.fieldnum == FIELD_MAX)
err(1, "line 1: too many fields");
- if (ctx->fieldnum < FIELD_OTHER)
+ if (ctx.fieldnum < FIELD_OTHER)
err(1, "line 1: not enough input columns");
if (strcasecmp(fields[0], "TYPE") != 0)
err(1, "line 1: 1st column is not \"TYPE\"");
@@ -214,29 +214,33 @@ tsv_to_agenda(AgendaCtx *ctx, FILE *fp)
err(1, "line 1: 3rd column is not \"END\"");
if (strcasecmp(fields[3], "RECUR") != 0)
err(1, "line 1: 4th column is not \"RECUR\"");
+
+ free(line);
+ line = NULL;
}
for (;;) {
char *fields[FIELD_MAX];
- ctx->linenum++;
- getline(&ln2, &sz2, fp);
+ ctx.linenum++;
+ getline(&line, &sz2, fp);
if (ferror(fp))
err(1, "reading stdin: %s", strerror(errno));
if (feof(fp))
break;
- strchomp(ln2);
- if (strsplit(ln2, fields, FIELD_MAX, "\t") != ctx->fieldnum)
+ strchomp(line);
+
+ if (strsplit(line, fields, FIELD_MAX, "\t") != ctx.fieldnum)
err(1, "line %zd: bad number of columns",
- ctx->linenum, strerror(errno));
+ ctx.linenum, strerror(errno));
- print(ctx, fields);
+ print(&ctx, fields);
}
fputc('\n', stdout);
- free(ln1);
- free(ln2);
+ free(line);
+ line = NULL;
}
static void
@@ -249,12 +253,8 @@ usage(void)
int
main(int argc, char **argv)
{
- AgendaCtx ctx = {0};
char c;
- if ((flag_from = time(NULL)) == (time_t)-1)
- err(1, "time: %s", strerror(errno));
-
if (pledge("stdio", "") < 0)
err(1, "pledge: %s", strerror(errno));
@@ -280,6 +280,6 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
- tsv_to_agenda(&ctx, stdin);
+ tsv2agenda(stdin);
return 0;
}
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.