hashwalk.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: hashwalk.c /main/3 1995/11/01 17:33:39 rswiston $ */
  24. /***************************************************************
  25. * *
  26. * AT&T - PROPRIETARY *
  27. * *
  28. * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
  29. * AT&T CORP. *
  30. * *
  31. * Copyright (c) 1995 AT&T Corp. *
  32. * All Rights Reserved *
  33. * *
  34. * This software is licensed by AT&T Corp. *
  35. * under the terms and conditions of the license in *
  36. * http://www.research.att.com/orgs/ssr/book/reuse *
  37. * *
  38. * This software was created by the *
  39. * Software Engineering Research Department *
  40. * AT&T Bell Laboratories *
  41. * *
  42. * For further information contact *
  43. * gsf@research.att.com *
  44. * *
  45. ***************************************************************/
  46. /* : : generated by proto : : */
  47. #if !defined(__PROTO__)
  48. #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
  49. #if defined(__cplusplus)
  50. #define __MANGLE__ "C"
  51. #else
  52. #define __MANGLE__
  53. #endif
  54. #define __STDARG__
  55. #define __PROTO__(x) x
  56. #define __OTORP__(x)
  57. #define __PARAM__(n,o) n
  58. #if !defined(__STDC__) && !defined(__cplusplus)
  59. #if !defined(c_plusplus)
  60. #define const
  61. #endif
  62. #define signed
  63. #define void int
  64. #define volatile
  65. #define __V_ char
  66. #else
  67. #define __V_ void
  68. #endif
  69. #else
  70. #define __PROTO__(x) ()
  71. #define __OTORP__(x) x
  72. #define __PARAM__(n,o) o
  73. #define __MANGLE__
  74. #define __V_ char
  75. #define const
  76. #define signed
  77. #define void int
  78. #define volatile
  79. #endif
  80. #if defined(__cplusplus) || defined(c_plusplus)
  81. #define __VARARG__ ...
  82. #else
  83. #define __VARARG__
  84. #endif
  85. #if defined(__STDARG__)
  86. #define __VA_START__(p,a) va_start(p,a)
  87. #else
  88. #define __VA_START__(p,a) va_start(p)
  89. #endif
  90. #endif
  91. #include "hashlib.h"
  92. /*
  93. * apply walker to each active bucket in the table
  94. */
  95. int
  96. hashwalk __PARAM__((Hash_table_t* tab, int flags, int register(*walker)(const char*, char*, __V_*), __V_* handle), (tab, flags, walker, handle)) __OTORP__(Hash_table_t* tab; int flags; int register(*walker)(); __V_* handle;){
  97. Hash_bucket_t* b;
  98. int v;
  99. Hash_position_t* pos;
  100. if (!(pos = hashscan(tab, flags))) return(-1);
  101. hash_info.table = tab->root->last.table = tab;
  102. v = 0;
  103. while (b = hashnext(pos))
  104. if ((v = (*walker)(hashname(b), (tab->flags & HASH_VALUE) ? b->value : (char*)b, handle)) < 0)
  105. break;
  106. hashdone(pos);
  107. return(v);
  108. }