home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / preview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-27  |  8.0 KB  |  254 lines

  1. /*
  2.  *   This software is Copyright 1988 by Radical Eye Software.
  3.  *   All Rights Reserved.
  4.  */
  5. /*
  6.  *   dviamiga.c of dviamiga software package.
  7.  *
  8.  *   This is a preliminary main routine.
  9.  */
  10. #include "structures.h"
  11. #include <string.h>
  12. /*
  13.  *   Our globals:
  14.  */
  15. TeXfontdesctype *TeXfonts[256] ;     /* font pointers */
  16. TeXfontdesctype *TeXfontlist ;
  17. fontdesctype *fontlist = NULL ;      /* list of resident fonts */
  18. Boolean landscape = 0 ;              /* are we in landscape? */
  19. FILE *dvifile, *pkfile ;             /* files for input and output */
  20. integer curpos ;                     /* dvi file position */
  21. integer thispage ;                   /* where this page is */
  22. integer rthispage ;
  23. integer prevpage ;                   /* previous page */
  24. integer pagenum, seq ;               /* page number */
  25. real conv, pxlconv ;                 /* to pixel conversion factors */
  26. integer iconv ;                      /* integer to pixel conversion factor */
  27. real vconv ;                         /* these are for the half mode */
  28. integer viconv ;
  29. real alpha ;                  /* conversion ratio, DVI unit per TFM unit */
  30. integer mag ;                 /* the magnification of this document */
  31. real screendpi = 100.0 ;             /* current screen resolution */
  32. shalfword hh, vv ;                   /* current pixel position */
  33. shalfword fnt ;                      /* current font (0-255) */
  34. fontdesctype *curfnt ;               /* current font (pointer) */
  35. char *resident ;                     /* where to find configuration info */
  36. char *tfmpath ;                      /* where to find tfm info */
  37. char *inputspath ;                   /* where to find input files */
  38. char *configpath ;
  39. char *headerpath ;
  40. char defaultfont[256] ;              /* the default font name, size */
  41. frametype frames[MAXFRAME] ;         /* stack for virtual fonts */
  42. quarterword *virpos ;         /* current position in virtual character packet */
  43. quarterword *virlim ;         /* final byte in virtual character packet */
  44. fontmaptype *ffont ;          /* first font in current frame */
  45. char *vfpath ;                    /* pointer to directories for vf files */
  46. char *pkpath ;                       /* where to find pk info */
  47. shalfword hhoffset, vvoffset ;       /* the horizontal and vertical off */
  48. shalfword hhmin, hhmax, vvmin, vvmax ; /* the borders of the screen */
  49. real hsize = 8.5, vsize = 11.0, hmarg = 1.0, vmarg = 1.0 ;
  50.                                      /* the page and margin size */
  51. real defhsize = 8.5, defvsize = 11.0, defhmarg = 1.0, defvmarg = 1.0 ;
  52. shalfword hhsize, vvsize, hhmarg, vvmarg ;
  53. shalfword rhhsize, rvvsize, rhhmarg, rvvmarg ;
  54. shalfword hbody, vbody, hpos, vpos ;
  55. integer hpot = 32768, vpot = 0 ;
  56. shalfword vscreen = 380 ;            /* screen size vertical */
  57. shalfword vwindow, vwindowheight, hwindow, hwindowwidth ;
  58. integer dvimag, num, den ;           /* sizes from dvi file */
  59. integer memalloc = 0 ;
  60. integer numalloc = 0 ;
  61. Boolean pageinterrupted = 0 ;
  62. integer messagebit ;                 /* the bit to wait for on IDCMP */
  63. real possibmag[] = {                 /* possible screen dots per inch */
  64.    33.4898,                          /* this one is writeable */
  65.    16.1506,   17.6921,   19.3807,   21.2305,   23.2568,
  66.    25.4766,   27.9082,   30.5719,   33.4898,   36.6862,
  67.    40.1878,   44.0235,   48.2253,   52.8282,
  68.    57.8704,   63.3938,   69.4444,   76.0726,   83.3333,
  69.    91.2871,  100.0000,  109.5445,  120.0000,  131.4534,
  70.   144.0000,  157.7441,  172.8000,  189.2929,  300.0000,
  71.   400.0000,    0.0000 } ;
  72. int existsize100[] = { 0, 69, 76, 83, 91, 100, 110, 120,
  73.     131, 144, 158, 173, 189, 207, 227, 249, 273, 299, 327, 358, 393,
  74.     430, 471, 516, 565, 619, 678, 743, 814, 892, 977, 1070, 32767 } ;
  75. int existsize300[] = { 0, 300, 329, 360, 432, 518, 622, 746, 896,
  76.     1075, 1290, 1548, 32767 } ;
  77. int existsize400[] = { 0, 400, 438, 480, 576, 691, 829, 995, 1194,
  78.     1433, 1720, 2064, 32767 } ;
  79. int *existsize = existsize100 ;
  80. real userdpi[] = { 91.2871, 120.0000 } ;
  81. int debugon = 0 ;
  82. int paranoia = 0 ;
  83. Boolean borderson = 1 ;
  84. Boolean dualpage = 0 ;
  85. Boolean orientationset = 0 ;
  86. Boolean reopenscreen = 0 ;
  87. shalfword vscreenheight = 400 ;
  88. Boolean interlaceon = 1 ;
  89. int first ;
  90. int x, y ;
  91. int tracking ;
  92. Boolean zoomed = 0 ;
  93. Boolean mocked = 0 ;
  94. char realname[200] ;
  95. char safebuf[200], filenamebuf[200] ;
  96. int redrawbars = 0 ;
  97. int turnitoff = 0 ;
  98. int nloc ;
  99. integer spage, sno ;
  100. Boolean redrawpage ;
  101. int rowsize, colsize ;
  102. Boolean autofront=1, autoactivate ;
  103. int actualdpi = 100 ;
  104. extern char pagebuf[] ;
  105. extern Boolean usersetsizes ;
  106. extern char defaulttitle[] ;
  107. extern char safebuf[] ;
  108. /*
  109.  *   The external routines we call:
  110.  */
  111. extern void dopage() ;
  112. extern void initialize() ;
  113. extern shalfword skipnop() ;
  114. extern void skipover() ;
  115. extern Boolean seekpage() ;
  116. extern void exit() ;
  117. extern void recalculate() ;
  118. extern int NXAlert() ;
  119. extern int NXRunAlertPanel() ;
  120. extern int NXGetAlertPanel() ;
  121. extern void TPSbop(), TPSeop() ;
  122. extern void texflush() ;
  123. extern void display() ;
  124. int dviOpenFile() ;
  125. extern void writeconsole() ;
  126. /*
  127.  *   Pops and deletes an alert panel to get around a bug.
  128.  */
  129. void fixalertbug() {
  130. #ifdef BADKLUDGE
  131.    NXRunAlertPanel("Howdy!", "This is TeXview 0.0\nCopyright 1989 Radical Eye Software\nAll Rights Reserved",
  132.        NULL, NULL, NULL) ;
  133. #endif
  134. }
  135. /*
  136.  *   error is called on all errors.  It prints the message, and exits
  137.  *   if the error starts with !.
  138.  */
  139. char temperrorbuf[80] ;
  140. extern char lastfile[] ;
  141. Boolean erroronscreen = 0 ;
  142. void error(s)
  143. register char *s ;
  144. {
  145.    fflush(stdout) ;
  146.    writeconsole(s) ;
  147.    NXRunAlertPanel(NULL, s, "OK", NULL, NULL) ;
  148.    if (*s=='!') {
  149.       if (lastfile[0])
  150.          NXRunAlertPanel(NULL, "Last font was %s\n", "OK", NULL, NULL, lastfile) ; /* jvc */
  151.       exit(1) ;
  152.    }
  153. }
  154. /*
  155.  *   Our main routine will get a file name from the command line.  First,
  156.  *   a routine to check if we need to quit.
  157.  */
  158. int checkformessage() {
  159.    return(0) ;
  160. }
  161. int gargc ;
  162. void more_main (argc, argv)
  163. int argc ;
  164. char *argv[] ;
  165. {
  166.    if (argc > 1 && argv[1][0]=='-' && argv[1][1]=='d') {
  167.       if (argv[1][2] <= '9' && argv[1][2] >= '0')
  168.          debugon = argv[1][2] - '0' ;
  169.       else
  170.          debugon = 1 ;
  171.       argc-- ; argv++ ;
  172.    }
  173.    while (argc > 1 && argv[1][0]=='-') {
  174.       argc-- ; argv++ ;
  175.    }
  176.    screendpi = userdpi[zoomed] ;
  177.    dvifile = NULL ;
  178.    usersetsizes = 0 ;
  179.    hsize = 8.5 ;
  180.    vsize = 11.0 ;
  181.    hmarg = 1.0 ;
  182.    vmarg = 1.0 ;
  183.    gargc = argc ;
  184.    initialize() ;
  185.    curpos = 0 ;
  186.    recalculate() ;
  187.    if (argc > 1) {
  188.       char *p, *last ;
  189.       last = 0 ;
  190.       strcpy(realname, argv[1]) ;
  191.       for (p=realname; *p; p++)
  192.          if (*p == '.')
  193.             last = p ;
  194.          else if (*p == '/')
  195.             last = 0 ;
  196.       if (last == 0)
  197.          strcat(realname, ".dvi") ;
  198.       if (dviOpenFile(realname) == 1)
  199.          display() ;
  200.    } else
  201.       display() ;
  202. }
  203. /*
  204.  *   This is where we fix the environment variable problem
  205.  *   caused by the fact that the WorkSpace environment
  206.  *   doesn't get environment variables.
  207.  */
  208. #undef getenv
  209. char *getenv(), *malloc() ;
  210. char *mgetenv(s)
  211. char *s ;
  212. {
  213.    static int envinit = 0 ;
  214.    static struct envpair {
  215.       struct envpair *next ;
  216.       char *name, *val ;
  217.       char s[1] ;
  218.    } *envbase = 0 ;
  219.    char inbuf[1000] ;
  220.    char *p ;
  221.    struct envpair *tp ;
  222.  
  223.    if (envinit == 0) {
  224.       FILE *f = popen("csh -c printenv", "r") ;
  225.       if (f) {
  226.          while (fgets(inbuf, 1000, f))
  227.             if (strlen(inbuf) > 3) {
  228.                inbuf[strlen(inbuf)-1] = 0 ;
  229.                for (p=inbuf; *p && *p != '='; p++) ;
  230.                if (*p == '=') {
  231.                   tp = (struct envpair *)
  232.                             malloc(sizeof(struct envpair) + strlen(inbuf)) ;
  233.                   tp->next = envbase ;
  234.                   strcpy(tp->s, inbuf) ;
  235.                   p = tp->s + (p - inbuf) ;
  236.                   tp->name = tp->s ;
  237.                   tp->val = p + 1 ;
  238.                   *p = 0 ;
  239.                   envbase = tp ;
  240.                }      
  241.             }
  242.          pclose(f) ;
  243.       }
  244.       envinit = 1 ;
  245.    }
  246.    p = getenv(s) ;
  247.    if (p)
  248.       return p ;
  249.    for (tp = envbase; tp; tp = tp->next)
  250.       if (strcmp(s, tp->name)==0)
  251.          return tp->val ;
  252.    return 0 ;
  253. }
  254.