diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-01 14:43:44 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-05 16:19:17 +0200 |
commit | c3f532d814e555abf67efb136491956428f19965 (patch) | |
tree | abc4ade3a94b47b0291a3529b7ecccd75a4a0c02 /src/day.c | |
parent | b0b994896c22c0a55ef196bd186b42c7b189fadc (diff) | |
download | 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>
Diffstat (limited to 'src/day.c')
-rw-r--r-- | src/day.c | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -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 (); +} |