summaryrefslogtreecommitdiffstats
path: root/lib/elstring.h
diff options
context:
space:
mode:
authorChris Hall <chris.hall@highwayman.com>2011-02-13 23:11:45 +0000
committerChris Hall <chris.hall@highwayman.com>2011-02-13 23:11:45 +0000
commit5cae7eea451f2b7d65b5892e2c1dafc70f8b836e (patch)
tree0fbd9679e9ae28e7d061b5bdda08756077415ecb /lib/elstring.h
parent64be6d766a65dc0749d17f5023d714678e9c96a6 (diff)
downloadquagga-5cae7eea451f2b7d65b5892e2c1dafc70f8b836e.tar.bz2
quagga-5cae7eea451f2b7d65b5892e2c1dafc70f8b836e.tar.xz
Second tranche of updates for pipework branch.
modified: bgpd/bgp_connection.c modified: bgpd/bgp_debug.c modified: bgpd/bgp_engine.h modified: bgpd/bgp_main.c modified: bgpd/bgp_packet.c modified: bgpd/bgp_peer.c modified: bgpd/bgp_route.c modified: bgpd/bgp_routemap.c modified: bgpd/bgp_session.c modified: bgpd/bgp_vty.c modified: bgpd/bgpd.c modified: bgpd/bgpd.h modified: configure.ac modified: isisd/dict.h modified: isisd/isis_misc.c modified: isisd/isis_routemap.c modified: isisd/isis_spf.c modified: lib/Makefile.am modified: lib/command.c modified: lib/command.h modified: lib/command_execute.h modified: lib/command_parse.c modified: lib/command_parse.h modified: lib/command_queue.c modified: lib/command_queue.h modified: lib/elstring.h modified: lib/heap.c modified: lib/if.c modified: lib/if.h modified: lib/keychain.c modified: lib/keystroke.c modified: lib/keystroke.h modified: lib/list_util.c modified: lib/list_util.h modified: lib/log.c modified: lib/log.h modified: lib/memory.c modified: lib/memory.h modified: lib/memtypes.c modified: lib/misc.h modified: lib/mqueue.c modified: lib/mqueue.h deleted: lib/node_type.h modified: lib/pthread_safe.c modified: lib/qfstring.c modified: lib/qiovec.c modified: lib/qiovec.h modified: lib/qpath.c modified: lib/qpnexus.c modified: lib/qpnexus.h modified: lib/qpselect.c modified: lib/qpthreads.h modified: lib/qstring.c modified: lib/qstring.h modified: lib/qtime.c modified: lib/qtime.h modified: lib/qtimers.c modified: lib/qtimers.h modified: lib/routemap.c modified: lib/symtab.h modified: lib/thread.h deleted: lib/uty.h modified: lib/vector.c modified: lib/vector.h modified: lib/version.h.in modified: lib/vio_fifo.c modified: lib/vio_fifo.h modified: lib/vio_lines.c modified: lib/vio_lines.h modified: lib/vty.c modified: lib/vty.h modified: lib/vty_cli.c modified: lib/vty_cli.h modified: lib/vty_io.c modified: lib/vty_io.h modified: lib/vty_io_basic.c modified: lib/vty_io_basic.h modified: lib/vty_io_file.c modified: lib/vty_io_file.h modified: lib/vty_io_shell.c modified: lib/vty_io_term.c modified: lib/vty_io_term.h modified: lib/vty_local.h modified: lib/vty_pipe.c modified: lib/workqueue.h modified: lib/zebra.h modified: ospf6d/ospf6_lsa.c modified: ripngd/ripngd.c modified: tests/test-list_util.c modified: tests/test-vector.c modified: vtysh/vtysh.c modified: vtysh/vtysh_config.c
Diffstat (limited to 'lib/elstring.h')
-rw-r--r--lib/elstring.h259
1 files changed, 101 insertions, 158 deletions
diff --git a/lib/elstring.h b/lib/elstring.h
index 051e5962..8ab1c58d 100644
--- a/lib/elstring.h
+++ b/lib/elstring.h
@@ -23,8 +23,6 @@
#define _ZEBRA_ELSTRING_H
#include "misc.h"
-#include "zassert.h"
-#include "memory.h"
/*==============================================================================
* This is some very simple support for strings which are Length/Body
@@ -34,8 +32,8 @@
* is the simplest possible encapsulation of strings which are NOT '\0'
* terminated.
*
- *
- *
+ * NB: this object knows NOTHING about whether there is a '\0' beyond the
+ * 'len' of the string.
*/
struct elstring
{
@@ -46,7 +44,6 @@ struct elstring
} body ;
ulen len ;
- bool term ; /* true <=> body is '\0' terminated */
} ;
typedef struct elstring elstring_t[1] ;
@@ -60,15 +57,48 @@ enum
ELSTRING_INIT_ALL_ZEROS = true
} ;
-/*------------------------------------------------------------------------------
- * Various forms of body -- NB:
+/*==============================================================================
+ * Pointer pair and unsigned pointer pair and const versions.
*/
+struct pp
+{
+ char* p ;
+ char* e ;
+} ;
+typedef struct pp pp_t[1] ;
+typedef struct pp* pp ;
-Inline void*
-els_body_nn(elstring els)
+struct cpp
{
- return els->body.v ;
+ const char* p ;
+ const char* e ;
} ;
+typedef struct cpp cpp_t[1] ;
+typedef struct cpp* cpp ;
+
+/*==============================================================================
+ * NULLs for all types of pp and for els
+ */
+Inline void pp_null(pp p) { p->p = p->e = NULL ; } ;
+Inline void cpp_null(cpp p) { p->p = p->e = NULL ; } ;
+
+Inline void els_null(elstring els) { els->body.v = NULL ; els->len = 0 ; } ;
+
+/*==============================================================================
+ * Access functions.
+ */
+
+Inline void* els_body(elstring els) ;
+Inline void* els_body_nn(elstring els) ;
+Inline ulen els_len(elstring els) ;
+Inline ulen els_len_nn(elstring els) ;
+Inline void* els_end(elstring els) ;
+Inline void* els_end_nn(elstring els) ;
+
+Inline void els_pp(pp p, elstring els) ;
+Inline void els_pp_nn(pp p, elstring els) ;
+Inline void els_cpp(cpp p, elstring els) ;
+Inline void els_cpp_nn(cpp p, elstring els) ;
Inline void*
els_body(elstring els)
@@ -76,10 +106,10 @@ els_body(elstring els)
return (els != NULL) ? els_body_nn(els) : NULL ;
} ;
-Inline ulen
-els_len_nn(elstring els)
+Inline void*
+els_body_nn(elstring els)
{
- return els->len ;
+ return els->body.v ;
} ;
Inline ulen
@@ -88,38 +118,70 @@ els_len(elstring els)
return (els != NULL) ? els_len_nn(els) : 0 ;
} ;
-Inline bool
-els_term_nn(elstring els)
+Inline ulen
+els_len_nn(elstring els)
{
- return els->term ;
+ return els->len ;
} ;
-Inline bool
-els_term(elstring els)
+Inline void*
+els_end(elstring els)
{
- return (els != NULL) ? els_term_nn(els) : false ;
+ return (els != NULL) ? els_end_nn(els) : NULL ;
} ;
-/*==============================================================================
- * All so simple that everything is implemented as Inline
- */
+Inline void*
+els_end_nn(elstring els)
+{
+ return (void*)((char*)els->body.v + els->len);
+} ;
-/*------------------------------------------------------------------------------
- * Initialise or create a new elstring
- */
-Inline elstring
-els_init_new(elstring els)
+Inline void
+els_pp(pp p, elstring els)
{
- if (els == NULL)
- els = XCALLOC(MTYPE_TMP, sizeof(elstring_t)) ;
+ if (els != NULL)
+ els_pp_nn(p, els) ;
else
- memset(els, 0, sizeof(elstring_t)) ;
+ pp_null(p) ;
+} ;
- confirm(ELSTRING_INIT_ALL_ZEROS) ;
+Inline void
+els_pp_nn(pp p, elstring els)
+{
+ p->p = els->body.v ;
+ p->e = p->p + els->len ;
+} ;
- return els ;
+Inline void
+els_cpp(cpp p, elstring els)
+{
+ if (els != NULL)
+ els_cpp_nn(p, els) ;
+ else
+ cpp_null(p) ;
+} ;
+
+Inline void
+els_cpp_nn(cpp p, elstring els)
+{
+ p->p = els->body.cv ;
+ p->e = p->p + els->len ;
} ;
+/*==============================================================================
+ * All so simple that most is implemented as Inline
+ */
+
+extern elstring els_init_new(elstring els) ;
+extern elstring els_new(void) ;
+extern elstring els_free(elstring els) ;
+
+extern int els_cmp(elstring a, elstring b) ;
+extern int els_cmp_word(elstring a, const char* w) ;
+extern int els_cmp_sig(elstring a, elstring b) ;
+extern bool els_equal(elstring a, elstring b) ;
+extern bool els_substring(elstring a, elstring b) ;
+
/*------------------------------------------------------------------------------
* Set elstring value from ordinary string.
*
@@ -134,7 +196,6 @@ els_set_nn(elstring els, const void* str)
{
els->body.cv = str ;
els->len = (str != NULL) ? strlen(str) : 0 ;
- els->term = (str != NULL) ;
} ;
/*------------------------------------------------------------------------------
@@ -148,7 +209,7 @@ Inline elstring
els_set(elstring els, const void* str)
{
if (els == NULL)
- els = XCALLOC(MTYPE_TMP, sizeof(elstring_t)) ;
+ els = els_new() ;
els_set_nn(els, str) ;
@@ -169,7 +230,6 @@ els_set_n_nn(elstring els, const void* body, ulen len)
{
els->body.cv = body ;
els->len = len ;
- els->term = false ;
} ;
/*------------------------------------------------------------------------------
@@ -183,7 +243,7 @@ Inline elstring
els_set_n(elstring els, const void* body, ulen len)
{
if (els == NULL)
- els = XCALLOC(MTYPE_TMP, sizeof(elstring_t)) ;
+ els = els_new() ;
els_set_n_nn(els, body, len) ;
@@ -203,31 +263,13 @@ els_clear(elstring els)
{
els->body.v = NULL ;
els->len = 0 ;
- els->term = false ;
} ;
} ;
/*------------------------------------------------------------------------------
- * Release dynamically allocated elstring.
- *
- * Returns NULL.
- *
- * NB: it is the callers responsibility to free the contents of the elstring.
- * if that is required, before freeing the elstring itself.
- */
-Inline elstring
-els_free(elstring els)
-{
- if (els != NULL)
- XFREE(MTYPE_TMP, els) ;
-
- return NULL ;
-} ;
-
-/*------------------------------------------------------------------------------
- * Set elstring length. And set term false.
+ * Set elstring 'len'.
*
- * NB: it is the caller's responsibility to set a valid length !!
+ * NB: it is the caller's responsibility to set a valid body !!
*
* NB: elstring MUST NOT be NULL.
*/
@@ -235,120 +277,21 @@ Inline void
els_set_len_nn(elstring els, ulen len)
{
els->len = len ;
- els->term = false ;
} ;
/*------------------------------------------------------------------------------
- * Set elstring body. And set term false.
+ * Set elstring body.
*
* NB: it is the caller's responsibility to set a valid body !!
*
+ * NB: it is the caller's responsibility to set a valid 'len'.
+ *
* NB: elstring MUST NOT be NULL.
*/
Inline void
els_set_body_nn(elstring els, const void* body)
{
els->body.cv = body ;
- els->term = false ;
-} ;
-
-/*------------------------------------------------------------------------------
- * Set elstring terminated.
- *
- * NB: it is the caller's responsibility to set a valid body !!
- *
- * NB: elstring MUST NOT be NULL.
- */
-Inline void
-els_set_term_nn(elstring els, bool term)
-{
- els->term = term ;
-} ;
-
-/*------------------------------------------------------------------------------
- * Compare two elstrings -- returns the usual -ve, 0, +ve cmp result.
- */
-Inline int
-els_cmp(elstring a, elstring b)
-{
- const uchar* ap ;
- const uchar* bp ;
- ulen al, bl ;
- ulen n ;
-
- ap = els_body(a) ;
- bp = els_body(b) ;
- al = els_len(a) ;
- bl = els_len(b) ;
-
- n = (al <= bl) ? al : bl ;
-
- while (n)
- {
- int d = *ap++ - *bp++ ;
- if (d != 0)
- return d ;
- --n ;
- } ;
-
- return al < bl ? -1 : (al == bl) ? 0 : +1 ;
-} ;
-
-/*------------------------------------------------------------------------------
- * Are two elstrings equal ? -- returns true if strings equal.
- */
-Inline bool
-els_equal(elstring a, elstring b)
-{
- const uchar* ap ;
- const uchar* bp ;
- ulen n ;
-
- n = els_len(b) ;
- if (n != els_len(a))
- return false ;
-
- ap = els_body(a) ;
- bp = els_body(b) ;
-
- while (n)
- {
- if (*ap++ != *bp++)
- return false ;
- --n ;
- } ;
-
- return true ;
-} ;
-
-/*------------------------------------------------------------------------------
- * Is 'b' a leading substring of 'a' ? -- returns true if it is.
- *
- * If 'b' is empty it is always a leading substring.
- */
-Inline int
-els_substring(elstring a, elstring b)
-{
- const uchar* ap ;
- const uchar* bp ;
- ulen n ;
-
- n = els_len(b) ;
- if (n > els_len(a))
- return false ;
-
- ap = els_body(a) ;
- bp = els_body(b) ;
-
- while (n)
- {
- if (*ap++ != *bp++)
- return false ;
- --n ;
- } ;
-
- return true ;
} ;
#endif /* _ZEBRA_ELSTRING_H */
-