summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2017-10-18 20:50:31 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2018-08-25 10:03:28 +0200
commit16d30327ba6047cb75fc6852020100bf7bfc6efa (patch)
treea8d58bc7ea4546f7a460ff1f77cc9003d3a9301a
parenta5febe2e22319d35ec65628c910c5210427ca943 (diff)
downloadcalcurse-16d30327ba6047cb75fc6852020100bf7bfc6efa.tar.gz
calcurse-16d30327ba6047cb75fc6852020100bf7bfc6efa.zip
Refactoring update_duration/day_edit_duration.
Incorporated day_edit_duraton() into update_duration(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/ui-day.c104
1 files changed, 49 insertions, 55 deletions
diff --git a/src/ui-day.c b/src/ui-day.c
index f1abf09..702d486 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -80,59 +80,6 @@ static int day_edit_time(int time)
}
}
-/* Request the user to enter a new time or duration. */
-static int day_edit_duration(int start, int dur, unsigned *new_duration)
-{
- char *timestr = mem_strdup("");
- const char *msg_time =
- _("Enter end time ([hh:mm], [hhmm]) or duration ([+hh:mm], [+xxxdxxhxxm]):");
- const char *enter_str = _("Press [Enter] to continue");
- const char *fmt_msg =
- _("You entered an invalid time, should be [hh:mm] or [hhmm]");
- long end;
-
- if (dur > 0)
- timestr = date_sec2date_str(start + dur, "%H:%M");
-
- for (;;) {
- int ret;
-
- status_mesg(msg_time, "");
- ret = updatestring(win[STA].p, &timestr, 0, 1);
- if (ret == GETSTRING_ESC) {
- return 0;
- } else if (ret == GETSTRING_RET) {
- *new_duration = 0;
- break;
- }
- if (*timestr == '+') {
- if (parse_duration(timestr + 1, new_duration)) {
- *new_duration *= MININSEC;
- break;
- }
- }
- end = start + dur;
- ret = parse_datetime(timestr, &end);
- /*
- * If the user enters no date and an end time which is smaller
- * than the start time, assume that the time belongs to the
- * next day.
- */
- if (!(ret & PARSE_DATETIME_HAS_DATE) && end < start)
- end = date_sec_change(end, 0, 1);
- /* Always check that the end comes after the start. */
- if (ret && start <= end) {
- *new_duration = end - start;
- break;
- }
- status_mesg(fmt_msg, enter_str);
- keys_wait_for_any_key(win[KEY].p);
- }
-
- mem_free(timestr);
- return 1;
-}
-
/* Request the user to enter a new end time or duration. */
static void update_start_time(long *start, long *dur, int update_dur)
{
@@ -163,12 +110,59 @@ static void update_start_time(long *start, long *dur, int update_dur)
while (valid_date == 0);
}
+/* Request the user to enter a new end time or duration. */
static void update_duration(long *start, long *dur)
{
+ char *timestr;
+ const char *msg_time =
+ _("Enter end time ([hh:mm], [hhmm]) or duration ([+hh:mm], [+xxxdxxhxxm]):");
+ const char *enter_str = _("Press [Enter] to continue");
+ const char *fmt_msg =
+ _("You entered an invalid time, should be [hh:mm] or [hhmm]");
+ long end;
unsigned newdur;
- if (day_edit_duration(*start, *dur, &newdur))
- *dur = newdur;
+ if (*dur > 0)
+ timestr = date_sec2date_str(*start + *dur, "%H:%M");
+ else
+ timestr = mem_strdup("");
+
+ for (;;) {
+ int ret;
+
+ status_mesg(msg_time, "");
+ ret = updatestring(win[STA].p, &timestr, 0, 1);
+ if (ret == GETSTRING_ESC)
+ return;
+ if (ret == GETSTRING_RET) {
+ newdur = 0;
+ break;
+ }
+ if (*timestr == '+') {
+ if (parse_duration(timestr + 1, &newdur)) {
+ newdur *= MININSEC;
+ break;
+ }
+ }
+ end = *start + *dur;
+ ret = parse_datetime(timestr, &end);
+ /*
+ * If the user enters a end time which is smaller than
+ * the start time, assume that the time belongs to the
+ * next day.
+ */
+ if (!(ret & PARSE_DATETIME_HAS_DATE) && end < *start)
+ end = date_sec_change(end, 0, 1);
+ if (ret) {
+ newdur = end - *start;
+ break;
+ }
+ status_mesg(fmt_msg, enter_str);
+ wgetch(win[KEY].p);
+ }
+
+ mem_free(timestr);
+ *dur = newdur;
}
static void update_desc(char **desc)