Back to index

tetex-bin  3.0
Classes | Enumerations | Functions
print-internal.h File Reference
#include "dvi-init.h"
#include "print-dialog.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  file_IO
struct  file_info
struct  specials_stack_elem
struct  specials_stack
struct  select_pages_info

Enumerations

enum  outputFormatT {
  FMT_PS, FMT_PS2PDF, FMT_DVI, FMT_ISO_8859_1,
  FMT_UTF8, FMT_NONE
}

Functions

void internal_print (struct select_pages_info *pinfo)
void internal_save (struct select_pages_info *pinfo, outputFormatT output_format)

Class Documentation

struct file_IO

Definition at line 33 of file print-internal.h.

Class Members
char * fname
FILE * fp
struct file_info

Definition at line 39 of file print-internal.h.

struct specials_stack_elem

Definition at line 49 of file print-internal.h.

Class Members
char * content
struct specials_stack

Definition at line 53 of file print-internal.h.

Collaboration diagram for specials_stack:
Class Members
struct specials_stack_elem * items
size_t stack_len

Enumeration Type Documentation

Enumerator:
FMT_PS 
FMT_PS2PDF 
FMT_DVI 
FMT_ISO_8859_1 
FMT_UTF8 
FMT_NONE 

Definition at line 30 of file print-internal.h.


Function Documentation

void internal_print ( struct select_pages_info pinfo)

Definition at line 789 of file print-internal.c.

{
    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);
    }
    printlog_create("Xdvik: Printing", "Automatically close this window when printing finishes",
                  cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_unkeep);
       
    if ((argv = create_dvips_argv(pinfo, False, FILE_PRINT)) == NULL) {
       /* something went *really* wrong; assume user has already been warned about it */
       return;
    }

    fork_dvips(argv, pinfo, dvips_exited);
    
    /* dellocate argv */
    for (i = 0; argv[i] != NULL; i++) {
       free(argv[i]);
    }
    free(argv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void internal_save ( struct select_pages_info pinfo,
outputFormatT  output_format 
)

Definition at line 661 of file print-internal.c.

{
    struct file_info *finfo = pinfo->finfo;
    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!");
    
    switch (output_format) {
       
    case FMT_DVI:
       /* here we first create a temporary file, and if that succeeded,
          move it to the final position */
       select_pages(pinfo);

       if (!select_pages_report_error(pinfo)) {
           /*
            * ... 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
            * (rename() will e.g. fail if the tmp directory is on a different file
            * 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)) {
              popup_message(globals.widgets.top_level,
                           MSG_ERR, NULL, "Creating %s failed: %s",
                           finfo->dvi_out.fname, strerror(errno));
           }
           else { /* moving worked */
              TRACE_GUI((stderr, "renamed %s to %s\n", finfo->dvi_tmp.fname, finfo->dvi_out.fname));

              if (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);
                     warn_files = xstrcat(warn_files, "\n");
                  }
                  popup_message(globals.widgets.top_level,
                              MSG_INFO,
                              "The files listed in the message (probably images) are not part "
                              "of the newly created DVI file; they are only referenced by that file. "
                              "Therefore, if you want to distribute this file or use it on a different computer,"
                              "you will need to distribute all the referenced files, too.\n\n"
                              "Tip: A better format for distributing files is Postscript or PDF. "
                              "To create a Postscript file, use the `File->Print' menu, "
                              "then select `Print to file' in the dialog window.",
                              "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);
                  free(warn_files);
              }
              else {
                  popup_message(globals.widgets.top_level,
                              MSG_INFO,
                              NULL,
                              "Created DVI file: %s.", finfo->dvi_out.fname);
              }
              unlink(finfo->dvi_tmp.fname);
           }
       }
       break;

    case FMT_PS2PDF:
       tmp_fd = xdvi_temp_fd(&(finfo->ps_out.fname)); /* this allocates finfo->ps_out.fname */
       if (tmp_fd == -1) {
           popup_message(globals.widgets.top_level,
                       MSG_ERR, NULL,
                       "Couldn't create temporary PS file for conversion to PDF: %s",
                       strerror(errno));
           return;
       }
       else {
           TRACE_GUI((stderr, "name of temporary PS file: |%s|", finfo->ps_out.fname));
       }
       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);
       }
       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 ((argv = create_dvips_argv(pinfo, do_pdf, FILE_SAVE)) == NULL) {
           /* something went *really* wrong; assume user has already been warned about it */
           return;
       }
       fork_dvips(argv, pinfo, dvips_exit_proc);

       /* dellocate argv */
       for (i = 0; argv[i] != NULL; i++) {
           free(argv[i]);
       }
       free(argv);

       break;
    case FMT_ISO_8859_1:
    case FMT_UTF8:
       if (search_extract_text(output_format, pinfo)) {
           popup_message(globals.widgets.top_level,
                       MSG_INFO,
                       NULL,
                       "Created text file %s.", finfo->txt_out.fname);
       }
       else {
           popup_message(globals.widgets.top_level,
                       MSG_INFO,
                       NULL,
                       "Extracting text from DVI file failed!");
       }
       break;
    case FMT_NONE:
       break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: