2 * Copyright (c) 1992-2009 Edwin Groothuis <edwin@FreeBSD.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
37 #include "pathnames.h"
41 event_add(int year, int month, int day, char *date, int var, char *txt,
47 * Creating a new event:
48 * - Create a new event
49 * - Copy the machine readable day and month
50 * - Copy the human readable and language specific date
51 * - Copy the text of the event
53 e = (struct event *)calloc(1, sizeof(struct event));
55 errx(1, "event_add: cannot allocate memory");
59 e->date = strdup(date);
61 errx(1, "event_add: cannot allocate memory");
62 e->text = strdup(txt);
64 errx(1, "event_add: cannot allocate memory");
66 if (extra != NULL && extra[0] != '\0')
67 e->extra = strdup(extra);
68 addtodate(e, year, month, day);
73 event_continue(struct event *e, char *txt)
78 * Adding text to the event:
79 * - Save a copy of the old text (unknown length, so strdup())
80 * - Allocate enough space for old text + \n + new text + 0
81 * - Store the old text + \n + new text
82 * - Destroy the saved copy.
84 text = strdup(e->text);
86 errx(1, "event_continue: cannot allocate memory");
89 e->text = (char *)malloc(strlen(text) + strlen(txt) + 3);
91 errx(1, "event_continue: cannot allocate memory");
92 strcpy(e->text, text);
93 strcat(e->text, "\n");
101 event_print_all(FILE *fp)
105 while (walkthrough_dates(&e) != 0) {
107 fprintf(stderr, "event_print_allmonth: %d, day: %d\n",
112 * Go through all events and print the text of the matching
116 (void)fprintf(fp, "%s%c%s%s%s%s\n", e->date,
117 e->var ? '*' : ' ', e->text,
118 e->extra != NULL ? " (" : "",
119 e->extra != NULL ? e->extra : "",
120 e->extra != NULL ? ")" : ""