Optional 'format' option added to '-x' flag, help updated

This commit is contained in:
Frederic Culot
2008-08-11 18:08:45 +00:00
parent 1674800d5f
commit d84bb63e93
13 changed files with 217 additions and 113 deletions

View File

@@ -1,4 +1,4 @@
/* $calcurse: args.c,v 1.36 2008/08/10 09:24:46 culot Exp $ */
/* $calcurse: args.c,v 1.37 2008/08/11 18:08:45 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -48,7 +48,7 @@ static void
usage ()
{
char *arg_usage =
_("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]]\n"
_("Usage: calcurse [-h|-v] [-N] [-an] [-t[num]] [-x[format]]\n"
" [-d <date>|<num>] [-s[date]] [-r[range]]\n"
" [-c<file> | -D<dir>]\n");
fputs (arg_usage, stdout);
@@ -120,11 +120,14 @@ help_arg ()
" print todo list and exit. If the optional number [num] is given,\n"
"\tthen only todos having a priority equal to [num] will be returned.\n"
"\tnote: priority number must be between 1 (highest) and 9 (lowest).\n"
"\n -x, --export\n"
" export user data to iCalendar format. Events, appointments and\n"
"\n -x[format], --export[=format]\n"
" export user data to the specified format. Events, appointments and\n"
"\ttodos are converted and echoed to stdout.\n"
"\tTwo possible formats are available: 'ical' and 'pcal'.\n"
"\tIf the optional argument format is not given, ical format is\n"
"\tselected by default.\n"
"\tnote: redirect standard output to export data to a file,\n"
"\tby issuing a command such as: calcurse --export > my_data.ics\n"
"\tby issuing a command such as: calcurse --export > calcurse.dat\n"
"\nFor more information, type '?' from within Calcurse, "
"or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\n");
@@ -578,13 +581,13 @@ parse_args (int argc, char **argv, conf_t *conf)
int vflag = 0; /* -v: print version number */
int xflag = 0; /* -x: export data to iCalendar format */
int tnum = 0;
int tnum = 0, xfmt = 0;
int non_interactive = 0, multiple_flag = 0, load_data = 0;
int no_file = 1;
char *ddate = "", *cfile = NULL, *range = NULL, *startday = NULL;
char *datadir = NULL;
static char *optstr = "hvnNaxt::d:c:r:s:D:";
static char *optstr = "hvnNax::t::d:c:r:s:D:";
struct option longopts[] = {
{"appointment", no_argument, NULL, 'a'},
@@ -598,7 +601,7 @@ parse_args (int argc, char **argv, conf_t *conf)
{"startday", required_argument, NULL, 's'},
{"todo", optional_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'},
{"export", no_argument, NULL, 'x'},
{"export", optional_argument, NULL, 'x'},
{NULL, no_argument, NULL, 0}
};
@@ -675,6 +678,25 @@ parse_args (int argc, char **argv, conf_t *conf)
xflag = 1;
multiple_flag++;
load_data++;
if (optarg != NULL)
{
if (strcmp (optarg, "ical") == 0)
xfmt = IO_EXPORT_ICAL;
else if (strcmp (optarg, "pcal") == 0)
xfmt = IO_EXPORT_PCAL;
else
{
fputs (_("Argumet for '-x' should be either "
"'ical' or 'pcal'\n"), stderr);
usage ();
usage_try ();
return EXIT_FAILURE;
}
}
else
{
xfmt = IO_EXPORT_ICAL;
}
break;
default:
usage ();
@@ -731,7 +753,8 @@ parse_args (int argc, char **argv, conf_t *conf)
{
notify_init_vars ();
custom_load_conf (conf, 0);
io_export_data (IO_EXPORT_NONINTERACTIVE, IO_EXPORT_ICAL, conf);
io_load_todo ();
io_export_data (IO_EXPORT_NONINTERACTIVE, xfmt, conf);
non_interactive = 1;
return (non_interactive);
}

View File

@@ -1,4 +1,4 @@
.\" $calcurse: calcurse.1,v 1.9 2008/08/08 14:22:19 culot Exp $
.\" $calcurse: calcurse.1,v 1.10 2008/08/11 18:08:45 culot Exp $
.\"
.\" Copyright (c) 2004-2008 Frederic Culot
.\"
@@ -23,7 +23,8 @@
Calcurse \- text-based organizer
.SH SYNOPSIS
.B "calcurse "
[\fB-h\fP|\fB-v\fP] [\fB-x\fP] [\fB-N\fP] [\fB-an\fP] [\fB-t\fP[\fInum\fP]]
[\fB-h\fP|\fB-v\fP] [\fB-N\fP] [\fB-an\fP] [\fB-t\fP[\fInum\fP]]
[\fB-x\fP[\fIformat\fP]]
.br
[\fB-d\fP <\fIdate\fP>|<\fInum\fP>] [\fB-s\fP[\fIdate\fP]]
[\fB-r\fP[\fIrange\fP]]
@@ -110,14 +111,17 @@ then only todos having a priority equal to \fInum\fP will be returned.
\fB-v\fP, \fB--version\fP
Display calcurse version and exit.
.TP
\fB-x\fP, \fB--export\fP
Export user data to iCalendar format. Events, appointments and
todos are converted and echoed to stdout.
\fB-x\fP[format], \fB--export\fP[=format]
Export user data to the specified format. Events, appointments and
todos are converted and echoed to stdout. Two possible formats are
available: \fIical\fP and \fIpcal\fP.
If the optional argument format is not given, ical format is
selected by default.
.br
\fINote:\fP redirect standard output to export data to a file,
by issuing a command such as:
.br
.B $ calcurse --export > my_data.ics
.B $ calcurse --export > calcurse.dat
.SH NOTES
Calcurse interface contains three different panels (calendar,
appointment list, and todo list) on which you can perform different
@@ -193,7 +197,12 @@ author, below.
.SH SEE ALSO
vi(1), less(1), ncurses(3), mkstemp(3)
.br
Calcurse home page : http://culot.org/calcurse/
The ical specification (rfc2445) can be found at:
http://tools.ietf.org/html/rfc2445
.br
The pcal project page: http://pcal.sourceforge.net/
.br
Calcurse home page: http://culot.org/calcurse/
.br
Calcurse complete manual, translated in many languages and maintained in
html format, can be found in the doc/ directory of the source package,

View File

@@ -1,4 +1,4 @@
/* $calcurse: help.c,v 1.27 2008/08/03 18:41:55 culot Exp $ */
/* $calcurse: help.c,v 1.28 2008/08/11 18:08:45 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -301,10 +301,16 @@ help_screen (void)
hscr[HELP_EXPORT].title = _("Export:\n");
hscr[HELP_EXPORT].text =
_("Pressing 'X' exports the Calcurse data to iCalendar format.\n\n"
_("Pressing 'X' leads to the export submenu, from which you can choose\n"
"between two different export formats: 'ical' and 'pcal'.\n"
"Choosing one of those formats lets you export the Calcurse data to\n"
"icalendar or pcal format.\n\n"
"You first need to specify the file to which the data will be exported.\n"
"By default, this file is:\n\n"
" ~/calcurse.ics\n\n"
"for an ical export, and:\n\n"
" ~/calcurse.txt\n\n"
"for a pcal export.\n"
"All of the calcurse data are exported, in the following order:\n"
"events, appointments, todos.\n");

View File

@@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.31 2008/08/10 09:24:46 culot Exp $ */
/* $calcurse: io.c,v 1.32 2008/08/11 18:08:45 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -40,6 +40,9 @@
#include "apoint.h"
#include "io.h"
#define ICALDATEFMT "%Y%m%d"
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
typedef enum
{
PROGRESS_BAR_SAVE,
@@ -282,7 +285,7 @@ ical_export_recur_events (FILE *stream)
for (i = recur_elist; i != 0; i = i->next)
{
date_sec2ical_date (i->day, ical_date);
date_sec2date_fmt (i->day, ICALDATEFMT, ical_date);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_date);
fprintf (stream, "RRULE:FREQ=%s;INTERVAL=%d",
@@ -290,7 +293,7 @@ ical_export_recur_events (FILE *stream)
if (i->rpt->until != 0)
{
date_sec2ical_date (i->rpt->until, ical_date);
date_sec2date_fmt (i->rpt->until, ICALDATEFMT, ical_date);
fprintf (stream, ";UNTIL=%s\n", ical_date);
}
else
@@ -298,11 +301,11 @@ ical_export_recur_events (FILE *stream)
if (i->exc != NULL)
{
date_sec2ical_date (i->exc->st, ical_date);
date_sec2date_fmt (i->exc->st, ICALDATEFMT, ical_date);
fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next)
{
date_sec2ical_date (day->st, ical_date);
date_sec2date_fmt (day->st, ICALDATEFMT, ical_date);
fprintf (stream, ",%s", ical_date);
}
fprintf (stream, "\n");
@@ -403,7 +406,7 @@ ical_export_events (FILE *stream)
for (i = eventlist; i != 0; i = i->next)
{
date_sec2ical_date (i->day, ical_date);
date_sec2date_fmt (i->day, ICALDATEFMT, ical_date);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_date);
fprintf (stream, "SUMMARY:%s\n", i->mesg);
@@ -434,7 +437,7 @@ ical_export_recur_apoints (FILE *stream)
pthread_mutex_lock (&(recur_alist_p->mutex));
for (i = recur_alist_p->root; i != 0; i = i->next)
{
date_sec2ical_datetime (i->start, ical_datetime);
date_sec2date_fmt (i->start, ICALDATETIMEFMT, ical_datetime);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_datetime);
fprintf (stream, "DURATION:P%ldS\n", i->dur);
@@ -443,7 +446,7 @@ ical_export_recur_apoints (FILE *stream)
if (i->rpt->until != 0)
{
date_sec2ical_date (i->rpt->until + HOURINSEC, ical_date);
date_sec2date_fmt (i->rpt->until + HOURINSEC, ICALDATEFMT, ical_date);
fprintf (stream, ";UNTIL=%s\n", ical_date);
}
else
@@ -451,11 +454,11 @@ ical_export_recur_apoints (FILE *stream)
if (i->exc != NULL)
{
date_sec2ical_date (i->exc->st, ical_date);
date_sec2date_fmt (i->exc->st, ICALDATEFMT, ical_date);
fprintf (stream, "EXDATE:%s", ical_date);
for (day = i->exc->next; day; day = day->next)
{
date_sec2ical_date (day->st, ical_date);
date_sec2date_fmt (day->st, ICALDATEFMT, ical_date);
fprintf (stream, ",%s", ical_date);
}
fprintf (stream, "\n");
@@ -540,7 +543,7 @@ ical_export_apoints (FILE *stream)
pthread_mutex_lock (&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next)
{
date_sec2ical_datetime (i->start, ical_datetime);
date_sec2date_fmt (i->start, ICALDATETIMEFMT, ical_datetime);
fprintf (stream, "BEGIN:VEVENT\n");
fprintf (stream, "DTSTART:%s\n", ical_datetime);
fprintf (stream, "DURATION:P%ldS\n", i->dur);

View File

@@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.47 2008/08/10 09:24:46 culot Exp $ */
/* $calcurse: utils.c,v 1.48 2008/08/11 18:08:45 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -556,45 +556,7 @@ date_sec2date_str (long sec, char *datefmt)
return (datestr);
}
/*
* Return a string containing an iCal date, given a date in
* seconds. This is used to build all-day long iCal VEVENT
* (calcurse event equivalent).
*/
void
date_sec2ical_date (long sec, char *ical_date)
{
#define DATELENGTH 9
struct tm *lt;
time_t t;
t = sec;
lt = localtime (&t);
strftime (ical_date, DATELENGTH, "%Y%m%d", lt);
}
/*
* Return a string containing an iCal date-time, given a date in
* seconds. This is used to build iCal VEVENT (calcurse appointment equivalent).
*/
void
date_sec2ical_datetime (long sec, char *ical_datetime)
{
#define DATETIMELENGTH 16
struct tm *lt;
time_t t;
t = sec;
lt = localtime (&t);
strftime (ical_datetime, DATETIMELENGTH, "%Y%m%dT%H%M%S", lt);
}
/*
* At least a generic function to format date...
* I promise I will learn how to code someday.
*/
/* Generic function to format date. */
void
date_sec2date_fmt (long sec, const char *fmt, char *datef)
{

View File

@@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.31 2008/08/10 09:24:46 culot Exp $ */
/* $calcurse: utils.h,v 1.32 2008/08/11 18:08:45 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -89,8 +89,6 @@ void status_bar (void);
long date2sec (date_t, unsigned, unsigned);
char *date_sec2hour_str (long);
char *date_sec2date_str (long, char *);
void date_sec2ical_date (long, char *);
void date_sec2ical_datetime (long, char *);
void date_sec2date_fmt (long, const char *, char *);
long date_sec_change (long, int, int);
long update_time_in_date (long, unsigned, unsigned);