00001 /* 00002 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu> 00003 ** 00004 ** This library is free software; you can redistribute it and/or 00005 ** modify it under the terms of the GNU Library General Public 00006 ** License as published by the Free Software Foundation; either 00007 ** version 2 of the License, or (at your option) any later version. 00008 ** 00009 ** This library is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 ** Library General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU Library General Public 00015 ** License along with this library; if not, write to the Free 00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00017 ** MA 02111-1307, USA 00018 ** 00019 ** @(#)$Id: st__find_8c-source.html,v 1.3 2006/09/04 15:12:18 spale Exp $ 00020 */ 00028 #include <string.h> 00029 00030 #include "dbprim.h" 00031 #include "dbprim_int.h" 00032 00033 RCSTAG("@(#)$Id: st__find_8c-source.html,v 1.3 2006/09/04 15:12:18 spale Exp $"); 00034 00035 unsigned long 00036 st_find(smat_table_t *table, smat_entry_t **entry_p, smat_head_t *head1, 00037 smat_head_t *head2) 00038 { 00039 hash_entry_t *ent; 00040 unsigned long retval; 00041 void *object[2]; 00042 db_key_t key; 00043 00044 initialize_dbpr_error_table(); /* initialize error table */ 00045 00046 /* Verify arguments */ 00047 if (!st_verify(table) || !sh_verify(head1) || !sh_verify(head2) || 00048 head1->sh_elem != SMAT_LOC_FIRST || head2->sh_elem != SMAT_LOC_SECOND) 00049 return DB_ERR_BADARGS; 00050 00051 /* If there are no entries in one of the lists, then return "no entry" */ 00052 if (!head1->sh_table || !head2->sh_table || head1->sh_head.lh_count == 0 || 00053 head2->sh_head.lh_count == 0) 00054 return DB_ERR_NOENTRY; 00055 00056 /* verify that everything's in the right tables */ 00057 if (head1->sh_table != table || head2->sh_table != table) 00058 return DB_ERR_WRONGTABLE; 00059 00060 /* Build the search key */ 00061 memset(object, 0, sizeof(object)); 00062 object[SMAT_LOC_FIRST] = sh_object(head1); 00063 object[SMAT_LOC_SECOND] = sh_object(head2); 00064 dk_key(&key) = object; 00065 dk_len(&key) = sizeof(object); 00066 00067 /* look up the entry */ 00068 if ((retval = ht_find(&table->st_table, &ent, &key))) 00069 return retval; 00070 00071 /* If the user wants the object, return it to him */ 00072 if (entry_p) 00073 *entry_p = he_value(ent); 00074 00075 return 0; /* search successful */ 00076 }