diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-07-06 14:18:26 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-07-06 14:18:26 +0200 |
commit | 0c43cda93477443a4690988a579e0900b099625a (patch) | |
tree | ea4e8896332abe8e99aa9027a93d06967204b101 /src | |
parent | d83cdd97922deb3d6780e799b58015162989cbdc (diff) |
write to stdin of print command
Diffstat (limited to 'src')
-rw-r--r-- | src/flpsed.cxx | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/flpsed.cxx b/src/flpsed.cxx index 9e7582f..e1bbe77 100644 --- a/src/flpsed.cxx +++ b/src/flpsed.cxx @@ -213,8 +213,8 @@ void save_cb() { } void print_cb() { - char *pref_cmd, tmpname[256]; - int r, tmp_fd; + char *pref_cmd; + int r; const char *print_cmd; Fl_Preferences prefs(Fl_Preferences::USER, "Johannes.HofmannATgmx.de", "flpsed"); @@ -227,27 +227,17 @@ void print_cb() { if (strcmp(print_cmd, pref_cmd)) prefs.set("printCommand", print_cmd); - strncpy(tmpname, "/tmp/flpsedXXXXXX", sizeof(tmpname)); - tmp_fd = mkstemp(tmpname); - - if (tmp_fd >= 0) { - FILE *fp = fdopen(tmp_fd, "w"); + FILE *fp = popen(print_cmd, "w"); + if (fp) { + signal(SIGPIPE, SIG_IGN); r = psed_p->save(fp); fclose(fp); - - if (r == 0) { - int len = strlen(tmpname) + strlen(print_cmd) + 10; - char *buf = (char*) malloc (len); - snprintf(buf, len, "%s %s", print_cmd, tmpname); - system(buf); - free(buf); - } else { - fprintf(stderr, "Failed to print file\n"); - } - - unlink(tmpname); + signal(SIGPIPE, SIG_DFL); } + + if (!fp || r) + fprintf(stderr, "Print Command %s failed\n", print_cmd); } void about_cb() { |