X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/d6e8d44dbb990fe77f9380ef6cbcd5101807208e..63621a81d16ab743de6b57d47578a9a2c670ad22:/uip/mhical.c diff --git a/uip/mhical.c b/uip/mhical.c index 27f7c9f1..d62fce95 100644 --- a/uip/mhical.c +++ b/uip/mhical.c @@ -1,5 +1,4 @@ -/* - * mhical.c -- operate on an iCalendar request +/* mhical.c -- operate on an iCalendar request * * This code is Copyright (c) 2014, by the authors of nmh. * See the COPYRIGHT file in the root directory of the nmh @@ -30,7 +29,7 @@ static void convert_common (contentline *, act); static void dump_unfolded (FILE *, contentline *); static void output (FILE *, contentline *, int); static void display (FILE *, contentline *, char *); -static const char *identity (const contentline *); +static const char *identity (const contentline *) PURE; static char *format_params (char *, param_list *); static char *fold (char *, int); @@ -57,6 +56,7 @@ DEFINE_SWITCH_ARRAY(MHICAL, switches); #undef X vevent vevents = { NULL, NULL, NULL}; +int parser_status = 0; int main (int argc, char *argv[]) { @@ -237,7 +237,7 @@ main (int argc, char *argv[]) { free (outfile); } - return 0; + return parser_status; } /* @@ -399,13 +399,14 @@ convert_common (contentline *clines, act action) { if ((node = find_contentline (clines, "VERSION", 0))) { if (! node->value) { - admonish (NULL, "Version property is missing value, assume 2.0"); + inform("Version property is missing value, assume 2.0, continuing..."); node->value = mh_xstrdup ("2.0"); } if (strcmp (node->value, "2.0")) { - admonish (NULL, "supports the Version 2.0 specified by RFC 5545 " - "but iCalendar object has Version %s", node->value); + inform("supports the Version 2.0 specified by RFC 5545 " + "but iCalendar object has Version %s, continuing...", + node->value); node->value = mh_xstrdup ("2.0"); } } @@ -460,10 +461,10 @@ convert_common (contentline *clines, act action) { free (node->value); node->value = mh_xstrdup (buf); } else { - admonish (NULL, "strftime unable to format current time"); + inform("strftime unable to format current time, continuing..."); } } else { - admonish (NULL, "gmtime_r failed on current time"); + inform("gmtime_r failed on current time, continuing..."); } } @@ -534,11 +535,10 @@ output (FILE *file, contentline *clines, int contenttype) { line = fold (add (node->value, line), clines->cr_before_lf == CR_BEFORE_LF); - if (clines->cr_before_lf == LF_ONLY) { - fprintf (file, "%s\n", line); - } else { - fprintf (file, "%s\r\n", line); - } + fputs(line, file); + if (clines->cr_before_lf != LF_ONLY) + putc('\r', file); + putc('\n', file); free (line); } } @@ -713,7 +713,7 @@ display (FILE *file, contentline *clines, char *nfs) { } /* Don't call on the END:VCALENDAR line. */ - if (clines->next) { + if (clines && clines->next) { (void) fmt_scan (fmt, buffer, INT_MAX, dat, NULL); fputs (charstring_buffer (buffer), file); fmt_free (fmt, 1); @@ -809,7 +809,7 @@ fold (char *line, int uses_cr) { #endif charstring_push_back_chars (folded_line, cp, char_len, 1); - remaining -= char_len > 0 ? char_len : 1; + remaining -= max(char_len, 1); /* remaining must be > 0 to pass the loop condition above, so if it's not > 1, it is == 1. */ @@ -824,7 +824,7 @@ fold (char *line, int uses_cr) { } } - cp += char_len > 0 ? char_len : 1; + cp += max(char_len, 1); } free (line);