home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / DVI_MGR / dvimgr_s.lzh / dvimgr / dviinit.h < prev    next >
Text File  |  1993-08-06  |  10KB  |  375 lines

  1. /* -*-C-*- dviinit.h */
  2. /*-->dviinit*/
  3. /**********************************************************************/
  4. /****************************** dviinit *******************************/
  5. /**********************************************************************/
  6.  
  7. void
  8. dviinit(filestr)        /* initialize DVI file processing */
  9. char *filestr;            /* command line filename string  */
  10. {
  11.     int i;            /* temporary */
  12.     INT16 k;            /* index in curpath[] and curname[] */
  13.     char* tcp;            /* temporary string pointers */
  14.     char* tcp1;            /* temporary string pointers */
  15.  
  16. #if    OS_UNIX
  17. /***********************************************************************
  18. Unix allows binary I/O on stdin and stdout; most other operating systems
  19. do not.  In order  to support this,  we use the  convention that a  null
  20. filestr (NOT  a (char*)NULL)  means the  dvifile is  on stdin,  and  the
  21. translated output is on stdout.  Error logging will be to dvixxx.err  or
  22. dvixxx.dvi-err.  Because random access is required of the dvifile, stdin
  23. may NOT be a pipe; it must be a disk file.
  24. ***********************************************************************/
  25. #define NO_FILENAME (filestr[0] == '\0')
  26. #endif
  27.  
  28. #if    CANON_A2
  29.  
  30. #ifdef CANON_TEST
  31.     char modestring[10];    /* for dynamic fopen() mode string */
  32. #endif /* CANON_TEST */
  33.  
  34. #endif
  35.  
  36. #if    (OS_TOPS20 | OS_VAXVMS)
  37.     char* tcp2;            /* temporary string pointers */
  38. #endif
  39.  
  40.     for (k = 0; k < 10; ++k)
  41.     tex_counter[k] = (INT32)0L;
  42.  
  43.     fontptr = (struct font_entry *)NULL;
  44.     hfontptr = (struct font_entry *)NULL;
  45.     pfontptr = (struct font_entry *)NULL;
  46.     fontfp = (FILE *)NULL;
  47.     cache_size = 0;
  48.     nopen = 0;
  49.  
  50.     /***********************************************************
  51.     Set up file names and open dvi and plot files.  Simple
  52.     filename parsing assumes forms like:
  53.  
  54.     Unix:    name
  55.         name.ext
  56.         /dir/subdir/.../subdir/name
  57.         /dir/subdir/.../subdir/name.ext
  58.     TOPS-20:    any Unix style (supported by PCC-20)
  59.         <directory>name
  60.         <directory>name.ext
  61.         <directory>name.ext.gen
  62.         device:<directory>name
  63.         device:<directory>name.ext
  64.         device:<directory>name.ext.gen
  65.         [directory]name
  66.         [directory]name.ext
  67.         [directory]name.ext.gen
  68.         device:[directory]name
  69.         device:[directory]name.ext
  70.         device:[directory]name.ext.gen
  71.         logname:name
  72.         logname:name.ext
  73.         logname:name.ext.gen
  74.  
  75.     The Unix style should work  under IBM PC DOS (backslash  can
  76.     usually be  replaced for  forward  slash), and  the  TOPS-20
  77.     style contains VAX VMS as  a subset.  Fancier TOPS-20  names
  78.     are possible (control-V quoting of arbitrary characters, and
  79.     attributes), but they are rare enough that we do not support
  80.     them.  For  TOPS-20  and  VAX VMS,  generation  numbers  are
  81.     recognized as a digit following  the last dot, and they  are
  82.     preserved for the DVI file only.  For the output files,  the
  83.     highest generation  will always  be  assumed.  This  is  for
  84.     convenience with the  TOPS-20 TeX  implementation, which  on
  85.     completion types  in a  command "TeXspool:  foo.dvi.13"  and
  86.     waits for the user to type a carriage return.
  87.  
  88.     We only  need  to  extract the  directory  path,  name,  and
  89.     extension, so the parsing is simple-minded.
  90.  
  91.     ***********************************************************/
  92.  
  93.     tcp = strrchr(filestr,'/'); /* find end of Unix file path */
  94.  
  95. #if    (OS_ATARI | OS_PCDOS)
  96.     if (tcp == (char*)NULL)    /* no Unix-style file path */
  97.     tcp = strrchr(filestr, '\\');    /* try \dos\path\ */
  98. #endif
  99.  
  100. #if    OS_TOPS20
  101.     if (tcp == (char*)NULL)    /* no Unix-style file path */
  102.     {
  103.     tcp = strrchr(filestr, '>');    /* try <dir> */
  104.     if (tcp == (char*)NULL)            /* no <dir> */
  105.         tcp = strrchr(filestr, ']');    /* try [dir] */
  106.     if (tcp == (char*)NULL)            /* no [dir] */
  107.         tcp = strrchr(filestr, ':');    /* try logname: */
  108.     }
  109. #endif
  110.  
  111. #if    OS_VAXVMS
  112.     if (tcp == (char*)NULL)    /* no Unix-style file path */
  113.     {
  114.     tcp = strrchr(filestr, ']');    /* try [dir] */
  115.     if (tcp == (char*)NULL)            /* no [dir] */
  116.         tcp = strrchr(filestr, ':');    /* try logname: */
  117.     }
  118. #endif
  119.  
  120.     if (tcp == (char*)NULL)    /* no file path */
  121.     {
  122.     curpath[0] = '\0';    /* empty path */
  123.     tcp = filestr;    /* point to start of name */
  124.     }
  125.     else            /* save path for later use */
  126.     {
  127.     k = (INT16)(tcp-filestr+1);
  128.     (void)strncpy(curpath, filestr, (int)k);
  129.     curpath[k] = '\0';
  130.     tcp++;            /* point to start of name */
  131.     }
  132.  
  133.     tcp1 = strrchr(tcp, '.');    /* find last dot in filename */
  134.  
  135. #if    (OS_TOPS20 | OS_VAXVMS)
  136.     if ((tcp1 != (char*)NULL) && isdigit(*(tcp1+1)))
  137.     {                /* then assume generation number */
  138.     tcp2 = tcp1;        /* remember dot position */
  139.     *tcp1 = '\0';        /* discard generation number */
  140.     tcp1 = strrchr(tcp,'.');/* find last dot in filename */
  141.     *tcp2 = '.';        /* restore dot */
  142.     }
  143. #endif
  144.  
  145.     if (tcp1 == (char*)NULL)
  146.     {                /* no dot, so name has no extension */
  147.     (void)strcpy(curname, tcp);    /* save name */
  148.     tcp1 = strchr(tcp, '\0');    /* set empty extension */
  149.     }
  150.     else            /* save name part */
  151.     {
  152.     k = (INT16)(tcp1-tcp);
  153.     (void)strncpy(curname, tcp, (int)k);
  154.     curname[k] = '\0';
  155.     }
  156.  
  157.     (void)strcpy(curext, tcp1);    /* save extension */
  158.  
  159.  
  160.     /* DVI file must always have extension DVIEXT; supply one if
  161.     necessary (e.g /u/jones/foo.dvi) */
  162.  
  163.     (void)strcpy(dviname, curpath);
  164.     (void)strcat(dviname, curname);
  165.     if (curext[0] == '\0')
  166.     (void)strcat(dviname, DVIEXT);
  167.     else
  168.     (void)strcat(dviname, curext);
  169.  
  170.     /* Device output file is PATH NAME . DVIPREFIX OUTFILE_EXT (e.g.
  171.        /u/jones/foo.dvi-alw) */
  172.  
  173.     (void)strcpy(dvoname, curpath);
  174.     (void)strcat(dvoname, curname);
  175.     (void)strcat(dvoname, ".");
  176.     (void)strcat(dvoname, DVIPREFIX);
  177.     (void)strcat(dvoname, OUTFILE_EXT);
  178.  
  179.     /* Font substitution file is PATH NAME SUBEXT (e.g.
  180.        /u/jones/foo.sub).  We do not tell user (via stderr)
  181.        about it until it is needed. */
  182.  
  183.     if (subfile[0] == '\0')    /* no -fsubfile; make default */
  184.     {
  185.     (void)strcpy(subfile, curpath);
  186.     (void)strcat(subfile, curname);
  187.     (void)strcat(subfile, subext);
  188.     }
  189.  
  190.  
  191. #if    OS_UNIX
  192.     if (NO_FILENAME)
  193.     {
  194.     dvifp = stdin;        /* already open, so no DEBUG_OPEN call */
  195.     if (fseek(dvifp,0L,0))
  196.     {
  197.         (void)fprintf(stderr,
  198.         "%s: Unable to fseek() on stdin--was it a pipe?\n",
  199.         g_progname);
  200.         (void)EXIT(1);
  201.     }
  202.     }
  203.     else
  204.     {
  205.     dvifp = FOPEN(dviname,RB_OPEN);
  206.     DEBUG_OPEN(dvifp,dviname,RB_OPEN);
  207.     }
  208. #else
  209.  
  210.     dvifp = FOPEN(dviname,RB_OPEN);
  211.     DEBUG_OPEN(dvifp,dviname,RB_OPEN);
  212. #endif
  213.  
  214.     if (dvifp == (FILE*)NULL)
  215.     {
  216.     (void)sprintf(message,"dviinit(): %s: can't open [%s]",
  217.         g_progname, dviname);
  218.     (void)fatal(message);
  219.     }
  220.  
  221.     /* We try both
  222.     PATH NAME . DVIPREFIX OUTFILE_EXT and
  223.          NAME . DVIPREFIX OUTFILE_EXT,
  224.         in case the user does not have write access to the directory PATH */
  225.     for (i = 1; i <= 2; ++i)        /* two tries here */
  226.     {
  227.  
  228. #if    BBNBITGRAPH
  229.     strcpy(dvoname,"stdout");    /* BitGraph always goes to stdout */
  230.     plotfp = stdout;
  231. #else /* NOT BBNBITGRAPH */
  232.  
  233. #if    OS_VAXVMS
  234.  
  235. #if    POSTSCRIPT
  236.     plotfp = FOPEN(dvoname,WB_OPEN);
  237. #else
  238.     /* Create binary files for other devices; they cause less trouble
  239.         with VMS spooler programs. */
  240.     plotfp = FOPEN(dvoname,WB_OPEN,"rfm=fix","bls=512","mrs=512");
  241. #endif /* POSTSCRIPT */
  242.  
  243. #else /* NOT OS_VAXVMS */
  244.  
  245. #if    OS_UNIX
  246.     plotfp = NO_FILENAME ? stdout : FOPEN(dvoname,WB_OPEN);
  247. #else
  248.     plotfp = FOPEN(dvoname,WB_OPEN);
  249. #endif /* OS_UNIX */
  250.  
  251. #endif /* OS_VAXVMS */
  252.  
  253. #endif /* BBNBITGRAPH */
  254.  
  255. #if    OS_UNIX
  256.     if (!NO_FILENAME)
  257. #endif
  258.  
  259.     DEBUG_OPEN(plotfp,dvoname,WB_OPEN);
  260.     if (plotfp != (FILE*)NULL)
  261.         break;            /* open okay */
  262.     if (i == 2)
  263.     {
  264.         (void)strcpy(dvoname, curname);
  265.         (void)strcat(dvoname, ".");
  266.         (void)strcat(dvoname, DVIPREFIX);
  267.         (void)strcat(dvoname, OUTFILE_EXT);
  268.     }
  269.     }
  270.  
  271.     if (plotfp == (FILE*)NULL)
  272.     {
  273.     (void)sprintf(message,"dviinit(): %s: can't open [%s]",
  274.         g_progname, dvoname);
  275.     (void)fatal(message);
  276.     }
  277.  
  278. #if    OS_TOPS20
  279.     /* Because of the PCC-20 arithmetic (instead of logical)
  280.        shift bug wherein a constant expression (1<<35) evaluates
  281.        to 0 instead of 400000,,000000, we must set CF_nud using a
  282.        variable, instead of just using a constant */
  283.     /* "ac1 = makefield(CF_nud,1);" */
  284.     ac1 = 1;
  285.     ac1 = makefield(CF_nud,ac1);
  286.     setfield(ac1,CF_jfn,jfnof(fileno(plotfp)));    /* jfn */
  287.     setfield(ac1,CF_dsp,FBbyv);    /* generation number index in fdb */
  288.     ac2 = makefield(FB_ret,-1);
  289.     ac3 = makefield(FB_ret,0);    /* set generation count to 0 (infinite) */
  290.     (void)jsys(JSchfdb,acs);    /* ignore any errors */
  291. #endif /* OS_TOPS20 */
  292.  
  293. #if    CANON_A2
  294.  
  295. #ifdef CANON_TEST
  296.  
  297. #if    OS_ATARI
  298.     strcpy(tmoname,"\\ca2XXX\.");
  299. #else
  300.     strcpy(tmoname,"ca2XXXXXX");
  301. #endif
  302.  
  303.     mktemp(tmoname);
  304.     savefp = plotfp;
  305.     (void)sprintf(modestring,"%s+",WB_OPEN);
  306.     plotfp = FOPEN(tmoname, modestring);
  307.     stor_total = 0;
  308. #endif /* CANON_TEST */
  309.  
  310. #endif /* CANON_A2 */
  311.  
  312.     if (!quiet
  313.  
  314. #if    OS_UNIX
  315.     && !NO_FILENAME
  316. #endif
  317.  
  318.     )
  319.     {
  320.     (void)fprintf(stderr,"[Input from DVI file %s]",dviname);
  321.     NEWLINE(stderr);
  322.     (void)fprintf(stderr,"[Output on file %s]",dvoname);
  323.     NEWLINE(stderr);
  324.     }
  325.  
  326.     if (strncmp(curpath,dvoname,strlen(curpath)) == 0)
  327.     (void)strcpy(g_logname, curpath);    /* used PATH on output file */
  328.     else
  329.     g_logname[0] = '\0';        /* no PATH on output file */
  330.  
  331. #if    OS_UNIX
  332.     if (NO_FILENAME)            /* use dvixxx as file prefix */
  333.     {
  334.     (void)strcpy(g_logname, "dvi");
  335.     (void)strcat(g_logname, OUTFILE_EXT);
  336.     }
  337. #endif
  338.  
  339.     (void)strcat(g_logname, curname);
  340.     (void)strcat(g_logname, ".");
  341.     (void)strcat(g_logname, DVIPREFIX);
  342.  
  343. #if    (OS_ATARI | OS_PCDOS | OS_UNIX)
  344.     (void)strcat(g_logname, "err");
  345. #endif
  346.  
  347. #if    (OS_TOPS20 | OS_VAXVMS)
  348.     /* Force new generation; otherwise fopen(,"w+") reuses existing file */
  349.     (void)strcat(g_logname, "err.-1");
  350. #endif
  351.  
  352.     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  353.     tmargin = (COORDINATE)(topmargin*((float)YDPI));
  354.  
  355. #if    (CANON_A2 | IMPRESS | HPJETPLUS)
  356.     /* Printer has (0,0) origin at (XORIGIN,YORIGIN) near, but not at,
  357.     upper left corner */
  358.     lmargin -= XORIGIN;
  359.     tmargin -= YORIGIN;
  360. #endif /* (CANON_A2 | IMPRESS | HPJETPLUS) */
  361.  
  362.     if ((BYTE)nosignex(dvifp,(BYTE)1) != PRE)
  363.     (void)fatal("dviinit(): PRE doesn't occur first--are you sure \
  364. this is a DVI file?");
  365.  
  366.     i = (int)signex(dvifp,(BYTE)1);
  367.     if (i != DVIFORMAT)
  368.     {
  369.     (void)sprintf(message,
  370.         "dviinit(): DVI format = %d, can only process DVI format %d files.",
  371.         i, (int)DVIFORMAT);
  372.     (void)fatal(message);
  373.     }
  374. }
  375.