home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / TeX / tex / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-01  |  25.6 KB  |  953 lines

  1. #include <limits.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. #define INITEXTERN
  6. #define EXTERN extern
  7.  
  8. #include "texd.h"
  9.  
  10. #undef VERBOSE        /* Debugging */
  11.  
  12. #ifdef atarist
  13. extern long crlfflag;    /* write \n as \r\n in textfiles ? */
  14. #endif
  15.  
  16. #ifdef AMIGA
  17. extern int do_rexx;    /* defined in arexx.c */
  18. int create_info_file = FALSE;
  19. char info_file_name[150] = "TeX:config/dvi.info";
  20. #endif
  21.  
  22. /*
  23.  *  Name des Konfigurationsfiles wird in `read_configfile()' gesetzt!!
  24.  *
  25.  */
  26.  
  27.  
  28. static void read_configfile(void);
  29. static void init_variables(void);
  30. static void debug_print_vals(void);
  31. extern void debug_print_x(void);
  32.  
  33.  
  34. #if defined(INITEX) && defined(STAT) && defined(VERBOSE)
  35. /*
  36.  * Da an einigen Stellen nicht ganz saubere Sachen verwendet werden, sollte
  37.  * hier nachgeprueft werden, ob dies auch auf dieser Maschine funktioniert.
  38.  * (Es reicht, wenn man dies nur beim Testen macht, deshalb nur wenn fuer
  39.  * TripTest STAT und INITEX definiert sind)
  40.  */
  41.  
  42. /* 1. Beim Laden eines Fonts werden nicht einzelne `getc'-Aufrufe verwendet,
  43.  * sondern gleich pack-weise `fread's ausgefuehrt.  Dabei sollte der UNION
  44.  * jedoch so liegen, dass die fourquarters richtig gelesen werden.  Ausserdem
  45.  * sollte er genau 4 Bytes lang sein, da sonst Informationen fehlen.
  46.  */
  47.   void
  48. check_architecture(void)
  49. {
  50.    SMALLmemoryword test;
  51.    int bad = 0;
  52.  
  53.    test.qqqq.b0 = 0x12;
  54.    test.qqqq.b1 = 0x34;
  55.    test.qqqq.b2 = 0x56;
  56.    test.qqqq.b3 = 0x78;
  57.  
  58.    if( test.cint == 0x78563412 )    /* LittleEndian, no BigEndian */
  59.     bad |= 1;
  60.  
  61.    if( test.cint != 0x12345678 )    /* ??? */
  62.     bad |= 2;
  63.  
  64.    if( sizeof(SMALLmemoryword) != 4 )
  65.     bad |= 4;
  66.  
  67.    if( bad ) {
  68.     fprintf(stderr, "check_architecture: Sorry bad=0%o\n", bad);
  69.     exit(1);
  70.    }
  71. }
  72. #endif
  73.  
  74.  
  75. static short alloc_ok;    /* all malloc()-calls ok ? */
  76.  
  77.    static void *
  78. check_malloc(char *name, char *type, size_t size, long len)
  79. {
  80.   void *temp;
  81.   long oldlen = len;
  82.  
  83. #ifdef VERBOSE
  84.   static long gesamt = 0L;
  85.  
  86.   gesamt += (size * len);
  87.   printf("DBG: allocate(%s, %s, %d, %d)  sum = %ld\n",
  88.     name, type, size, len, gesamt);
  89. #endif
  90.  
  91.   if( alloc_ok == 0 ) {
  92.      fprintf(stderr, "\
  93. !! (`%s' requires %ld * %ld bytes of memory [parameter `%s'])\n",
  94.     name, len, size, type);
  95.      return NULL;
  96.   }
  97.  
  98.  
  99.   /* Hat man nicht genug Speicher ist es besser, wenn man einen moeglichen
  100.      Wert angezeigt bekommt, sodass man besser mit den Parametern spielen
  101.      kann.
  102.    */
  103.   while( (temp = malloc(size*len)) == NULL ) {
  104.     len -= len/1024;
  105.     len -= 8L;
  106.     if( len < 0L )
  107.     break;
  108.   }
  109.  
  110.   if( temp == NULL ) {
  111.      fprintf(stderr, "\
  112. !! Can't allocate enough memory for `%s' [parameter `%s'].\n\
  113. !! Please decrease parameters!\n",
  114.     name, type, "", "");
  115.      alloc_ok = 0;
  116.   } else if( len != oldlen ) {
  117.      fprintf(stderr, "\
  118. !! Can't allocate enough memory for `%s' [parameter `%s'].\n\
  119. !! (Using %ld elements instead of %ld (elementsize is %ld))\n\
  120. !! Please decrease parameters for proper run!\n",
  121.     name, type, len, oldlen, size);
  122.      alloc_ok = 0;
  123.   }
  124.   return temp;
  125. }
  126.  
  127.  
  128. /***************************/
  129. /* EXTERN................. */
  130. /***************************/
  131.    void
  132. init_arrays(int debugflag)
  133. {
  134. #if defined(INITEX) && defined(STAT) && defined(VERBOSE)
  135.   check_architecture();
  136. #endif
  137.  
  138.   /* in VirTeX mark, if an extra codepage is given in
  139.    * the configuration file, which should be used instead
  140.    * of the one given in the format file
  141.    */
  142. #ifdef ERW_CODEPAGE
  143.   codepage_given = 0;
  144. #endif
  145.  
  146.   init_variables();
  147.   read_configfile();
  148.  
  149.   if( debugflag ) {
  150. #if defined(NONASCII)
  151.     debug_print_x();
  152. #endif
  153.     debug_print_vals();
  154.   }
  155.  
  156.   alloc_ok = 1;
  157.  
  158. #ifdef EQTB_ALLOC
  159.   zeqtb = (MEDmemoryword *) check_malloc( "Equivalent Table (Internal)",
  160.         "eqtbsize", sizeof(MEDmemoryword), (eqtbsize +1) );
  161.  
  162.   zzzae = (quarterword *) check_malloc( "Equivalent Table Level (Internal)",
  163.         "xeqlevel", sizeof(quarterword), (eqtbsize-intbase+1) );
  164.   /* it's more efficient to "offset" `xeqlevel' at the beginning! */
  165.   zzzae -= (long) intbase;
  166.  
  167.   zzzaf = (twohalves *) check_malloc( "Hash Table (Internal)", "hashbase",
  168.         sizeof(twohalves), (undefinedcontrolsequence - hashbase +1) );
  169.   /* it's more efficient to "offset" `hash' at the beginning! */
  170.   zzzaf -= (long)hashbase;
  171.  
  172.   /* Note: access to locations below xeqlevel[intbase] or hash[hashbase]
  173.    * is forbidden, this is (should be) checked in the code.
  174.    * (This is secure, because the original code substracts these offsets
  175.    * each time it accesses the arrays...)
  176.    */
  177. #endif
  178.  
  179.   buffer = (ASCIIcode *) check_malloc( "input buffer", "bufsize",
  180.             sizeof(ASCIIcode), (bufsize+1) );
  181.   trickbuf = (ASCIIcode *) check_malloc( "trickbuffer", "errorline",
  182.             sizeof(ASCIIcode), (errorline+1) );
  183.   linestack = (integer *) check_malloc( "linestack", "maxinopen",
  184.             sizeof(integer), (maxinopen+1) );
  185.   inputfile = (alphafile *) check_malloc( "inputfiles", "maxinopen",
  186.             sizeof(alphafile), (maxinopen+1) );
  187.   inputstack = (instaterecord *) check_malloc( "inputstack", "stacksize",
  188.             sizeof(instaterecord), (stacksize+1) );
  189.   paramstack = (halfword *) check_malloc( "parameter stack", "paramsize",
  190.             sizeof(halfword), (paramsize+1) );
  191.   nest = (liststaterecord *) check_malloc( "semantic nest", "nestsize",
  192.             sizeof(liststaterecord), (nestsize+1) );
  193.  
  194.   fontinfo = (SMALLmemoryword *) check_malloc( "fontinfo", "fontmemsize",
  195.             sizeof(SMALLmemoryword), (fontmemsize+1) );
  196.  
  197.   fontdsize = (scaled *) check_malloc( "fontdsize", "fontmax",
  198.             sizeof(scaled), (fontmax+1) );
  199.   fontsize = (scaled *) check_malloc( "fontsize", "fontmax",
  200.             sizeof(scaled), (fontmax+1) );
  201.  
  202.   fontarea = (strnumber *) check_malloc( "fontarea", "fontmax",
  203.             sizeof(strnumber), (fontmax+1) );
  204.   fontname = (strnumber *) check_malloc( "fontname", "fontmax",
  205.             sizeof(strnumber), (fontmax+1) );
  206.  
  207.   fontused = (boolean *) check_malloc( "fontused", "fontmax",
  208.             sizeof(boolean), (fontmax+1) );
  209.  
  210. #ifdef FONTSTRUCT
  211.  
  212.   fontdesc = (struct font_desc *) check_malloc( "font", "fontmax",
  213.             sizeof(struct font_desc), (fontmax+1) );
  214.  
  215. #else
  216.  
  217.   fontcheck = (fourquarters *) check_malloc( "fontcheck", "fontmax",
  218.             sizeof(fourquarters), (fontmax+1) );
  219.   fontparams = (SMALLhalfword *) check_malloc( "fontparams", "fontmax",
  220.             sizeof(SMALLhalfword), (fontmax+1) );
  221. #ifdef FONTPTR
  222.   font_bcec = (struct fnt_bcec *) check_malloc( "fontbc/ec", "fontmax",
  223.             sizeof(struct fnt_bcec), (fontmax+1) );
  224. #else
  225.   fontbc = (eightbits *) check_malloc( "fontbc", "fontmax",
  226.             sizeof(eightbits), (fontmax+1) );
  227.   fontec = (eightbits *) check_malloc( "fontec", "fontmax",
  228.             sizeof(eightbits), (fontmax+1) );
  229. #endif
  230.   fontglue = (halfword *) check_malloc( "fontglue", "fontmax",
  231.             sizeof(halfword), (fontmax+1) );
  232.   hyphenchar = (integer *) check_malloc( "hyphenchar", "fontmax",
  233.             sizeof(integer), (fontmax+1) );
  234.   skewchar = (integer *) check_malloc( "skewchar", "fontmax",
  235.             sizeof(integer), (fontmax+1) );
  236.   bcharlabel = (fontindex *) check_malloc( "bcharlabel", "fontmax",
  237.             sizeof(fontindex), (fontmax+1) );
  238.   fontbchar = (short *) check_malloc( "fontbchar", "fontmax",
  239.             sizeof(short), (fontmax+1) );
  240.   fontfalsebchar = (short *) check_malloc( "fontfalsebchar", "fontmax",
  241.             sizeof(short), (fontmax+1) );
  242. #ifdef FONTPTR
  243. # define F_BASE_EL SMALLmemoryword *
  244. #else
  245. # define F_BASE_EL integer
  246. #endif
  247.   charbase = (F_BASE_EL *) check_malloc( "charbase", "fontmax",
  248.             sizeof(F_BASE_EL), (fontmax+1) );
  249.   widthbase = (F_BASE_EL *) check_malloc( "widthbase", "fontmax",
  250.             sizeof(F_BASE_EL), (fontmax+1) );
  251.   heightbase = (F_BASE_EL *) check_malloc( "heightbase", "fontmax",
  252.             sizeof(F_BASE_EL), (fontmax+1) );
  253.   depthbase = (F_BASE_EL *) check_malloc( "depthbase", "fontmax",
  254.             sizeof(F_BASE_EL), (fontmax+1) );
  255.   italicbase = (F_BASE_EL *) check_malloc( "italicbase", "fontmax",
  256.             sizeof(F_BASE_EL), (fontmax+1) );
  257.   ligkernbase = (F_BASE_EL *) check_malloc( "ligkernbase", "fontmax",
  258.             sizeof(F_BASE_EL), (fontmax+1) );
  259.   kernbase = (F_BASE_EL *) check_malloc( "kernbase", "fontmax",
  260.             sizeof(F_BASE_EL), (fontmax+1) );
  261.   extenbase = (integer *) check_malloc( "extenbase", "fontmax",
  262.             sizeof(integer), (fontmax+1) );
  263.   parambase = (integer *) check_malloc( "parambase", "fontmax",
  264.             sizeof(integer), (fontmax+1) );
  265.  
  266. #endif
  267.  
  268.   savestack = (MEDmemoryword *) check_malloc( "savestack", "fontmax",
  269.             sizeof(MEDmemoryword), (savesize+1) );
  270.   strpool = (packedASCIIcode *) check_malloc( "strpool", "fontmax",
  271.             sizeof(packedASCIIcode), (poolsize+1) );
  272.   strstart = (poolpointer *) check_malloc( "strstart", "fontmax",
  273.             sizeof(poolpointer), (maxstrings+1) );
  274.  
  275. #ifdef HYPHSTRUCT
  276.   hyph_op = (struct hyph_op *) check_malloc( "hyphenation operands", "trieopsize",
  277.             sizeof(struct hyph_op), (trieopsize+1) );
  278. #else
  279.   hyfdistance = (smallnumber *) check_malloc( "hyfdistance", "trieopsize",
  280.             sizeof(smallnumber), (trieopsize+1) );
  281.   hyfnum = (smallnumber *) check_malloc( "hyfnum", "trieopsize",
  282.             sizeof(smallnumber), (trieopsize+1) );
  283.   hyfnext = (trieopcode *) check_malloc( "hyfnext", "trieopsize",
  284.             sizeof(trieopcode), (trieopsize+1) );
  285. #endif
  286.  
  287. #ifdef INITEX
  288.   zzzaj = (SMALLhalfword *) check_malloc( "trieophash", "trieopsize",
  289.             sizeof(SMALLhalfword), (2*trieopsize+1) );
  290.   trieoplang = (ASCIIcode *) check_malloc( "trieoplang", "trieopsize",
  291.             sizeof(ASCIIcode), (trieopsize+1) );
  292.   trieopval = (trieopcode *) check_malloc( "trieopval", "trieopsize",
  293.             sizeof(trieopcode), (trieopsize+1) );
  294. #endif
  295.  
  296.   trietrl = (halfword *) check_malloc( "trie_trl", "triesize",
  297.             sizeof(halfword), (triesize+1) );
  298.   trietro = (halfword *) check_malloc( "trie_tro", "triesize",
  299.             sizeof(halfword), (triesize+1) );
  300.   trietrc = (quarterword *) check_malloc( "trie_trc", "triesize",
  301.             sizeof(quarterword), (triesize+1) );
  302.  
  303. #ifdef INITEX
  304.   triec = (packedASCIIcode *) check_malloc( "trie_c", "triesize",
  305.             sizeof(packedASCIIcode), (triesize+1) );
  306. #ifdef ORIGTRIE
  307.   trieo = (trieopcode *) check_malloc( "trie_o", "triesize",
  308.             sizeof(trieopcode), (triesize+1) );
  309.   trietaken = (boolean *) check_malloc( "trie_taken", "triesize",
  310.             sizeof(boolean), (triesize+1) );
  311. #else
  312.   ztrie = (trie_struct *) check_malloc( "trie_o/taken", "triesize",
  313.             sizeof(trie_struct), (triesize+1) );
  314. #endif
  315.   triehash = (triepointer *) check_malloc( "trie_hash", "triesize",
  316.             sizeof(triepointer), (triesize+1) );
  317.   triel = (triepointer *) check_malloc( "trie_l", "triesize",
  318.             sizeof(triepointer), (triesize+1) );
  319.   trier = (triepointer *) check_malloc( "trie_r", "triesize",
  320.             sizeof(triepointer), (triesize+1) );
  321. #endif
  322.  
  323.   dvibuf = (eightbits *) check_malloc( "DVI buffer", "dvibufsize",
  324.             sizeof(eightbits), (dvibufsize+1) );
  325.  
  326. #ifdef DEBUG
  327.   zzzab = (boolean *) check_malloc( "free array (debug)", "memmax",
  328.             sizeof(boolean), (memmax - memmin +1) );
  329.   zzzac = (boolean *) check_malloc( "was free array (debug)", "memmax",
  330.             sizeof(boolean), (memmax - memmin +1) );
  331. #endif
  332.  
  333. #if 0  /* !defined(INITEX) && defined(atarist) */
  334.   /* Fuer `virtex' ist `memmax' der maximal zu holende Speicher.  Falls nicht
  335.    * mehr so viel vorhanden, moeglichst viel holen.
  336.    */
  337. #ifdef VERBOSE
  338.   printf("malloc mem: memmax: %d memtop: %d alloc_ok: %d \n",
  339.      memmax, memtop, alloc_ok);
  340. #endif
  341.   if( alloc_ok != 0 ) {
  342.     size_t len = memmax - memmin + 1;
  343.  
  344.     while( len >= memtop ) {
  345. #ifdef VERBOSE
  346.       printf("malloc mem-loop: len: %d memtop: %d\n", len, memtop);
  347. #endif
  348.       if( (zzzaa = (memoryword *) malloc( sizeof(memoryword) * len )) != NULL )
  349.     break;
  350.       len -= 256;
  351.     }
  352.     /* ... und fuer den Fall, dass der malloc gescheitert ist, benutzen wir
  353.      * die normale Routine, um dem Benutzer den freien Speicher noch
  354.      * anzuzeigen.
  355.      */
  356.     if( len < memtop ) {
  357.       zzzaa = (memoryword *) check_malloc( "TeX's main memory", "memmax",
  358.                 sizeof(memoryword), (memmax - memmin +1) );
  359.     } else {
  360.       /* ... ansonsten `memmax' auf den neuen Wert setzen */
  361.       memmax = len + memmin - 1;
  362.       if( debugflag )
  363.     printf("DEBUG: set memmax = %ld\n", memmax);
  364.     }
  365.   }
  366. #else
  367.   zzzaa = (memoryword *) check_malloc( "TeX's main memory", "memmax",
  368.             sizeof(memoryword), (memmax - memmin +1) );
  369. #endif
  370.  
  371.   /* all malloc()-Calls ok ? */
  372.   if( alloc_ok == 0 )
  373.     exit(2);
  374.  
  375. #ifdef AMIGA
  376.   { char *ptr;
  377.  
  378.     do_rexx = 0;
  379.     if( (ptr = getenv("TEXREXX")) != NULL ) {
  380.       if( !stricmp(ptr, "edit") )
  381.     do_rexx = 2;        /* edit file immediatly */
  382.       else
  383.     do_rexx = 1;
  384.     }
  385.   }
  386. #endif
  387. }
  388.  
  389.  
  390. #  define c_memmax        65530L
  391. #  define c_memtop        c_memmax
  392. #  define c_bufsize        2000 
  393. #  define c_errorline        79 
  394. #  define c_halferrorline    50  
  395. #  define c_maxprintline    79
  396. #  define c_stacksize        200 
  397. #  define c_maxinopen        15 
  398. #  define c_fontmax        120 
  399. #  define c_fontmemsize        36000L
  400. #  define c_maxstrings        4400 
  401. #  define c_stringvacancies    15000
  402. #  define c_poolsize        45000L
  403. #  define c_savesize        2000
  404. #  define c_paramsize        60
  405. #  define c_nestsize        40
  406. #  define c_trieopsize        500
  407. #ifdef INITEX
  408. #  define c_triesize        19000
  409. #else
  410. #  define c_triesize        16000
  411. #endif
  412. #  define c_hyphsize        608
  413. #  define c_dvibufsize        16384
  414.  
  415.  
  416. #if defined(NONASCII)
  417.    void
  418. debug_print_x(void)
  419. { short i;
  420.  
  421.   for( i = 0 ; i <= 255 ; i++ )
  422.      if( xchr[i] != i || xord[i] != i
  423.     || (printable[i] && (i < 32 || i > 126)) )
  424.  
  425.     printf("DEBUG: 0x%x:  xord[]= 0x%x  xchr[]= 0x%x  is%s printable\n",
  426.         i, xord[i], xchr[i], (printable[i] ? "" : " not") );
  427. }
  428. #endif
  429.  
  430.  
  431.    static void
  432. init_variables(void)
  433. { short i;
  434.  
  435.   /* Initialize charset:  xchr: internalASCII -> external
  436.               xord: external      -> internalASCII
  437.    */
  438.  
  439.   /* The ST use an ASCII encoding, so ... (save space) */
  440.   for( i = 0 ; i <= 255 ; i++ ) {
  441.     xchr[i] = chr(i);
  442.     /* ... and the rest is just this: (only for this xchr[] !!) */
  443.     xord[i] = i;    /* xord[xchr[i]] = i;  xord[127] = 127; */
  444.   }
  445.   /* The CodePage is read in init_variables(), it changes both arrays */
  446.  
  447.   /* Initialize printable table */
  448.   for( i = 0 ; i < 32 ; i++ )
  449.     printable[i] = 0;
  450.   for( i = 32 ; i < 127 ; i++ )
  451.     printable[i] = 1;
  452.   for( i = 127 ; i < 256 ; i++ )
  453.     printable[i] = 0;
  454.  
  455.  
  456. #if defined(INITEX) && defined(NONASCII)
  457.  
  458. #if 0
  459.   /* Vielleicht eine gute Idee... als Default nicht 1:1 Umsetzung, sondern
  460.      auch noch andere anbieten...
  461.    */
  462.   /* Setup standard Translation tables: */
  463.   /* 1. Atari ST --> Cork Extended Font Encoding */
  464.   { unsigned char table[128] = {
  465.     0xc7,    0xfc,    0xe9,    0xe2,    0xe4,    0xe0,    0xe5,    0xe7,
  466.     0xea,    0xeb,    0xe8,    0xef,    0xee,    0xec,    0xc4,    0xc5,
  467.     0xc9,    0xe6,    0xc6,    0xf4,    0xf6,    0xf2,    0xfb,    0xf9,
  468.     0xb8,    0xd6,    0xdc,    0,    0xbf,    0,    0xff,    0,
  469.     0xe1,    0xed,    0xf3,    0xfa,    0,    0,    0,    0,
  470.     0xbe,    0,    0,    0,    0,    0x1a,    0x13,    0x14,
  471.     0xe3,    0xf5,    0xd8,    0xf8,    0xf7,    0xd7,    0xc1,    0xc3,
  472.     0xd5,    0x04,    0x01,    0,    0,    0,    0,    0,
  473.     0xbc,    0x9c,    0,    0,    0,    0,    0,    0,
  474.     0,    0,    0,    0,    0,    0,    0,    0,
  475.     0,    0,    0,    0,    0,    0,    0,    0,
  476.     0,    0,    0,    0,    0,    0x9f,    0,    0,
  477.     0,    0,    0,    0,    0,    0,    0,    0,
  478.     0,    0,    0,    0,    0,    0,    0,    0,
  479.     0,    0,    0,    0,    0,    0,    0,    0,
  480.     0x06,    0x0a,    0,    0,    0,    0,    0,    0x09
  481.     }
  482.     if( std_end_flag ) {
  483.       for( i = 0 ; i < 128 ; i++ ) {
  484.     if( table[i] != 0 ) {
  485.       xchr[i+128] = table[i];
  486.       printable[i] = 1;
  487.     }
  488.       }
  489.     }
  490.   }
  491. #endif
  492. #endif
  493.  
  494.    bufsize = c_bufsize;
  495.    errorline = c_errorline;
  496.    halferrorline = c_halferrorline;
  497.    maxprintline = c_maxprintline;
  498.    stacksize = c_stacksize;
  499.    maxinopen = c_maxinopen;
  500.    fontmax = c_fontmax;
  501.    fontmemsize = c_fontmemsize;
  502.    maxstrings = c_maxstrings;
  503.    stringvacancies = c_stringvacancies;
  504.    poolsize = c_poolsize;
  505.    savesize = c_savesize;
  506.    paramsize = c_paramsize;
  507.    nestsize = c_nestsize;
  508.    triesize = c_triesize;
  509.    trieopsize = c_trieopsize;
  510.    memtop = c_memtop;
  511. /*   hyphsize = c_hyphsize; */
  512.    dvibufsize = c_dvibufsize;
  513.  
  514.    /* In INITEX sollte memtop=memmax sein, in VIRTEX kann memax >= memtop
  515.     * sein, dabei wird nur bis memtop aus dem fmt-File gelesen (es steht ja
  516.     * auch nicht mehr drin ;-)
  517.     */
  518. #ifdef INITEX
  519.    memmax = c_memtop;
  520. #else
  521.    memmax = c_memmax;
  522. #endif
  523.    /* FUER MEMBOT: !!!! */
  524.    /* Jetzt sollte man noch memmin = membot fuer IniTeX setzen und
  525.     * memmin = 0 fuer VirTeX.  Jedoch wird dann bei jedem Zugriff auf das
  526.     * `mem' Array vom Index noch `memmin' abgezogen ==> langsamer....
  527.     */
  528. }
  529.  
  530. static long crash_int;        /* temporaer */
  531.  
  532. static struct iname {
  533.     char *name;
  534.     long *value;
  535. } init_var_name[] = {
  536.     "memmax",        &memmax,
  537.     "fontmax",        &fontmax,
  538.     "fontmemsize",        &fontmemsize,
  539.     "stringvacancies",    &stringvacancies,
  540.     "maxstrings",        &maxstrings,
  541.     "poolsize",        &poolsize,
  542.     "savesize",        &savesize,
  543.     "paramsize",        ¶msize,
  544.     "nestsize",        &nestsize,
  545.     "bufsize",        &bufsize,
  546.     "errorline",        &errorline,
  547.     "halferrorline",    &halferrorline,
  548.     "maxprintline",        &maxprintline,
  549.     "maxinopen",        &maxinopen,
  550.     "stacksize",        &stacksize,
  551.     "triesize",        &triesize,
  552.     "trieopsize",        &trieopsize,
  553.     "dvibufsize",        &dvibufsize,
  554.     "memtop",        &memtop,
  555. #ifdef INITEX
  556.     "itriesize",        &triesize,
  557. #else
  558.     "itriesize",        &crash_int,
  559. #endif
  560. #ifdef atarist
  561.     "crlf",            &crlfflag,
  562. #endif
  563.     "language",        &user_language,
  564.     (char *)NULL,        (long *)NULL
  565. };
  566.  
  567.  
  568.    static void
  569. debug_print_vals()
  570. {
  571.   struct iname *ip;
  572.  
  573.   ip = init_var_name;
  574.   while( ip->name != NULL ) {
  575.     if( ip->value != &crash_int )
  576.     printf("DEBUG: %s = %ld\n", ip->name, *(ip->value));
  577.     ip++;
  578.   }
  579. }
  580.  
  581.  
  582.  
  583.    static void
  584. read_cnf(FILE *cf, char *filename)
  585.   unsigned char readbuf[256];
  586.   signed long temp;
  587.   unsigned char *cp, *endp;
  588.   int index;
  589.   struct iname *ip;
  590.   long cnf_line = 0;
  591.  
  592.   while (fgets((char *)readbuf, 255, cf) != NULL) {
  593.     cnf_line++;
  594.  
  595.     if (readbuf[0] == '#')        /* Ende des Files */
  596.     return;
  597.  
  598.  
  599.     /* Search for percent sign */
  600.     cp = readbuf;
  601.     while( *cp && *cp != '%' )
  602.     cp++;
  603.     if (*cp == '%')            /* Kommentarzeile */
  604.     *cp = '\0';    /* ignore rest of line */
  605.  
  606.  
  607.     /* Get first word starting in column 1 */
  608.     cp = readbuf;
  609.     while( *cp && isascii(*cp) && !isspace(*cp) )
  610.     cp++;
  611.     if( *cp == '\0' )    /* Leerzeile ? */
  612.     continue;
  613.     if( cp == readbuf )    /* faengt mit Spaces an... Zeile ignorieren */
  614.     continue;
  615.     *cp++ = '\0';    /* erstes Wort mit \0 abschliessen */
  616.  
  617.  
  618.     /* ... und gleich weiterlesen (schadet nicht) */
  619.     while( *cp && isascii(*cp) && isspace(*cp) )
  620.     cp++;
  621.  
  622.  
  623.     /* Is it an environment variable ? */
  624.     index = get_env_var_index((char *)readbuf);
  625.     if( index >= 0 ) {
  626.     if( *cp == '\0' ) {    /* anscheinend keine Dir-Liste */
  627.       fprintf(stderr,
  628.           "%s (l.%ld): No Directory list for `%s', ignored.\n",
  629.           filename, cnf_line, readbuf);
  630.        continue;
  631.     }
  632.     endp = cp;
  633.     while( *endp && isascii(*endp) && !isspace(*endp) )
  634.        endp++;
  635.     *endp = '\0';
  636.  
  637.     /* Setze Pfad */ 
  638.     do_path(index, (char *)cp);
  639.     continue;
  640.     }
  641.  
  642.  
  643. #ifdef AMIGA
  644.     /* Info-Files fuer DVI-File erzeugen.. ja oder? */
  645.     if( !strcmp("create-info", (char *)readbuf) ) {
  646.       if( !strncmp("on", cp, 2) ) {
  647.         create_info_file = TRUE;
  648.       }
  649.       continue;        /* go to next line */
  650.     }
  651.     if( !strcmp("info-file-name", (char *)readbuf) ) {
  652.       endp = cp;
  653.       while( *endp && isascii(*endp) && !isspace(*endp) )
  654.         endp++;
  655.       *endp = '\0';
  656.       if( strlen(cp) < sizeof(info_file_name) ) {
  657.         strcpy(info_file_name, cp);
  658.       }
  659.       continue;
  660.     }
  661. #endif
  662.  
  663.  
  664. #if 0
  665.     /* Include file ... subfile */
  666.     /* Dies kann zu Rekursion fuehren... aber das merkt man spaetestens
  667.      * dann, wenn keine `file descriptors' mehr vorhanden sind.
  668.      */
  669.     if( !strcmp("include", (char *)readbuf) ) {
  670.     alphafile subfp;
  671.     int flag;
  672.  
  673.     endp = cp;
  674.     while( *endp && isascii(*endp) && !isspace(*endp) )
  675.        endp++;
  676.     *endp = '\0';
  677.  
  678.     sprintf(nameoffile, " %s ", cp);
  679.     namelength = strlen(cp);
  680.     flag = aopenin(subfp, TEXCONFIGPATH);
  681.  
  682.     /* 'cf' hat undefinierten Wert, falls File nicht lesbar, deshalb ganz
  683.      * auf Nummer Sicher ...
  684.      */
  685.     if (!flag || subfp == NULL) {
  686.       fprintf(stderr,
  687.           "%s (l.%ld): Includefile `%s' not found, ignored.\n",
  688.           filename, cnf_line, cp);
  689.     } else {
  690.       read_cnf(subfp, (char *)cp);
  691.       aclose(subfp);
  692.     }
  693.         continue;
  694.     }
  695. #endif /* include */
  696.  
  697.  
  698.     /* Starting a codepage ... ? */
  699.     if( !strcmp("codepage", (char *)readbuf) ) {
  700.  
  701. #if defined(NONASCII)
  702.     short c1, c2, op, tmp;
  703.  
  704. #ifdef ERW_CODEPAGE
  705.     /* codepage for VirTeX is marked with a `*' after `codepage' */
  706.     if( *cp == '*' )
  707.       codepage_given = 1;
  708. #endif
  709.  
  710.     while (fgets((char *)readbuf, 255, cf) != NULL) {
  711.       cnf_line++;
  712.       cp = readbuf;
  713.       op = 0;
  714.  
  715.       /* read over whitespace before first number/operand */
  716.       while( *cp && isascii(*cp) && isspace(*cp) )
  717.         cp++;
  718.  
  719. #define is_hex(c) \
  720.   ( ((c) >= '0' && (c) <= '9') || ((c) >= 'a' && ((c) <= 'f')) )
  721.  
  722.       /* Read number 1 */
  723.       if( *cp == '<' ) {
  724.          op = 3;
  725.          c1 = 1;
  726.       } else if( *cp == '^' && *(cp + 1) == '^'
  727.           && *((unsigned char *)(cp + 2)) < 128 ) {
  728.          cp += 2;
  729.          c1 = *cp;
  730.          tmp = *(cp + 1);
  731.          if( is_hex(c1) && is_hex(tmp) ) {
  732.         c1 = ( (c1 <= '9') ? (c1 - '0') : (c1 - 'a' + 10) ) * 16
  733.             + ((tmp <= '9') ? (tmp - '0') : (tmp - 'a' + 10)) ;
  734.         cp++;
  735.          } else
  736.         c1 += ( c1 < 64 ) ? +64 : -64;
  737.       } else if( *cp == '\0' ) {
  738.          /* \n und \r sollten natuerlich (isspace() == true) sein !! */
  739.          continue;        /* Leerzeile ignorieren */
  740.       } else
  741.          c1 = *((unsigned char *)cp);
  742.       cp++;
  743.  
  744.       /* Read the operand '<<', '<', '<|', '=' or '>' */
  745.       if( op == 3 ) {    /* Read '<' before ? */
  746.          if( *cp == '<' )
  747.         break;        /* while */
  748.          if( *cp == '|' ) {
  749.         op = 4;
  750.         cp++;
  751.          }
  752.       } else {
  753.          /* read over whitespace before operand */
  754.          while( *cp && isascii(*cp) && isspace(*cp) )
  755.         cp++;
  756.  
  757.          if( *cp == '>' ) {
  758.         op = 2;
  759.         cp++;
  760.          } else if( *cp == '=' ) {
  761.         op = 1;
  762.          cp++;
  763.          } else {
  764.         fprintf(stderr,
  765.           "%s (l.%ld): Syntax error in Codepage, false operand.\n",
  766.           filename, cnf_line);
  767.         exit(2);
  768.          }
  769.       }
  770.  
  771.       /* read over whitespace after operand */
  772.       while( *cp && isascii(*cp) && isspace(*cp) )
  773.         cp++;
  774.  
  775.       /* Read number2 */
  776.       if( *cp == '^' && *(cp + 1) == '^'
  777.        && *((unsigned char *)(cp + 2)) < 128 ) {
  778.          cp += 2;
  779.          c2 = *((unsigned char *)cp);
  780.          tmp = *((unsigned char *)(cp + 1));
  781.          if( is_hex(c2) && is_hex(tmp) ) {
  782.         c2 = ( (c2 <= '9') ? (c2 - '0') : (c2 - 'a' + 10) ) * 16
  783.             + ((tmp <= '9') ? (tmp - '0') : (tmp - 'a' + 10)) ;
  784.         cp++;
  785.          } else
  786.         c2 += ( c2 < 64 ) ? +64 : -64;
  787.       } else
  788.          c2 = *((unsigned char *)cp);
  789.  
  790.       /* Now we have read 2 number and an operand */
  791.  
  792.       /* The 2 numbers must < 32 or > 126 and != [0,10,13] */
  793.       if( (c1 >= 32 && c1 <= 126) || c1 == 0 || c1 == 10 || c1 == 13 ) {
  794.         fprintf(stderr,
  795. "%s (l.%ld): Invalid value for %s number (0x%x) in codepage, ignored.\n",
  796.         filename, cnf_line, "first", c2);
  797.         continue;        /* while */
  798.       }
  799.       /* For x>y, y is not restricted */
  800.       if( (op != 2) && ( (c2 >= 32 && c2 <= 126)
  801.                 || c2 == 0 || c2 == 10 || c2 == 13 ) ) {
  802.         fprintf(stderr,
  803. "%s (l.%ld): Invalid value for %s number (0x%x) in codepage, ignored.\n",
  804.         filename, cnf_line, "second", c2);
  805.         continue;        /* while */
  806.       }
  807.  
  808.       switch( op ) {
  809.       case 4:
  810. #ifdef VERBOSE
  811.          printf("DBG: Char %d is set unprintable ( xchr[%d] = %d ).\n",
  812.         c2, c2, c2);
  813. #endif
  814.          xchr[c2] = c2;
  815.          printable[c2] = 0;
  816.          break;
  817.       case 3:
  818. #ifdef VERBOSE
  819.          printf("DBG: Char %d is set printable ( xchr[%d] = %d ).\n",
  820.         c2, c2, c2);
  821. #endif
  822.          xchr[c2] = c2;
  823.          printable[c2] = 1;
  824.          break;
  825.       case 2:
  826. #ifdef VERBOSE
  827.          printf("DBG: read %d as %d ( xord[%d] = %d ).\n",
  828.         c1, c2, c1, c2);
  829. #endif
  830.          xord[c1] = c2;
  831.          break;
  832.       case 1:
  833. #ifdef VERBOSE
  834.          printf(
  835.     "DBG: read %d as %d, write %d as %d ( xord[%d] = %d ; xchr[%d] = %d ).\n",
  836.         c1, c2, c2, c1, c1, c2, c2, c1);
  837. #endif
  838.          xord[c1] = c2;
  839.          xchr[c2] = c1;
  840.          printable[c2] = 1;
  841.          break;
  842.       default:
  843.          /* dies kann nicht sein, da sonst oben exit()-call */
  844.          break;
  845.       }
  846.  
  847.     }    /* end while */
  848. #else
  849.     /* Otherwise (VirTeX): Read until "<<" found */
  850.  
  851.     while (fgets((char *)readbuf, 255, cf) != NULL) {
  852.       cnf_line++;
  853.       cp = readbuf;
  854.       /* read over whitespace before first number/operand */
  855.       while( *cp && isascii(*cp) && isspace(*cp) )
  856.         cp++;
  857.       if( *cp == '<' && *(cp+1) == '<' )
  858.         break;
  859.     }
  860. #endif
  861.     continue;    /* Read next lines in Config-File */
  862.     }
  863.  
  864.     /* ... else look for other parameters. */
  865.     ip = init_var_name;
  866.     while( ip->name != NULL && strcmp(ip->name, (char *)readbuf) )
  867.     ip++;
  868.  
  869.     if( ip->name == NULL ) {
  870.     fprintf(stderr, "%s (l.%ld): Unknown parameter `%s', ignored.\n",
  871.         filename, cnf_line, readbuf);
  872.     continue;
  873.     }
  874.  
  875.     /* 'cp' steht schon am Anfang des Wertes (siehe oben) */
  876.  
  877.     /* Ist der 3.Parameter von 'strtol' 0, kann man -- wie in C --
  878.      * die Basis mit der Zahl angeben, also z.B. 011 ist oktal (dez. = 9)
  879.      * 0xff oder 0Xff ist hexadezimal (dez. = 255).
  880.      */
  881.     temp = strtol((char *)cp, NULL, 0);
  882.  
  883.     /* Bei Overflow ist 'errno' gesetzt und Wert = LONG_MAX/MIN */
  884.     if( temp != LONG_MAX && temp != LONG_MIN ) {
  885.     *(ip->value) = temp;
  886.     } else {
  887.     fprintf(stderr, "%s (l.%ld): Incorrect value for `%s', ignored.\n",
  888.         filename, cnf_line, ip->name);
  889.     }
  890.   }        /* while( fgets(...) ) */
  891. }
  892.  
  893.  
  894.    static void
  895. read_configfile(void)
  896. {
  897.   alphafile cf;
  898.   int flag;
  899.  
  900. #ifdef AMIGA
  901. #ifdef BIG
  902.   char cnfname[] = "BigTeX.cnf";
  903. #else
  904.   char cnfname[] = "TeX.cnf";
  905. #endif
  906. #else
  907.   /* Fuer den ST ist es unter TOS unwichtig, ob Gross- oder Kleinschreibung.
  908.    * Mit MiNT bzw. den GCC-libs kann es jedoch schon Probleme geben, da man
  909.    * hier ein evtl. Mapping hat (ueber File .dir).
  910.    */
  911. #ifdef BIG
  912.   char cnfname[] = "bigtex.cnf";
  913. #else
  914.   char cnfname[] = "tex.cnf";
  915. #endif
  916. #endif
  917.  
  918.   sprintf(nameoffile, " %s ", cnfname);
  919.   namelength = strlen(cnfname);
  920.   flag = aopenin(cf, TEXCONFIGPATH);
  921.  
  922.   /* 'cf' hat undefinierten Wert, falls File nicht lesbar, deshalb ganz
  923.    * auf Nummer Sicher ...
  924.    */
  925.   if (!flag || cf == NULL) {
  926.     fprintf(stderr,
  927.     "Warning: %s not found, using the default values.\n", cnfname);
  928.     return;
  929.   }
  930.  
  931.   read_cnf(cf, cnfname);
  932.  
  933. #ifdef INITEX
  934.   memmax = memtop;    /* fuer INITEX: immer memtop = memmax */
  935.             /* Damit kann memmax & memtop fuer Initex & Virtex */
  936.             /* im gleichen Configfile angegeben werden. */
  937. #endif
  938.  
  939.   if( memtop > memmax ) {
  940.     fprintf(stderr, "Error in Config-File %s: 'mem_top' > 'memmax'!\n",
  941.     cnfname);
  942.     memmax = memtop;    /* memtop <= memmax !! */
  943.     /* Da mindestens 'memtop' Platz benoetigt wird, um das gedumpte
  944.      * Format einzulesen, wird nicht memtop=memmax verwendet.
  945.      */
  946.   }
  947.   /* ... und das ganze auch wieder schliessen ... */
  948.   aclose(cf);
  949. }
  950.  
  951. /* end of init.c */
  952.