summaryrefslogtreecommitdiffstats
path: root/src/apoint.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/apoint.c')
-rw-r--r--src/apoint.c140
1 files changed, 67 insertions, 73 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 6fd9e64..1ca6639 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -46,21 +46,21 @@ static struct apoint bkp_cut_apoint;
static int hilt;
void
-apoint_free_bkp (enum eraseflg flag)
+apoint_free_bkp (void)
{
if (bkp_cut_apoint.mesg)
{
mem_free (bkp_cut_apoint.mesg);
bkp_cut_apoint.mesg = 0;
}
- erase_note (&bkp_cut_apoint.note, flag);
+ erase_note (&bkp_cut_apoint.note);
}
static void
apoint_free (struct apoint *apt)
{
mem_free (apt->mesg);
- erase_note (&apt->note, ERASE_FORCE_KEEP_NOTE);
+ erase_note (&apt->note);
mem_free (apt);
}
@@ -103,28 +103,28 @@ apoint_hilt_set (int highlighted)
}
void
-apoint_hilt_decrease (void)
+apoint_hilt_decrease (int n)
{
- hilt--;
+ hilt -= n;
}
void
-apoint_hilt_increase (void)
+apoint_hilt_increase (int n)
{
- hilt++;
+ hilt += n;
}
/* Return which appointment is highlighted. */
int
apoint_hilt (void)
{
- return (hilt);
+ return hilt;
}
static int
apoint_cmp_start (struct apoint *a, struct apoint *b)
{
- return (a->start < b->start ? -1 : (a->start == b->start ? 0 : 1));
+ return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
struct apoint *
@@ -154,27 +154,28 @@ void
apoint_add (void)
{
#define LTIME 6
+#define LDUR 12
char *mesg_1 =
- _("Enter start time ([hh:mm] or [h:mm]), "
- "leave blank for an all-day event : ");
+ _("Enter start time ([hh:mm]), leave blank for an all-day event : ");
char *mesg_2 =
- _("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
+ _("Enter end time ([hh:mm]) or duration ([+hh:mm]) : ");
char *mesg_3 = _("Enter description :");
char *format_message_1 =
- _("You entered an invalid start time, should be [h:mm] or [hh:mm]");
+ _("You entered an invalid start time, should be [hh:mm]");
char *format_message_2 =
- _("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
+ _("You entered an invalid end time, should be [hh:mm], [+hh:mm] or [+mm]");
char *enter_str = _("Press [Enter] to continue");
int Id = 1;
char item_time[LTIME] = "";
char item_mesg[BUFSIZ] = "";
- long apoint_duration = 0, apoint_start;
+ long apoint_start;
unsigned heures, minutes;
+ unsigned apoint_duration;
unsigned end_h, end_m;
int is_appointment = 1;
/* Get the starting time */
- do
+ for (;;)
{
status_mesg (mesg_1, "");
if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC)
@@ -184,18 +185,18 @@ apoint_add (void)
is_appointment = 0;
break;
}
- else if (check_time (item_time) != 1)
+
+ if (parse_time (item_time, &heures, &minutes) == 1)
+ break;
+ else
{
status_mesg (format_message_1, enter_str);
- (void)wgetch (win[STA].p);
+ wgetch (win[STA].p);
}
- else
- (void)sscanf (item_time, "%u:%u", &heures, &minutes);
}
else
return;
}
- while (check_time (item_time) != 1);
/*
* Check if an event or appointment is entered,
@@ -205,23 +206,16 @@ apoint_add (void)
if (is_appointment)
{ /* Get the appointment duration */
item_time[0] = '\0';
- do
+ for (;;)
{
status_mesg (mesg_2, "");
- if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_VALID)
- return; //nothing entered, cancel adding of event
- else if (check_time (item_time) == 0)
- {
- status_mesg (format_message_2, enter_str);
- (void)wgetch (win[STA].p);
- }
- else
+ if (getstring (win[STA].p, item_time, LDUR, 0, 1) != GETSTRING_ESC)
{
- if (check_time (item_time) == 2)
- apoint_duration = atoi (item_time);
- else if (check_time (item_time) == 1)
+ if (*item_time == '+' && parse_duration (item_time + 1,
+ &apoint_duration) == 1)
+ break;
+ else if (parse_time (item_time, &end_h, &end_m) == 1)
{
- (void)sscanf (item_time, "%u:%u", &end_h, &end_m);
if (end_h < heures || ((end_h == heures) && (end_m < minutes)))
{
apoint_duration = MININSEC - minutes + end_m
@@ -232,10 +226,17 @@ apoint_add (void)
apoint_duration = MININSEC - minutes
+ end_m + (end_h - (heures + 1)) * MININSEC;
}
+ break;
+ }
+ else
+ {
+ status_mesg (format_message_2, enter_str);
+ wgetch (win[STA].p);
}
}
+ else
+ return;
}
- while (check_time (item_time) == 0);
}
else /* Insert the event Id */
Id = 1;
@@ -246,14 +247,12 @@ apoint_add (void)
if (is_appointment)
{
apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes);
- (void)apoint_new (item_mesg, 0L, apoint_start,
- min2sec (apoint_duration), 0L);
+ apoint_new (item_mesg, 0L, apoint_start, min2sec (apoint_duration), 0L);
if (notify_bar ())
notify_check_added (item_mesg, apoint_start, 0L);
}
else
- (void)event_new (item_mesg, 0L,
- date2sec (*calendar_get_slctd_day (), 12, 0), Id);
+ event_new (item_mesg, 0L, date2sec (*calendar_get_slctd_day (), 0, 0), Id);
if (hilt == 0)
hilt++;
@@ -384,9 +383,9 @@ apoint_inday (struct apoint *i, long start)
{
if (i->start <= start + DAYINSEC && i->start + i->dur > start)
{
- return (1);
+ return 1;
}
- return (0);
+ return 0;
}
void
@@ -395,21 +394,21 @@ apoint_sec2str (struct apoint *o, int type, long day, char *start, char *end)
struct tm *lt;
time_t t;
- if (o->start < day && type == APPT)
- (void)strncpy (start, "..:..", 6);
+ if (o->start < day)
+ strncpy (start, "..:..", 6);
else
{
t = o->start;
lt = localtime (&t);
- (void)snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
- if (o->start + o->dur > day + DAYINSEC && type == APPT)
- (void)strncpy (end, "..:..", 6);
+ if (o->start + o->dur > day + DAYINSEC)
+ strncpy (end, "..:..", 6);
else
{
t = o->start + o->dur;
lt = localtime (&t);
- (void)snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
+ snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
}
}
@@ -421,25 +420,23 @@ apoint_write (struct apoint *o, FILE *f)
t = o->start;
lt = localtime (&t);
- (void)fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
- lt->tm_min);
+ fprintf (f, "%02u/%02u/%04u @ %02u:%02u", lt->tm_mon + 1, lt->tm_mday,
+ 1900 + lt->tm_year, lt->tm_hour, lt->tm_min);
t = o->start + o->dur;
lt = localtime (&t);
- (void)fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
- lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
- lt->tm_min);
+ fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ", lt->tm_mon + 1, lt->tm_mday,
+ 1900 + lt->tm_year, lt->tm_hour, lt->tm_min);
if (o->note != NULL)
- (void)fprintf (f, ">%s ", o->note);
+ fprintf (f, ">%s ", o->note);
if (o->state & APOINT_NOTIFY)
- (void)fprintf (f, "!");
+ fputc ('!', f);
else
- (void)fprintf (f, "|");
+ fputc ('|', f);
- (void)fprintf (f, "%s\n", o->mesg);
+ fprintf (f, "%s\n", o->mesg);
}
struct apoint *
@@ -449,10 +446,10 @@ apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
time_t tstart, tend, t;
t = time (NULL);
- (void)localtime (&t);
+ localtime (&t);
/* Read the appointment description */
- (void)fgets (buf, sizeof buf, f);
+ fgets (buf, sizeof buf, f);
newline = strchr (buf, '\n');
if (newline)
*newline = '\0';
@@ -468,7 +465,7 @@ apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
tend = mktime (&end);
EXIT_IF (tstart == -1 || tend == -1 || tstart > tend,
_("date error in appointment"));
- return (apoint_new (buf, note, tstart, tend - tstart, state));
+ return apoint_new (buf, note, tstart, tend - tstart, state);
}
/* Retrieve an appointment from the list, given the day and item position. */
@@ -500,20 +497,18 @@ apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
switch (flag)
{
case ERASE_FORCE_ONLY_NOTE:
- erase_note (&apt->note, flag);
+ erase_note (&apt->note);
break;
case ERASE_CUT:
- apoint_free_bkp (ERASE_FORCE);
+ apoint_free_bkp ();
apoint_dup (apt, &bkp_cut_apoint);
- erase_note (&apt->note, ERASE_FORCE_KEEP_NOTE);
+ erase_note (&apt->note);
/* FALLTHROUGH */
default:
if (notify_bar ())
need_check_notify = notify_same_item (apt->start);
LLIST_TS_REMOVE (&alist_p, i);
mem_free (apt->mesg);
- if (flag != ERASE_FORCE_KEEP_NOTE && flag != ERASE_CUT)
- erase_note (&apt->note, flag);
mem_free (apt);
if (need_check_notify)
notify_check_next_app (0);
@@ -581,7 +576,7 @@ apoint_scroll_pad_up (int nb_events_inday)
static int
apoint_starts_after (struct apoint *apt, long time)
{
- return (apt->start > time);
+ return apt->start > time;
}
/*
@@ -611,7 +606,7 @@ apoint_check_next (struct notify_app *app, long start)
LLIST_TS_UNLOCK (&alist_p);
- return (app);
+ return app;
}
/*
@@ -627,7 +622,7 @@ apoint_recur_s2apoint_s (struct recur_apoint *p)
a->mesg = mem_strdup (p->mesg);
a->start = p->start;
a->dur = p->dur;
- return (a);
+ return a;
}
/*
@@ -686,7 +681,7 @@ apoint_update_panel (int which_pan)
if (slctd_date.dd < 10)
title_xpos++;
date = date2sec (slctd_date, 0, 0);
- day_write_pad (date, app_width, app_length, hilt);
+ day_write_pad (date, app_width, app_length, (which_pan == APP) ? hilt : 0);
/* Print current date in the top right window corner. */
erase_window_part (win[APP].p, 1, title_lines, win[APP].w - 2,
@@ -726,12 +721,11 @@ apoint_paste_item (void)
bkp_time = get_item_time (bkp_cut_apoint.start);
bkp_start = calendar_get_slctd_day_sec () + bkp_time;
- (void)apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note,
- bkp_start, bkp_cut_apoint.dur,
- bkp_cut_apoint.state);
+ apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note, bkp_start,
+ bkp_cut_apoint.dur, bkp_cut_apoint.state);
if (notify_bar ())
notify_check_added (bkp_cut_apoint.mesg, bkp_start, bkp_cut_apoint.state);
- apoint_free_bkp (ERASE_FORCE_KEEP_NOTE);
+ apoint_free_bkp ();
}