=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/term/Attic/pslatex.trm,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.2 diff -u -p -r1.1.1.1 -r1.1.1.2 --- OpenXM_contrib/gnuplot/term/Attic/pslatex.trm 2000/01/09 17:01:15 1.1.1.1 +++ OpenXM_contrib/gnuplot/term/Attic/pslatex.trm 2000/01/22 14:16:28 1.1.1.2 @@ -1,5 +1,5 @@ /* - * $Id: pslatex.trm,v 1.1.1.1 2000/01/09 17:01:15 maekawa Exp $ + * $Id: pslatex.trm,v 1.1.1.2 2000/01/22 14:16:28 maekawa Exp $ */ /* GNUPLOT - pslatex.trm */ @@ -91,7 +91,7 @@ static int PSLATEX_justify; static int PSLATEX_rotate = TRUE; static char *PSLATEX_psfile = NULL; static TBOOLEAN PSLATEX_useAuxFile = FALSE; /* do we write two files? */ -static FILE *PSLATEX_auxFile; +static FILE *PSLATEX_auxFile = NULL; static TBOOLEAN PSLATEX_output = TRUE; /* do we write LaTeX? */ struct text_command { @@ -176,34 +176,41 @@ TERM_PUBLIC void PSLATEX_init() if (strcmp(term->name, "pstex") == 0) PSLATEX_output = FALSE; - PSLATEX_auxFile = NULL; /* until we know otherwise */ + /* until we know otherwise */ + PSLATEX_auxFile = NULL; + /* dont tweak PSLATEX_useAuxFile if we decide we cannot comply * since this affects subsequent plots even after a set out * Instead, we will use PSLATEX_auxFile != NULL to indicate * use of an aux file */ + /* if there's no extension, append ".ps" */ + if ((dotIndex = strrchr(outstr, '.')) == NULL) + dotIndex = strchr(outstr, NUL); + /* try to open the auxiliary file for the postscript parts. */ - if (outstr && PSLATEX_useAuxFile == TRUE && - (dotIndex = strrchr(outstr, '.'))) { + if (outstr && PSLATEX_useAuxFile == TRUE) { - /* assume file name is ending in ".tex" */ - if (PSLATEX_psfile) - free(PSLATEX_psfile); - PSLATEX_psfile = gp_alloc(dotIndex - outstr + 3, "pslatex aux filename"); + /* length of outstr plus ('.' or '\0') plus "ps" plus '\0' */ + PSLATEX_psfile = gp_realloc (PSLATEX_psfile,(dotIndex - outstr) + 4,"pslatex aux filename"); if (PSLATEX_psfile) { - /* including . */ - safe_strncpy(PSLATEX_psfile, outstr, dotIndex - outstr + 1); - strcpy(PSLATEX_psfile + (dotIndex - outstr) + 1, "ps"); - if ((PSLATEX_auxFile = fopen(PSLATEX_psfile, "w")) == (FILE *) NULL) { + /* include period or '\0' */ + strncpy(PSLATEX_psfile, outstr, (dotIndex - outstr) + 1); + /* period or '\0' is overwritten with period, and "ps" appended */ + strcpy(PSLATEX_psfile + (dotIndex - outstr), ".ps"); + PSLATEX_auxFile = fopen(PSLATEX_psfile, "w"); + if (PSLATEX_auxFile == (FILE *) NULL) { fprintf(stderr, "Cannot open aux file %s for output\n", PSLATEX_psfile); + /* And what? Error handling????? */ } } else { fprintf(stderr, "\ Cannot make PostScript file name from %s\n\ Turning off auxfile option\n", outstr); PSLATEX_auxFile = NULL; + /* NEW! */ PSLATEX_useAuxFile = FALSE; } } if (PSLATEX_output) { @@ -272,24 +279,39 @@ TERM_PUBLIC void PSLATEX_graphics() struct termentry *t = term; if (PSLATEX_output) - fprintf(gpoutfile, "\\begin{picture}(%d,%d)(0,0)%%\n", (int) (xsize * t->xmax), (int) - (ysize * t->ymax)); + fprintf(gpoutfile, "\\begin{picture}(%d,%d)(0,0)%%\n", + (int) (xsize * t->xmax), (int) (ysize * t->ymax)); else - fprintf(gpoutfile, "\\GNUPLOTpicture(%d,%d)\n", (int) (xsize * t->xmax), (int) (ysize * t->ymax)); + fprintf(gpoutfile, "\\GNUPLOTpicture(%d,%d)\n", + (int) (xsize * t->xmax), (int) (ysize * t->ymax)); if (PSLATEX_auxFile) { FILE *tmp; - /* - * these are taken from the post.trm file computation - * of the bounding box, but without the X_OFF and Y_OFF - */ - int urx = (int) (xsize * (PS_XMAX) / PS_SC + 0.5), ury = (int) (ysize * (PS_YMAX) / PS_SC - + 0.5); + /* these are taken from the post.trm file computation + * of the bounding box, but without the X_OFF and Y_OFF */ + int urx = (int) (xsize * (PS_XMAX) / PS_SC + 0.5); + int ury = (int) (ysize * (PS_YMAX) / PS_SC + 0.5); + /* moved this code here from beginning of the function + * PSLATEX_psfile is only != NULL with the `auxfile' option */ + char *psfile_basename = strrchr(PSLATEX_psfile, DIRSEP1); + if (psfile_basename) + psfile_basename++; + else { + if (DIRSEP2 != NUL) { + psfile_basename = strrchr(PSLATEX_psfile, DIRSEP2); + if (psfile_basename) + psfile_basename++; + else + psfile_basename = PSLATEX_psfile; + } else + psfile_basename = PSLATEX_psfile; + } + /* generate special which xdvi and dvips can handle */ fprintf(gpoutfile, "\\special{psfile=%s llx=0 lly=0 urx=%d ury=%d rwi=%d}\n", - PSLATEX_psfile, urx, ury, 10 * urx); + psfile_basename, urx, ury, 10 * urx); tmp = gpoutfile; gpoutfile = PSLATEX_auxFile; PS_graphics(); @@ -601,9 +623,9 @@ START_HELP(pslatex) " This is useful if your pictures are large enough that dvips cannot handle", " them. The name of the auxiliary PostScript file is derived from the name of", " the TeX file given on the `set output` command; it is determined by replacing", -" the trailing `.tex` (actually just the final extent in the file name---and", -" the option will be turned off if there is no extent) with `.ps` in the output", -" file name. Remember to close the file before leaving `gnuplot`.", +" the trailing `.tex` (actually just the final extent in the file name) with", +" `.ps` in the output file name, or, if the TeX file has no extension, `.ps`", +" is appended. Remember to close the file before leaving `gnuplot`.", "", " All drivers for LaTeX offer a special way of controlling text positioning:", " If any text string begins with '{', you also need to include a '}' at the",