1: #include <X/mit-copyright.h> 2: 3: /* $Header: XLookUpAssoc.c,v 10.4 86/02/01 15:36:21 tony Rel $ */ 4: /* Copyright Massachusetts Institute of Technology 1985 */ 5: 6: #include "XlibInternal.h" 7: 8: /* 9: * XLookUpAssoc - Retrieve the data stored in an XAssocTable by its XId. 10: * If an appropriately matching XId can be found in the table the routine will 11: * return apointer to the data associated with it. If the XId can not be found 12: * in the table the routine will return a NULL pointer. All XId's are relative 13: * to the currently active Display. 14: */ 15: caddr_t XLookUpAssoc(table, x_id) 16: register XAssocTable *table; /* XAssocTable to search in. */ 17: register XId x_id; /* XId to search for. */ 18: { 19: int hash; 20: register XAssoc *bucket; 21: register XAssoc *entry; 22: 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->table)[hash]; 27: /* Get the first entry in the bucket. */ 28: entry = bucket->next; 29: 30: /* Scan through the entries in the bucket for the right XId. */ 31: for (entry; entry != bucket; entry = entry->next) { 32: if (entry->x_id == x_id) { 33: /* We have the right XId. */ 34: if (entry->display == _XlibCurrentDisplay) { 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: }