1 /* $NetBSD: sym_test.c,v 1.6 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: sym_test.c,v 1.28 2007/06/19 23:46:59 tbox Exp */
26 #include <isc/commandline.h>
28 #include <isc/symtab.h>
35 undefine_action(char *key
, unsigned int type
, isc_symvalue_t value
, void *arg
)
40 isc_mem_free(mctx
, key
);
41 isc_mem_free(mctx
, value
.as_pointer
);
45 main(int argc
, char *argv
[]) {
46 char s
[1000], *cp
, *key
;
52 isc_symexists_t exists_policy
= isc_symexists_reject
;
53 isc_boolean_t case_sensitive
= ISC_FALSE
;
55 while ((c
= isc_commandline_parse(argc
, argv
, "tarc")) != -1) {
61 exists_policy
= isc_symexists_add
;
64 exists_policy
= isc_symexists_replace
;
67 case_sensitive
= ISC_TRUE
;
72 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx
) == ISC_R_SUCCESS
);
73 RUNTIME_CHECK(isc_symtab_create(mctx
, 691, undefine_action
, NULL
,
74 case_sensitive
, &st
) == ISC_R_SUCCESS
);
76 while (fgets(s
, sizeof(s
), stdin
) != NULL
) {
78 if (len
> 0U && s
[len
- 1] == '\n') {
87 result
= isc_symtab_undefine(st
, cp
, 1);
88 if (trace
|| result
!= ISC_R_SUCCESS
)
89 printf("undefine('%s'): %s\n", cp
,
90 isc_result_totext(result
));
93 while (*cp
!= '\0' && *cp
!= ' ' && *cp
!= '\t')
96 result
= isc_symtab_lookup(st
, key
, 0, &value
);
97 if (trace
|| result
!= ISC_R_SUCCESS
) {
98 printf("lookup('%s'): %s", key
,
99 isc_result_totext(result
));
100 if (result
== ISC_R_SUCCESS
) {
101 cp
= value
.as_pointer
;
102 printf(", value == '%s'", cp
);
108 key
= isc_mem_strdup(mctx
, key
);
109 value
.as_pointer
= isc_mem_strdup(mctx
, cp
);
110 result
= isc_symtab_define(st
, key
, 1, value
,
112 if (trace
|| result
!= ISC_R_SUCCESS
) {
113 printf("define('%s', '%s'): %s\n",
115 isc_result_totext(result
));
116 if (result
!= ISC_R_SUCCESS
)
117 undefine_action(key
, 1,
124 isc_symtab_destroy(&st
);
125 isc_mem_stats(mctx
, stdout
);
126 isc_mem_destroy(&mctx
);