aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xChangeLog5
-rwxr-xr-xTODO2
-rwxr-xr-xsrc/args.c47
-rwxr-xr-xsrc/calcurse.c8
-rwxr-xr-xsrc/calendar.c32
-rwxr-xr-xsrc/calendar.h6
-rwxr-xr-xsrc/custom.c61
-rwxr-xr-xsrc/custom.h6
-rwxr-xr-xsrc/day.c34
-rwxr-xr-xsrc/day.h5
-rwxr-xr-xsrc/io.c12
-rwxr-xr-xsrc/recur.c28
-rwxr-xr-xsrc/recur.h4
-rwxr-xr-xsrc/utils.c92
-rwxr-xr-xsrc/utils.h6
-rwxr-xr-xsrc/vars.c7
-rwxr-xr-xsrc/vars.h12
17 files changed, 229 insertions, 138 deletions
diff --git a/ChangeLog b/ChangeLog
index 38970a4..3b66c05 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+09 Apr 2008:
+ Tony's patch concerning date format configuration imported, many
+ thanks to him
+ TODO list updated
+
05 Apr 2008:
'-N' flag added, which allows the display of note contents in
non-interactive mode (many thanks to Erik Saule for submiting
diff --git a/TODO b/TODO
index 7582beb..0effaca 100755
--- a/TODO
+++ b/TODO
@@ -21,8 +21,6 @@ High
Average
-------
o Improve the '-d' option by adding more date formats
- o Accept dates entered in other formats such as d/m/yyyy or d/m/yy,
- make the date format user configurable
o Make keys user configurable
o Add searching capabilities with support for regex
diff --git a/src/args.c b/src/args.c
index c933266..5701a09 100755
--- a/src/args.c
+++ b/src/args.c
@@ -1,8 +1,8 @@
-/* $calcurse: args.c,v 1.30 2008/04/05 14:55:59 culot Exp $ */
+/* $calcurse: args.c,v 1.31 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -230,7 +230,7 @@ next_arg(void)
* Print the date on stdout.
*/
static void
-arg_print_date(long date)
+arg_print_date(long date, conf_t *conf)
{
char date_str[BUFSIZ];
time_t t;
@@ -238,8 +238,7 @@ arg_print_date(long date)
t = date;
lt = localtime(&t);
- snprintf(date_str, BUFSIZ, "%02u/%02u/%04u",
- lt->tm_mon+1, lt->tm_mday, 1900+lt->tm_year);
+ strftime(date_str, BUFSIZ, conf->output_datefmt, lt);
fputs(date_str,stdout);
fputs(":\n",stdout);
}
@@ -250,7 +249,7 @@ arg_print_date(long date)
* If there is also no date given, current date is considered.
*/
static int
-app_arg(int add_line, date_t *day, long date, int print_note)
+app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
{
struct recur_event_s *re;
struct event_s *j;
@@ -281,7 +280,7 @@ app_arg(int add_line, date_t *day, long date, int print_note)
add_line = 0;
}
if (print_date) {
- arg_print_date(today);
+ arg_print_date(today, conf);
print_date = false;
}
fputs(" * ", stdout);
@@ -299,7 +298,7 @@ app_arg(int add_line, date_t *day, long date, int print_note)
add_line = 0;
}
if (print_date) {
- arg_print_date(today);
+ arg_print_date(today, conf);
print_date = false;
}
fputs(" * ", stdout);
@@ -321,7 +320,7 @@ app_arg(int add_line, date_t *day, long date, int print_note)
add_line = 0;
}
if (print_date) {
- arg_print_date(today);
+ arg_print_date(today, conf);
print_date = false;
}
apoint_sec2str(apoint_recur_s2apoint_s(ra),
@@ -349,7 +348,7 @@ app_arg(int add_line, date_t *day, long date, int print_note)
add_line = 0;
}
if (print_date) {
- arg_print_date(today);
+ arg_print_date(today, conf);
print_date = false;
}
apoint_sec2str(i, APPT, today, apoint_start_time,
@@ -375,13 +374,12 @@ app_arg(int add_line, date_t *day, long date, int print_note)
* days.
*/
static void
-date_arg(char *ddate, int add_line, int print_note)
+date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
{
int i;
date_t day;
int numdays = 0, num_digit = 0;
int arg_len = 0, app_found = 0;
- int date_valid = 0;
static struct tm t;
time_t timer;
@@ -410,22 +408,23 @@ date_arg(char *ddate, int add_line, int print_note)
day.dd = t.tm_mday;
day.mm = t.tm_mon + 1;
day.yyyy = t.tm_year + 1900;
- app_found = app_arg(add_line, &day, 0, print_note);
+ app_found = app_arg(add_line, &day, 0, print_note, conf);
if (app_found)
add_line = 1;
t.tm_mday++;
mktime(&t);
}
} else { /* a date was entered */
- date_valid = check_date(ddate);
- if (date_valid) {
- sscanf(ddate, "%d / %d / %d", &day.mm, &day.dd, &day.yyyy);
- app_found = app_arg(add_line, &day, 0, print_note);
+ if (parse_date(ddate, conf->input_datefmt,
+ &day.yyyy, &day.mm, &day.dd)) {
+ app_found = app_arg(add_line, &day, 0, print_note, conf);
} else {
fputs(_("Argument to the '-d' flag is not valid\n"),
stdout);
- fputs(_("Possible argument formats are : 'mm/dd/yyyy' or 'n'\n"),
- stdout);
+ char outstr[BUFSIZ];
+ snprintf(outstr, BUFSIZ, "Possible argument format are: '%s' or 'n'\n",
+ DATEFMT_DESC(conf->input_datefmt));
+ fputs(_(outstr), stdout);
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"),
stdout);
fputs
@@ -575,12 +574,18 @@ parse_args(int argc, char **argv, conf_t *conf)
non_interactive = 1;
}
if (dflag) {
- date_arg(ddate, add_line, Nflag);
+ notify_init_vars();
+ vars_init(conf);
+ custom_load_conf(conf, 0);
+ date_arg(ddate, add_line, Nflag, conf);
non_interactive = 1;
} else if (aflag) {
date_t day;
day.dd = day.mm = day.yyyy = 0;
- app_found = app_arg(add_line, &day, 0, Nflag);
+ notify_init_vars();
+ vars_init(conf);
+ custom_load_conf(conf, 0);
+ app_found = app_arg(add_line, &day, 0, Nflag, conf);
non_interactive = 1;
}
} else {
diff --git a/src/calcurse.c b/src/calcurse.c
index d004ae8..4e7acb7 100755
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -1,4 +1,4 @@
-/* $calcurse: calcurse.c,v 1.60 2008/01/13 12:40:45 culot Exp $ */
+/* $calcurse: calcurse.c,v 1.61 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -220,7 +220,7 @@ main(int argc, char **argv)
case 'g': /* Goto function */
erase_status_bar();
calendar_set_current_date();
- calendar_change_day();
+ calendar_change_day(conf.input_datefmt);
do_storage = true;
day_changed = true;
break;
@@ -305,7 +305,7 @@ main(int argc, char **argv)
case 'E':
case 'e': /* Edit an existing item */
if (wins_slctd() == APP && apoint_hilt() != 0)
- day_edit_item();
+ day_edit_item(&conf);
else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_edit_item();
do_storage = true;
@@ -324,7 +324,7 @@ main(int argc, char **argv)
case 'R':
case 'r':
if (wins_slctd() == APP && apoint_hilt() != 0)
- recur_repeat_item();
+ recur_repeat_item(&conf);
do_storage = true;
break;
diff --git a/src/calendar.c b/src/calendar.c
index f5255be..93b461c 100755
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -1,8 +1,8 @@
-/* $calcurse: calendar.c,v 1.13 2007/12/10 18:59:48 culot Exp $ */
+/* $calcurse: calendar.c,v 1.14 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -332,10 +332,11 @@ calendar_update_panel(WINDOW *cwin)
* with the newly selected date.
*/
void
-calendar_change_day(void)
+calendar_change_day(int datefmt)
{
#define LDAY 11
char selected_day[LDAY] = "";
+ char outstr[BUFSIZ];
date_t today;
int dday, dmonth, dyear;
int wrong_day = 1;
@@ -343,10 +344,12 @@ calendar_change_day(void)
_("The day you entered is not valid (should be between 01/01/1902 and 12/31/2037)");
char *mesg_line2 = _("Press [ENTER] to continue");
char *request_date =
- _("Enter the day to go to [ENTER for today] : mm/dd/yyyy");
+ "Enter the day to go to [ENTER for today] : %s";
while (wrong_day) {
- status_mesg(request_date, "");
+ snprintf(outstr, BUFSIZ, request_date,
+ DATEFMT_DESC(datefmt));
+ status_mesg(_(outstr), "");
if (getstring(win[STA].p, selected_day, LDAY, 0, 1) ==
GETSTRING_ESC)
return;
@@ -364,24 +367,15 @@ calendar_change_day(void)
wrong_day = 1;
- } else {
+ } else if (parse_date(selected_day, datefmt,
+ &dyear, &dmonth, &dday)) {
- sscanf(selected_day, "%u/%u/%u",
- &dmonth, &dday, &dyear);
wrong_day = 0;
- /* basic check on entered date */
- if ((dday <= 0) || (dday >= 32) ||
- (dmonth <= 0) || (dmonth >= 13) ||
- (dyear <= 1901) || (dyear >= 2038))
- wrong_day = 1;
-
/* go to chosen day */
- if (wrong_day != 1) {
- slctd_day.dd = dday;
- slctd_day.mm = dmonth;
- slctd_day.yyyy = dyear;
- }
+ slctd_day.dd = dday;
+ slctd_day.mm = dmonth;
+ slctd_day.yyyy = dyear;
}
if (wrong_day) {
diff --git a/src/calendar.h b/src/calendar.h
index 4c4a8f4..270ab97 100755
--- a/src/calendar.h
+++ b/src/calendar.h
@@ -1,8 +1,8 @@
-/* $calcurse: calendar.h,v 1.8 2007/12/10 19:00:45 culot Exp $ */
+/* $calcurse: calendar.h,v 1.9 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -79,7 +79,7 @@ void calendar_init_slctd_day(void);
date_t *calendar_get_slctd_day(void);
long calendar_get_slctd_day_sec(void);
void calendar_update_panel(WINDOW *);
-void calendar_change_day(void);
+void calendar_change_day(int datefmt);
void calendar_move(move_t);
char *calendar_get_pom(time_t);
diff --git a/src/custom.c b/src/custom.c
index 2f17391..ce77cde 100755
--- a/src/custom.c
+++ b/src/custom.c
@@ -1,8 +1,8 @@
-/* $calcurse: custom.c,v 1.18 2008/02/16 13:14:04 culot Exp $ */
+/* $calcurse: custom.c,v 1.19 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -285,7 +285,18 @@ custom_load_conf(conf_t *conf, int background)
strncpy(nbar->cmd, e_conf, strlen(e_conf) + 1);
var = 0;
break;
- default:
+ case CUSTOM_CONF_OUTPUTDATEFMT:
+ if (e_conf[0] != '\0')
+ strncpy(conf->output_datefmt, e_conf, strlen(e_conf) + 1);
+ var = 0;
+ break;
+ case CUSTOM_CONF_INPUTDATEFMT:
+ conf->input_datefmt = atoi(e_conf);
+ if (conf->input_datefmt < 1 || conf->input_datefmt > 3)
+ conf->input_datefmt = 1;
+ var = 0;
+ break;
+ default:
fputs(_("FATAL ERROR in custom_load_conf: "
"configuration variable unknown.\n"), stderr);
exit(EXIT_FAILURE);
@@ -318,6 +329,10 @@ custom_load_conf(conf_t *conf, int background)
var = CUSTOM_CONF_NOTIFYBARWARNING;
else if (strncmp(e_conf, "notify-bar_command=", 19) ==0)
var = CUSTOM_CONF_NOTIFYBARCOMMAND;
+ else if (strncmp(e_conf, "output_datefmt=", 12) ==0)
+ var = CUSTOM_CONF_OUTPUTDATEFMT;
+ else if (strncmp(e_conf, "input_datefmt=", 12) ==0)
+ var = CUSTOM_CONF_INPUTDATEFMT;
}
fclose(data_file);
pthread_mutex_unlock(&nbar->mutex);
@@ -675,6 +690,8 @@ custom_print_general_options(WINDOW *optwin, conf_t *conf)
char *option4 = _("skip_system_dialogs = ");
char *option5 = _("skip_progress_bar = ");
char *option6 = _("week_begins_on_monday = ");
+ char *option7 = _("output_datefmt = ");
+ char *option8 = _("input_datefmt = ");
x_pos = 3;
y_pos = 3;
@@ -715,6 +732,22 @@ custom_print_general_options(WINDOW *optwin, conf_t *conf)
mvwprintw(optwin, y_pos + 16, x_pos,
_("(if set to YES, monday is the first day of the week, else it is sunday)"));
+ mvwprintw(optwin, y_pos + 18, x_pos, "[7] %s ", option7);
+ custom_apply_attr(optwin, ATTR_HIGHEST);
+ mvwprintw(optwin, y_pos + 18, x_pos + 4 + strlen(option7), "%s",
+ conf->output_datefmt);
+ custom_remove_attr(optwin, ATTR_HIGHEST);
+ mvwprintw(optwin, y_pos + 19, x_pos,
+ _("(Format of the date to be displayed in non-interactive mode)"));
+
+ mvwprintw(optwin, y_pos + 21, x_pos, "[8] %s ", option8);
+ custom_apply_attr(optwin, ATTR_HIGHEST);
+ mvwprintw(optwin, y_pos + 21, x_pos + 4 + strlen(option7), "%d",
+ conf->input_datefmt);
+ custom_remove_attr(optwin, ATTR_HIGHEST);
+ mvwprintw(optwin, y_pos + 22, x_pos,
+ _("(Format to be used when entering a date: 1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd)"));
+
wmove(win[STA].p, 1, 0);
wnoutrefresh(optwin);
doupdate();
@@ -726,8 +759,13 @@ custom_general_config(conf_t *conf)
{
window_t conf_win;
char *number_str = _("Enter an option number to change its value [Q to quit] ");
+ char *output_datefmt_str =
+ _("Enter the date format (see 'man 3 strftime' for possible formats) ");
+ char *input_datefmt_str =
+ _("Enter the date format (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) ");
int ch;
char label[BUFSIZ];
+ char *buf = (char *) malloc(BUFSIZ);
clear();
snprintf(label, BUFSIZ, _("CalCurse %s | general options"), VERSION);
@@ -772,9 +810,26 @@ custom_general_config(conf_t *conf)
case '6':
calendar_change_first_day_of_week();
break;
+ case '7':
+ status_mesg(output_datefmt_str, "");
+ strncpy(buf, conf->output_datefmt, strlen(conf->output_datefmt) + 1);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ strncpy(conf->output_datefmt, buf, strlen(buf) + 1);
+ }
+ status_mesg(number_str, "");
+ break;
+ case '8':
+ status_mesg(input_datefmt_str, "");
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ int val = atoi(buf);
+ if (val >= 1 && val <= 3) conf->input_datefmt = val;
+ }
+ status_mesg(number_str, "");
+ break;
}
status_mesg(number_str, "");
custom_print_general_options(conf_win.p, conf);
}
+ free(buf);
delwin(conf_win.p);
}
diff --git a/src/custom.h b/src/custom.h
index 71909c2..fd9d78a 100755
--- a/src/custom.h
+++ b/src/custom.h
@@ -1,8 +1,8 @@
-/* $calcurse: custom.h,v 1.10 2007/10/21 13:41:29 culot Exp $ */
+/* $calcurse: custom.h,v 1.11 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -59,6 +59,8 @@ enum { /* Configuration variables */
CUSTOM_CONF_NOTIFYBARCLOCK,
CUSTOM_CONF_NOTIFYBARWARNING,
CUSTOM_CONF_NOTIFYBARCOMMAND,
+ CUSTOM_CONF_OUTPUTDATEFMT,
+ CUSTOM_CONF_INPUTDATEFMT,
CUSTOM_CONF_VARIABLES
};
diff --git a/src/day.c b/src/day.c
index 9d7fe79..e2a587f 100755
--- a/src/day.c
+++ b/src/day.c
@@ -1,4 +1,4 @@
-/* $calcurse: day.c,v 1.34 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: day.c,v 1.35 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -564,11 +564,12 @@ update_desc(char **desc)
}
static void
-update_rept(struct rpt_s **rpt, const long start)
+update_rept(struct rpt_s **rpt, const long start, conf_t *conf)
{
const int SINGLECHAR = 2;
- int ch, cancel, newfreq, date_entered, valid_date;
+ int ch, cancel, newfreq, date_entered;
long newuntil;
+ char outstr[BUFSIZ];
char *typstr, *freqstr, *timstr;
char *msg_rpt_type =
_("Enter the new repetition type: (D)aily, (W)eekly, "
@@ -578,8 +579,8 @@ update_rept(struct rpt_s **rpt, const long start)
char *msg_wrong_time =
_("Invalid time: start time must be before end time!");
char *msg_wrong_date = _("The entered date is not valid.");
- char *msg_fmts = _("Possible formats are [mm/dd/yyyy] or '0' "
- "for an endless repetetition");
+ char *msg_fmts = "Possible formats are [%s] or '0' "
+ "for an endless repetetition";
char *msg_enter = _("Press [Enter] to continue");
do {
@@ -615,9 +616,10 @@ update_rept(struct rpt_s **rpt, const long start)
} while (newfreq == 0);
do {
- status_mesg(_("Enter the new ending date: [mm/dd/yyyy] or '0'"),
- "");
- timstr = date_sec2date_str((*rpt)->until);
+ snprintf(outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
+ DATEFMT_DESC(conf->input_datefmt));
+ status_mesg(_(outstr), "");
+ timstr = date_sec2date_str((*rpt)->until, DATEFMT(conf->input_datefmt));
cancel = updatestring(win[STA].p, &timstr, 0, 1);
if (cancel) {
free(timstr);
@@ -632,10 +634,8 @@ update_rept(struct rpt_s **rpt, const long start)
date_t new_date;
int newmonth, newday, newyear;
- valid_date = check_date(timstr);
- if (valid_date) {
- sscanf(timstr, "%d / %d / %d",
- &newmonth, &newday, &newyear);
+ if (parse_date(timstr, conf->input_datefmt,
+ &newyear, &newmonth, &newday)) {
t = start;
lt = localtime(&t);
new_date.dd = newday;
@@ -650,7 +650,9 @@ update_rept(struct rpt_s **rpt, const long start)
} else
date_entered = 1;
} else {
- status_mesg(msg_wrong_date, msg_fmts);
+ snprintf(outstr, BUFSIZ, msg_fmts,
+ DATEFMT_DESC(conf->input_datefmt));
+ status_mesg(msg_wrong_date, _(outstr));
wgetch(win[STA].p);
date_entered = 0;
}
@@ -665,7 +667,7 @@ update_rept(struct rpt_s **rpt, const long start)
/* Edit an already existing item. */
void
-day_edit_item(void)
+day_edit_item(conf_t *conf)
{
#define STRT '1'
#define END '2'
@@ -698,7 +700,7 @@ day_edit_item(void)
update_desc(&re->mesg);
break;
case '2':
- update_rept(&re->rpt, re->day);
+ update_rept(&re->rpt, re->day, conf);
break;
default:
return;
@@ -727,7 +729,7 @@ day_edit_item(void)
update_desc(&ra->mesg);
break;
case REPT:
- update_rept(&ra->rpt, ra->start);
+ update_rept(&ra->rpt, ra->start, conf);
break;
case ESCAPE:
return;
diff --git a/src/day.h b/src/day.h
index 8412777..10bf3a5 100755
--- a/src/day.h
+++ b/src/day.h
@@ -1,4 +1,4 @@
-/* $calcurse: day.h,v 1.17 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: day.h,v 1.18 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -27,6 +27,7 @@
#ifndef CALCURSE_DAY_H
#define CALCURSE_DAY_H
+#include "vars.h"
#include "utils.h"
#include "calendar.h"
@@ -66,7 +67,7 @@ day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *);
void day_write_pad(long, int, int, int);
void day_popup_item(void);
int day_check_if_item(date_t);
-void day_edit_item(void);
+void day_edit_item(conf_t *);
int day_erase_item(long, int, erase_flag_e);
struct day_item_s *day_get_item(int);
int day_item_nb(long, int, int);
diff --git a/src/io.c b/src/io.c
index bb300d5..2396cc7 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.27 2008/01/20 10:45:38 culot Exp $ */
+/* $calcurse: io.c,v 1.28 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -486,6 +486,16 @@ io_save_cal(conf_t *conf)
fprintf(data_file, "notify-bar_command=\n");
fprintf(data_file, "%s\n", nbar->cmd);
+ fprintf(data_file,
+ "\n# Format of the date to be displayed in non-interactive mode :\n");
+ fprintf(data_file, "output_datefmt=\n");
+ fprintf(data_file, "%s\n", conf->output_datefmt);
+
+ fprintf(data_file,
+ "\n# Format to be used when entering a date (1-mm/dd/yyyy, 2-dd/mm/yyyy, 3-yyyy/mm/dd) :\n");
+ fprintf(data_file, "input_datefmt=\n");
+ fprintf(data_file, "%d\n", conf->input_datefmt);
+
pthread_mutex_unlock(&nbar->mutex);
fclose(data_file);
diff --git a/src/recur.c b/src/recur.c
index 740f10b..22f477e 100755
--- a/src/recur.c
+++ b/src/recur.c
@@ -1,4 +1,4 @@
-/* $calcurse: recur.c,v 1.33 2008/01/20 10:45:39 culot Exp $ */
+/* $calcurse: recur.c,v 1.34 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -601,14 +601,15 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
* and then delete the selected item to recreate it as a recurrent one
*/
void
-recur_repeat_item(void)
+recur_repeat_item(conf_t *conf)
{
struct tm *lt;
time_t t;
int ch = 0;
- int valid_date = 0, date_entered = 0;
+ int date_entered = 0;
int year = 0, month = 0, day = 0;
date_t until_date;
+ char outstr[BUFSIZ];
char user_input[BUFSIZ] = "";
char *mesg_type_1 =
_("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
@@ -618,10 +619,10 @@ recur_repeat_item(void)
char *mesg_wrong_freq =
_("The frequence you entered is not valid.");
char *mesg_until_1 =
- _("Enter the ending date: [mm/dd/yyyy] or '0' for an endless repetition");
+ _("Enter the ending date: [%s] or '0' for an endless repetition");
char *mesg_wrong_1 = _("The entered date is not valid.");
char *mesg_wrong_2 =
- _("Possible formats are [mm/dd/yyyy] or '0' for an endless repetetition");
+ _("Possible formats are [%s] or '0' for an endless repetetition");
char *wrong_type_1 = _("This item is already a repeated one.");
char *wrong_type_2 = _("Press [ENTER] to continue.");
char *mesg_older =
@@ -669,18 +670,18 @@ recur_repeat_item(void)
}
while (!date_entered) {
- status_mesg(mesg_until_1, "");
- if (getstring(win[STA].p, user_input, 11, 0, 1) ==
+ snprintf(outstr, BUFSIZ, mesg_until_1,
+ DATEFMT_DESC(conf->input_datefmt));
+ status_mesg(_(outstr), "");
+ if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) ==
GETSTRING_VALID) {
if (strlen(user_input) == 1 &&
strncmp(user_input, "0", 1) == 0 ) {
until = 0;
date_entered = 1;
} else {
- valid_date = check_date(user_input);
- if (valid_date) {
- sscanf(user_input, "%d / %d / %d",
- &month, &day, &year);
+ if (parse_date(user_input, conf->input_datefmt,
+ &year, &month, &day)) {
t = p->start; lt = localtime(&t);
until_date.dd = day;
until_date.mm = month;
@@ -696,7 +697,10 @@ recur_repeat_item(void)
date_entered = 1;
}
} else {
- status_mesg(mesg_wrong_1, mesg_wrong_2);
+ snprintf(outstr, BUFSIZ, mesg_wrong_2,
+ DATEFMT_DESC(conf->input_datefmt));
+ status_mesg(mesg_wrong_1, _(outstr));
+ wgetch(win[STA].p);
date_entered = 0;
}
}
diff --git a/src/recur.h b/src/recur.h
index e039656..0027652 100755
--- a/src/recur.h
+++ b/src/recur.h
@@ -1,4 +1,4 @@
-/* $calcurse: recur.h,v 1.17 2008/01/20 10:45:39 culot Exp $ */
+/* $calcurse: recur.h,v 1.18 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -90,7 +90,7 @@ void recur_event_erase(long, unsigned, unsigned,
erase_flag_e);
void recur_apoint_erase(long, unsigned, unsigned,
erase_flag_e);
-void recur_repeat_item(void);
+void recur_repeat_item(conf_t *);
struct days_s *recur_exc_scan(FILE *);
struct notify_app_s *recur_apoint_check_next(struct notify_app_s *,
long, long);
diff --git a/src/utils.c b/src/utils.c
index d7a9b36..f7f0717 100755
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,4 @@
-/* $calcurse: utils.c,v 1.43 2008/02/11 21:26:01 culot Exp $ */
+/* $calcurse: utils.c,v 1.44 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -512,22 +512,20 @@ char *date_sec2hour_str(long sec)
/* Return a string containing the date, given a date in seconds. */
char *
-date_sec2date_str(long sec)
+date_sec2date_str(long sec, char *datefmt)
{
- const int DATELEN = 11;
struct tm *lt;
time_t t;
char *datestr;
- datestr = (char *)malloc(sizeof(char) * DATELEN);
+ datestr = (char *)malloc(sizeof(char) * BUFSIZ);
if (sec == 0)
- snprintf(datestr, DATELEN, "0");
+ snprintf(datestr, BUFSIZ, "0");
else {
t = sec;
lt = localtime(&t);
- snprintf(datestr, DATELEN, "%02u/%02u/%04u", lt->tm_mon + 1,
- lt->tm_mday, lt->tm_year + 1900);
+ strftime(datestr, BUFSIZ, datefmt, lt);
}
return (datestr);
@@ -616,43 +614,6 @@ get_sec_date(date_t date)
return long_date;
}
-/*
- * Check if the entered date is of a valid format.
- * First check the format by itself, and then check the
- * numbers correctness.
- */
-int
-check_date(char *date)
-{
- int ok = 0;
- char month[3] = "";
- char day[3] = "";
- char year[5] = "";
- if (
- (strlen(date) == 10) &
- (isdigit(date[0]) != 0) &
- (isdigit(date[1]) != 0) &
- (date[2] == '/') &
- (isdigit(date[3]) != 0) &
- (isdigit(date[4]) != 0) &
- (date[5] == '/') &
- (isdigit(date[6])!=0) & (isdigit(date[7])!=0) &
- (isdigit(date[8])!=0) & (isdigit(date[9])!=0)
- ) {
- strncpy(month, date, 2);
- strncpy(day, date + 3, 2);
- strncpy(year, date + 6, 4);
- if ( (atoi(month) <= 12) &
- (atoi(month) >= 1) &
- (atoi(day) <= 31) &
- (atoi(day) >= 1) &
- (atoi(year) <= 9999) &
- (atoi(year) > 1))
- ok = 1;
- }
- return ok;
-}
-
long
min2sec(unsigned minutes)
{
@@ -923,3 +884,46 @@ erase_note(char **note, erase_flag_e flag)
free(*note);
*note = NULL;
}
+/*
+ * Convert a string containing a date into three integers containing the year,
+ * month and day.
+ * Returns 1 if sucessfully converted or 0 if the string is an invalid date.
+ */
+int parse_date(char *date_string, int datefmt,
+ int *year, int *month, int *day) {
+ int in1, in2, in3;
+ int lyear, lmonth, lday;
+ if (date_string == NULL)
+ return 0;
+ if (sscanf(date_string, "%d / %d / %d", &in1, &in2, &in3) < 3 )
+ return 0;
+ switch (datefmt) {
+ case 1:
+ lmonth = in1;
+ lday = in2;
+ lyear = in3;
+ break;
+ case 2:
+ lday = in1;
+ lmonth = in2;
+ lyear = in3;
+ break;
+ case 3:
+ lyear = in1;
+ lmonth = in2;
+ lday = in3;
+ break;
+ default:
+ return (0);
+ }
+ if (lyear < 1 || lyear > 9999 || lmonth < 1 || lmonth > 12 ||
+ lday < 1 || lday > 31)
+ return 0;
+ if (year != NULL)
+ *year = lyear;
+ if (month != NULL)
+ *month = lmonth;
+ if (day != NULL)
+ *day = lday;
+ return (1);
+}
diff --git a/src/utils.h b/src/utils.h
index 051dc4b..5580909 100755
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,4 +1,4 @@
-/* $calcurse: utils.h,v 1.27 2008/02/11 21:26:01 culot Exp $ */
+/* $calcurse: utils.h,v 1.28 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -82,12 +82,11 @@ int is_all_digit(char *);
void status_bar(void);
long date2sec(date_t, unsigned, unsigned);
char *date_sec2hour_str(long);
-char *date_sec2date_str(long);
+char *date_sec2date_str(long, char *);
void date_sec2ical_date(long, char *);
void date_sec2ical_datetime(long, char *);
long update_time_in_date(long, unsigned, unsigned);
long get_sec_date(date_t);
-int check_date(char *);
long min2sec(unsigned);
int check_time(char *);
void draw_scrollbar(WINDOW *, int, int, int, int, int, bool);
@@ -101,5 +100,6 @@ long mystrtol(const char *);
void print_option_incolor(WINDOW *, bool, int, int);
char *new_tempfile(const char *, int);
void erase_note(char **, erase_flag_e);
+int parse_date(char *, int, int *, int *, int *);
#endif /* CALCURSE_UTILS_H */
diff --git a/src/vars.c b/src/vars.c
index 6dab20b..db09bf8 100755
--- a/src/vars.c
+++ b/src/vars.c
@@ -1,8 +1,8 @@
-/* $calcurse: vars.c,v 1.6 2007/12/30 16:27:59 culot Exp $ */
+/* $calcurse: vars.c,v 1.7 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2006 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include "i18n.h"
#include "calendar.h"
@@ -101,6 +102,8 @@ vars_init(conf_t *conf)
conf->auto_save = true;
conf->skip_system_dialogs = false;
conf->skip_progress_bar = false;
+ strncpy(conf->output_datefmt, "%D", 3);
+ conf->input_datefmt = 1;
/* Default external editor and pager */
ed = getenv("VISUAL");
diff --git a/src/vars.h b/src/vars.h
index 515c710..7f3db8f 100755
--- a/src/vars.h
+++ b/src/vars.h
@@ -1,8 +1,8 @@
-/* $calcurse: vars.h,v 1.20 2008/02/13 19:44:37 culot Exp $ */
+/* $calcurse: vars.h,v 1.21 2008/04/09 20:38:29 culot Exp $ */
/*
* Calcurse - text-based organizer
- * Copyright (c) 2004-2007 Frederic Culot
+ * Copyright (c) 2004-2008 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -55,6 +55,12 @@
#define STATUSHEIGHT 2
#define NOTESIZ 6
+#define DATEFMT(datefmt) (datefmt == 1 ? "%m/%d/%Y" : \
+ (datefmt == 2 ? "%d/%m/%Y" : "%Y/%m/%d"))
+
+#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \
+ (datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd")))
+
struct pad_s {
int width;
int length;
@@ -82,6 +88,8 @@ typedef struct {
bool skip_progress_bar;
char *editor;
char *pager;
+ char output_datefmt[BUFSIZ]; /* format for displaying date */
+ int input_datefmt; /* format for reading date */
} conf_t;
extern int col, row;