Back to index

tetex-bin  3.0
aleph.c
Go to the documentation of this file.
00001 /* aleph.c: C routines to support the Aleph Pascal Web distribution
00002  * based on omega.c from the Omega project
00003 
00004 This file is part of the Aleph project
00005 
00006 Copyleft (c) 2004 the Aleph team
00007 
00008 This library is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU Library General Public
00010 License as published by the Free Software Foundation; either
00011 version 2 of the License, or (at your option) any later version.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 Library General Public License for more details.
00017 
00018 You should have received a copy of the GNU Library General Public
00019 License along with this library; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00021 
00022 #define EXTERN extern
00023 #include "alephd.h"
00024 
00025 void
00026 btestin(void)
00027 {
00028     string fname =
00029     kpse_find_file (nameoffile + 1, kpse_program_binary_format, true);
00030 
00031     if (fname) {
00032       libcfree(nameoffile);
00033       nameoffile = xmalloc(2+strlen(fname));
00034       namelength = strlen(fname);
00035       strcpy(nameoffile+1, fname);
00036     }
00037     else {
00038       libcfree(nameoffile);
00039       nameoffile = xmalloc(2);
00040       namelength = 0;
00041       nameoffile[0] = 0;
00042       nameoffile[1] = 0;
00043     }
00044 }
00045 
00046 int
00047 getfilemode P2C(FILE *, f, int, def)
00048 {
00049     int c,m;
00050     if ((def==0)||(feof(f))) m=0;
00051     else {
00052        c = getc(f);
00053        if (c==EOF) m=0;
00054        else if (c==0x5c) {
00055           if (feof(f)) m=0;
00056           else {
00057              c = getc(f);
00058              if (c==EOF) m=0;
00059              else if (c==0) m=4;
00060              else m=1;
00061              ungetc(c,f);
00062              c=0x5c;
00063           }
00064        }
00065        else if (c==0x25) {
00066           if (feof(f)) m=0;
00067           else {
00068              c = getc(f);
00069              if (c==EOF) m=0;
00070              else if (c==0) m=4;
00071              else m=1;
00072              ungetc(c,f);
00073              c=0x25;
00074           }
00075        }
00076        else if (c==0xe0) m=2;
00077        else if (c==0x6c) m=2;
00078        else if (c==0) {
00079           if (feof(f)) m=0;
00080           else {
00081              c = getc(f);
00082              if (c==EOF) m=0;
00083              else if (c==0x5c) m=3;
00084              else if (c==0x25) m=3;
00085              else m=def;
00086              ungetc(c,f);
00087              c=0;
00088           }
00089        }
00090        else m=def;
00091        ungetc(c,f);
00092     }
00093     return m;
00094 }
00095 
00096 int
00097 getc_two_LE P1C(FILE *, f)
00098 {
00099     register int i,j;
00100     i = getc(f);
00101     if (i==EOF) { return i; }
00102     j = getc(f);
00103     if (j==EOF) { return j; }
00104     return ((j<<8)|i);
00105 }
00106 
00107 void
00108 ungetc_two_LE P2C(int, c, FILE *, f)
00109 {
00110     ungetc((c>>8), f);
00111     ungetc((c&0377), f);
00112 }
00113 
00114 int
00115 getc_two P1C(FILE *, f)
00116 {      
00117     register int i,j;
00118     i = getc(f);
00119     if (i==EOF) { return i; }
00120     j = getc(f);
00121     if (j==EOF) { return j; }
00122     return ((i<<8)|j);
00123 }
00124  
00125 void
00126 ungetc_two P2C(int, c, FILE *, f)
00127 {
00128     ungetc((c&0377), f);
00129     ungetc((c>>8), f);
00130 }
00131  
00132 extern boolean zpnewinputln ();
00133 
00134 boolean
00135 newinputln P4C(FILE *,f, halfword,themode, halfword,translation, boolean,bypass)
00136 {
00137     return zpnewinputln((alphafile)f,
00138                         (halfword)themode,
00139                         (halfword)translation,
00140                         (boolean) bypass);
00141 }
00142  
00143 boolean
00144 new_input_line P2C(FILE *, f, halfword, themode)
00145 {
00146   register int i=EOF;
00147  
00148   last = first;
00149   otpinputend = 0;
00150  
00151   if (themode==1) {
00152      while ((otpinputend < ocpbufsize) && ((i = getc (f)) != EOF) &&
00153             ((i != '\r') && (i != '\n')))
00154         otpinputbuf[++otpinputend] = i;
00155      if (i=='\r') {
00156          i=getc(f); if (i != '\n') ungetc(i,f);
00157      }
00158   } else if (themode==2) {
00159      while ((otpinputend < ocpbufsize) && ((i = getc (f)) != EOF) &&
00160             (i != 0x25))
00161         otpinputbuf[++otpinputend] = i;
00162   } else if (themode==3) {
00163      while ((otpinputend < ocpbufsize) && ((i = getc_two (f)) != EOF) &&
00164             ((i != '\r') && (i != '\n')))
00165         otpinputbuf[++otpinputend] = i;
00166      if (i=='\r') {
00167          i=getc_two(f); if (i != '\n') ungetc_two(i,f);
00168      }
00169   } else /* themode==4 */ {
00170      while ((otpinputend < ocpbufsize) && ((i = getc_two_LE (f)) != EOF) &&
00171             ((i != '\r') && (i != '\n')))
00172         otpinputbuf[++otpinputend] = i;
00173      if (i=='\r') {
00174          i=getc_two_LE(f); if (i != '\n') ungetc_two_LE(i,f);
00175      }
00176   }
00177  
00178   if (i == EOF && otpinputend == 0)
00179       return false;
00180  
00181   /* We didn't get the whole line because our buffer was too small.
00182 */
00183  if (i != EOF && (((themode!=2) && (i != '\n')) || ((themode==2) && (i != 0x25))))
00184     {
00185       (void) fprintf (stderr,
00186                      "! Unable to read an entire line---ocp_buf_size=%ld.\n",ocpbufsize);
00187       (void) fprintf (stderr, "Please increase ocp_buf_size in texmf.cnf.\n");
00188       uexit (1);
00189     }
00190  
00191     return true;
00192 }
00193 
00194 extern memoryword ziniteqtbentry () ;
00195 
00196 hashword hashtable[HASHTABLESIZE];
00197 
00198 void
00199 inithhashtable P1H(void)
00200 {
00201    int i;
00202    for (i=0; i<HASHTABLESIZE; i++) {
00203       hashtable[i].p = -1;
00204    }
00205       
00206 }
00207 
00208 hashword *
00209 createeqtbpos P1C(int, p)
00210 {
00211    hashword *runner= &(hashtable[p%HASHTABLESIZE]);
00212    if (runner->p==p) return runner;
00213    while (runner->p != -1) {
00214       runner = runner->ptr; 
00215       if (runner->p == p) return runner;
00216    } 
00217    runner->p = p;
00218    runner->mw = ziniteqtbentry(p);
00219    runner->ptr = (hashword *) xmalloc(sizeof(hashword));
00220    (runner->ptr)->p = -1;
00221    return runner;
00222 }
00223 
00224 memoryword *
00225 createeqtbptr P1C(int, p)
00226 {
00227    hashword *runner= &(hashtable[p%HASHTABLESIZE]);
00228    if (runner->p==p) return (&(runner->mw));
00229    while (runner->p != -1) {
00230       runner = runner->ptr; 
00231       if (runner->p == p) return (&(runner->mw));
00232    } 
00233    runner->p = p;
00234    runner->mw = ziniteqtbentry(p);
00235    runner->ptr = (hashword *) xmalloc(sizeof(hashword));
00236    (runner->ptr)->p = -1;
00237    return (&(runner->mw));
00238 }
00239 
00240 hashword *
00241 createxeqlevel P1C(int, p)
00242 {
00243    hashword *runner= &(hashtable[p%HASHTABLESIZE]);
00244    if (runner->p==p) return runner;
00245    while (runner->p != -1) {
00246       runner = runner->ptr;
00247       if (runner->p == p) return runner;
00248    }
00249    runner->p = p;
00250    runner->mw.cint = 1;
00251    runner->mw.cint1 = 0;
00252    runner->ptr = (hashword *) xmalloc(sizeof(hashword));
00253    (runner->ptr)->p = -1;
00254    return runner;
00255 }
00256 
00257 hashword *
00258 createhashpos P1C(int, p)
00259 {
00260    hashword *runner= &(hashtable[p%HASHTABLESIZE]);
00261    if (runner->p==p) return runner;
00262    while (runner->p != -1) {
00263       runner = runner->ptr; 
00264       if (runner->p == p) return runner;
00265    } 
00266    runner->p = p;
00267    runner->mw.cint = 0;
00268    runner->mw.cint1 = 0;
00269    runner->ptr = (hashword *) xmalloc(sizeof(hashword));
00270    (runner->ptr)->p = -1;
00271    return runner;
00272 }
00273 
00274 void
00275 dumphhashtable P1H(void)
00276 {
00277    int i;
00278    hashword *runner;
00279    for (i=0; i<HASHTABLESIZE; i++) {
00280       runner=&(hashtable[i]);
00281       if (runner->p != -1) {
00282          dumpint(-i);
00283          while (runner->p != -1) {
00284             dumpint(runner->p);
00285             dumpwd(runner->mw);
00286             runner=runner->ptr;
00287          }
00288       }
00289    }
00290    dumpint(-HASHTABLESIZE);
00291 }
00292 
00293 void
00294 undumphhashtable P1H(void)
00295 {
00296    int i,j;
00297    hashword *runner;
00298    j=0;
00299    undumpint(i);
00300    while (j<HASHTABLESIZE) {
00301       i = (-i);
00302       while (j<i) {
00303          hashtable[j].p = -1;
00304          j++;
00305       }
00306       if (i<HASHTABLESIZE) {
00307          runner = &(hashtable[j]);
00308          undumpint(i);
00309          while (i>=0) {
00310             runner->p = i;
00311             undumpwd(runner->mw);
00312             undumpint(i);
00313             runner->ptr = (hashword *) xmalloc(sizeof(hashword));
00314             runner = runner->ptr;
00315          }
00316          runner->p = -1;
00317          j++;
00318       }
00319    }
00320 }
00321 
00322 void
00323 odateandtime P4C(int,timecode, int,daycode, int,monthcode, int,yearcode)
00324 {
00325     integer tc,dc,mc,yc;
00326     dateandtime(tc,dc,mc,yc);
00327     setneweqtbint(timecode,tc);
00328     setneweqtbint(daycode,dc);
00329     setneweqtbint(monthcode,mc);
00330     setneweqtbint(yearcode,yc);
00331 }
00332 
00333 memoryword **fonttables;
00334 static int font_entries = 0;
00335 
00336 void
00337 allocatefonttable P2C(int, font_number, int, font_size)
00338 {
00339     int i;
00340     if (font_entries==0) {
00341       fonttables = (memoryword **) xmalloc(256*sizeof(memoryword**));
00342       font_entries=256;
00343     } else if ((font_number==256)&&(font_entries==256)) {
00344       fonttables = xrealloc(fonttables, 65536);
00345       font_entries=65536;
00346     }
00347     fonttables[font_number] =
00348        (memoryword *) xmalloc((font_size+1)*sizeof(memoryword));
00349     fonttables[font_number][0].cint = font_size;
00350     fonttables[font_number][0].cint1 = 0;
00351     for (i=1; i<=font_size; i++) {
00352         fonttables[font_number][i].cint  = 0;
00353         fonttables[font_number][i].cint1 = 0;
00354     }
00355 }
00356 
00357 void
00358 dumpfonttable P2C(int, font_number, int, words)
00359 {
00360     fonttables[font_number][0].cint=words;
00361     dumpthings(fonttables[font_number][0], fonttables[font_number][0].cint+1);
00362 }
00363 
00364 void
00365 undumpfonttable(font_number)
00366 int font_number;
00367 {
00368     memoryword sizeword;
00369     if (font_entries==0) {
00370       fonttables = (memoryword **) xmalloc(256*sizeof(memoryword**));
00371       font_entries=256;
00372     } else if ((font_number==256)&&(font_entries==256)) {
00373       fonttables = xrealloc(fonttables, 65536);
00374       font_entries=65536;
00375     }
00376 
00377     undumpthings(sizeword,1);
00378     fonttables[font_number] =
00379         (memoryword *) xmalloc((sizeword.cint+1)*sizeof(memoryword));
00380     fonttables[font_number][0].cint = sizeword.cint;
00381     undumpthings(fonttables[font_number][1], sizeword.cint);
00382 }
00383 
00384 memoryword **fontsorttables;
00385 static int fontsort_entries = 0;
00386 
00387 void
00388 allocatefontsorttable P2C(int, fontsort_number, int, fontsort_size)
00389 {
00390     int i;
00391     if (fontsort_entries==0) {
00392       fontsorttables = (memoryword **) xmalloc(256*sizeof(memoryword**));
00393       fontsort_entries=256;
00394     } else if ((fontsort_number==256)&&(fontsort_entries==256)) {
00395       fontsorttables = xrealloc(fontsorttables, 65536);
00396       fontsort_entries=65536;
00397     }
00398     fontsorttables[fontsort_number] =
00399        (memoryword *) xmalloc((fontsort_size+1)*sizeof(memoryword));
00400     fontsorttables[fontsort_number][0].cint = fontsort_size;
00401     fontsorttables[fontsort_number][0].cint1 = 0;
00402     for (i=1; i<=fontsort_size; i++) {
00403         fontsorttables[fontsort_number][i].cint  = 0;
00404         fontsorttables[fontsort_number][i].cint1 = 0;
00405     }
00406 }
00407 
00408 void
00409 dumpfontsorttable P2C(int, fontsort_number, int, words)
00410 {
00411     fontsorttables[fontsort_number][0].cint=words;
00412     dumpthings(fontsorttables[fontsort_number][0],
00413                fontsorttables[fontsort_number][0].cint+1);
00414 }
00415 
00416 void
00417 undumpfontsorttable(fontsort_number)
00418 int fontsort_number;
00419 {
00420     memoryword sizeword;
00421     if (fontsort_entries==0) {
00422       fontsorttables = (memoryword **) xmalloc(256*sizeof(memoryword**));
00423       fontsort_entries=256;
00424     } else if ((fontsort_number==256)&&(fontsort_entries==256)) {
00425       fontsorttables = xrealloc(fontsorttables, 65536);
00426       fontsort_entries=65536;
00427     }
00428 
00429     undumpthings(sizeword,1);
00430     fontsorttables[fontsort_number] =
00431         (memoryword *) xmalloc((sizeword.cint+1)*sizeof(memoryword));
00432     fontsorttables[fontsort_number][0].cint = sizeword.cint;
00433     undumpthings(fontsorttables[fontsort_number][1], sizeword.cint);
00434 }
00435 
00436 int **ocptables;
00437 static int ocp_entries = 0;
00438 
00439 void
00440 allocateocptable P2C(int, ocp_number, int, ocp_size)
00441 {
00442     int i;
00443     if (ocp_entries==0) {
00444       ocptables = (int **) xmalloc(256*sizeof(int**));
00445       ocp_entries=256;
00446     } else if ((ocp_number==256)&&(ocp_entries==256)) {
00447       ocptables = xrealloc(ocptables, 65536);
00448       ocp_entries=65536;
00449     }
00450     ocptables[ocp_number] =
00451        (int *) xmalloc((1+ocp_size)*sizeof(int));
00452     ocptables[ocp_number][0] = ocp_size;
00453     for (i=1; i<=ocp_size; i++) {
00454         ocptables[ocp_number][i]  = 0;
00455     }
00456 }
00457 
00458 void
00459 dumpocptable P1C(int, ocp_number)
00460 {
00461     dumpthings(ocptables[ocp_number][0], ocptables[ocp_number][0]+1);
00462 }
00463 
00464 void
00465 undumpocptable P1C(int, ocp_number)
00466 {
00467     int sizeword;
00468     if (ocp_entries==0) {
00469       ocptables = (int **) xmalloc(256*sizeof(int**));
00470       ocp_entries=256;
00471     } else if ((ocp_number==256)&&(ocp_entries==256)) {
00472       ocptables = xrealloc(ocptables, 65536);
00473       ocp_entries=65536;
00474     }
00475     undumpthings(sizeword,1);
00476     ocptables[ocp_number] =
00477         (int *) xmalloc((1+sizeword)*sizeof(int));
00478     ocptables[ocp_number][0] = sizeword;
00479     undumpthings(ocptables[ocp_number][1], sizeword);
00480 }