home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / stex2-18.zip / SeeTeX / Xtex / xtex.c < prev    next >
C/C++ Source or Header  |  1992-06-25  |  10KB  |  318 lines

  1. /*
  2.  * Copyright 1989 Dirk Grunwald
  3.  * 
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without fee,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Dirk Grunwald or M.I.T.
  9.  * not be used in advertising or publicity pertaining to distribution of
  10.  * the software without specific, written prior permission.  Dirk
  11.  * Grunwald and M.I.T. makes no representations about the suitability of
  12.  * this software for any purpose.  It is provided "as is" without express
  13.  * or implied warranty.
  14.  * 
  15.  * DIRK GRUNWALD AND M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL M.I.T.  BE LIABLE FOR ANY SPECIAL, INDIRECT
  18.  * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  19.  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  21.  * OR PERFORMANCE OF THIS SOFTWARE.
  22.  * 
  23.  * Author:
  24.  *     Dr. Dirk Grunwald
  25.  *     Dept. of Computer Science
  26.  *     Campus Box 430
  27.  *     Univ. of Colorado, Boulder
  28.  *     Boulder, CO 80309
  29.  * 
  30.  *     grunwald@colorado.edu
  31.  *     
  32.  */ 
  33.  
  34. #include "xtex.h"
  35. #include "mark.h"
  36. #include <string.h>
  37. #include "dvi-simple.h"
  38.  
  39. char *ProgName = "xtex";
  40. char *ClassName = "Xtex";
  41.  
  42. extern void BuildTopLevelWidget();
  43.  
  44. xtexResourceStruct xtexResources;
  45.  
  46. #define Offset(field) (XtOffset(xtexResourceStruct *, field))
  47.  
  48. static XtResource resources[] = {
  49.  
  50. /*
  51.  * Some variables for sanity checking
  52.  */
  53.  
  54.   {"incorrectlyInstalled", XtCString, XtRBool, sizeof(Bool),
  55.      Offset(incorrectlyInstalled), XtRString, "True"},
  56.  
  57.   {"programVersion", XtCString, XtRFloat, sizeof(float),
  58.      Offset(programVersion), XtRString, XTEX_VERSION},
  59.  
  60.   {"resourcesVersion", XtCString, XtRFloat, sizeof(float),
  61.      Offset(resourcesVersion), XtRString, "0.0"},
  62.  
  63.   {"print", XtCString, XtRString, sizeof(char *),
  64.      Offset(printProgram), XtRString, "lpr -d"},
  65.  
  66.   {"tfmPath", XtCString, XtRString, sizeof(char *),
  67.      Offset(tfmPath), XtRString, ""},
  68.  
  69.   {"xFontPath", XtCString, XtRString, sizeof(char *),
  70.      Offset(xFontPath), XtRString, ""},
  71.  
  72.   {"makeFont",  XtCString, XtRString, sizeof(char *),
  73.      Offset(makeFont), XtRString, ""},
  74.  
  75.   {"automakeFont",  XtCString, XtRBool, sizeof(Bool),
  76.      Offset(automakeFont), XtRString, "false"},
  77.  
  78.   {"mag", XtCString, XtRInt, sizeof(int),
  79.      Offset(userMag), XtRString, "500"},
  80.  
  81.   {"topOffset", XtCString, XtRFloat, sizeof(float),
  82.      Offset(topOffset), XtRString, "1"},
  83.  
  84.   {"leftOffset", XtCString, XtRFloat, sizeof(float),
  85.      Offset(leftOffset), XtRString, "1"},
  86.  
  87.   {"paperWidth", XtCString, XtRFloat, sizeof(float),
  88.      Offset(paperWidth), XtRString, "8.5"},
  89.  
  90.   {"paperHeight", XtCString, XtRFloat, sizeof(float),
  91.      Offset(paperHeight), XtRString, "11"},
  92.  
  93.   {"smallMag", XtCString, XtRInt, sizeof(int),
  94.      Offset(smallMag), XtRString, "333"},
  95.  
  96.   {"largeMag", XtCString, XtRInt, sizeof(int),
  97.      Offset(largeMag), XtRString, "500"},
  98.  
  99.   {"dpiHoriz", XtCString, XtRFloat, sizeof(float),
  100.      Offset(dpiHoriz), XtRString, "300"},
  101.  
  102.   {"dpiVert", XtCString, XtRFloat, sizeof(float),
  103.      Offset(dpiVert), XtRString, "-1"},
  104.  
  105.   {"debug", XtCString, XtRBool, sizeof(Bool),
  106.      Offset(debug), XtRString, "True"},
  107.  
  108.   {"pageMaxWd", XtCString, XtRInt, sizeof(int),
  109.      Offset(pageMaxWd), XtRString, "0"},
  110.  
  111.   {"pageMaxHt", XtCString, XtRInt, sizeof(int),
  112.      Offset(pageMaxHt), XtRString, "0"},
  113.  
  114.   {"autoSize", XtCString, XtRBool, sizeof(Bool),
  115.      Offset(autoSize), XtRString, "True"},
  116.  
  117.   {"useButtons", XtCString, XtRBool, sizeof(Bool),
  118.      Offset(useButtons), XtRString, "True"},
  119.  
  120.   {"updateNames", XtCString, XtRBool, sizeof(Bool),
  121.      Offset(updateNames), XtRString, "True"},
  122.  
  123.   {"pushOnStart", XtCString, XtRString, sizeof(char *),
  124.      Offset(pushOnStart), XtRString, "open"},
  125.  
  126.   {"divertByPush", XtCString, XtRBool, sizeof(Bool),
  127.      Offset(divertByPush), XtRString, "true"},
  128.  
  129.   {"fontPath", XtCString, XtRString, sizeof(char *),
  130.      Offset(fontPath), XtRString, ""},
  131.  
  132.   {"showPostScript", XtCString, XtRBool, sizeof(Bool),
  133.      Offset(showPostScript), XtRString, "True"},
  134.  
  135. /* default is to use DPS, then NEWS, then GhostScript 
  136.  * we will sort out which one to actually use later */
  137.  
  138. #if defined(HAVE_DPS) 
  139.   {"useDPS", XtCString, XtRBool, sizeof(Bool),
  140.      Offset(useDPS), XtRString, "True"},
  141. #else
  142.   {"useDPS", XtCString, XtRBool, sizeof(Bool),
  143.      Offset(useDPS), XtRString, "False"},
  144. #endif
  145.  
  146. #if defined(HAVE_NEWS) 
  147.   {"useNEWS", XtCString, XtRBool, sizeof(Bool),
  148.      Offset(useNEWS), XtRString, "True"},
  149. #else
  150.   {"useNEWS", XtCString, XtRBool, sizeof(Bool),
  151.      Offset(useNEWS), XtRString, "False"},
  152. #endif
  153.  
  154. #if defined(HAVE_GHOSTSCRIPT) && !defined(HAVE_DPS) && !defined(HAVE_NEWS)
  155.   {"useGhostScript", XtCString, XtRBool, sizeof(Bool),
  156.      Offset(useGhostScript), XtRString, "True"},
  157. #else
  158.   {"useGhostScript", XtCString, XtRBool, sizeof(Bool),
  159.      Offset(useGhostScript), XtRString, "False"},
  160. #endif
  161.  
  162. /*
  163.  *    the following options overide various globals, but aren't set
  164.  *    via command line switches.
  165.  */
  166.   {"helpText", "HelpText",
  167.      XtRString, sizeof(String),
  168.      Offset(helpText),
  169.      XtRString, "Warning -- Someone forgot to install APPDEFAULTSDIR/Xtex;\n\
  170. (You can also set the XAPPLRESDIR environment variable to point to it)"}
  171. };
  172.  
  173. static XrmOptionDescRec Options[] = {
  174.   {"-print", "*.print", XrmoptionSepArg, (caddr_t) NULL},
  175.   {"-automakeFont", "*.automakeFont", XrmoptionNoArg, (caddr_t) "True"},
  176.   {"-mag", "*.mag", XrmoptionSepArg, (caddr_t) NULL},
  177.   {"-topOffset", "*.topOffset", XrmoptionSepArg, (caddr_t) NULL},
  178.   {"-leftOffset", "*.leftOffset", XrmoptionSepArg, (caddr_t) NULL},
  179.   {"-paperWidth", "*.paperWidth", XrmoptionSepArg, (caddr_t) NULL},
  180.   {"-paperHeight", "*.paperHeight", XrmoptionSepArg, (caddr_t) NULL},
  181.   {"-smallMag", "*.smallMag", XrmoptionSepArg, (caddr_t) NULL},
  182.   {"-largeMag", "*.largeMag", XrmoptionSepArg, (caddr_t) NULL},
  183.   {"-dpi", "*.dpiHoriz", XrmoptionSepArg, (caddr_t) NULL},
  184.   {"-dpiVert", "*.dpiVert", XrmoptionSepArg, (caddr_t) NULL},
  185.   {"-debug", "*.debug", XrmoptionSepArg, (caddr_t) NULL},
  186.   {"-pageMaxWd", "*.pageMaxWd", XrmoptionSepArg, (caddr_t) NULL},
  187.   {"-pageMaxHt", "*.pageMaxHt", XrmoptionSepArg, (caddr_t) NULL},
  188.   {"-autoSize", "*.autoSize", XrmoptionSepArg, (caddr_t) NULL},
  189.   {"-useButtons", "*.useButtons", XrmoptionSepArg, (caddr_t) NULL},
  190.   {"-updateNames", "*.updateNames", XrmoptionSepArg, (caddr_t) NULL},
  191.   {"-tfmPath", "*.tfmPath", XrmoptionSepArg, (caddr_t) NULL},
  192.   {"-xFontPath", "*.xFontPath", XrmoptionSepArg, (caddr_t) NULL},
  193.   {"-pushOnStart", "*.pushOnStart", XrmoptionSepArg, (caddr_t) NULL},
  194.   {"-divertByPush", "*.divertByPush", XrmoptionSepArg, (caddr_t) NULL},
  195.   {"-fontPath", "*.fontPath", XrmoptionSepArg, (caddr_t) NULL},
  196.   {"-showPostScript", "*.showPostScript", XrmoptionSepArg, (caddr_t) NULL},
  197.   {"-useGhostScript", "*.useGhostScript", XrmoptionSepArg, (caddr_t) NULL}
  198. };
  199.  
  200. int Argc;
  201. char **Argv;
  202. Widget TopLevelWidget;
  203.  
  204. extern int FileOpenShouldCopy;
  205.  
  206. static void
  207. ArgError(argc, argv)
  208. int argc;
  209. char **argv;
  210. {
  211.   int i;
  212.   fprintf(stderr,"Following %s not understood:\n",
  213.       (argc == 2) ? "arg" : "args");
  214.   for (i = 1; i < argc; i++ ) {
  215.     fprintf(stderr,"%s ", argv[i]);
  216.   }
  217.   fprintf(stderr,"\n The following are valid arguments\n");
  218.  
  219.   fprintf(stderr,"%25s%20s\n",
  220.       "Command Line Option", "Resource Name");
  221.   for (i = 0; i < XtNumber(Options); i++ ) {
  222.     fprintf(stderr,"%25s%20s\n",
  223.         Options[i].option, Options[i].specifier);
  224.   }
  225.   exit(1);
  226. }
  227.  
  228. void 
  229. main(argc,argv)
  230. char ** argv;
  231. int argc;
  232. {
  233.  
  234.   Argc = argc;
  235.   Argv = argv;
  236.  
  237.   if( (ProgName = strrchr(argv[0], '/')) == NULL )
  238.     ProgName = argv[0];
  239.   else
  240.     ProgName++;
  241.  
  242.   TopLevelWidget = XtInitialize(ProgName, ClassName,
  243.                 Options, XtNumber(Options),
  244.                 &Argc, Argv);
  245.  
  246.   XtGetApplicationResources(TopLevelWidget,
  247.                 (caddr_t) &xtexResources, 
  248.                 resources, XtNumber(resources),
  249.                 NULL, (Cardinal) 0);
  250.  
  251.   /* barf if anything other than program name & file name is left */
  252.  
  253.   if ( Argc > 2 || Argc > 1 && *Argv[1] == '-' ) { 
  254.     ArgError(Argc,Argv);
  255.   }
  256.  
  257.   if ( xtexResources.incorrectlyInstalled ) {
  258.     fprintf(stderr,"ERROR: xtex has been incorrectly installed.\n");
  259.     fprintf(stderr,"Tell your local installation guru that the file\n");
  260.     fprintf(stderr,"``Xtex.ad'' must be installed in the system application\n");
  261.     fprintf(stderr,"defaults directory, e.g. ``/usr/lib/X11/app-defaults/Xtex''\n");
  262.     exit(0);
  263.   }
  264.  
  265.   TeXFileInstallActions();
  266.   TeXPageInstallActions();
  267.   TeXMarkInstallActions();
  268.  
  269.   BuildTopLevelWidget(TopLevelWidget);
  270.   XtRealizeWidget(TopLevelWidget);
  271.  
  272.   if ( xtexResources.programVersion != xtexResources.resourcesVersion ) {
  273.     fprintf(stderr,"WARNING: program version does not match resource file version\n");
  274.     error(0,0, "WARNING: program version does not match resource file version\n");
  275.   }
  276.  
  277.   fontPathInsurePaths( XtDisplay( TopLevelWidget ), xtexResources.fontPath );
  278.  
  279.   if ( Argc > 1 ) {
  280.     register char *p;
  281.  
  282.     /* set the directory name */
  283.     setDirectory( Argv[1] );
  284.  
  285.     /* peel off directory names & set the file name with the remainder */
  286.  
  287.     p = Argv[1];
  288.     p += strlen(Argv[1]) - 1;
  289.     while( p != Argv[1] && *p != '/' )
  290.       --p;
  291.     if( *p == '/' ) p++;
  292.     setFileName( p );
  293.  
  294.     if ( strcmp( xtexResources.pushOnStart, "open") == 0) {
  295.       FileOpenShouldCopy = False;
  296.     }
  297.     else {
  298.       FileOpenShouldCopy = True;
  299.     }
  300.  
  301.     setFile( p , FileOpenShouldCopy );
  302.     if ( DviFile != 0 ) {
  303.       TeXPageBuild();
  304.     }
  305.  
  306.   }
  307.   else {
  308.     setDirectory(".");
  309.   }
  310.  
  311.   if ( Argc > 2 ) {
  312.     error(0,0,"Additional arguments ignored");
  313.   }
  314.  
  315.   XtMainLoop();
  316.   exit(0);
  317. }
  318.