[2759] | 1 | /*********************************************************************** |
---|
| 2 | |
---|
| 3 | COPYRIGHT |
---|
| 4 | |
---|
| 5 | The following is a notice of limited availability of the code and |
---|
| 6 | Government license and disclaimer which must be included in the |
---|
| 7 | prologue of the code and in all source listings of the code. |
---|
| 8 | |
---|
| 9 | Copyright notice |
---|
| 10 | (c) 1977 University of Chicago |
---|
| 11 | |
---|
| 12 | Permission is hereby granted to use, reproduce, prepare |
---|
| 13 | derivative works, and to redistribute to others at no charge. If |
---|
| 14 | you distribute a copy or copies of the Software, or you modify a |
---|
| 15 | copy or copies of the Software or any portion of it, thus forming |
---|
| 16 | a work based on the Software and make and/or distribute copies of |
---|
| 17 | such work, you must meet the following conditions: |
---|
| 18 | |
---|
| 19 | a) If you make a copy of the Software (modified or verbatim) |
---|
| 20 | it must include the copyright notice and Government |
---|
| 21 | license and disclaimer. |
---|
| 22 | |
---|
| 23 | b) You must cause the modified Software to carry prominent |
---|
| 24 | notices stating that you changed specified portions of |
---|
| 25 | the Software. |
---|
| 26 | |
---|
| 27 | This software was authored by: |
---|
| 28 | |
---|
| 29 | Argonne National Laboratory |
---|
| 30 | J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov |
---|
| 31 | Mathematics and Computer Science Division |
---|
| 32 | Argonne National Laboratory, Argonne, IL 60439 |
---|
| 33 | |
---|
| 34 | ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES |
---|
| 35 | OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT, |
---|
| 36 | AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A |
---|
| 37 | CONTRACT WITH THE DEPARTMENT OF ENERGY. |
---|
| 38 | |
---|
| 39 | GOVERNMENT LICENSE AND DISCLAIMER |
---|
| 40 | |
---|
| 41 | This computer code material was prepared, in part, as an account |
---|
| 42 | of work sponsored by an agency of the United States Government. |
---|
| 43 | The Government is granted for itself and others acting on its |
---|
| 44 | behalf a paid-up, nonexclusive, irrevocable worldwide license in |
---|
| 45 | this data to reproduce, prepare derivative works, distribute |
---|
| 46 | copies to the public, perform publicly and display publicly, and |
---|
| 47 | to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT |
---|
| 48 | NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF |
---|
| 49 | THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR |
---|
| 50 | ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, |
---|
| 51 | COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, |
---|
| 52 | PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD |
---|
| 53 | NOT INFRINGE PRIVATELY OWNED RIGHTS. |
---|
| 54 | |
---|
| 55 | ***************************************************************************/ |
---|
| 56 | /* sym.c |
---|
| 57 | |
---|
| 58 | Implementation dependent routines for using symtab_gen.c |
---|
| 59 | in N32 . |
---|
| 60 | |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | #include <stdio.h> |
---|
| 64 | #include "sym.h" |
---|
| 65 | |
---|
| 66 | extern sym_nodeptr symget() ; |
---|
| 67 | |
---|
| 68 | static char ** symtab ; /* 2-19-90 */ |
---|
| 69 | |
---|
| 70 | int |
---|
| 71 | sym_init() /* 2-19-90, initialize symbol table package */ |
---|
| 72 | { |
---|
| 73 | create_ht( &symtab ) ; |
---|
| 74 | if (symtab == NULL) |
---|
| 75 | { |
---|
| 76 | fprintf(stderr,"init_sym(): could not create hash table") ; |
---|
| 77 | exit(1) ; |
---|
| 78 | } |
---|
| 79 | return(0) ; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | sym_nodeptr |
---|
| 83 | sym_add( name ) |
---|
| 84 | char * name ; |
---|
| 85 | { |
---|
| 86 | sym_nodeptr new_sym_node(); |
---|
| 87 | char **node_name() ; |
---|
| 88 | sym_nodeptr *node_next() ; |
---|
| 89 | return( symget( name, new_sym_node, node_name, node_next, symtab, 1 ) ) ; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | sym_nodeptr |
---|
| 93 | sym_get( name ) |
---|
| 94 | char * name ; |
---|
| 95 | { |
---|
| 96 | sym_nodeptr new_sym_node(); |
---|
| 97 | char **node_name() ; |
---|
| 98 | sym_nodeptr *node_next() ; |
---|
| 99 | return( symget( name, new_sym_node, node_name, node_next, symtab, 0 ) ) ; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | sym_nodeptr |
---|
| 103 | new_sym_node() |
---|
| 104 | { |
---|
| 105 | void * malloc() ; |
---|
| 106 | sym_nodeptr p ; |
---|
| 107 | p = (sym_nodeptr) malloc( sizeof( struct sym_node ) ) ; |
---|
| 108 | p->name = NULL ; |
---|
| 109 | p->next = NULL ; |
---|
| 110 | |
---|
| 111 | return( p ) ; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | char ** |
---|
| 115 | node_name(p) |
---|
| 116 | sym_nodeptr p ; |
---|
| 117 | { |
---|
| 118 | char ** x ; |
---|
| 119 | x = &(p->name) ; |
---|
| 120 | return( x ) ; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | sym_nodeptr * |
---|
| 124 | node_next(p) |
---|
| 125 | sym_nodeptr p ; |
---|
| 126 | { |
---|
| 127 | sym_nodeptr *x ; |
---|
| 128 | x = &(p->next) ; |
---|
| 129 | return( x ) ; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | int |
---|
| 133 | show_entry(x) |
---|
| 134 | sym_nodeptr x ; |
---|
| 135 | { |
---|
| 136 | int i ; |
---|
| 137 | if ( x == NULL ) return(0) ; |
---|
| 138 | printf("Symbol table entry:\n") ; |
---|
| 139 | printf("lexeme %s\n", x->name ) ; |
---|
| 140 | printf(" dim %s\n", (x->dim==1?"M":(x->dim==2?"N":"O")) ) ; |
---|
| 141 | printf(" ndims %d\n", x->ndims ) ; |
---|
| 142 | for ( i = 0 ; i < x->ndims && i < 7 ; i++ ) |
---|
| 143 | printf(" dim %d -> %s\n",i,(x->dims[i]==1?"M":(x->dims[i]==2?"N":"O")) ) ; |
---|
| 144 | return(0) ; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | /* MEMORY LEAK !!!! -- this just abandons the old table and leaves on the heap. */ |
---|
| 148 | /* The registry mechanism is not a long-running program and is not apt to |
---|
| 149 | run into memory problems. Might want to fix this anyway, though, someday. */ |
---|
| 150 | int |
---|
| 151 | sym_forget() |
---|
| 152 | { |
---|
| 153 | create_ht( &symtab ) ; |
---|
| 154 | if (symtab == NULL) |
---|
| 155 | { |
---|
| 156 | fprintf(stderr,"init_sym(): could not create hash table") ; |
---|
| 157 | exit(1) ; |
---|
| 158 | } |
---|
| 159 | return(0) ; |
---|
| 160 | } |
---|
| 161 | |
---|