summaryrefslogtreecommitdiff
path: root/src/event.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-04-13 23:31:06 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2013-04-14 00:19:01 +0200
commit694d28eb78dfad98e2e7ea670d93a153d8efd368 (patch)
tree485dc11d3644d9dadb5fd4d67c5ef8103be79623 /src/event.c
parent9907069f442c56c90b67accb2d8fbd046dfce6db (diff)
downloadcalcurse-694d28eb78dfad98e2e7ea670d93a153d8efd368.zip
Use tabs instead of spaces for indentation
This completes our switch to the Linux kernel coding style. Note that we still use deeply nested constructs at some places which need to be fixed up later. Converted using the `Lindent` script from the Linux kernel code base, along with some manual fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/event.c')
-rw-r--r--src/event.c140
1 files changed, 70 insertions, 70 deletions
diff --git a/src/event.c b/src/event.c
index 637dd6d..38305b8 100644
--- a/src/event.c
+++ b/src/event.c
@@ -45,124 +45,124 @@ llist_t eventlist;
void event_free(struct event *ev)
{
- mem_free(ev->mesg);
- erase_note(&ev->note);
- mem_free(ev);
+ mem_free(ev->mesg);
+ erase_note(&ev->note);
+ mem_free(ev);
}
struct event *event_dup(struct event *in)
{
- EXIT_IF(!in, _("null pointer"));
-
- struct event *ev = mem_malloc(sizeof(struct event));
- ev->id = in->id;
- ev->day = in->day;
- ev->mesg = mem_strdup(in->mesg);
- if (in->note)
- ev->note = mem_strdup(in->note);
- else
- ev->note = NULL;
-
- return ev;
+ EXIT_IF(!in, _("null pointer"));
+
+ struct event *ev = mem_malloc(sizeof(struct event));
+ ev->id = in->id;
+ ev->day = in->day;
+ ev->mesg = mem_strdup(in->mesg);
+ if (in->note)
+ ev->note = mem_strdup(in->note);
+ else
+ ev->note = NULL;
+
+ return ev;
}
void event_llist_init(void)
{
- LLIST_INIT(&eventlist);
+ LLIST_INIT(&eventlist);
}
void event_llist_free(void)
{
- LLIST_FREE_INNER(&eventlist, event_free);
- LLIST_FREE(&eventlist);
+ LLIST_FREE_INNER(&eventlist, event_free);
+ LLIST_FREE(&eventlist);
}
static int event_cmp_day(struct event *a, struct event *b)
{
- return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
+ return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1);
}
/* Create a new event */
struct event *event_new(char *mesg, char *note, long day, int id)
{
- struct event *ev;
+ struct event *ev;
- ev = mem_malloc(sizeof(struct event));
- ev->mesg = mem_strdup(mesg);
- ev->day = day;
- ev->id = id;
- ev->note = (note != NULL) ? mem_strdup(note) : NULL;
+ ev = mem_malloc(sizeof(struct event));
+ ev->mesg = mem_strdup(mesg);
+ ev->day = day;
+ ev->id = id;
+ ev->note = (note != NULL) ? mem_strdup(note) : NULL;
- LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
+ LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
- return ev;
+ return ev;
}
/* Check if the event belongs to the selected day */
unsigned event_inday(struct event *i, long *start)
{
- return (i->day < *start + DAYINSEC && i->day >= *start);
+ return (i->day < *start + DAYINSEC && i->day >= *start);
}
/* Write to file the event in user-friendly format */
void event_write(struct event *o, FILE * f)
{
- struct tm lt;
- time_t t;
-
- t = o->day;
- localtime_r(&t, &lt);
- fprintf(f, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday,
- 1900 + lt.tm_year, o->id);
- if (o->note != NULL)
- fprintf(f, ">%s ", o->note);
- fprintf(f, "%s\n", o->mesg);
+ struct tm lt;
+ time_t t;
+
+ t = o->day;
+ localtime_r(&t, &lt);
+ fprintf(f, "%02u/%02u/%04u [%d] ", lt.tm_mon + 1, lt.tm_mday,
+ 1900 + lt.tm_year, o->id);
+ if (o->note != NULL)
+ fprintf(f, ">%s ", o->note);
+ fprintf(f, "%s\n", o->mesg);
}
/* Load the events from file */
struct event *event_scan(FILE * f, struct tm start, int id, char *note)
{
- char buf[BUFSIZ], *nl;
- time_t tstart;
-
- EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
- !check_time(start.tm_hour, start.tm_min),
- _("date error in event"));
-
- /* Read the event description */
- if (!fgets(buf, sizeof buf, f))
- return NULL;
-
- nl = strchr(buf, '\n');
- if (nl) {
- *nl = '\0';
- }
- start.tm_hour = 0;
- start.tm_min = 0;
- start.tm_sec = 0;
- start.tm_isdst = -1;
- start.tm_year -= 1900;
- start.tm_mon--;
-
- tstart = mktime(&start);
- EXIT_IF(tstart == -1, _("date error in the event\n"));
-
- return event_new(buf, note, tstart, id);
+ char buf[BUFSIZ], *nl;
+ time_t tstart;
+
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min),
+ _("date error in event"));
+
+ /* Read the event description */
+ if (!fgets(buf, sizeof buf, f))
+ return NULL;
+
+ nl = strchr(buf, '\n');
+ if (nl) {
+ *nl = '\0';
+ }
+ start.tm_hour = 0;
+ start.tm_min = 0;
+ start.tm_sec = 0;
+ start.tm_isdst = -1;
+ start.tm_year -= 1900;
+ start.tm_mon--;
+
+ tstart = mktime(&start);
+ EXIT_IF(tstart == -1, _("date error in the event\n"));
+
+ return event_new(buf, note, tstart, id);
}
/* Delete an event from the list. */
void event_delete(struct event *ev)
{
- llist_item_t *i = LLIST_FIND_FIRST(&eventlist, ev, NULL);
+ llist_item_t *i = LLIST_FIND_FIRST(&eventlist, ev, NULL);
- if (!i)
- EXIT(_("no such appointment"));
+ if (!i)
+ EXIT(_("no such appointment"));
- LLIST_REMOVE(&eventlist, i);
+ LLIST_REMOVE(&eventlist, i);
}
void event_paste_item(struct event *ev, long date)
{
- ev->day = date;
- LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
+ ev->day = date;
+ LLIST_ADD_SORTED(&eventlist, ev, event_cmp_day);
}