aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-07-01 14:43:44 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-07-05 16:19:17 +0200
commitc3f532d814e555abf67efb136491956428f19965 (patch)
treeabc4ade3a94b47b0291a3529b7ecccd75a4a0c02
parentb0b994896c22c0a55ef196bd186b42c7b189fadc (diff)
downloadcalcurse-c3f532d814e555abf67efb136491956428f19965.tar.gz
calcurse-c3f532d814e555abf67efb136491956428f19965.zip
Add day_pipe_item() function
Serializes an appointment or an event, prompts for a shell command and executes that command in a new process, piping serialized item data to its stdin. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/calcurse.h1
-rw-r--r--src/day.c55
2 files changed, 56 insertions, 0 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index 45c01e5..f753d97 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -637,6 +637,7 @@ struct day_item *day_get_item (int);
int day_item_nb (long, int, int);
void day_edit_note (char *);
void day_view_note (char *);
+void day_pipe_item (struct conf *);
/* dmon.c */
void dmon_start (int);
diff --git a/src/day.c b/src/day.c
index 7ad0b27..ffbe567 100644
--- a/src/day.c
+++ b/src/day.c
@@ -1098,3 +1098,58 @@ day_view_note (char *pager)
(void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, p->note);
wins_launch_external (fullname, pager);
}
+
+/* Pipe an appointment or event to an external program. */
+void
+day_pipe_item (struct conf *conf)
+{
+ char cmd[BUFSIZ] = "";
+ int pout;
+ int pid;
+ FILE *fpout;
+ int item_num;
+ long date;
+ struct day_item *p;
+ struct recur_apoint *ra;
+ struct apoint *a;
+ struct recur_event *re;
+ struct event *e;
+
+ status_mesg (_("Pipe item to external command:"), "");
+ if (getstring (win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
+ return;
+
+ wins_prepare_external ();
+ if ((pid = shell_exec (NULL, &pout, cmd)))
+ {
+ fpout = fdopen (pout, "w");
+
+ item_num = apoint_hilt ();
+ p = day_get_item (item_num);
+ date = calendar_get_slctd_day_sec ();
+ switch (p->type)
+ {
+ case RECUR_EVNT:
+ re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
+ recur_event_write (re, fpout);
+ break;
+ case EVNT:
+ e = event_get (date, day_item_nb (date, item_num, EVNT));
+ event_write (e, fpout);
+ break;
+ case RECUR_APPT:
+ ra = recur_get_apoint (date, day_item_nb (date, item_num, RECUR_APPT));
+ recur_apoint_write (ra, fpout);
+ break;
+ case APPT:
+ a = apoint_get (date, day_item_nb (date, item_num, APPT));
+ apoint_write (a, fpout);
+ break;
+ }
+
+ fclose (fpout);
+ child_wait (NULL, &pout, pid);
+ press_any_key ();
+ }
+ wins_unprepare_external ();
+}