From c3f532d814e555abf67efb136491956428f19965 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 1 Jul 2011 14:43:44 +0200 Subject: 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 --- src/calcurse.h | 1 + src/day.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'src') 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 (); +} -- cgit v1.2.3-70-g09d2