home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / s2latex.tar.Z / s2latex.tar / symtab.c < prev    next >
C/C++ Source or Header  |  1985-02-05  |  2KB  |  73 lines

  1. /*    symtab.c    1.2    85/02/04    */
  2. /* symbol table routines for scribe-to-latex 
  3.  *
  4.  * copyright (c) 1984 by Van Jacobson, Lawrence Berkeley Laboratory
  5.  * This program may be freely redistributed but not for profit.  This
  6.  * comment must remain in the program or any derivative.
  7.  */
  8.  
  9. #include <ctype.h>
  10. #include "symtab.h"
  11.  
  12. #define    HASHSIZE    127
  13. #define    MAXSYM        128    /* max char in a symbol name */
  14.  
  15. static struct stab *sthash[HASHSIZE];
  16.  
  17. #define SYMHASH(str)    ((str[0]+(str[1]<<8))%HASHSIZE)
  18.  
  19.  
  20. struct stab *lookup( str )
  21.     register char *str;
  22. {
  23.     register struct stab *s;
  24.     char text[MAXSYM];
  25.     register char *cp = text;
  26.     register char *textend = &text[MAXSYM-1];
  27.  
  28.     /* convert the string to lower case, then try to find it */
  29.     while( *str && cp<textend )
  30.         *cp++ = (isupper(*str)? tolower(*str++): *str++);
  31.  
  32.     *cp = '\0';
  33.  
  34.     s = sthash[SYMHASH(text)];
  35.     while( s && strcmp(text,s->s_text) )
  36.         s = s->s_next;
  37.  
  38.     return(s);
  39. }
  40.  
  41. struct stab *enter( text, type, reptext )
  42.     char    *text, *reptext;
  43.     int    type;
  44. {
  45.     register struct stab *n;
  46.  
  47.     /* set up the new entry */
  48.  
  49.     n = (struct stab *) malloc( sizeof(struct stab) );
  50.     n->s_text = (char *) malloc( strlen(text)+1 );
  51.     lc_strcpy( n->s_text, text );
  52.     n->s_reptext = (char *) malloc( strlen(reptext)+1 );
  53.     lc_strcpy( n->s_reptext, reptext );
  54.     n->s_type = type;
  55.  
  56.     /* add it to the table */
  57.  
  58.     n->s_next = sthash[SYMHASH(n->s_text)];
  59.     sthash[SYMHASH(n->s_text)] = n;
  60.     return(n);
  61. }
  62.  
  63. /* copy a string converting upper case to lower case. */
  64. lc_strcpy( dst, src )
  65. char *dst;
  66. char *src;
  67. {
  68.     while( *src )
  69.         *dst++ = isupper(*src)? tolower(*src++): *src++;
  70.     
  71.     *dst = '\0';
  72. }
  73.