XLookAssoc.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright Massachusetts Institute of Technology 1985 */
  2. #include "copyright.h"
  3. #include <config.h>
  4. #include <X11/Xlib.h>
  5. #include <X11/Xresource.h>
  6. #include "X10.h"
  7. #ifndef NULL
  8. #define NULL 0
  9. #endif
  10. /*
  11. * XLookUpAssoc - Retrieve the data stored in an XAssocTable by its XId.
  12. * If an appropriately matching XId can be found in the table the routine will
  13. * return apointer to the data associated with it. If the XId can not be found
  14. * in the table the routine will return a NULL pointer. All XId's are relative
  15. * to the currently active Display.
  16. */
  17. caddr_t XLookUpAssoc(Display *dpy,
  18. XAssocTable *table, /* XAssocTable to search in. */
  19. XID x_id) /* XId to search for. */
  20. {
  21. int hash;
  22. register XAssoc *bucket;
  23. register XAssoc *Entry;
  24. /* Hash the XId to get the bucket number. */
  25. hash = x_id & (table->size - 1);
  26. /* Look up the bucket to get the entries in that bucket. */
  27. bucket = &table->buckets[hash];
  28. /* Get the first entry in the bucket. */
  29. Entry = bucket->next;
  30. /* Scan through the entries in the bucket for the right XId. */
  31. for (; Entry != bucket; Entry = Entry->next) {
  32. if (Entry->x_id == x_id) {
  33. /* We have the right XId. */
  34. if (Entry->display == dpy) {
  35. /* We have the right display. */
  36. /* We have the right entry! */
  37. return(Entry->data);
  38. }
  39. /* Oops, identical XId's on different displays! */
  40. continue;
  41. }
  42. if (Entry->x_id > x_id) {
  43. /* We have gone past where it should be. */
  44. /* It is apparently not in the table. */
  45. return(NULL);
  46. }
  47. }
  48. /* It is apparently not in the table. */
  49. return(NULL);
  50. }