diff options
-rw-r--r-- | Readme.md | 4 | ||||
-rw-r--r-- | src/calendar.c | 4 | ||||
-rw-r--r-- | src/opt.c | 6 | ||||
-rw-r--r-- | src/opt.h | 2 | ||||
-rw-r--r-- | src/print.c | 13 |
5 files changed, 13 insertions, 16 deletions
@@ -78,7 +78,7 @@ Usage: ./dbg_every [-c CALENDAR_FILE] [-e TEXT_EDITOR] [COMMAND] -v --version print the version of every in use and exit -c --calendar=FILE path to calendar file -e --editor=CMD text editor for editing calendars - --line-delim=CHAR line delimiter for scripting output + --line-term=CHAR line terminator for scripting output --col-delim=CHAR column delimiter for scripting output Commands @@ -108,7 +108,7 @@ equivalent. ### script `every s` prints the upcoming events in an easily-parseable format, for use in -scripting. each line (by-default separated with `\n`) represents one upcoming +scripting. each line (by-default terminated with `\n`) represents one upcoming event, with fields (by default) delimited with `\t`. the fields are: diff --git a/src/calendar.c b/src/calendar.c index b852b1c..e656525 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -596,9 +596,9 @@ static char* sub_get_msg(struct state_s *s) } } - if (c == opt_line_delim() || c == opt_col_delim()) { + if (c == opt_line_term() || c == opt_col_delim()) { sub_set_pos(s, sub_get_pos(s)); - ERRP("message may not contain line or column delimiter characters"); + ERRP("message may not contain column delimiter or line terminator"); s->err_flag = true; free(msg); return NULL; @@ -17,8 +17,8 @@ static struct simple_opt options[] = { "path to calendar file", "FILE" }, { SIMPLE_OPT_STRING, 'e', "editor", true, "text editor for editing calendars", "CMD" }, - { SIMPLE_OPT_CHAR, '\0', "line-delim", true, - "line delimiter for scripting output" }, + { SIMPLE_OPT_CHAR, '\0', "line-term", true, + "line terminator for scripting output" }, { SIMPLE_OPT_CHAR, '\0', "col-delim", true, "column delimiter for scripting output" }, { SIMPLE_OPT_END } @@ -99,7 +99,7 @@ char* opt_editor(void) return getenv("EDITOR"); } -char opt_line_delim(void) +char opt_line_term(void) { if (options[4].was_seen) return options[4].val.v_char; @@ -12,7 +12,7 @@ void opt_parse(int argc, char **argv); char* opt_calpath(void); char* opt_editor(void); -char opt_line_delim(void); +char opt_line_term(void); char opt_col_delim(void); enum opt_command_e opt_command(void); diff --git a/src/print.c b/src/print.c index 02f78c6..34c1802 100644 --- a/src/print.c +++ b/src/print.c @@ -195,8 +195,7 @@ void print_script(struct calendar_s *cal) size_t i, j; struct tm t = { 0 }; time_t now = time(NULL), *rttmp; - char cd; - bool first = true; + char cd, lt; struct buf_s *buf = malloc(cal->count * sizeof(*buf)); if (buf == NULL) { @@ -205,6 +204,7 @@ void print_script(struct calendar_s *cal) } cd = opt_col_delim(); + lt = opt_line_term(); /* fill buffer with active events */ for (i = 0, j = 0; i < cal->count; i++) { @@ -223,23 +223,20 @@ void print_script(struct calendar_s *cal) for (i = 0; i < j; i++) { t = *localtime( &(buf[i].rt) ); - if (!first) - printf("%c", opt_line_delim()); - printf( "%d%c%d%c%d%c%d%c%d%c%d%c" /* date */ "%d%c" /* urgent */ "%d%c" /* local */ "%s" /* msg */ + "%c" /* line_end */ , t.tm_year + 1900, cd, t.tm_mon + 1, cd, t.tm_mday, cd, t.tm_hour, cd, t.tm_min, cd, t.tm_sec, cd, cal->entries[i].urgent, cd, cal->entries[i].local, cd, - (cal->entries[i].msg == NULL ? "" : cal->entries[i].msg) + (cal->entries[i].msg == NULL ? "" : cal->entries[i].msg), + lt ); - - first = false; } free(buf); |