Moved map functions from clixon_string to _map, new ptr2ptr map
This commit is contained in:
parent
781c9d9d27
commit
275cefbae7
47 changed files with 366 additions and 180 deletions
|
|
@ -166,6 +166,6 @@ loc:
|
|||
find . -name '*.[chyl]' -type f | xargs wc -l | tail -1 2> /dev/null
|
||||
|
||||
TAGS:
|
||||
find $(srcdir) -not \( -type d \( -path './.git' -o -path './docker' -o -path './doc' \) -prune \) -name '*.[chyl]' -type f | grep -v \.tab\.[ch] | grep -v lex.*.c | grep -v .yy.c | etags -
|
||||
find $(srcdir) -not \( -type d \( -path './.git' -o -path './docker' -o -path './doc' \) -prune \) -name '*.[chyl]' -type f | grep -v \.tab\.[ch] | grep -v lex.*.c | grep -v .yy.c | xargs etags
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ extern "C" {
|
|||
#include <clixon/clixon_netns.h>
|
||||
#include <clixon/clixon_yang_type.h>
|
||||
#include <clixon/clixon_event.h>
|
||||
#include <clixon/clixon_map.h>
|
||||
#include <clixon/clixon_string.h>
|
||||
#include <clixon/clixon_proc.h>
|
||||
#include <clixon/clixon_file.h>
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
struct clicon_hash {
|
||||
qelem_t h_qelem;
|
||||
char *h_key;
|
||||
char *h_key; /* Key must be NULL-terinated string */
|
||||
size_t h_vlen;
|
||||
void *h_val;
|
||||
};
|
||||
|
|
|
|||
88
lib/clixon/clixon_map.h
Normal file
88
lib/clixon/clixon_map.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2017-2019 Olof Hagsand
|
||||
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate)
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
the GNU General Public License Version 3 or later (the "GPL"),
|
||||
in which case the provisions of the GPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of the GPL, and not to allow others to
|
||||
use your version of this file under the terms of Apache License version 2,
|
||||
indicate your decision by deleting the provisions above and replace them with
|
||||
the notice and other provisions required by the GPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the Apache License version 2 or the GPL.
|
||||
|
||||
***** END LICENSE BLOCK *****
|
||||
|
||||
Map between strings and ints
|
||||
*/
|
||||
|
||||
#ifndef _CLIXON_MAP_H_
|
||||
#define _CLIXON_MAP_H_
|
||||
|
||||
/*! Struct used to map between int and strings. Typically used to map between
|
||||
*
|
||||
* values and their names. Note NULL terminated
|
||||
* Example:
|
||||
* @code
|
||||
static const map_str2int atmap[] = {
|
||||
{"One", 1},
|
||||
{"Two", 2},
|
||||
{NULL, -1}
|
||||
};
|
||||
* @endcode
|
||||
* @see clicon_int2str
|
||||
* @see clicon_str2int
|
||||
*/
|
||||
struct map_str2int{
|
||||
char *ms_str;
|
||||
int ms_int;
|
||||
};
|
||||
typedef struct map_str2int map_str2int;
|
||||
|
||||
/*! Struct used to map between two strings.
|
||||
*/
|
||||
struct map_str2str{
|
||||
char *ms_s0;
|
||||
char *ms_s1;
|
||||
};
|
||||
typedef struct map_str2str map_str2str;
|
||||
|
||||
/*! Map from ptr to ptr
|
||||
*/
|
||||
struct map_ptr2ptr{
|
||||
void *mp_p0;
|
||||
void *mp_p1;
|
||||
};
|
||||
typedef struct map_ptr2ptr map_ptr2ptr;
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
const char *clicon_int2str(const map_str2int *mstab, int i);
|
||||
int clicon_str2int(const map_str2int *mstab, char *str);
|
||||
int clicon_str2int_search(const map_str2int *mstab, char *str, int upper);
|
||||
char *clicon_str2str(const map_str2str *mstab, char *str);
|
||||
void *clixon_ptr2ptr(map_ptr2ptr *mptab, void *ptr);
|
||||
int clixon_ptr2ptr_add(map_ptr2ptr **mptab, void *ptr0, void *ptr1);
|
||||
|
||||
#endif /* _CLIXON_MAP_H_ */
|
||||
|
|
@ -38,34 +38,6 @@
|
|||
#ifndef _CLIXON_STRING_H_
|
||||
#define _CLIXON_STRING_H_
|
||||
|
||||
/*! Struct used to map between int and strings. Typically used to map between
|
||||
*
|
||||
* values and their names. Note NULL terminated
|
||||
* Example:
|
||||
* @code
|
||||
static const map_str2int atmap[] = {
|
||||
{"One", 1},
|
||||
{"Two", 2},
|
||||
{NULL, -1}
|
||||
};
|
||||
* @endcode
|
||||
* @see clicon_int2str
|
||||
* @see clicon_str2int
|
||||
*/
|
||||
struct map_str2int{
|
||||
char *ms_str;
|
||||
int ms_int;
|
||||
};
|
||||
typedef struct map_str2int map_str2int;
|
||||
|
||||
/*! Struct used to map between two strings.
|
||||
*/
|
||||
struct map_str2str{
|
||||
char *ms_s0;
|
||||
char *ms_s1;
|
||||
};
|
||||
typedef struct map_str2str map_str2str;
|
||||
|
||||
/*! A malloc version that aligns on 4 bytes. To avoid warning from valgrind */
|
||||
#define align4(s) (((s)/4)*4 + 4)
|
||||
|
||||
|
|
@ -99,11 +71,6 @@ int xml_chardata_encode(char **escp, int quote, const char *fmt, ... ) __attr
|
|||
int xml_chardata_cbuf_append(cbuf *cb, int quote, char *str);
|
||||
int xml_chardata_decode(char **escp, const char *fmt,...);
|
||||
int uri_percent_decode(char *enc, char **str);
|
||||
|
||||
const char *clicon_int2str(const map_str2int *mstab, int i);
|
||||
int clicon_str2int(const map_str2int *mstab, char *str);
|
||||
int clicon_str2int_search(const map_str2int *mstab, char *str, int upper);
|
||||
char *clicon_str2str(const map_str2str *mstab, char *str);
|
||||
int nodeid_split(char *nodeid, char **prefix, char **id);
|
||||
char *clixon_trim(char *str);
|
||||
char *clixon_trim2(char *str, char *trims);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ CPPFLAGS = @CPPFLAGS@
|
|||
INCLUDES = -I. @INCLUDES@ -I$(top_srcdir)/lib/clixon -I$(top_srcdir)/include -I$(top_srcdir)
|
||||
|
||||
SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_debug.c clixon_err.c clixon_event.c \
|
||||
clixon_string.c clixon_regex.c clixon_handle.c clixon_file.c \
|
||||
clixon_string.c clixon_map.c clixon_regex.c clixon_handle.c clixon_file.c \
|
||||
clixon_xml.c clixon_xml_io.c clixon_xml_sort.c clixon_xml_map.c clixon_xml_vec.c \
|
||||
clixon_xml_default.c clixon_xml_bind.c clixon_json.c clixon_proc.c \
|
||||
clixon_yang.c clixon_yang_type.c clixon_yang_module.c clixon_netconf_monitoring.c \
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@
|
|||
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_digest.h"
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ hash_bucket(const char *str)
|
|||
*
|
||||
* @retval hash Pointer to new hash table.
|
||||
* @retval NULL Error
|
||||
* @see hash_free For freeing the hash-table
|
||||
* @see clicon_hash_free For freeing the hash-table
|
||||
*/
|
||||
clicon_hash_t *
|
||||
clicon_hash_init(void)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
235
lib/src/clixon_map.c
Normal file
235
lib/src/clixon_map.c
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2017-2019 Olof Hagsand
|
||||
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate)
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
the GNU General Public License Version 3 or later (the "GPL"),
|
||||
in which case the provisions of the GPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of the GPL, and not to allow others to
|
||||
use your version of this file under the terms of Apache License version 2,
|
||||
indicate your decision by deleting the provisions above and replace them with
|
||||
the notice and other provisions required by the GPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the Apache License version 2 or the GPL.
|
||||
|
||||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "clixon_config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_err.h"
|
||||
|
||||
/*! Map from int to string using str2int map
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] i Input integer
|
||||
* @retval str String value
|
||||
* @retval NULL Error, not found
|
||||
* @note linear search
|
||||
*/
|
||||
const char *
|
||||
clicon_int2str(const map_str2int *mstab,
|
||||
int i)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
|
||||
for (ms = &mstab[0]; ms->ms_str; ms++)
|
||||
if (ms->ms_int == i)
|
||||
return ms->ms_str;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Map from string to int using str2int map
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] str Input string
|
||||
* @retval int Value
|
||||
* @retval -1 Error, not found
|
||||
* @see clicon_str2int_search for optimized lookup, but strings must be sorted
|
||||
*/
|
||||
int
|
||||
clicon_str2int(const map_str2int *mstab,
|
||||
char *str)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
|
||||
for (ms = &mstab[0]; ms->ms_str; ms++)
|
||||
if (strcmp(ms->ms_str, str) == 0)
|
||||
return ms->ms_int;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Map from string to int using binary (alphatical) search
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] str Input string
|
||||
* @param[in] low Lower bound index
|
||||
* @param[in] upper Upper bound index
|
||||
* @param[in] len Length of array (max)
|
||||
* @param[out] found Integer found (can also be negative)
|
||||
* @retval 1 Found with "found" value set.
|
||||
* @retval 0 Not found
|
||||
* @note Assumes sorted strings, tree search
|
||||
*/
|
||||
static int
|
||||
str2int_search1(const map_str2int *mstab,
|
||||
char *str,
|
||||
int low,
|
||||
int upper,
|
||||
int len,
|
||||
int *found)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
int mid;
|
||||
int cmp;
|
||||
|
||||
if (upper < low)
|
||||
return 0; /* not found */
|
||||
mid = (low + upper) / 2;
|
||||
if (mid >= len) /* beyond range */
|
||||
return 0; /* not found */
|
||||
ms = &mstab[mid];
|
||||
if ((cmp = strcmp(str, ms->ms_str)) == 0){
|
||||
*found = ms->ms_int;
|
||||
return 1; /* found */
|
||||
}
|
||||
else if (cmp < 0)
|
||||
return str2int_search1(mstab, str, low, mid-1, len, found);
|
||||
else
|
||||
return str2int_search1(mstab, str, mid+1, upper, len, found);
|
||||
}
|
||||
|
||||
/*! Map from string to int using str2int map
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] str Input string
|
||||
* @retval int Value
|
||||
* @retval -1 Error, not found
|
||||
* @note Assumes sorted strings, tree search
|
||||
* @note -1 can not be value
|
||||
*/
|
||||
int
|
||||
clicon_str2int_search(const map_str2int *mstab,
|
||||
char *str,
|
||||
int len)
|
||||
{
|
||||
int found;
|
||||
|
||||
if (str2int_search1(mstab, str, 0, len, len, &found))
|
||||
return found;
|
||||
return -1; /* not found */
|
||||
}
|
||||
|
||||
/*! Map from string to string using str2str map
|
||||
*
|
||||
* @param[in] mstab String, string map
|
||||
* @param[in] str Input string
|
||||
* @retval str Output string
|
||||
* @retval NULL Error, not found
|
||||
*/
|
||||
char*
|
||||
clicon_str2str(const map_str2str *mstab,
|
||||
char *str)
|
||||
{
|
||||
const struct map_str2str *ms;
|
||||
|
||||
for (ms = &mstab[0]; ms->ms_s0; ms++)
|
||||
if (strcmp(ms->ms_s0, str) == 0)
|
||||
return ms->ms_s1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Map from pointer to pointer using mptab map
|
||||
*
|
||||
* @param[in] mptab Ptr to ptr map
|
||||
* @param[in] ptr Input pointer
|
||||
* @retval ptr Output pointer
|
||||
* @retval NULL Error, not found
|
||||
*/
|
||||
void*
|
||||
clixon_ptr2ptr(map_ptr2ptr *mptab,
|
||||
void *ptr)
|
||||
{
|
||||
struct map_ptr2ptr *mp;
|
||||
|
||||
for (mp = &mptab[0]; mp->mp_p0; mp++)
|
||||
if (mp->mp_p0 == ptr)
|
||||
return mp->mp_p1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Add pointer pairto mptab map
|
||||
*
|
||||
* @param[in] mptab Ptr to ptr map
|
||||
* @param[in] ptr0 Input pointer
|
||||
* @param[in] ptr1 Output pointer
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_ptr2ptr_add(map_ptr2ptr **mptabp,
|
||||
void *ptr0,
|
||||
void *ptr1)
|
||||
{
|
||||
int retval = -1;
|
||||
struct map_ptr2ptr *mp;
|
||||
struct map_ptr2ptr *mptab0;
|
||||
struct map_ptr2ptr *mptab1;
|
||||
int i;
|
||||
|
||||
if (mptabp == NULL) {
|
||||
clixon_err(OE_YANG, EINVAL, "mptabp is NULL");
|
||||
goto done;
|
||||
}
|
||||
mptab0 = *mptabp;
|
||||
for (i=0, mp = &mptab0[0]; mp->mp_p0; mp++, i++);
|
||||
if ((mptab1 = realloc(mptab0, (i+2)*sizeof(*mp))) == NULL){
|
||||
clixon_err(OE_UNIX, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
mptab1[i].mp_p0 = ptr0;
|
||||
mptab1[i++].mp_p1 = ptr1;
|
||||
mptab1[i].mp_p0 = NULL;
|
||||
mptab1[i].mp_p1 = NULL;
|
||||
*mptabp = mptab1;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -57,6 +57,7 @@
|
|||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_json.h"
|
||||
#include "clixon_text_syntax.h"
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@
|
|||
#include "clixon_uid.h"
|
||||
#include "clixon_event.h"
|
||||
#include "clixon_sig.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_netconf_lib.h"
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@
|
|||
#include "clixon_yang_module.h"
|
||||
#include "clixon_plugin.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
#include "clixon_xpath.h"
|
||||
#include "clixon_proto.h"
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
|
|
|
|||
|
|
@ -960,126 +960,6 @@ uri_str2cvec(char *string,
|
|||
goto done;
|
||||
}
|
||||
|
||||
/*! Map from int to string using str2int map
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] i Input integer
|
||||
* @retval str String value
|
||||
* @retval NULL Error, not found
|
||||
* @note linear search
|
||||
*/
|
||||
const char *
|
||||
clicon_int2str(const map_str2int *mstab,
|
||||
int i)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
|
||||
for (ms = &mstab[0]; ms->ms_str; ms++)
|
||||
if (ms->ms_int == i)
|
||||
return ms->ms_str;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Map from string to int using str2int map
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] str Input string
|
||||
* @retval int Value
|
||||
* @retval -1 Error, not found
|
||||
* @see clicon_str2int_search for optimized lookup, but strings must be sorted
|
||||
*/
|
||||
int
|
||||
clicon_str2int(const map_str2int *mstab,
|
||||
char *str)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
|
||||
for (ms = &mstab[0]; ms->ms_str; ms++)
|
||||
if (strcmp(ms->ms_str, str) == 0)
|
||||
return ms->ms_int;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Map from string to int using binary (alphatical) search
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] str Input string
|
||||
* @param[in] low Lower bound index
|
||||
* @param[in] upper Upper bound index
|
||||
* @param[in] len Length of array (max)
|
||||
* @param[out] found Integer found (can also be negative)
|
||||
* @retval 1 Found with "found" value set.
|
||||
* @retval 0 Not found
|
||||
* @note Assumes sorted strings, tree search
|
||||
*/
|
||||
static int
|
||||
str2int_search1(const map_str2int *mstab,
|
||||
char *str,
|
||||
int low,
|
||||
int upper,
|
||||
int len,
|
||||
int *found)
|
||||
{
|
||||
const struct map_str2int *ms;
|
||||
int mid;
|
||||
int cmp;
|
||||
|
||||
if (upper < low)
|
||||
return 0; /* not found */
|
||||
mid = (low + upper) / 2;
|
||||
if (mid >= len) /* beyond range */
|
||||
return 0; /* not found */
|
||||
ms = &mstab[mid];
|
||||
if ((cmp = strcmp(str, ms->ms_str)) == 0){
|
||||
*found = ms->ms_int;
|
||||
return 1; /* found */
|
||||
}
|
||||
else if (cmp < 0)
|
||||
return str2int_search1(mstab, str, low, mid-1, len, found);
|
||||
else
|
||||
return str2int_search1(mstab, str, mid+1, upper, len, found);
|
||||
}
|
||||
|
||||
/*! Map from string to int using str2int map
|
||||
*
|
||||
* @param[in] ms String, integer map
|
||||
* @param[in] str Input string
|
||||
* @retval int Value
|
||||
* @retval -1 Error, not found
|
||||
* @note Assumes sorted strings, tree search
|
||||
* @note -1 can not be value
|
||||
*/
|
||||
int
|
||||
clicon_str2int_search(const map_str2int *mstab,
|
||||
char *str,
|
||||
int len)
|
||||
{
|
||||
int found;
|
||||
|
||||
if (str2int_search1(mstab, str, 0, len, len, &found))
|
||||
return found;
|
||||
return -1; /* not found */
|
||||
}
|
||||
|
||||
/*! Map from string to string using str2str map
|
||||
*
|
||||
* @param[in] mstab String, string map
|
||||
* @param[in] str Input string
|
||||
* @retval str Output string
|
||||
* @retval NULL Error, not found
|
||||
*/
|
||||
char*
|
||||
clicon_str2str(const map_str2str *mstab,
|
||||
char *str)
|
||||
{
|
||||
const struct map_str2str *ms;
|
||||
|
||||
for (ms = &mstab[0]; ms->ms_s0; ms++)
|
||||
if (strcmp(ms->ms_s0, str) == 0)
|
||||
return ms->ms_s1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Split colon-separated node identifier into prefix and name
|
||||
*
|
||||
* @param[in] node-id
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -57,11 +57,11 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_log.h"
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_digest.h"
|
||||
|
|
|
|||
|
|
@ -57,11 +57,11 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_log.h"
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ xml_nsctx_node(cxobj *xn,
|
|||
* Primary use is Yang path statements, eg leafrefs and others
|
||||
* Fully explore all prefix:namespace pairs from context of one node
|
||||
* @param[in] yn Yang statement in module tree (or module itself)
|
||||
* @param[out] ncp XML namespace context
|
||||
* @param[out] ncp XML namespace context (caller frees with cvec_free)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ There are some special lexical rules in https://www.w3.org/TR/xpath-10
|
|||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@
|
|||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
#include "clixon_xpath.h"
|
||||
#include "clixon_xpath_function.h"
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@
|
|||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_map.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue