⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyword.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/keyword.c,v 1.3 2003/01/15 14:04:31 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: keyword.c,v $ * Revision 1.3  2003/01/15 14:04:31  josh * directory structure shifting * * Revision 1.2  2001/11/08 15:56:22  tneale * Updated for newest file layout * * Revision 1.1.1.1  2001/11/05 17:48:41  tneale * Tornado shuffle * * Revision 1.11  2001/01/19 22:23:42  paul * Update copyright. * * Revision 1.10  2000/03/17 00:12:39  meister * Update copyright message * * Revision 1.9  1998/07/02 06:55:35  sra * Make Snark restartable under pSOS, and other minor cleanups. * * Revision 1.8  1998/02/25 15:21:47  sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 1.7  1998/02/25 04:57:24  sra * Update copyrights. * * Revision 1.6  1997/03/20 06:52:54  sra * DFARS-safe copyright text.  Zap! * * Revision 1.5  1997/03/19 22:05:35  sra * Perhaps we should include install.h before testing install options? * * Revision 1.4  1997/03/19 20:17:56  sra * Fun with "const" attributes.  Remove gratuitous Attache dependencies. * * Revision 1.3  1997/03/19 04:47:35  sra * Get rid of some gratuitous historical dependencies on Attache. * * Revision 1.2  1997/03/09 18:39:33  sra * Fix some compiler warnings, change from compile-time to run-time init * macros for keyword tables. * * Revision 1.1  1997/02/19 08:13:05  sra * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <stddef.h>#include <stdlib.h>#include <wrn/wm/common/install.h>#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/common/bug.h>/* * This business with (const char * const *) is pretty grotty, * but the idea is that we're converting a pointer to constant data * into a pointer to a constant pointer to constant data. * The syntax is awful, but without the second const token in the cast, * gcc correctly objects to the cast as throwing away the constraint * that came with the original (const void *) argument. */static int q_compare(const void *thing1, const void *thing2){  return STRICMP(*(const char * const *) thing1,		 *(const char * const *) thing2);}static int b_compare(const void *key, const void *thing){  return STRNICMP((const char *) key,		  *(const char * const *) thing,		  STRLEN((const char *) key));}/* ref(a,i) :=: &a[i] */#define ref(_a_,_i_) (((char *) (_a_)) + ((_i_) * s))void *keyword_find(struct keyword_table *table, const char *name){  void *r, *t = table->table;  size_t n = table->table_length, s = table->entry_size;  BUG_ASSERT(table && table->table && name);  r = table->result = bsearch(name, t, n, s, b_compare);  if (!r)    table->error = KEYWORD_ERROR_NOT_FOUND;  else if ((ref(r, 0) > ref(t, 0)     && !b_compare(name, ref(r, -1))) ||	   (ref(r, 0) < ref(t, n - 1) && !b_compare(name, ref(r, +1))))    table->error = KEYWORD_ERROR_AMBIGUOUS;  else    table->error = KEYWORD_ERROR_OK;  return table->error == KEYWORD_ERROR_OK ? r : 0;}void  keyword_init(struct keyword_table *table,	       void * array,	       size_t array_length,	       size_t entry_size){  BUG_ASSERT(table && array && array_length && entry_size);  MEMSET(table, 0, sizeof(*table));  table->table = array;  table->table_length = array_length;  table->entry_size = entry_size;#if 0  /*   * If we were worried about loading the keyword table from   * read-only memory, we'd do this here.   */  table->table = GLUE_ALLOC(array_length);  BUG_ASSERT(table->table);  MEMCPY(table->table, array, array_length);#endif /* 0 */  qsort(table->table, array_length, entry_size, q_compare);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -