summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-07-06 13:46:05 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-07-06 13:46:05 +0200
commitd83cdd97922deb3d6780e799b58015162989cbdc (patch)
tree13e16f0bb9a97583e6371c32ea7041e7b4b42d0b
parent111d49a9265463914b8021a0135d032bda08aab7 (diff)
cleanup print_cb()
-rw-r--r--src/flpsed.cxx43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/flpsed.cxx b/src/flpsed.cxx
index 9a81970..9e7582f 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -53,7 +53,7 @@ int check_save(void) {
"Cancel", "Save", "Discard Changes");
if (r == 1) {
- save_cb(); // Save the file...
+ save_cb();
return !psed_p->modified();
}
@@ -213,34 +213,39 @@ void save_cb() {
}
void print_cb() {
- char tmpname[256];
- char buf[256];
- int tmp_fd;
- char *prefCommand;
- const char *printCommand;
+ char *pref_cmd, tmpname[256];
+ int r, tmp_fd;
+ const char *print_cmd;
Fl_Preferences prefs(Fl_Preferences::USER,
"Johannes.HofmannATgmx.de", "flpsed");
- prefs.get("printCommand", prefCommand, "lpr");
-
- printCommand = fl_input("Print Command", prefCommand);
- if (!printCommand || printCommand[0] == '\0')
+ prefs.get("printCommand", pref_cmd, "lpr");
+ print_cmd = fl_input("Print Command", pref_cmd);
+ if (!print_cmd || print_cmd[0] == '\0')
return;
- if (strcmp(printCommand, prefCommand))
- prefs.set("printCommand", printCommand);
+ if (strcmp(print_cmd, pref_cmd))
+ prefs.set("printCommand", print_cmd);
- strncpy(tmpname, "/tmp/PSEditWidgetXXXXXX", sizeof(tmpname));
+ strncpy(tmpname, "/tmp/flpsedXXXXXX", sizeof(tmpname));
tmp_fd = mkstemp(tmpname);
if (tmp_fd >= 0) {
- close(tmp_fd);
- if (psed_p->save(tmpname) != 0) {
- fprintf(stderr, "Failed to print file\n");
- } else {
- snprintf(buf, 256, "%s %s", printCommand, tmpname);
+ FILE *fp = fdopen(tmp_fd, "w");
+
+ 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);
}
}
@@ -571,7 +576,6 @@ int main(int argc, char** argv) {
psed_p->property_changed_callback(property_changed_cb);
scroll->end();
-
fl_open_display();
Fl::add_handler(xev_handler);
@@ -581,7 +585,6 @@ int main(int argc, char** argv) {
win->callback((Fl_Callback *)quit_cb);
win->show(1, argv);
-
if (zoom_val)
psed_p->zoom(zoom_val);