Blame view
include/search.h
4.02 KB
83d290c56 SPDX: Convert all... |
1 |
/* SPDX-License-Identifier: LGPL-2.1+ */ |
a6826fbc5 Add hash table su... |
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. |
a6826fbc5 Add hash table su... |
6 7 8 9 10 |
*/ /* * Based on code from uClibc-0.9.30.3 * Extensions for use within U-Boot |
ea009d474 hashtable: prepar... |
11 |
* Copyright (C) 2010-2013 Wolfgang Denk <wd@denx.de> |
a6826fbc5 Add hash table su... |
12 |
*/ |
362664356 search.h: Numerou... |
13 14 |
#ifndef _SEARCH_H_ #define _SEARCH_H_ |
a6826fbc5 Add hash table su... |
15 |
|
9fb625ce0 env: Move env_set... |
16 |
#include <env.h> |
a6826fbc5 Add hash table su... |
17 |
#include <stddef.h> |
cb2ba9db5 env: Drop the dou... |
18 |
#define set_errno(val) do { errno = val; } while (0) |
a6826fbc5 Add hash table su... |
19 |
|
3f0d68074 env: Drop the ACT... |
20 21 22 23 24 |
/* enum env_action: action which shall be performed in the call to hsearch */ enum env_action { ENV_FIND, ENV_ENTER, }; |
a6826fbc5 Add hash table su... |
25 |
|
dd2408cac env: Drop the ENT... |
26 27 |
/** struct env_entry - An entry in the environment hashtable */ struct env_entry { |
84b5e8022 Constify getenv()... |
28 |
const char *key; |
a6826fbc5 Add hash table su... |
29 |
char *data; |
170ab1107 env: Add support ... |
30 31 |
int (*callback)(const char *name, const char *value, enum env_op op, int flags); |
2598090b7 env: Add environm... |
32 |
int flags; |
dd2408cac env: Drop the ENT... |
33 |
}; |
a6826fbc5 Add hash table su... |
34 |
|
a6826fbc5 Add hash table su... |
35 36 37 |
/* * Family of hash table handling functions. The functions also * have reentrant counterparts ending with _r. The non-reentrant |
362664356 search.h: Numerou... |
38 |
* functions all work on a single internal hash table. |
a6826fbc5 Add hash table su... |
39 40 41 42 |
*/ /* Data type for reentrant functions. */ struct hsearch_data { |
25e51e90f env: Drop _ENTRY |
43 |
struct env_entry_node *table; |
a6826fbc5 Add hash table su... |
44 45 |
unsigned int size; unsigned int filled; |
c5983592e env: add check/ap... |
46 47 |
/* * Callback function which will check whether the given change for variable |
cb2ba9db5 env: Drop the dou... |
48 |
* "item" to "newval" may be applied or not, and possibly apply such change. |
c5983592e env: add check/ap... |
49 50 |
* When (flag & H_FORCE) is set, it shall not print out any error message and * shall force overwriting of write-once variables. |
362664356 search.h: Numerou... |
51 |
* Must return 0 for approval, 1 for denial. |
c5983592e env: add check/ap... |
52 |
*/ |
cb2ba9db5 env: Drop the dou... |
53 |
int (*change_ok)(const struct env_entry *item, const char *newval, |
dd2408cac env: Drop the ENT... |
54 |
enum env_op, int flag); |
a6826fbc5 Add hash table su... |
55 |
}; |
cb2ba9db5 env: Drop the dou... |
56 57 |
/* Create a new hash table which will contain at most "nel" elements. */ int hcreate_r(size_t nel, struct hsearch_data *htab); |
a6826fbc5 Add hash table su... |
58 |
|
362664356 search.h: Numerou... |
59 |
/* Destroy current internal hash table. */ |
cb2ba9db5 env: Drop the dou... |
60 |
void hdestroy_r(struct hsearch_data *htab); |
a6826fbc5 Add hash table su... |
61 62 |
/* |
cb2ba9db5 env: Drop the dou... |
63 64 65 66 |
* Search for entry matching item.key in internal hash table. If * action is `ENV_FIND' return found entry or signal error by returning * NULL. If action is `ENV_ENTER' replace existing data (if any) with * item.data. |
a6826fbc5 Add hash table su... |
67 |
* */ |
cb2ba9db5 env: Drop the dou... |
68 69 |
int hsearch_r(struct env_entry item, enum env_action action, struct env_entry **retval, struct hsearch_data *htab, int flag); |
a6826fbc5 Add hash table su... |
70 |
|
560d424b6 env: re-add suppo... |
71 |
/* |
cb2ba9db5 env: Drop the dou... |
72 |
* Search for an entry matching "match". Otherwise, Same semantics |
560d424b6 env: re-add suppo... |
73 74 |
* as hsearch_r(). */ |
cb2ba9db5 env: Drop the dou... |
75 76 |
int hmatch_r(const char *match, int last_idx, struct env_entry **retval, struct hsearch_data *htab); |
560d424b6 env: re-add suppo... |
77 |
|
cb2ba9db5 env: Drop the dou... |
78 79 |
/* Search and delete entry matching "key" in internal hash table. */ int hdelete_r(const char *key, struct hsearch_data *htab, int flag); |
a6826fbc5 Add hash table su... |
80 |
|
cb2ba9db5 env: Drop the dou... |
81 82 |
ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag, char **resp, size_t size, int argc, char * const argv[]); |
a6826fbc5 Add hash table su... |
83 |
|
348b1f1c6 env: make himport... |
84 85 86 87 |
/* * nvars: length of vars array * vars: array of strings (variable names) to import (nvars == 0 means all) */ |
cb2ba9db5 env: Drop the dou... |
88 89 90 |
int himport_r(struct hsearch_data *htab, const char *env, size_t size, const char sep, int flag, int crlf_is_lf, int nvars, char * const vars[]); |
a6826fbc5 Add hash table su... |
91 |
|
170ab1107 env: Add support ... |
92 |
/* Walk the whole table calling the callback on each element */ |
cb2ba9db5 env: Drop the dou... |
93 94 |
int hwalk_r(struct hsearch_data *htab, int (*callback)(struct env_entry *entry)); |
170ab1107 env: Add support ... |
95 |
|
be11235ab env: Hide '.' var... |
96 |
/* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */ |
c4e0057fa env: Refactor do_... |
97 98 99 |
#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 env: Hide '.' var... |
100 |
#define H_HIDE_DOT (1 << 3) /* don't print env vars that begin with '.' */ |
ea009d474 hashtable: prepar... |
101 102 103 104 |
#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 "env grep" - add ... |
105 106 107 |
#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 env: Rename seten... |
108 |
#define H_PROGRAMMATIC (1 << 9) /* indicate that an import is from env_set() */ |
94b467b14 env: Distinguish ... |
109 |
#define H_ORIGIN_FLAGS (H_INTERACTIVE | H_PROGRAMMATIC) |
a6826fbc5 Add hash table su... |
110 |
|
362664356 search.h: Numerou... |
111 |
#endif /* _SEARCH_H_ */ |