lookup.c 1.7 KB

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