summaryrefslogtreecommitdiff
path: root/src/day.c
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2007-07-28 13:11:42 +0000
committerFrederic Culot <calcurse@culot.org>2007-07-28 13:11:42 +0000
commit4b987f70ac463121f9791eb3493952a77aba495f (patch)
tree2754295b8dd40b6818ddd80d97a327329de854c0 /src/day.c
parentfdc325acd8549acf0fb52c84b8074aef0c2c38c7 (diff)
downloadcalcurse-4b987f70ac463121f9791eb3493952a77aba495f.zip
unuseful headers removed and some functions became static
Diffstat (limited to 'src/day.c')
-rwxr-xr-xsrc/day.c399
1 files changed, 201 insertions, 198 deletions
diff --git a/src/day.c b/src/day.c
index bb8e8c3..0ed71dc 100755
--- a/src/day.c
+++ b/src/day.c
@@ -1,4 +1,4 @@
-/* $calcurse: day.c,v 1.24 2007/07/20 19:05:19 culot Exp $ */
+/* $calcurse: day.c,v 1.25 2007/07/28 13:11:42 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -24,105 +24,117 @@
*
*/
-#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <ctype.h>
-#include <stdbool.h>
#include <time.h>
#include "i18n.h"
#include "utils.h"
#include "apoint.h"
#include "event.h"
-#include "recur.h"
#include "day.h"
-#include "vars.h"
-#include "args.h"
-static struct day_item_s *day_items_ptr;
-static struct day_saved_item_s *day_saved_item = NULL;
+static struct day_item_s *day_items_ptr;
+static struct day_saved_item_s *day_saved_item = NULL;
-
-/*
- * Store the events and appointments for the selected day, and write
- * those items in a pad. If selected day is null, then store items for current
- * day. This is useful to speed up the appointment panel update.
- */
-day_items_nb_t *
-day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
+/* Free the current day linked list containing the events and appointments. */
+static void
+day_free_list(void)
{
- long date;
- date_t day;
-
- if (slctd_date)
- day = *slctd_date;
- else
- calendar_store_current_date(&day);
-
- date = date2sec(day, 0, 0);
-
- /* Inits */
- if (apad->length != 0)
- delwin(apad->ptrwin);
-
- /* Store the events and appointments (recursive and normal items). */
- apad->length = day_store_items(date,
- &inday->nb_events, &inday->nb_apoints);
-
- /* Create the new pad with its new length. */
- if (day_changed)
- apad->first_onscreen = 0;
- apad->ptrwin = newpad(apad->length, apad->width);
+ struct day_item_s *p, *q;
- return (inday);
+ for (p = day_items_ptr; p != 0; p = q) {
+ q = p->next;
+ free(p->mesg);
+ free(p);
+ }
+ day_items_ptr = NULL;
}
-/*
- * Store all of the items to be displayed for the selected day.
- * Items are of four types: recursive events, normal events,
- * recursive appointments and normal appointments.
- * The items are stored in the linked list pointed by *day_items_ptr
- * and the length of the new pad to write is returned.
- * The number of events and appointments in the current day are also updated.
- */
-int day_store_items(long date, int *pnb_events, int *pnb_apoints)
+/* Add an event in the current day list */
+static struct day_item_s *
+day_add_event(int type, char *mesg, long day, int id)
{
- int pad_length;
- int nb_events, nb_recur_events;
- int nb_apoints, nb_recur_apoints;
-
- pad_length = nb_events = nb_apoints = 0;
- nb_recur_events = nb_recur_apoints = 0;
+ struct day_item_s *o, **i;
+ o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
+ o->mesg = (char *) malloc(strlen(mesg) + 1);
+ strncpy(o->mesg, mesg, strlen(mesg) + 1);
+ o->type = type;
+ o->appt_dur = 0;
+ o->appt_pos = 0;
+ o->start = day;
+ o->evnt_id = id;
+ i = &day_items_ptr;
+ for (;;) {
+ if (*i == 0) {
+ o->next = *i;
+ *i = o;
+ break;
+ }
+ i = &(*i)->next;
+ }
+ return o;
+}
- if (day_items_ptr != 0)
- day_free_list();
- nb_recur_events = day_store_recur_events(date);
- nb_events = day_store_events(date);
- *pnb_events = nb_events;
- nb_recur_apoints = day_store_recur_apoints(date);
- nb_apoints = day_store_apoints(date);
- *pnb_apoints = nb_apoints;
- pad_length = nb_recur_events + nb_events + 1 +
- 3*(nb_recur_apoints + nb_apoints);
- *pnb_apoints += nb_recur_apoints;
- *pnb_events += nb_recur_events;
+/* Add an appointment in the current day list. */
+static struct day_item_s *
+day_add_apoint(int type, char *mesg, long start, long dur, char state,
+ int real_pos)
+{
+ struct day_item_s *o, **i;
+ int insert_item = 0;
- return pad_length;
+ o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
+ o->mesg = (char *) malloc(strlen(mesg) + 1);
+ strncpy(o->mesg, mesg, strlen(mesg) + 1);
+ o->start = start;
+ o->appt_dur = dur;
+ o->appt_pos = real_pos;
+ o->state = state;
+ o->type = type;
+ o->evnt_id = 0;
+ i = &day_items_ptr;
+ for (;;) {
+ if (*i == 0) {
+ insert_item = 1;
+ } else if ( ((*i)->start > start) &&
+ ((*i)->type > EVNT) ) {
+ insert_item = 1;
+ }
+ if (insert_item) {
+ o->next = *i;
+ *i = o;
+ break;
+ }
+ i = &(*i)->next;
+ }
+ return o;
}
-/* Free the current day linked list containing the events and appointments. */
-void day_free_list(void)
+/*
+ * Store the events for the selected day in structure pointed
+ * by day_items_ptr. This is done by copying the events
+ * from the general structure pointed by eventlist to the structure
+ * dedicated to the selected day.
+ * Returns the number of events for the selected day.
+ */
+static int
+day_store_events(long date)
{
- struct day_item_s *p, *q;
+ struct event_s *j;
+ struct day_item_s *ptr;
+ int e_nb = 0;
- for (p = day_items_ptr; p != 0; p = q) {
- q = p->next;
- free(p->mesg);
- free(p);
+ for (j = eventlist; j != 0; j = j->next) {
+ if (event_inday(j, date)) {
+ e_nb++;
+ ptr = day_add_event(EVNT, j->mesg, j->day, j->id);
+ }
}
- day_items_ptr = NULL;
+
+ return e_nb;
}
/*
@@ -132,7 +144,8 @@ void day_free_list(void)
* dedicated to the selected day.
* Returns the number of recurrent events for the selected day.
*/
-int day_store_recur_events(long date)
+static int
+day_store_recur_events(long date)
{
struct recur_event_s *j;
struct day_item_s *ptr;
@@ -150,26 +163,30 @@ int day_store_recur_events(long date)
}
/*
- * Store the events for the selected day in structure pointed
- * by day_items_ptr. This is done by copying the events
- * from the general structure pointed by eventlist to the structure
- * dedicated to the selected day.
- * Returns the number of events for the selected day.
+ * Store the apoints for the selected day in structure pointed
+ * by day_items_ptr. This is done by copying the appointments
+ * from the general structure pointed by alist_p->root to the
+ * structure dedicated to the selected day.
+ * Returns the number of appointments for the selected day.
*/
-int day_store_events(long date)
+static int
+day_store_apoints(long date)
{
- struct event_s *j;
+ apoint_llist_node_t *j;
struct day_item_s *ptr;
- int e_nb = 0;
+ int a_nb = 0;
- for (j = eventlist; j != 0; j = j->next) {
- if (event_inday(j, date)) {
- e_nb++;
- ptr = day_add_event(EVNT, j->mesg, j->day, j->id);
+ pthread_mutex_lock(&(alist_p->mutex));
+ for (j = alist_p->root; j != 0; j = j->next) {
+ if (apoint_inday(j, date)) {
+ a_nb++;
+ ptr = day_add_apoint(APPT, j->mesg, j->start, j->dur,
+ j->state, 0);
}
}
+ pthread_mutex_unlock(&(alist_p->mutex));
- return e_nb;
+ return a_nb;
}
/*
@@ -179,7 +196,8 @@ int day_store_events(long date)
* structure dedicated to the selected day.
* Returns the number of recurrent appointments for the selected day.
*/
-int day_store_recur_apoints(long date)
+static int
+day_store_recur_apoints(long date)
{
recur_apoint_llist_node_t *j;
struct day_item_s *ptr;
@@ -203,87 +221,89 @@ int day_store_recur_apoints(long date)
}
/*
- * Store the apoints for the selected day in structure pointed
- * by day_items_ptr. This is done by copying the appointments
- * from the general structure pointed by alist_p->root to the
- * structure dedicated to the selected day.
- * Returns the number of appointments for the selected day.
+ * Store all of the items to be displayed for the selected day.
+ * Items are of four types: recursive events, normal events,
+ * recursive appointments and normal appointments.
+ * The items are stored in the linked list pointed by *day_items_ptr
+ * and the length of the new pad to write is returned.
+ * The number of events and appointments in the current day are also updated.
*/
-int day_store_apoints(long date)
+static int
+day_store_items(long date, int *pnb_events, int *pnb_apoints)
{
- apoint_llist_node_t *j;
- struct day_item_s *ptr;
- int a_nb = 0;
+ int pad_length;
+ int nb_events, nb_recur_events;
+ int nb_apoints, nb_recur_apoints;
- pthread_mutex_lock(&(alist_p->mutex));
- for (j = alist_p->root; j != 0; j = j->next) {
- if (apoint_inday(j, date)) {
- a_nb++;
- ptr = day_add_apoint(APPT, j->mesg, j->start, j->dur,
- j->state, 0);
- }
- }
- pthread_mutex_unlock(&(alist_p->mutex));
+ pad_length = nb_events = nb_apoints = 0;
+ nb_recur_events = nb_recur_apoints = 0;
- return a_nb;
+ if (day_items_ptr != 0)
+ day_free_list();
+ nb_recur_events = day_store_recur_events(date);
+ nb_events = day_store_events(date);
+ *pnb_events = nb_events;
+ nb_recur_apoints = day_store_recur_apoints(date);
+ nb_apoints = day_store_apoints(date);
+ *pnb_apoints = nb_apoints;
+ pad_length = nb_recur_events + nb_events + 1 +
+ 3*(nb_recur_apoints + nb_apoints);
+ *pnb_apoints += nb_recur_apoints;
+ *pnb_events += nb_recur_events;
+
+ return pad_length;
}
-/* Add an event in the current day list */
-struct day_item_s *day_add_event(int type, char *mesg, long day, int id)
+/*
+ * Store the events and appointments for the selected day, and write
+ * those items in a pad. If selected day is null, then store items for current
+ * day. This is useful to speed up the appointment panel update.
+ */
+day_items_nb_t *
+day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
{
- struct day_item_s *o, **i;
- o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->type = type;
- o->appt_dur = 0;
- o->appt_pos = 0;
- o->start = day;
- o->evnt_id = id;
- i = &day_items_ptr;
- for (;;) {
- if (*i == 0) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
- }
- return o;
+ long date;
+ date_t day;
+
+ if (slctd_date)
+ day = *slctd_date;
+ else
+ calendar_store_current_date(&day);
+
+ date = date2sec(day, 0, 0);
+
+ /* Inits */
+ if (apad->length != 0)
+ delwin(apad->ptrwin);
+
+ /* Store the events and appointments (recursive and normal items). */
+ apad->length = day_store_items(date,
+ &inday->nb_events, &inday->nb_apoints);
+
+ /* Create the new pad with its new length. */
+ if (day_changed)
+ apad->first_onscreen = 0;
+ apad->ptrwin = newpad(apad->length, apad->width);
+
+ return (inday);
}
-/* Add an appointment in the current day list. */
-struct day_item_s *day_add_apoint(int type, char *mesg, long start, long dur,
- char state, int real_pos)
+/*
+ * Returns a structure of type apoint_llist_node_t given a structure of type
+ * day_item_s
+ */
+static apoint_llist_node_t *
+day_item_s2apoint_s(struct day_item_s *p)
{
- struct day_item_s *o, **i;
- int insert_item = 0;
+ apoint_llist_node_t *a;
- o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
- o->mesg = (char *) malloc(strlen(mesg) + 1);
- strncpy(o->mesg, mesg, strlen(mesg) + 1);
- o->start = start;
- o->appt_dur = dur;
- o->appt_pos = real_pos;
- o->state = state;
- o->type = type;
- o->evnt_id = 0;
- i = &day_items_ptr;
- for (;;) {
- if (*i == 0) {
- insert_item = 1;
- } else if ( ((*i)->start > start) &&
- ((*i)->type > EVNT) ) {
- insert_item = 1;
- }
- if (insert_item) {
- o->next = *i;
- *i = o;
- break;
- }
- i = &(*i)->next;
- }
- return o;
+ a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
+ a->mesg = (char *) malloc(strlen(p->mesg) + 1);
+ a->state = p->state;
+ a->start = p->start;
+ a->dur = p->appt_dur;
+ a->mesg = p->mesg;
+ return a;
}
/*
@@ -355,23 +375,6 @@ day_write_pad(long date, int width, int length, int incolor)
}
}
-/*
- * Returns a structure of type apoint_llist_node_t given a structure of type
- * day_item_s
- */
-apoint_llist_node_t *day_item_s2apoint_s(struct day_item_s *p)
-{
- apoint_llist_node_t *a;
-
- a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
- a->mesg = (char *) malloc(strlen(p->mesg) + 1);
- a->state = p->state;
- a->start = p->start;
- a->dur = p->appt_dur;
- a->mesg = p->mesg;
- return a;
-}
-
/* Display an item inside a popup window. */
void day_popup_item(void)
{
@@ -431,6 +434,27 @@ void day_popup_item(void)
return 0;
}
+/* Request the user to enter a new time. */
+static char *
+day_edit_time(long time) {
+ char *timestr;
+ char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
+ char *enter_str = _("Press [Enter] to continue");
+ char *fmt_msg =
+ _("You entered an invalid time, should be [h:mm] or [hh:mm]");
+
+ while (1) {
+ status_mesg(msg_time, "");
+ timestr = date_sec2hour_str(time);
+ updatestring(swin, &timestr, 0, 1);
+ if (check_time(timestr) != 1 || strlen(timestr) == 0) {
+ status_mesg(fmt_msg, enter_str);
+ wgetch(swin);
+ } else
+ return timestr;
+ }
+}
+
/* Edit an already existing item. */
void
day_edit_item(int item_num)
@@ -644,27 +668,6 @@ day_edit_item(int item_num)
}
}
-/* Request the user to enter a new time. */
-char *
-day_edit_time(long time) {
- char *timestr;
- char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
- char *enter_str = _("Press [Enter] to continue");
- char *fmt_msg =
- _("You entered an invalid time, should be [h:mm] or [hh:mm]");
-
- while (1) {
- status_mesg(msg_time, "");
- timestr = date_sec2hour_str(time);
- updatestring(swin, &timestr, 0, 1);
- if (check_time(timestr) != 1 || strlen(timestr) == 0) {
- status_mesg(fmt_msg, enter_str);
- wgetch(swin);
- } else
- return timestr;
- }
-}
-
/*
* In order to erase an item, we need to count first the number of
* items for each type (in order: recurrent events, events,