lookup.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Id$";
  3. #endif
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "param.h"
  7. #include "types.h"
  8. #include "tes.h"
  9. #include "lookup.h"
  10. #include "alloc.h"
  11. #include "proinf.h"
  12. /*
  13. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  14. * See the copyright notice in the ACK home directory, in the file "Copyright".
  15. *
  16. * Author: Hans van Staveren
  17. */
  18. unsigned hash(string) char *string; {
  19. register char *p;
  20. register unsigned i,sum;
  21. for (sum=i=0,p=string;*p;i += 3)
  22. sum ^= (*p++)<<(i&07);
  23. return(sum);
  24. }
  25. sym_p symlookup(name,status,flags) char *name; int status,flags; {
  26. register sym_p *spp,sp;
  27. register i;
  28. static short genfrag = 32767;
  29. spp = &symhash[hash(name)%NSYMHASH];
  30. while (*spp != (sym_p) 0)
  31. if (strncmp((*spp)->s_name,name,IDL)==0) {
  32. sp = *spp;
  33. if ((sp->s_flags^flags)&SYMPRO)
  34. error("%s is both proc and datalabel",name);
  35. if (status == DEFINING) {
  36. if (sp->s_flags&SYMDEF)
  37. error("redefined symbol %s",name);
  38. sp->s_flags |= SYMDEF;
  39. }
  40. return(sp);
  41. } else
  42. spp = &(*spp)->s_next;
  43. /*
  44. * symbol not found, enter in table
  45. */
  46. i = strlen(name) + 1;
  47. if (i & 1)
  48. i++;
  49. if (i > IDL)
  50. i = IDL;
  51. *spp = sp = newsym(i);
  52. strncpy(sp->s_name,name,i);
  53. sp->s_flags = flags;
  54. if (status == DEFINING)
  55. sp->s_flags |= SYMDEF;
  56. sp->s_frag = genfrag--;
  57. return(sp);
  58. }
  59. num_p numlookup(number) unsigned number; {
  60. register num_p *npp, np;
  61. npp = &curpro.numhash[number%NNUMHASH];
  62. while (*npp != (num_p) 0)
  63. if ((*npp)->n_number == number)
  64. return(*npp);
  65. else
  66. npp = &(*npp)->n_next;
  67. /*
  68. * local label not found, enter in tabel
  69. */
  70. *npp = np = newnum();
  71. np->n_number = number;
  72. np->n_repl = np;
  73. return(np);
  74. }