home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / texsrc.arc / EXTRA.C < prev    next >
C/C++ Source or Header  |  1988-09-14  |  22KB  |  809 lines

  1. /*
  2.  * Hand-coded routines for C TeX.
  3.  * This module should contain any system-dependent code.
  4.  *
  5.  * This code was written by Tim Morgan, drawing from other Unix
  6.  * ports of TeX.
  7.  * hacked up for MEGAMAX-C on ATARI ST by David Dermott
  8.  */
  9.  
  10. /*#define    CATCHINT*/        /* Catch ^C's */
  11. /*#undef    SYSV        */    /* Turn on System V compatibility */
  12. /*#define    BSD    */        /* 4.[23]BSD */
  13.  
  14. #define    EXTERN            /* Actually instantiate globals here */
  15.  
  16. #include "texd.h"
  17. #include <osbind.h>   /* st os routines */
  18. #ifdef    CATCHINT
  19. #include <signal.h>
  20. #endif
  21. #ifdef    BSD
  22. #include <sys/time.h>
  23. #else
  24. #include <time.h>
  25. #endif
  26. /*#if defined(BSD)||defined(SYSV)
  27. #include <sgtty.h>
  28. #endif
  29. */
  30.  
  31. #ifdef    VMS
  32. #define    index    strchr        /* Sys V compatibility */
  33. #endif
  34.  
  35. /* C library stuff that we're going to use */
  36. extern char *strcpy(), *strcat(), *malloc(), *sprintf(), *index(), *getenv();
  37.  
  38. /* Local stuff */
  39. static int gargc;
  40. static char **gargv;
  41. static char texformats[filenamesize], texinputs[filenamesize];
  42. static char texfonts[filenamesize], texpool[filenamesize];
  43. static char my_realnameoffile[filenamesize];
  44. /*static char *texeditvalue = "/usr/ucb/vi +%d %s";*/
  45. static char *texeditvalue = "EMACS.TTP -g%d %s";
  46.  
  47. #define    TRUE    1
  48. #define    FALSE    0
  49.  
  50. #ifdef    CATCHINT
  51. /* If we're catching ^C, come here when one comes in. */
  52. static catchint()
  53. {
  54.     interrupt = 1;
  55.     (void) signal(SIGINT, catchint);
  56. }
  57. #endif
  58.  
  59. /* Do the obvious */
  60. get_date_and_time(minutes, day, month, year)
  61. integer *minutes, *day, *month, *year;
  62. {
  63.     long clock, time();
  64.     struct tm *tmptr, *localtime();
  65.  
  66.     clock = time((long *) 0);
  67.     tmptr = localtime(&clock);
  68.  
  69.     *minutes = tmptr->tm_hour * 60 + tmptr->tm_min;
  70.     *day = tmptr->tm_mday;
  71.     *month = tmptr->tm_mon + 1;
  72.     *year = tmptr->tm_year + 1900;
  73. #ifdef    CATCHINT
  74.     (void) signal(SIGINT, catchint);
  75. #endif
  76.  
  77. }
  78.  
  79. #ifdef    INITEX
  80. /* Read until we pass end of line on the input file, a la Pascal */
  81. readln(f)
  82. FILE *f;
  83. {
  84.     register int c;
  85.  
  86.     do
  87.     c = getc(f);
  88.     while (c != '\n' && c != EOF);
  89. }
  90.  
  91. /* Same as in Pascal --- return TRUE if EOF or next char is newline */
  92. eoln(f)
  93. FILE *f;
  94. {
  95.     register int c;
  96.  
  97.     if (feof(f)) return(TRUE);
  98.     c = getc(f);
  99.     if (c != EOF)
  100.     (void) ungetc(c, f);
  101.     return (c == '\n' || c == EOF);
  102. }
  103. #endif    /* INITEX */
  104.  
  105. static void copy_path(ptr, defptr, override)
  106. char *ptr, *defptr, *override;
  107. {
  108.     if (override) {
  109.     if (strlen(override) >= 1024) {
  110.         (void) fprintf(stderr, "Path too long\n");
  111.         exit(1);
  112.     }
  113.     (void) strcpy(ptr, override);
  114.     }
  115.     else
  116.     (void) strcpy(ptr, defptr);
  117. }
  118.  
  119.  
  120. /* Initialize path variables for loading fonts and things */
  121. setpaths()
  122. {
  123.     copy_path(texformats, TEXFORMATS, getenv("TEXFORMATS"));
  124.     copy_path(texinputs, TEXINPUTS, getenv("TEXINPUTS"));
  125.     copy_path(texfonts, TEXFONTS, getenv("TEXFONTS"));
  126.     copy_path(texpool, TEXPOOL, getenv("TEXPOOL"));
  127. }
  128.  
  129. /*
  130.  *  The following procedure is due to sjc@s1-c.
  131.  *
  132.  *    calledit(filename, fnstart, fnlength, linenumber)
  133.  *
  134.  *  TeX82 can call this to implement the 'e' feature in error-recovery
  135.  *  mode, invoking a text editor on the erroneous source file.
  136.  *  
  137.  *  You should pass to "filename" the first character of the packed array
  138.  *  containing the filename, and to "fnstart" and "fnlength" the index and
  139.  *  length of the filename as it appears inside that array.
  140.  *  
  141.  *  Ordinarily, this invokes "/usr/ucb/vi". If you want a different
  142.  *  editor, create a shell environment variable TEXEDIT containing
  143.  *  the string that invokes that editor, with "%s" indicating where
  144.  *  the filename goes and "%d" indicating where the decimal
  145.  *  linenumber (if any) goes. For example, a TEXEDIT string for a
  146.  *  variant copy of "vi" might be:
  147.  *  
  148.  *    setenv TEXEDIT "/usr/local/bin/vi +%d %s"
  149.  *  
  150.  */
  151.  
  152. calledit(filename, fnstart, fnlength, linenumber)
  153. ASCIIcode filename[];
  154. poolpointer fnstart;
  155. integer fnlength, linenumber;
  156. {
  157.     char *temp, *command, c;
  158.     int sdone, ddone, i;
  159. /* close all input files */
  160.         for (i=1;i<= inopen;i++)fclose(inputfile[i]);
  161. /* so they can be editted */
  162.     freemem();/* free some memory*/
  163.     sdone = ddone = 0;
  164.     filename += fnstart;
  165.  
  166.     /* Replace default with environment variable if possible. */
  167.     if (NULL != (temp = getenv("TEXEDIT")))
  168.     texeditvalue = temp;
  169.  
  170.     /* Make command string containing envvalue, filename, and linenumber */
  171.     if (NULL ==
  172.     (command = (char *) malloc((unsigned) strlen(texeditvalue) + (int)fnlength
  173.                    + 25))) {
  174.     (void) fprintf(stderr, "! Not enough memory to issue editor command\n");
  175.     exit(1);
  176.     }
  177.     temp = command;
  178.     while ((c = *texeditvalue++) != '\0') {
  179.     if (c == '%') {
  180.         switch (c = *texeditvalue++) {
  181.         case 'd':
  182.         if (ddone) {
  183.             (void) fprintf(stderr,
  184.             "! Line number cannot appear twice in editor command\n");
  185.             exit(1);
  186.         }
  187.         (void) sprintf(temp, "%d", (int)linenumber);
  188.         while (*temp != '\0')
  189.             temp++;
  190.         ddone = 1;
  191.         break;
  192.         case 's':
  193.         if (sdone) {
  194.             (void) fprintf(stderr,
  195.               "! Filename cannot appear twice in editor command\n");
  196.             exit(1);
  197.         }
  198.         i = 0;
  199.         while (i < fnlength)
  200.             *temp++ = filename[i++];
  201.         sdone = 1;
  202.         break;
  203.         case '\0':
  204.         *temp++ = '%';
  205.         texeditvalue--;    /* Back up to \0 to force termination. */
  206.         break;
  207.         default:
  208.         *temp++ = '%';
  209.         *temp++ = c;
  210.         break;
  211.         }
  212.     }
  213.     else
  214.         *temp++ = c;
  215.     }
  216.     *temp = '\0';
  217.     /* Execute command. */
  218.     if (system(command)) 
  219.     (void) fprintf(stderr, "! Trouble executing command %s\n", command);
  220.  
  221.     /* Quit, indicating TeX found an error */
  222.     exit(1);
  223. }
  224.  
  225.  
  226. /*
  227.  * Change a Pascal-like filename into a C-like string.
  228.  * If running on a non-ASCII system, will have to use xchr[]
  229.  * array to convert from internal character set (in the "nameoffile"
  230.  * array) into the enternal character set (in "realnameoffile").
  231.  * "nameoffile" is an array indexed starting with 1, so we add 1
  232.  * to all references to point to the first character in the name.
  233.  */
  234. static packrealnameoffile(prefix)
  235. char *prefix;
  236. {
  237.     register char *cp, *p, *q;
  238.  
  239.     p = prefix;
  240.     for (q = my_realnameoffile; p && *p && *p != ';'; *q++ = *p++);
  241.     if (prefix && *prefix)
  242.     *q++ = '\\';
  243.     for (cp = nameoffile+1, p = realnameoffi + 1; *cp != ' ' && *cp;)
  244. #ifdef    NONASCII
  245.     *q++ = xchr[*p++ = *cp++];
  246. #else
  247.     *q++ = (*p++ = *cp++);
  248. #endif
  249.     *p = ' ';
  250.     *q = '\0';
  251. }
  252.  
  253. /* Open an input file f */
  254. Openin(f, pathspec,fmode)
  255. FILE **f;
  256. int pathspec;
  257. char fmode[];
  258. {
  259.     register char *prefix, *nprefix;
  260.     register char *cp;
  261. /*printf("name %s mode %s path %d  ",&nameoffile[1],fmode,pathspec);*/
  262.     switch (pathspec) {
  263.     case inputpathspec:
  264.     case readpathspec:
  265.     prefix = texinputs;
  266.     break;
  267.     case fontpathspec:
  268.     prefix = texfonts;
  269.     break;
  270.     case poolpathspec:
  271.     prefix = texpool;
  272.     break;
  273.     case fmtpathspec:
  274.     prefix = texformats;
  275.     break;
  276.     default:            /* "Can't" happen */
  277.     (void) fprintf(stderr, "INTERNAL CONFUSION---IMPLEMENTATION ERROR\n");
  278.     exit(1);
  279.     }
  280. /*printf(" %s \n",prefix);*/
  281.     if ((nameoffile[2] == ':')||(nameoffile[1] == '/')) {/* Absolute pathname */
  282.     for (cp = nameoffile+1; *cp && *cp != ' '; ++cp);
  283.     *cp = '\0';
  284. /*printf("absolute %s\n",nameoffile);*/
  285.     cnvtfn(nameoffile+1);
  286.     if (*f = fopen(nameoffile+1, fmode)) {
  287.         (void) strcpy(realnameoffi + 1, nameoffile+1);
  288.         (void) strcat(realnameoffi + 1, " ");
  289.         if (pathspec == fontpathspec)
  290.         tfmtemp = getc(*f);    /* Simulate readahead */
  291.         return (1);
  292.     }
  293.     return (0);
  294.     }
  295.     /* Else relative pathname */
  296.     while (prefix) {
  297.     packrealnameoffile(prefix);
  298. /*printf("try %s  %s\n",my_realnameoffile,prefix);*/
  299.     cnvtfn(my_realnameoffile);
  300.     *f = fopen(my_realnameoffile, fmode);
  301.     if (*f) {
  302.         (void) strcpy(realnameoffi + 1, my_realnameoffile);
  303.         (void) strcat(realnameoffi + 1, " ");
  304.         if (pathspec == fontpathspec)
  305.         tfmtemp = getc(*f);    /* Simulate Pascal readahead */
  306.         return (1);
  307.     }
  308.     nprefix = index(prefix, ';');
  309.     if (nprefix)
  310.         prefix = nprefix + 1;
  311.     else
  312.         break;
  313.     }
  314.     return (0);
  315. }
  316. /* translate / to \ in file name */
  317. cnvtfn(p)
  318. char *p;
  319. {
  320.   while(*p != 0){
  321.     if(*p == '/')*p = '\\';
  322.     p++;
  323.     }
  324. }
  325.      
  326.  
  327. /* Open an output file f */
  328. Openout(f,fmode)
  329. FILE **f;
  330. char fmode[];
  331. {
  332. /*printf("open write %s mode %s\n",&nameoffile[1],fmode);*/
  333.     packrealnameoffile((char *) NULL);
  334. /*printf("packed name %s\n",my_realnameoffile);*/
  335.     *f = fopen(my_realnameoffile, fmode);
  336.     return (*f != NULL);
  337. }
  338.  
  339.  
  340. /*
  341.  * Read a line of input as efficiently as possible while still
  342.  * looking like Pascal.
  343.  * Sets last==first and returns FALSE if eof is hit.
  344.  * Otherwise, TRUE is returned and either last==first or buffer[last-1]!=' ';
  345.  * that is, last == first + length(line except trailing whitespace).
  346.  */
  347. boolean zinputln(f)
  348. FILE *f;
  349. {
  350.     register int i;
  351.  
  352.  
  353.     last = first;
  354.     while ( last < bufsize && ((i = getc(f)) != EOF) && i != '\n') {
  355.     buffer[last++] = i;
  356.     }
  357.     if (i == EOF && last == first)
  358.     return(FALSE);
  359.     if (i != EOF && i != '\n') {
  360.     /* We didn't get whole line because of lack of buffer space */
  361.     (void) fprintf(stderr, "\nUnable to read an entire line---bufsize=%d\n",
  362.         bufsize);
  363.     exit(1);
  364.     }
  365.     buffer[last] = ' ';
  366.     if (last >= maxbufstack)
  367.     maxbufstack = last;    /* Record keeping */
  368.     /* Trim trailing whitespace by decrementing "last" */
  369.     while (last > first && (buffer[last-1] == ' ' || buffer[last-1] == '\t'))
  370.     --last;
  371.     /* Now, either last==first or buffer[last-1] != ' ' (or tab) */
  372. /*
  373.  * If we're running on a system with ASCII characters like TeX's
  374.  * internal character set, we can save some time by not executing
  375.  * this loop.
  376.  */
  377. #ifdef    NOTASCII
  378.     for (i = first; i <= last; i++)
  379.     buffer[i] = xord[buffer[i]];
  380. #endif
  381. /*printf("line done last= %ld\n",last);*/
  382.     return(TRUE);
  383. }
  384.  
  385. /*
  386.  * Clear any pending terminal input.
  387.  * The usual way to do this in Unix is to switch the terminal to get
  388.  * the current tty flags, set RAW mode, then switch back to the original
  389.  * setting.  If the user isn't in COOKED mode, though, this won't work.
  390.  * At least, it leaves his terminal in its original mode.
  391.  */
  392. cleartermina()
  393. {
  394. #ifdef    BSD
  395.     struct sgttyb sb;
  396.     int flags;        /* We save the original flags here */
  397.  
  398.     if (ioctl(fileno(stdout), TIOCGETP, &sb) < 0)
  399.     return;        /* Failed for some reason */
  400.     flags = sb.sg_flags;
  401.  
  402.     sb.sg_flags |= RAW;
  403.     if (ioctl(fileno(stdout), TIOCSETP, &sb) < 0)
  404.     return;        /* Punt if it fails */
  405.  
  406.     sb.sg_flags = flags;
  407.     (void) ioctl(fileno(stdout), TIOCSETP, &sb);
  408. #endif    /* BSD */
  409. }
  410.  
  411.  
  412. /*
  413.  * Cancel any output cancellation (^O) by the user.  This is 4.2BSD code.
  414.  * Systems which don't have this feature might want to #define wakeupterminal
  415.  * to do nothing, rather than call this empty routine, but it's only called
  416.  * when about to read from the terminal, so the extra time (compared with
  417.  * the human's response time) is minimal.
  418.  */
  419. wakeuptermin()
  420. {
  421. #ifdef    BSD
  422.     int i = LFLUSHO;
  423.  
  424.     (void) ioctl(fileno(stdout), TIOCLBIC, (struct sgttyb *) &i);
  425. #endif    /* BSD */
  426. }
  427.  
  428.  
  429. /*
  430.  * "Open the terminal for input".  Actually, copy any command-line
  431.  * arguments for processing.  If nothing is available, or we've
  432.  * been called already (and hence, gargc==0), we return with last==first.
  433.  */
  434. topenin()
  435. {
  436.     register int i;
  437.  
  438.     if (gargc > 1) {
  439.     buffer[first] = '\0';    /* This makes the first strcat work */
  440.     for (i=1; i<gargc; i++) {
  441.         (void) strcat((char *) &buffer[first], gargv[i]);
  442.         (void) strcat((char *) &buffer[first], " ");
  443.     }
  444.     gargc = 0;    /* Don't do this again */
  445.     for (last=first; buffer[last]; ++last);
  446.     for (--last; last >= first && buffer[last] == ' '; --last);
  447.     ++last;
  448.     }
  449.     else last = first;    /* This signals that nothing is available */
  450. }
  451.  
  452.  
  453. #ifdef    sequent
  454. /*
  455.  * On a Sequent Balance system under Dynix 2.1, if u and v are unsigned
  456.  * quantities, then "(int) u - (int) v" does not perform a signed
  457.  * subtraction.  Hence we have to call this routine to force the compiler
  458.  * to treat u and v as ints instead of unsigned ints.
  459.  */
  460. int ztoint(x)
  461. {
  462.     return(x);
  463. }
  464. #endif
  465. putlw(lword,fpp)
  466. long lword;
  467. FILE *fpp;
  468. {
  469. fwrite(&lword,4,1,fpp);
  470. }
  471. fmtwrite(bb,l1,l2,fpp)
  472. char *bb;
  473. int l1;
  474. long l2;
  475. FILE *fpp;
  476. {
  477. register long l1l2,i;
  478. l1l2=l1*l2;
  479. /*fflush(fpp);
  480. Fwrite(fileno(fpp),l1l2,bb);*/
  481. for (i=0;i<l1l2;i++)putc(bb[i],fpp);
  482. }
  483.  
  484. fmtread(bb,l1,l2,fpp)
  485. char *bb;
  486. int l1;
  487. long l2;
  488. FILE *fpp;
  489. {
  490. register long l1l2,i;
  491. l1l2=l1*l2;
  492. /*fflush(fpp);
  493. Fread(fileno(fpp),l1l2,bb);*/
  494. for (i=0;i<l1l2;i++)bb[i]=getc(fpp);
  495. }
  496.  
  497. /* special dvi write for VMS */
  498. /* always write 512 bytes */
  499. dwrite(bb,l1,l2,fpp)
  500. char bb[];
  501. int l1,l2;
  502. FILE *fpp;
  503. {
  504. int i,k;
  505. int l1l2;
  506. l1l2=l1*l2;
  507. k=512;
  508. if(l1l2 > 512)k=1024;
  509. /*printf("l1,l2 %d %d %d %d\n",l1,l2,l1l2,k);*/
  510. if(l1l2 <= 0)return;
  511. if(l1l2 < k){
  512. for(i=l1l2;i<k;i++)bb[i]=0xDF;
  513. }
  514.  write(fileno(fpp),bb,k);
  515. }
  516.  
  517.  
  518. /*
  519.  * Get things going under Unix: set up for rescanning the command line,
  520.  * then call TeX's main body.
  521.  */
  522. main(argc, argv)
  523. int argc;
  524. char *argv[];
  525. {
  526.     gargc=argc;
  527.     gargv=argv;
  528.     memtop=MEMTOP;
  529.     memmax=MEMMAX;
  530.     memall(); /* allocate memory */
  531.     printf(" memory free %ld\n",(long)Malloc(-1L));
  532.  
  533. /*printf("zmem,zeqt %lx  %lx \n",(long)zzzaa,(long)zeqtb);*/
  534. #include "arrays.h"
  535.     texbody();
  536.  
  537.  
  538. #ifdef    DEBUG
  539. getint()
  540. {
  541.     int i;
  542.  
  543.     if (fscanf(stdin, "%d", &i)) return(i);
  544.     return(0);
  545. }
  546. #endif    /* DEBUG */
  547. /* getenv wasn't in MEGAMAX library */
  548. /* also time() and localtime() and time.h had to be written */
  549. extern long *_base;
  550. char *getenv(stpath)
  551. char stpath[];
  552. {
  553. char *ptr;
  554. int i;
  555.  ptr= (char *)*(_base+11);
  556. i=strlen(stpath);
  557. while(*ptr != 0){
  558.     if((strncmp(stpath,ptr,i)== 0)&&(ptr[i] == '='))return(ptr+i+1);
  559.     ptr=ptr+strlen(ptr)+1;
  560.     }
  561. return(NULL);
  562. }
  563. /* simple time functions NOT UNIX compatible but they 
  564. suit some purposes */
  565.  
  566.  
  567. long time(ttime)
  568. long *ttime;
  569. {
  570. int  ttvec[2];
  571. long daytime;
  572.         daytime=Gettime();
  573.         ttvec[0]=(daytime & 0xffff);
  574.         ttvec[1]=(daytime>>16) & 0xffff;
  575.     Tsettime(ttvec[0]);
  576.     Tsetdate(ttvec[1]);
  577.     if((ttime != NULL)  )*ttime=daytime;
  578.         return(daytime);
  579. }
  580.  
  581. struct tm *localtime(daytime)
  582. long *daytime;
  583. {
  584. int ttvec[2];
  585. static struct tm tt;
  586.         ttvec[0]=(*daytime & 0xffff);
  587.         ttvec[1]=(*daytime>>16) & 0xffff;
  588.     tt.tm_sec= (ttvec[0]&31)*2;
  589.     tt.tm_min= (ttvec[0]>>5)&63;
  590.     tt.tm_hour= (ttvec[0]>>11)&31;
  591.     tt.tm_mday= (ttvec[1]&31);
  592.     tt.tm_mon= ((ttvec[1]>>5)&15)-1;
  593.     tt.tm_year= ((ttvec[1]>>9)&127)+80;
  594.     tt.tm_isdst= 0;
  595.     return (&tt);
  596.                  }   
  597.  
  598.  
  599.  
  600.  
  601. extern char *palloc();
  602. memall()
  603. {
  604. /* ASCIIcode strpool[poolsize + 1] ; */
  605. strpool = (ASCIIcode *)palloc( (long)poolsize + 1,sizeof(ASCIIcode ) );
  606. /* poolpointer strstart[maxstrings + 1] ; */
  607. strstart = (poolpointer *)palloc( (long)maxstrings + 1,sizeof(poolpointer ) );
  608. /* memoryword zzzaa[memmax - memmin + 1] ; */
  609. zzzaa = (memoryword *)palloc( (long)memmax - memmin + 1,sizeof(memoryword ) );
  610. #ifdef DEBUG
  611. /* boolean zzzab[memmax - memmin + 1], *freearr ; */
  612. zzzab = (boolean *)palloc( (long)memmax - memmin + 1,sizeof(boolean ) );
  613. /* boolean zzzac[memmax - memmin + 1], *wasfree ; */
  614. zzzac = (boolean *)palloc( (long)memmax - memmin + 1,sizeof(boolean ) );
  615. #endif /* DEBUG*/
  616. /* memoryword zeqtb[5977] ; */
  617. zeqtb = (memoryword *)palloc( (long)5977,sizeof(memoryword ) );
  618. /* quarterword zzzad[710], *xeqlevel ; */
  619. zzzad = (quarterword *)palloc( (long)710,sizeof(quarterword ) );
  620. /* twohalves zzzae[3267], *hash ; */
  621. zzzae = (twohalves *)palloc( (long)3267,sizeof(twohalves ) );
  622. /* memoryword savestack[savesize + 1] ; */
  623. savestack = (memoryword *)palloc( (long)savesize + 1,sizeof(memoryword ) );
  624. /* instaterecor inputstack[stacksize + 1] ; */
  625. inputstack =(instaterecor *)palloc( (long)stacksize + 1,sizeof(instaterecor) );
  626. /* memoryword fontinfo[fontmemsize + 1] ; */
  627. fontinfo = (memoryword *)palloc( (long)fontmemsize + 1,sizeof(memoryword ) );
  628. /* fourquarters fontcheck[fontmax + 1] ; */
  629. fontcheck = (fourquarters *)palloc( (long)fontmax + 1,sizeof(fourquarters ) );
  630. /* scaled fontsize[fontmax + 1] ; */
  631. fontsize = (scaled *)palloc( (long)fontmax + 1,sizeof(scaled ) );
  632. /* scaled fontdsize[fontmax + 1] ; */
  633. fontdsize = (scaled *)palloc( (long)fontmax + 1,sizeof(scaled ) );
  634. /* halfword fontparams[fontmax + 1] ; */
  635. fontparams = (halfword *)palloc( (long)fontmax + 1,sizeof(halfword ) );
  636. /* strnumber fontname[fontmax + 1] ; */
  637. fontname = (strnumber *)palloc( (long)fontmax + 1,sizeof(strnumber ) );
  638. /* strnumber fontarea[fontmax + 1] ; */
  639. fontarea = (strnumber *)palloc( (long)fontmax + 1,sizeof(strnumber ) );
  640. /* eightbits fontbc[fontmax + 1] ; */
  641. fontbc = (eightbits *)palloc( (long)fontmax + 1,sizeof(eightbits ) );
  642. /* eightbits fontec[fontmax + 1] ; */
  643. fontec = (eightbits *)palloc( (long)fontmax + 1,sizeof(eightbits ) );
  644. /* halfword fontglue[fontmax + 1] ; */
  645. fontglue = (halfword *)palloc( (long)fontmax + 1,sizeof(halfword ) );
  646. /* boolean fontused[fontmax + 1] ; */
  647. fontused = (boolean *)palloc( (long)fontmax + 1,sizeof(boolean ) );
  648. /* integer hyphenchar[fontmax + 1] ; */
  649. hyphenchar = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  650. /* integer skewchar[fontmax + 1] ; */
  651. skewchar = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  652. /* integer charbase[fontmax + 1] ; */
  653. charbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  654. /* integer widthbase[fontmax + 1] ; */
  655. widthbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  656. /* integer heightbase[fontmax + 1] ; */
  657. heightbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  658. /* integer depthbase[fontmax + 1] ; */
  659. depthbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  660. /* integer italicbase[fontmax + 1] ; */
  661. italicbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  662. /* integer ligkernbase[fontmax + 1] ; */
  663. ligkernbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  664. /* integer kernbase[fontmax + 1] ; */
  665. kernbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  666. /* integer extenbase[fontmax + 1] ; */
  667. extenbase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  668. /* integer parambase[fontmax + 1] ; */
  669. parambase = (integer *)palloc( (long)fontmax + 1,sizeof(integer ) );
  670. /* twohalves trie[triesize + 1] ; */
  671. trie = (twohalves *)palloc( (long)triesize + 1,sizeof(twohalves ) );
  672. #ifdef INITEX
  673. /* ASCIIcode triec[triesize + 1] ; */
  674. triec = (ASCIIcode *)palloc( (long)triesize + 1,sizeof(ASCIIcode ) );
  675. /* quarterword trieo[triesize + 1] ; */
  676. trieo = (quarterword *)palloc( (long)triesize + 1,sizeof(quarterword ) );
  677. /* triepointer triel[triesize + 1] ; */
  678. triel = (triepointer *)palloc( (long)triesize + 1,sizeof(triepointer ) );
  679. /* triepointer trier[triesize + 1] ; */
  680. trier = (triepointer *)palloc( (long)triesize + 1,sizeof(triepointer ) );
  681. /* triepointer triehash[triesize + 1] ; */
  682. triehash = (triepointer *)palloc( (long)triesize + 1,sizeof(triepointer ) );
  683. /* boolean trietaken[triesize + 1] ; */
  684. trietaken = (boolean *)palloc( (long)triesize + 1,sizeof(boolean ) );
  685. #endif /* INITEX */
  686.  
  687. }
  688. /* allocate memory */
  689. char *palloc(nelem,sizel)
  690. long nelem;
  691. int sizel;
  692. {
  693. register    char *pp;
  694. /*     printf(" allocating %ld\n",nelem*sizel);*/
  695.      if(pp =(char *)Malloc(nelem*sizel)) {
  696. /*     printf(" memory free %ld\n",(long)Malloc(-1L));*/
  697.      return(pp);}
  698.   else {
  699.      printf("can't allocate \n");
  700.      exit(1);}
  701. }
  702. freemem() /* free memory */
  703. {
  704. #ifdef INITEX
  705. Mfree(trietaken);
  706. Mfree(triehash);
  707. Mfree(trier);
  708. Mfree(triel);
  709. Mfree(trieo);
  710. Mfree(triec);
  711. #endif /* INITEX */
  712. Mfree(trie);
  713. Mfree(parambase);
  714. Mfree(extenbase);
  715. Mfree(kernbase);
  716. Mfree(ligkernbase);
  717. Mfree(italicbase);
  718. Mfree(depthbase);
  719. Mfree(heightbase);
  720. Mfree(widthbase);
  721. Mfree(charbase);
  722. Mfree(skewchar);
  723. Mfree(hyphenchar);
  724. Mfree(fontused);
  725. Mfree(fontglue);
  726. Mfree(fontec);
  727. Mfree(fontbc);
  728. Mfree(fontarea);
  729. Mfree(fontname);
  730. Mfree(fontparams);
  731. Mfree(fontdsize);
  732. Mfree(fontsize);
  733. Mfree(fontcheck);
  734. Mfree(fontinfo);
  735. Mfree(inputstack);
  736. Mfree(savestack);
  737. Mfree(zzzae);
  738. Mfree(zzzad);
  739. Mfree(zeqtb);
  740. #ifdef DEBUG
  741. Mfree(zzzac);
  742. Mfree(zzzab);
  743. #endif */DEBUG */
  744. Mfree(zzzaa);
  745. Mfree(strstart);
  746. Mfree(strpool);
  747.     printf(" memory free %ld\n",(long)Malloc(-1L));
  748.  
  749. }
  750.  
  751.  
  752. /* homebrew system function */
  753. system(command)
  754. char *command;
  755. {char pname[20];
  756.  char fpname[40];
  757.  char comtail[40];
  758.  char *ptr;
  759.  int l;
  760. for(l=0;l<strlen(command);l++){
  761.    if(command[l] == ' ')break;
  762.    pname[l]=command[l];
  763.     }
  764. pname[l]=0;
  765. if(command[l]== ' '){ strcpy(&comtail[1],&command[l+1]);
  766.              comtail[0]=strlen(&comtail[1]);
  767.                     }
  768.         else {comtail[0]=0;comtail[1]=0;}
  769. if(find_file(pname,fpname) == 0)return (-1);
  770.  return(Pexec(0x00, fpname, comtail, NULL)); /* load and execute */
  771.  
  772. }
  773. /* find a file using PATH environment */
  774. find_file(temptr,fullnam)
  775. char *temptr,*fullnam;
  776. {
  777.    char *ptrz,*ptry;
  778.  
  779.    int ch;
  780.    int fflag;
  781.  
  782. fflag=0;
  783. ptrz=getenv("PATH");
  784. strcpy(fullnam,temptr);
  785. if((index(fullnam,':')!= NULL) || (index(fullnam,'\\')!= NULL))fflag=1;
  786. while(1){
  787.  
  788.  
  789.    if ((ch = Fopen(fullnam, 0)) >= 0)
  790.          {
  791.        Fclose(ch);
  792.            return(1);
  793.          }
  794.    if((fflag == 1)||(*ptrz == 0))break;
  795.    ptry=fullnam;
  796.    while((*ptrz != ';')&&(*ptrz != 0)){
  797.                  *ptry = *ptrz;
  798.          ptry++;
  799.                  ptrz++;
  800.          }
  801.    if(*(ptry-1) != '\\')*ptry++ = '\\';
  802.    strcpy(ptry,temptr);
  803.    if(*ptrz == ';')ptrz++;
  804.    }
  805.    return(0);
  806. }
  807.  
  808.