XLookAssoc.c 1.6 KB

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