1 /* Loglan82 Compiler&Interpreter
2 Copyright (C) 1993 Institute of Informatics, University of Warsaw
3 Copyright (C) 1993, 1994 LITA, Pau
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
16 =======================================================================
25 static long hash_search(char *);
30 static long hash_search();
37 /* ===================== for debugger ======================== */
38 /* files organization : */
39 /* fil21 ( .DEB ) : */
41 /* idict(maxidict), ind, prot(ind) */
42 /* dfile ( .DCD ) : */
44 /* idict(maxidict), protbreakl, ind, prot(ind) */
49 static int idict[maxidict]; /* dictionary of prototypes */
50 static int *prot; /* array of prototypes */
51 static int ind; /* last used in PROT */
54 /* put dispnr and offset into prototypes */
57 while( i < maxidict ){
61 /* pr - address of zero word of the prototype */
65 /* hash table of prototype */
66 for( j = pr+5 ; j <= pr+12 ; j++){
70 /* el - address of zero word of list element */
73 if( prot[el+1] % 8 < 4 ){ /* not not taken */
76 /* prz - address of debugger protype */
77 if( prz < -15 ){ /* variable or constant */
80 if( prot[prz] == 5 ) /* variable */
81 prot[prz+3] = ipmem[prot[prz+3] - 2];
85 prz = prot[el]; /* next element */
95 void ts3( fname ) char *fname; {
97 /* wpisuje dispnr i offset do prototypow debuggera */
98 /* czyta prototypy z pliku fil21, pisze na dfile */
100 FILE *fil21; /* input - prototypes from TS2 */
105 strcpy( fnameaux, fname );
106 fil21 = fopen( strcat( fnameaux, ".deb" ) , "rw" );
107 fseek( fil21, maxhash * sizeof(int) ,0 );
108 fread( idict, sizeof(*idict), maxidict, fil21 );
109 fread( &ind, sizeof(ind), 1, fil21 );
111 position = ftell( fil21 );
112 prot=(int *)calloc(ind+1,sizeof(int));
113 fread( prot+1, sizeof(int), ind*4, fil21 );
114 /* changing prototypes */
117 fseek( fil21, position, 0 );
118 fwrite( prot+1, sizeof(int), ind*4, fil21 );
119 fseek( fil21, 0L, 0);
120 fread( hash, 8000, sizeof(long), fil21 );
121 printf("searching do for begin aaa ala i nikldksjkehtr");getchar();
122 printf("#%ld",hash_search("do"));getchar();
123 printf("#%ld",hash_search("for"));getchar();
124 printf("#%ld",hash_search("begin"));getchar();
125 printf("#%ld",hash_search("aaa"));getchar();
126 printf("#%ld",hash_search("ala"));getchar();
127 printf("#%ld",hash_search("i"));getchar();
128 printf("#%ld",hash_search("niksehfkertk"));getchar();
133 /* ======================================================== */
138 static long hash_search (str) char *str;{
143 int H; /* do poszukiwan po hash */
144 int N; /* do przechodzenia po name */
146 /* pakowanie nazwy do poszukiwan w hash */
148 for( i=0; i<20 && *str!='\0'; i++ )
149 if( i % 2 == 0 ) name[ i/2 ] = ord( *( str++ ) );
150 else name[ i/2 ] = name[ i/2 ] * BYTE + ord( *( str++ ) );
152 name[ (i+1)/2 ]= -1 ;
154 H = ( name[0] % M ) * 2;
157 printf("comparing name H=%d,name[0]=%d",H,name[0]);getchar();
162 while( hash[ H+1 ] <0 && hash[ H ] == name[ N ] ){
163 printf("Nth pare OK %d",N);getchar();
165 H = - hash[ H+1 ] - 1;
170 if( hash[ H ] != name[ N ] ){
172 while( hash[ H+1 ] <0 ) H = - hash[ H+1 ] - 1;
173 if( hash[ H+1 ] == 0 ) return -1;
179 if( name[ N+1 ] == -1 ) return result;
180 if( hash[ H+1 ] == 0 ) return -1;
189 static int ord_tab[]={
190 63,63,63,63,63,63,63,63,36,63,63,63,37,
191 36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,
192 63,43,63,63,63,63,44,52,53,48,39,
193 42,40,38,41,0,1,2,3,4,5,6,7,8,9,47,45,50,49,51,63,63,
194 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
195 30,31,32,33,34,35,63,63,63,63,46,
196 63,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
200 static int ord(c) char c;{
201 if( c>122 ) return 63;
202 return ord_tab[ c-1 ];