summaryrefslogtreecommitdiff
path: root/Build/source/texk/xdvik/print-internal.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2008-07-01 15:42:36 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2008-07-01 15:42:36 +0000
commit6552be7f745c5a8d506148c8af9d367c9d996d24 (patch)
treeb9d673871a1490b64273a265d4d961316a2174db /Build/source/texk/xdvik/print-internal.c
parent48e2b240973977c208bc840b589b75b91a6f4c30 (diff)
xdvik 22.84.14
git-svn-id: svn://tug.org/texlive/trunk@9142 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/xdvik/print-internal.c')
-rw-r--r--Build/source/texk/xdvik/print-internal.c334
1 files changed, 198 insertions, 136 deletions
diff --git a/Build/source/texk/xdvik/print-internal.c b/Build/source/texk/xdvik/print-internal.c
index c47ab73ed84..e20c266dc9f 100644
--- a/Build/source/texk/xdvik/print-internal.c
+++ b/Build/source/texk/xdvik/print-internal.c
@@ -35,7 +35,7 @@
* the caller may be executed *before* the child has finished. (Note
* e.g. how unlink()ing the temporary PS file is done inside
* ps2pdf_exited() and not in the callers). This is the reason why we
- * often need to pass information to the subprocess (via a data `void *').
+ * often need to pass information to the subprocess via a data pointer.
*/
#include "xdvi-config.h"
@@ -83,17 +83,20 @@
static struct xchild print_child = {NULL, 0, True, "dvips", NULL, NULL, NULL };
-static char *read_from_dvips(int);
+static char *read_from_dvips(int, void *);
+
static struct xio print_xio = { NULL, 0, XIO_IN,
#if HAVE_POLL
NULL,
#endif
read_from_dvips,
- NULL /* write proc - not needed */
+ NULL, /* write proc - not needed */
+ NULL /* data */
};
-static void dvips_alarm(struct xtimer *);
-static struct xtimer dvips_timer = {NULL, {0, 0}, XTM_DEFAULT, dvips_alarm
+static void dvips_alarm(struct xtimer *this, void *data);
+
+static struct xtimer dvips_timer = {NULL, {0, 0}, XTM_DEFAULT, dvips_alarm, NULL
#if XDVI_XT_TIMER_HACK
, NULL, NULL
#endif
@@ -119,36 +122,42 @@ static const int DVIPS_STAT_WAIT = 2;
*/
static void
-fork_dvips(char **argv, const struct select_pages_info *pinfo, childProcT proc)
+fork_dvips(char **argv, struct save_or_print_info *info, childProcT proc)
{
int print_io[2];
int i;
- const struct file_info *finfo = pinfo->finfo;
+ struct file_info *finfo = info->finfo;
/* printlog_append(argv[0], strlen(argv[0])); */
FILE *fout = NULL;
- if (finfo->ps_out.fname != NULL) {
- /* printing to PS file, open file for writing */
- if ((fout = XFOPEN(finfo->ps_out.fname, "w")) == NULL) {
+ if (info->act == FILE_SAVE || info->print_target == TO_FILE) { /* printing to PS file, open file for writing */
+ const char *out_file;
+
+ if (info->print_target == TO_FILE || info->fmt == FMT_PS)
+ out_file = finfo->out_file;
+ else
+ out_file = finfo->tmp_ps_file;
+
+ if ((fout = XFOPEN(out_file, "w")) == NULL) {
popup_message(globals.widgets.top_level,
MSG_ERR,
NULL, "Could not open %s for writing: %s.",
- finfo->ps_out.fname,
+ out_file,
strerror(errno));
return;
}
}
- printlog_popup();
+ printlog_popup(info);
- printlog_append_str("Calling: `");
- printlog_append_str(argv[0]);
+ printlog_append_str(info, "Calling: `");
+ printlog_append_str(info, argv[0]);
for (i = 1; argv[i] != NULL; i++) {
- printlog_append_str(" ");
- printlog_append_str(argv[i]);
+ printlog_append_str(info, " ");
+ printlog_append_str(info, argv[i]);
}
- printlog_append_str("'\n");
+ printlog_append_str(info, "'\n");
if (xpipe(print_io) != 0) {
perror("[xdvi] pipe");
@@ -165,7 +174,7 @@ fork_dvips(char **argv, const struct select_pages_info *pinfo, childProcT proc)
print_child.name = xstrdup(argv[0]);
print_child.proc = proc;
- print_child.data = (void *)pinfo;
+ print_child.data = info;
print_child.pid = fork();
if (print_child.pid == 0) { /* if child */
/* change into dir of DVI file so that included image files etc. are found */
@@ -174,16 +183,16 @@ fork_dvips(char **argv, const struct select_pages_info *pinfo, childProcT proc)
if (globals.debug & DBG_FILES) {
char path[MAXPATHLEN];
getcwd(path, MAXPATHLEN);
- fprintf(stderr, "Directory of running `%s': `%s'\n",
- argv[0], path);
+ /* fprintf(stderr, "Directory of running `%s': `%s'\n", argv[0], path); */
}
/* make the input file pointer the STDIN of the dvips process */
- if (finfo->dvi_tmp.fp != NULL) { /* printing selected pages from temporary file */
- (void)dup2(fileno(finfo->dvi_tmp.fp), STDIN_FILENO);
+ if (info->page_selection == PAGE_MARKED) { /* printing selected pages from temporary file */
+ ASSERT(finfo->tmp_dvi_fp != NULL, "tmp fp mustn't be NULL!");
+ (void)dup2(fileno(finfo->tmp_dvi_fp), STDIN_FILENO);
}
else { /* printing from main or backup file */
- (void)dup2(fileno(finfo->dvi_in.fp), STDIN_FILENO);
+ (void)dup2(fileno(finfo->in_fp), STDIN_FILENO);
}
(void)lseek(0, 0, SEEK_SET);
@@ -230,24 +239,27 @@ fork_dvips(char **argv, const struct select_pages_info *pinfo, childProcT proc)
/* Set up file descriptor for non-blocking I/O */
prep_fd(print_io[0], True);
print_xio.fd = print_io[0];
+ print_xio.data = info;
set_io(&print_xio);
dvips_status = DVIPS_STAT_RUN; /* running */
}
/*
- * Create an argument list for dvips, using information from pinfo
+ * Create an argument list for dvips, using information from info
* and X resources. Returns the result list in freshly allocated
* memory.
*/
static char **
-create_dvips_argv(const struct select_pages_info *pinfo, Boolean do_pdf, printOrSaveActionT act)
+create_dvips_argv(const struct save_or_print_info *info, Boolean do_pdf)
{
+ const struct select_pages_info *pinfo = info->pinfo;
+
size_t argv_len = 128; /* should be ample ... */
char **argv = xmalloc(argv_len * sizeof *argv);
size_t idx = 0;
- const char *printer_options = get_printer_options();
- char *dvips_options = get_dvips_options(act);
+ const char *printer_options = info->printer_options;
+ const char *dvips_options = info->dvips_options;
char from_page[LENGTH_OF_INT];
char to_page[LENGTH_OF_INT];
@@ -269,7 +281,7 @@ create_dvips_argv(const struct select_pages_info *pinfo, Boolean do_pdf, printOr
argv[idx++] = xstrdup("-f");
- if (printer_options != NULL && pinfo->finfo->ps_out.fname == NULL) { /* printing to printer */
+ if (info->print_target == TO_PRINTER && printer_options != NULL) { /* printing to printer */
char **printer_args = get_separated_list(printer_options, " \t", True); /* this allocates printer_args */
int i;
ASSERT(*printer_args != NULL, "args should contain at least the string \"lpr\"");
@@ -286,7 +298,7 @@ create_dvips_argv(const struct select_pages_info *pinfo, Boolean do_pdf, printOr
idx++;
}
- if (pinfo->callback == check_pagerange) {
+ if (info->page_selection == PAGE_RANGE) {
/* convert back from 0-based to 1-based, also taking globals.pageno_correct into accout
* (which is 1 by default, so we need to add 2) */
argv[idx] = xstrdup("-p=");
@@ -306,17 +318,17 @@ create_dvips_argv(const struct select_pages_info *pinfo, Boolean do_pdf, printOr
/* Check if selecting pages worked, report error else */
static Boolean
-select_pages_report_error(const struct select_pages_info *pinfo)
+select_pages_report_error(const struct save_or_print_info *info)
{
- if (pinfo->errflag == NO_ERROR)
+ if (info->pinfo->errflag == NO_ERROR)
return False;
popup_message(globals.widgets.top_level,
MSG_INFO,
NULL,
"Could not save DVI file to %s: %s.",
- pinfo->finfo->dvi_tmp.fname,
- get_dvi_error(pinfo->errflag));
+ info->finfo->tmp_dvi_file,
+ get_dvi_error(info->pinfo->errflag));
return True;
}
@@ -327,10 +339,11 @@ select_pages_report_error(const struct select_pages_info *pinfo)
* the output, for later filtering.
*/
static char *
-read_from_dvips(int ignored)
+read_from_dvips(int ignored, void *data)
{
int bytes;
char line[80];
+ struct save_or_print_info *info = data;
UNUSED(ignored);
@@ -353,7 +366,7 @@ read_from_dvips(int ignored)
#ifdef MOTIF
line[bytes] = '\0';
#endif
- printlog_append(line, bytes);
+ printlog_append(info, line, bytes);
}
}
return NULL; /* TODO */
@@ -368,29 +381,35 @@ dvips_exited(int exitval, struct xchild *child)
char str[128] = "";
int ms;
- struct select_pages_info *pinfo = (struct select_pages_info *)child->data;
+ struct save_or_print_info *info = (struct save_or_print_info *)child->data;
- read_from_dvips(0);
+ read_from_dvips(0, info);
clear_io(&print_xio);
(void)close(print_xio.fd);
if (WIFEXITED(exitval)) {
if (WEXITSTATUS(exitval) == 0) {
- if (pinfo->finfo->ps_out.fname != NULL) {
- printlog_append_str("\nCreated Postscript file ");
- printlog_append_str(pinfo->finfo->ps_out.fname);
- printlog_append_str(".\n");
+ if (info->act == FILE_SAVE || info->print_target == TO_FILE) {
+ printlog_append_str(info, "\nCreated Postscript file ");
+ printlog_append_str(info, info->finfo->out_file);
+ printlog_append_str(info, ".\n");
}
else {
- printlog_append_str("Done.\n");
+ printlog_append_str(info, "Done.\n");
}
/* remove temporary DVI file if it exists */
- if (pinfo->finfo->dvi_tmp.fname != NULL) {
+ if (info->finfo->tmp_dvi_file != NULL) {
if (globals.debug & DBG_GUI)
- TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", pinfo->finfo->dvi_tmp.fname));
- else
- unlink(pinfo->finfo->dvi_tmp.fname);
+ TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", info->finfo->tmp_dvi_file));
+ else {
+ if (info->finfo->tmp_dvi_fp != NULL) {
+ fclose(info->finfo->tmp_dvi_fp);
+ info->finfo->tmp_dvi_fp = NULL;
+ }
+ unlink(info->finfo->tmp_dvi_file);
+ info->finfo->tmp_dvi_file = NULL;
+ }
}
}
else
@@ -403,12 +422,13 @@ dvips_exited(int exitval, struct xchild *child)
ms = resource.dvips_hang;
if (str[0] != '\0') {
- XBell(DISP, 0);
+ xdvi_bell();
ms = resource.dvips_fail_hang;
- printlog_append_str(str);
+ printlog_append_str(info, str);
}
if (ms > 0) {
+ dvips_timer.data = info;
set_timer(&dvips_timer, ms);
dvips_status = DVIPS_STAT_WAIT;
}
@@ -416,7 +436,7 @@ dvips_exited(int exitval, struct xchild *child)
dvips_status = DVIPS_STAT_NONE;
}
- printlog_enable_closebutton();
+ printlog_enable_closebutton(info);
}
/*
@@ -427,39 +447,40 @@ ps2pdf_exited(int status, struct xchild *this)
{
char *err_msg = NULL;
int ms = resource.dvips_hang;
+ struct save_or_print_info *info = (struct save_or_print_info *)this->data;
+
/* if child exited with error and xio struct is available for child,
print error text */
if (this->io != NULL && (WIFEXITED(status) != 0)) {
if ((WEXITSTATUS(status) != 0)
- && (err_msg = (this->io->read_proc)(this->io->fd)) != NULL) {
+ && (err_msg = (this->io->read_proc)(this->io->fd, NULL)) != NULL) {
char buf[LENGTH_OF_INT];
SNPRINTF(buf, LENGTH_OF_INT, "%d", WEXITSTATUS(status));
ms = resource.dvips_fail_hang;
- XBell(DISP, 0);
- printlog_append_str("\n\nError calling ");
+ xdvi_bell();
+ printlog_append_str(info, "\n\nError calling ");
if (this->name != NULL) {
- printlog_append_str("\"");
- printlog_append_str(this->name);
- printlog_append_str("\" ");
+ printlog_append_str(info, "\"");
+ printlog_append_str(info, this->name);
+ printlog_append_str(info, "\" ");
}
- printlog_append_str("\nCommand exited with error code ");
- printlog_append_str(buf);
- printlog_append_str(":\n");
- printlog_append_str(err_msg);
+ printlog_append_str(info, "\nCommand exited with error code ");
+ printlog_append_str(info, buf);
+ printlog_append_str(info, ":\n");
+ printlog_append_str(info, err_msg);
free(err_msg);
}
else {
- const struct select_pages_info *pinfo = (const struct select_pages_info *)this->data;
int retval;
- printlog_append_str("\nCreated PDF file ");
- printlog_append_str(pinfo->finfo->pdf_out.fname);
- printlog_append_str(".\n");
+ printlog_append_str(info, "\nCreated PDF file ");
+ printlog_append_str(info, info->finfo->out_file);
+ printlog_append_str(info, ".\n");
TRACE_FILES((stderr, "Removing temporary PS file: `%s'",
- pinfo->finfo->ps_out.fname));
- retval = unlink(pinfo->finfo->ps_out.fname);
+ info->finfo->tmp_ps_file));
+ retval = unlink(info->finfo->tmp_ps_file);
if (retval != 0) {
fprintf(stderr, "Could not unlink `%s': %s.\n",
- pinfo->finfo->ps_out.fname, strerror(errno));
+ info->finfo->tmp_ps_file, strerror(errno));
}
}
}
@@ -469,6 +490,7 @@ ps2pdf_exited(int status, struct xchild *this)
"Internal error: ps2pdf_exited() called while child still running?");
}
if (ms > 0) {
+ dvips_timer.data = info;
set_timer(&dvips_timer, ms);
dvips_status = DVIPS_STAT_WAIT;
}
@@ -476,7 +498,7 @@ ps2pdf_exited(int status, struct xchild *this)
dvips_status = DVIPS_STAT_NONE;
}
- printlog_enable_closebutton();
+ printlog_enable_closebutton(info);
free(this->name);
free(this->io);
@@ -484,19 +506,19 @@ ps2pdf_exited(int status, struct xchild *this)
}
static void
-call_ps2pdf(const char *path, const struct select_pages_info *pinfo)
+call_ps2pdf(const char *path, const struct save_or_print_info *info)
{
const char *argv[5];
size_t idx = 0;
argv[idx++] = path;
- argv[idx++] = pinfo->finfo->ps_out.fname;
- argv[idx++] = pinfo->finfo->pdf_out.fname;
+ argv[idx++] = info->finfo->tmp_ps_file;
+ argv[idx++] = info->finfo->out_file;
argv[idx++] = NULL;
/* need to run this in globals.xdvi_dir again, since the dvips conversion directory
globals.dvi_file.dirname may not be writable! */
- if (!fork_process("ps2pdf", True, globals.xdvi_dir, ps2pdf_exited, (void *)pinfo, (char **)argv)) {
+ if (!fork_process("ps2pdf", True, globals.cwd, ps2pdf_exited, (void *)info, (char **)argv)) {
popup_message(globals.widgets.top_level,
MSG_ERR,
NULL, "Couldn't fork %s process: %s\n", argv[0], strerror(errno));
@@ -508,29 +530,35 @@ dvips_ps2pdf(int exitval, struct xchild *child)
{
char str[128] = "";
int ms;
- struct select_pages_info *pinfo = (struct select_pages_info *)child->data;
+ struct save_or_print_info *info = (struct save_or_print_info *)child->data;
- read_from_dvips(0);
+ read_from_dvips(0, info);
clear_io(&print_xio);
(void)close(print_xio.fd);
if (WIFEXITED(exitval)) {
if (WEXITSTATUS(exitval) == 0) {
/* dvips ended OK; call ps2pdf: */
- TRACE_GUI((stderr, "Created temporary PS file |%s|", pinfo->finfo->ps_out.fname));
- printlog_append_str("\nCalling ");
- printlog_append_str(resource.ps2pdf_path);
- printlog_append_str(" ...");
+ TRACE_GUI((stderr, "Created temporary PS file |%s|", info->finfo->tmp_ps_file));
+ printlog_append_str(info, "\nCalling ");
+ printlog_append_str(info, resource.ps2pdf_path);
+ printlog_append_str(info, " ...");
/* remove temporary DVI file if it exists */
- if (pinfo->finfo->dvi_tmp.fname != NULL) {
+ if (info->finfo->tmp_dvi_file != NULL) {
if (globals.debug & DBG_GUI)
- TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", pinfo->finfo->dvi_tmp.fname));
- else
- unlink(pinfo->finfo->dvi_tmp.fname);
+ TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", info->finfo->tmp_dvi_file));
+ else {
+ if (info->finfo->tmp_dvi_fp != NULL) {
+ fclose(info->finfo->tmp_dvi_fp);
+ info->finfo->tmp_dvi_fp = NULL;
+ }
+ unlink(info->finfo->tmp_dvi_file);
+ info->finfo->tmp_dvi_file = NULL;
+ }
}
/* invoke ps2pdf conversion */
- call_ps2pdf(resource.ps2pdf_path, pinfo);
+ call_ps2pdf(resource.ps2pdf_path, info);
}
else
sprintf(str, "\nPrint process returned exit code %d.\n",
@@ -546,11 +574,12 @@ dvips_ps2pdf(int exitval, struct xchild *child)
/* enable close button only if dvips conversion already failed */
ms = resource.dvips_hang;
if (str[0] != '\0') {
- XBell(DISP, 0);
+ xdvi_bell();
ms = resource.dvips_fail_hang;
- printlog_append_str(str);
+ printlog_append_str(info, str);
if (ms > 0) {
+ dvips_timer.data = info;
set_timer(&dvips_timer, ms);
dvips_status = DVIPS_STAT_WAIT;
}
@@ -558,17 +587,18 @@ dvips_ps2pdf(int exitval, struct xchild *child)
dvips_status = DVIPS_STAT_NONE;
}
- printlog_enable_closebutton();
+ printlog_enable_closebutton(info);
}
}
static void
-dvips_alarm(struct xtimer *should_be_timer)
+dvips_alarm(struct xtimer *this, void *data)
{
- UNUSED(should_be_timer);
+ struct save_or_print_info *info = (struct save_or_print_info *)data;
+ UNUSED(this);
- printlog_popdown(False);
+ printlog_popdown(info, False);
dvips_status = DVIPS_STAT_NONE;
}
@@ -576,7 +606,7 @@ dvips_alarm(struct xtimer *should_be_timer)
static void
-cb_dvips_unkeep(Widget w, XtPointer client_data, XtPointer call_data)
+cb_dvips_keep(Widget w, XtPointer client_data, XtPointer call_data)
{
UNUSED(w);
@@ -604,14 +634,15 @@ cb_dvips_unkeep(Widget w, XtPointer client_data, XtPointer call_data)
static void
cb_dvips_destroy(Widget w, XtPointer client_data, XtPointer call_data)
{
+ struct save_or_print_info *info = (struct save_or_print_info *)client_data;
+
UNUSED(w);
- UNUSED(client_data);
UNUSED(call_data);
if (dvips_status == DVIPS_STAT_RUN) {
kill(print_child.pid, dvips_sig);
dvips_sig = SIGKILL;
- printlog_append_str("^C");
+ printlog_append_str(info, "^C");
}
if (dvips_status == DVIPS_STAT_WAIT) {
@@ -619,15 +650,16 @@ cb_dvips_destroy(Widget w, XtPointer client_data, XtPointer call_data)
cancel_timer(&dvips_timer);
}
- printlog_reset();
- printlog_popdown(True);
+ printlog_reset(info);
+ printlog_popdown(info, True);
}
static void
cb_dvips_cancel(Widget w, XtPointer client_data, XtPointer call_data)
{
+ struct save_or_print_info *info = (struct save_or_print_info *)client_data;
+
UNUSED(w);
- UNUSED(client_data);
UNUSED(call_data);
if (dvips_status != DVIPS_STAT_RUN)
@@ -635,14 +667,15 @@ cb_dvips_cancel(Widget w, XtPointer client_data, XtPointer call_data)
kill(print_child.pid, dvips_sig);
dvips_sig = SIGKILL;
- printlog_append_str("^C");
+ printlog_append_str(info, "^C");
}
static void
cb_dvips_close(Widget w, XtPointer client_data, XtPointer call_data)
{
+ struct save_or_print_info *info = (struct save_or_print_info *)client_data;
+
UNUSED(w);
- UNUSED(client_data);
UNUSED(call_data);
if (dvips_status == DVIPS_STAT_RUN)
@@ -653,31 +686,37 @@ cb_dvips_close(Widget w, XtPointer client_data, XtPointer call_data)
cancel_timer(&dvips_timer);
}
- printlog_popdown(True);
+ printlog_popdown(info, True);
}
void
-internal_save(struct select_pages_info *pinfo,
- outputFormatT output_format)
+internal_save(struct save_or_print_info *info)
{
- struct file_info *finfo = pinfo->finfo;
+ struct file_info *finfo = info->finfo;
+ static struct callback_info cinfo = {
+ cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_keep
+ };
int tmp_fd;
char **argv = NULL;
int i;
childProcT dvips_exit_proc = dvips_exited; /* default procedure to call after fork_dvips() */
Boolean do_pdf = False; /* force `-Ppdf' for dvips? (used for ps2pdf conversion) */
- ASSERT(output_format != FMT_NONE, "No valid output format selected!");
+ ASSERT(info->fmt != FMT_NONE, "No valid output format selected!");
+
+ /* fprintf(stderr, "INTERNAL SAVE - format: %d; selection: %d\n", info->fmt, info->page_selection); */
+
+ info->callbacks = &cinfo;
- switch (output_format) {
+ switch (info->fmt) {
case FMT_DVI:
/* here we first create a temporary file, and if that succeeded,
move it to the final position */
- select_pages(pinfo);
+ select_pages(info);
- if (!select_pages_report_error(pinfo)) {
+ if (!select_pages_report_error(info)) {
/*
* ... else, move the temporary file to its final destination. For that, we
* try the more efficient rename() first; if this fails, try copying the file
@@ -685,21 +724,21 @@ internal_save(struct select_pages_info *pinfo,
* system). We could perhaps examine errno after the renaming attempt to
* find out whether we need to do the copy attempt in the first place, but
* that'd be rather error-prone ... */
- ASSERT(finfo->dvi_tmp.fname != NULL, "filename mustn't be NULL");
- if (rename(finfo->dvi_tmp.fname, finfo->dvi_out.fname) != 0
- && !copy_file(finfo->dvi_tmp.fname, finfo->dvi_out.fname)) {
+ ASSERT(finfo->tmp_dvi_file != NULL, "filename mustn't be NULL");
+ if (rename(finfo->tmp_dvi_file, finfo->out_file) != 0
+ && !copy_file(finfo->tmp_dvi_file, finfo->out_file)) {
popup_message(globals.widgets.top_level,
MSG_ERR, NULL, "Creating %s failed: %s",
- finfo->dvi_out.fname, strerror(errno));
+ finfo->out_file, strerror(errno));
}
else { /* moving worked */
- TRACE_GUI((stderr, "renamed %s to %s\n", finfo->dvi_tmp.fname, finfo->dvi_out.fname));
+ TRACE_GUI((stderr, "renamed %s to %s\n", finfo->tmp_dvi_file, finfo->out_file));
- if (pinfo->warn_files.stack_len > 0) { /* do we need to warn user about referenced files? */
+ if (info->pinfo->warn_files.stack_len > 0) { /* do we need to warn user about referenced files? */
char *warn_files = xstrdup("");
size_t i;
- for (i = 0; i < pinfo->warn_files.stack_len; i++) {
- warn_files = xstrcat(warn_files, pinfo->warn_files.items[i].content);
+ for (i = 0; i < info->pinfo->warn_files.stack_len; i++) {
+ warn_files = xstrcat(warn_files, info->pinfo->warn_files.items[i].content);
warn_files = xstrcat(warn_files, "\n");
}
popup_message(globals.widgets.top_level,
@@ -714,22 +753,34 @@ internal_save(struct select_pages_info *pinfo,
"Created %s.\n"
"Please note that the following files are referenced by this file, "
"and are needed for displaying or printing it correctly:\n%s\n",
- finfo->dvi_out.fname, warn_files);
+ finfo->out_file, warn_files);
free(warn_files);
}
else {
+/* char *ptr = strrchr(finfo->out_file, '/'); */
+/* if (ptr == NULL) */
+/* ptr = finfo->out_file; */
+/* else */
+/* ptr++; */
popup_message(globals.widgets.top_level,
MSG_INFO,
NULL,
- "Created DVI file: %s.", finfo->dvi_out.fname);
+ "Created DVI file:\n%s.", finfo->out_file);
+ }
+ if (info->finfo->tmp_dvi_fp != NULL) {
+ fclose(info->finfo->tmp_dvi_fp);
+ info->finfo->tmp_dvi_fp = NULL;
}
- unlink(finfo->dvi_tmp.fname);
+ unlink(finfo->tmp_dvi_file);
+ info->finfo->tmp_dvi_file = NULL;
}
}
break;
case FMT_PS2PDF:
- tmp_fd = xdvi_temp_fd(&(finfo->ps_out.fname)); /* this allocates finfo->ps_out.fname */
+ free(finfo->tmp_ps_file);
+ finfo->tmp_ps_file = NULL;
+ tmp_fd = xdvi_temp_fd(&(finfo->tmp_ps_file)); /* this allocates finfo->tmp_ps_file */
if (tmp_fd == -1) {
popup_message(globals.widgets.top_level,
MSG_ERR, NULL,
@@ -738,25 +789,28 @@ internal_save(struct select_pages_info *pinfo,
return;
}
else {
- TRACE_GUI((stderr, "name of temporary PS file: |%s|", finfo->ps_out.fname));
+ TRACE_GUI((stderr, "name of temporary PS file: |%s|", finfo->tmp_ps_file));
}
dvips_exit_proc = dvips_ps2pdf; /* call ps2pdf conversion after dvips exited */
do_pdf = True;
/* fall through */
case FMT_PS:
- if (pinfo->callback == check_marked) { /* want to print selected pages? */
- ASSERT(finfo->dvi_tmp.fp != NULL, "Temporary file pointer musn't be NULL!");
- ASSERT(finfo->dvi_tmp.fname != NULL, "Temporary filename musn't be NULL!");
- select_pages(pinfo);
+ if (info->page_selection == PAGE_MARKED) { /* want to save selected pages? */
+ ASSERT(info->pinfo->callback != NULL, "Callback musn't be NULL!");
+ ASSERT(finfo->tmp_dvi_fp != NULL, "Temporary file pointer musn't be NULL!");
+ ASSERT(finfo->tmp_dvi_file != NULL, "Temporary filename musn't be NULL!");
+ select_pages(info);
}
- printlog_create("Xdvik: Saving", "Automatically close this window after file has been saved",
- cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_unkeep);
+ if (info->printlog == NULL)
+ printlog_create(info, "Xdvik: Saving", "Automatically close this window after file has been saved");
+ else
+ printlog_enable_cancelbutton(info);
- if ((argv = create_dvips_argv(pinfo, do_pdf, FILE_SAVE)) == NULL) {
+ if ((argv = create_dvips_argv(info, do_pdf)) == NULL) {
/* something went *really* wrong; assume user has already been warned about it */
return;
}
- fork_dvips(argv, pinfo, dvips_exit_proc);
+ fork_dvips(argv, info, dvips_exit_proc);
/* dellocate argv */
for (i = 0; argv[i] != NULL; i++) {
@@ -767,11 +821,11 @@ internal_save(struct select_pages_info *pinfo,
break;
case FMT_ISO_8859_1:
case FMT_UTF8:
- if (search_extract_text(output_format, pinfo)) {
+ if (search_extract_text(info)) {
popup_message(globals.widgets.top_level,
MSG_INFO,
NULL,
- "Created text file %s.", finfo->txt_out.fname);
+ "Created text file %s.", finfo->out_file);
}
else {
popup_message(globals.widgets.top_level,
@@ -786,25 +840,33 @@ internal_save(struct select_pages_info *pinfo,
}
void
-internal_print(struct select_pages_info *pinfo)
+internal_print(struct save_or_print_info *info)
{
+ static struct callback_info cinfo = {
+ cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_keep
+ };
char **argv = NULL;
int i;
- if (pinfo->callback == check_marked) { /* want to print selected pages? */
- ASSERT(pinfo->finfo->dvi_tmp.fp != NULL, "Temporary file pointer musn't be NULL!");
- ASSERT(pinfo->finfo->dvi_tmp.fname != NULL, "Temporary filename musn't be NULL!");
- select_pages(pinfo);
+ info->callbacks = &cinfo;
+
+ if (info->page_selection == PAGE_MARKED) { /* want to print selected pages? */
+ ASSERT(info->pinfo->callback != NULL, "Callback musn't be NULL!");
+ ASSERT(info->finfo->tmp_dvi_fp != NULL, "Temporary file pointer musn't be NULL!");
+ ASSERT(info->finfo->tmp_dvi_file != NULL, "Temporary filename musn't be NULL!");
+ select_pages(info);
}
- printlog_create("Xdvik: Printing", "Automatically close this window when printing finishes",
- cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_unkeep);
+ if (info->printlog == NULL)
+ printlog_create(info, "Xdvik: Printing", "Automatically close this window when printing finishes");
+ else
+ printlog_enable_cancelbutton(info);
- if ((argv = create_dvips_argv(pinfo, False, FILE_PRINT)) == NULL) {
+ if ((argv = create_dvips_argv(info, False)) == NULL) {
/* something went *really* wrong; assume user has already been warned about it */
return;
}
- fork_dvips(argv, pinfo, dvips_exited);
+ fork_dvips(argv, info, dvips_exited);
/* dellocate argv */
for (i = 0; argv[i] != NULL; i++) {