Blame view

include/search.h 4.11 KB
a6826fbc5   Wolfgang Denk   Add hash table su...
1
2
3
4
5
  /*
   * Declarations for System V style searching functions.
   * Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
   * This file is part of the GNU C Library.
   *
eee479cf6   Wolfgang Denk   Add LGPL-2.1+ SPD...
6
   * SPDX-License-Identifier:	LGPL-2.1+
a6826fbc5   Wolfgang Denk   Add hash table su...
7
8
9
10
11
   */
  
  /*
   * Based on code from uClibc-0.9.30.3
   * Extensions for use within U-Boot
ea009d474   Wolfgang Denk   hashtable: prepar...
12
   * Copyright (C) 2010-2013 Wolfgang Denk <wd@denx.de>
a6826fbc5   Wolfgang Denk   Add hash table su...
13
   */
362664356   Robert P. J. Day   search.h: Numerou...
14
15
  #ifndef _SEARCH_H_
  #define _SEARCH_H_
a6826fbc5   Wolfgang Denk   Add hash table su...
16
17
18
19
  
  #include <stddef.h>
  
  #define __set_errno(val) do { errno = val; } while (0)
7afcf3a55   Joe Hershberger   env: Refactor app...
20
21
22
23
24
  enum env_op {
  	env_op_create,
  	env_op_delete,
  	env_op_overwrite,
  };
362664356   Robert P. J. Day   search.h: Numerou...
25
  /* Action which shall be performed in the call to hsearch.  */
a6826fbc5   Wolfgang Denk   Add hash table su...
26
27
28
29
30
31
  typedef enum {
  	FIND,
  	ENTER
  } ACTION;
  
  typedef struct entry {
84b5e8022   Wolfgang Denk   Constify getenv()...
32
  	const char *key;
a6826fbc5   Wolfgang Denk   Add hash table su...
33
  	char *data;
170ab1107   Joe Hershberger   env: Add support ...
34
35
  	int (*callback)(const char *name, const char *value, enum env_op op,
  		int flags);
2598090b7   Joe Hershberger   env: Add environm...
36
  	int flags;
a6826fbc5   Wolfgang Denk   Add hash table su...
37
38
39
40
41
42
43
44
  } ENTRY;
  
  /* Opaque type for internal use.  */
  struct _ENTRY;
  
  /*
   * Family of hash table handling functions.  The functions also
   * have reentrant counterparts ending with _r.  The non-reentrant
362664356   Robert P. J. Day   search.h: Numerou...
45
   * functions all work on a single internal hash table.
a6826fbc5   Wolfgang Denk   Add hash table su...
46
47
48
49
50
51
52
   */
  
  /* Data type for reentrant functions.  */
  struct hsearch_data {
  	struct _ENTRY *table;
  	unsigned int size;
  	unsigned int filled;
c5983592e   Gerlando Falauto   env: add check/ap...
53
54
  /*
   * Callback function which will check whether the given change for variable
362664356   Robert P. J. Day   search.h: Numerou...
55
   * "__item" to "newval" may be applied or not, and possibly apply such change.
c5983592e   Gerlando Falauto   env: add check/ap...
56
57
   * When (flag & H_FORCE) is set, it shall not print out any error message and
   * shall force overwriting of write-once variables.
362664356   Robert P. J. Day   search.h: Numerou...
58
   * Must return 0 for approval, 1 for denial.
c5983592e   Gerlando Falauto   env: add check/ap...
59
   */
7afcf3a55   Joe Hershberger   env: Refactor app...
60
61
  	int (*change_ok)(const ENTRY *__item, const char *newval, enum env_op,
  		int flag);
a6826fbc5   Wolfgang Denk   Add hash table su...
62
  };
362664356   Robert P. J. Day   search.h: Numerou...
63
  /* Create a new hash table which will contain at most "__nel" elements.  */
a6826fbc5   Wolfgang Denk   Add hash table su...
64
  extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
362664356   Robert P. J. Day   search.h: Numerou...
65
  /* Destroy current internal hash table.  */
c4e0057fa   Joe Hershberger   env: Refactor do_...
66
  extern void hdestroy_r(struct hsearch_data *__htab);
a6826fbc5   Wolfgang Denk   Add hash table su...
67
68
  
  /*
362664356   Robert P. J. Day   search.h: Numerou...
69
   * Search for entry matching __item.key in internal hash table.  If
a6826fbc5   Wolfgang Denk   Add hash table su...
70
71
   * ACTION is `FIND' return found entry or signal error by returning
   * NULL.  If ACTION is `ENTER' replace existing data (if any) with
362664356   Robert P. J. Day   search.h: Numerou...
72
   * __item.data.
a6826fbc5   Wolfgang Denk   Add hash table su...
73
   * */
a6826fbc5   Wolfgang Denk   Add hash table su...
74
  extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
c4e0057fa   Joe Hershberger   env: Refactor do_...
75
  		     struct hsearch_data *__htab, int __flag);
a6826fbc5   Wolfgang Denk   Add hash table su...
76

560d424b6   Mike Frysinger   env: re-add suppo...
77
  /*
362664356   Robert P. J. Day   search.h: Numerou...
78
   * Search for an entry matching "__match".  Otherwise, Same semantics
560d424b6   Mike Frysinger   env: re-add suppo...
79
80
81
82
   * as hsearch_r().
   */
  extern int hmatch_r(const char *__match, int __last_idx, ENTRY ** __retval,
  		    struct hsearch_data *__htab);
362664356   Robert P. J. Day   search.h: Numerou...
83
  /* Search and delete entry matching "__key" in internal hash table. */
152874b65   Gerlando Falauto   env: check and ap...
84
  extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
c4e0057fa   Joe Hershberger   env: Refactor do_...
85
  		     int __flag);
a6826fbc5   Wolfgang Denk   Add hash table su...
86

a6826fbc5   Wolfgang Denk   Add hash table su...
87
  extern ssize_t hexport_r(struct hsearch_data *__htab,
be11235ab   Joe Hershberger   env: Hide '.' var...
88
  		     const char __sep, int __flag, char **__resp, size_t __size,
37f2fe747   Wolfgang Denk   env: allow to exp...
89
  		     int argc, char * const argv[]);
a6826fbc5   Wolfgang Denk   Add hash table su...
90

348b1f1c6   Gerlando Falauto   env: make himport...
91
92
93
94
  /*
   * nvars: length of vars array
   * vars: array of strings (variable names) to import (nvars == 0 means all)
   */
a6826fbc5   Wolfgang Denk   Add hash table su...
95
96
  extern int himport_r(struct hsearch_data *__htab,
  		     const char *__env, size_t __size, const char __sep,
ecd1446fe   Alexander Holler   Add option -r to ...
97
98
  		     int __flag, int __crlf_is_lf, int nvars,
  		     char * const vars[]);
a6826fbc5   Wolfgang Denk   Add hash table su...
99

170ab1107   Joe Hershberger   env: Add support ...
100
101
  /* Walk the whole table calling the callback on each element */
  extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));
be11235ab   Joe Hershberger   env: Hide '.' var...
102
  /* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */
c4e0057fa   Joe Hershberger   env: Refactor do_...
103
104
105
  #define H_NOCLEAR	(1 << 0) /* do not clear hash table before importing */
  #define H_FORCE		(1 << 1) /* overwrite read-only/write-once variables */
  #define H_INTERACTIVE	(1 << 2) /* indicate that an import is user directed */
be11235ab   Joe Hershberger   env: Hide '.' var...
106
  #define H_HIDE_DOT	(1 << 3) /* don't print env vars that begin with '.' */
ea009d474   Wolfgang Denk   hashtable: prepar...
107
108
109
110
  #define H_MATCH_KEY	(1 << 4) /* search/grep key  = variable names	     */
  #define H_MATCH_DATA	(1 << 5) /* search/grep data = variable values	     */
  #define H_MATCH_BOTH	(H_MATCH_KEY | H_MATCH_DATA) /* search/grep both     */
  #define H_MATCH_IDENT	(1 << 6) /* search for indentical strings	     */
be29df6a1   Wolfgang Denk   "env grep" - add ...
111
112
113
  #define H_MATCH_SUBSTR	(1 << 7) /* search for substring matches	     */
  #define H_MATCH_REGEX	(1 << 8) /* search for regular expression matches    */
  #define H_MATCH_METHOD	(H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX)
382bee57f   Simon Glass   env: Rename seten...
114
  #define H_PROGRAMMATIC	(1 << 9) /* indicate that an import is from env_set() */
94b467b14   Joe Hershberger   env: Distinguish ...
115
  #define H_ORIGIN_FLAGS	(H_INTERACTIVE | H_PROGRAMMATIC)
a6826fbc5   Wolfgang Denk   Add hash table su...
116

362664356   Robert P. J. Day   search.h: Numerou...
117
  #endif /* _SEARCH_H_ */