Reformat and normalize licenses and headerss

This commit is purely aestetic/taste, nothing important.

I don't really like this *huge* license at the top of every file
but I guess it must stay so add it to some files where it wasn't
included so they are the same. Slightly reformat them.

Unindent extra indentation found in some headers.

Strip trailing whitespace in files and enabled setting in
editor, which caused a lot of noise in this commit but that should
be the end of it.

Remove the comment at the top of each file that said who created
it and when (it will remain in VCS history for reference and was
always Don who created the files).
This commit is contained in:
Matthew Brush 2013-03-04 15:38:21 -08:00
parent eb89c4bf8e
commit 01d2b274b7
16 changed files with 1036 additions and 983 deletions

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-07-09 21:44:59 /*
* Authors: Don * cfu.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cfu.h" #include "cfu.h"
struct libcfu_item { struct libcfu_item {

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-07-06 07:34:51 /*
* Authors: Don * cfu.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LIBCFU_H_ #ifndef _LIBCFU_H_
#define _LIBCFU_H_ #define _LIBCFU_H_

View File

@ -1,44 +1,40 @@
/* Creation date: 2005-07-08 22:23:31 /*
* Authors: Don * cfuconf.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cfu.h" #include "cfu.h"
#include "cfuconf.h" #include "cfuconf.h"
@ -68,7 +64,7 @@ cfuconf_new() {
conf->type = libcfu_t_conf; conf->type = libcfu_t_conf;
conf->containers = cfuhash_new_with_flags(CFUHASH_IGNORE_CASE); conf->containers = cfuhash_new_with_flags(CFUHASH_IGNORE_CASE);
conf->directives = cfuhash_new_with_flags(CFUHASH_IGNORE_CASE); conf->directives = cfuhash_new_with_flags(CFUHASH_IGNORE_CASE);
return conf; return conf;
} }
@ -106,7 +102,7 @@ _directive_free_val_list_fn(void *data) {
cfulist_t *val_list = (cfulist_t *)data; cfulist_t *val_list = (cfulist_t *)data;
assert(cfu_is_list(val_list)); assert(cfu_is_list(val_list));
cfulist_destroy_with_free_fn(val_list, _free_val_fn); cfulist_destroy_with_free_fn(val_list, _free_val_fn);
} }
static void static void
@ -153,7 +149,7 @@ _get_directive_last_val_list(cfuconf_t *conf, char *directive, cfulist_t **val_l
if (!conf) { if (!conf) {
return -1; return -1;
} }
directives = cfuconf_get_directives(conf); directives = cfuconf_get_directives(conf);
if (!directives) { if (!directives) {
return -1; return -1;
@ -168,7 +164,7 @@ _get_directive_last_val_list(cfuconf_t *conf, char *directive, cfulist_t **val_l
return 0; return 0;
} }
} }
return -1; return -1;
} }
@ -186,7 +182,7 @@ cfuconf_get_directive_one_arg(cfuconf_t *conf, char *directive, char **rvalue) {
} else { } else {
return -1; return -1;
} }
return -1; return -1;
} }
@ -218,9 +214,9 @@ cfuconf_get_directive_n_args(cfuconf_t *conf, char *directive, size_t n, ...) {
} }
} }
va_end(ap); va_end(ap);
if (i == n) rv = 0; if (i == n) rv = 0;
} }
return rv; return rv;
@ -261,7 +257,7 @@ static cfulist_t *
_slurp_file_from_fp(FILE *fp) { _slurp_file_from_fp(FILE *fp) {
cfulist_t *lines = cfulist_new(); cfulist_t *lines = cfulist_new();
char *buf = NULL; char *buf = NULL;
while ( (buf = cfuconf_get_line(fp)) ) { while ( (buf = cfuconf_get_line(fp)) ) {
cfulist_push(lines, buf); cfulist_push(lines, buf);
} }
@ -302,7 +298,7 @@ _get_name(char **buf) {
while (*ptr && *ptr != '>' && !_is_whitespace(*ptr)) ptr++; while (*ptr && *ptr != '>' && !_is_whitespace(*ptr)) ptr++;
name = cfustring_dup_c_str_n(name, ptr - name); name = cfustring_dup_c_str_n(name, ptr - name);
*buf = ptr; *buf = ptr;
return name; return name;
} }
@ -320,7 +316,7 @@ _get_value(char **buf) {
while (*ptr && *ptr != '>' && !_is_whitespace(*ptr)) ptr++; while (*ptr && *ptr != '>' && !_is_whitespace(*ptr)) ptr++;
value = cfustring_dup_c_str_n(value, ptr - value); value = cfustring_dup_c_str_n(value, ptr - value);
*buf = ptr; *buf = ptr;
return value; return value;
} }
@ -332,7 +328,7 @@ _dup_c_str_n_drop_escape(const char *str, size_t n, char escape) {
char *ns_ptr = NULL; char *ns_ptr = NULL;
char last_char = '\000'; char last_char = '\000';
char *end = (char *)str + n; char *end = (char *)str + n;
if (n == 0) return NULL; if (n == 0) return NULL;
ptr = (char *)str; ptr = (char *)str;
@ -388,7 +384,7 @@ _get_quoted_value(char **buf, char quote) {
} }
if (!*ptr) return NULL; if (!*ptr) return NULL;
*buf = ptr; *buf = ptr;
if (found_escape) { if (found_escape) {
value = _dup_c_str_n_drop_escape(value, ptr - value, '\\'); value = _dup_c_str_n_drop_escape(value, ptr - value, '\\');
} else { } else {
@ -418,7 +414,7 @@ _get_next_value(char **buf) {
} }
*buf = ptr; *buf = ptr;
return value; return value;
} }
@ -439,7 +435,7 @@ _get_long_value(char **buf) {
value = cfustring_dup_c_str_n(value, ptr - value - 1); value = cfustring_dup_c_str_n(value, ptr - value - 1);
*buf = ptr; *buf = ptr;
return value; return value;
} }
#endif #endif
@ -469,7 +465,7 @@ _cfuconf_parse_list(cfulist_t *lines, char **error) {
free(line); free(line);
continue; continue;
} }
if (*ptr == '<') { /* opening or closing container tag */ if (*ptr == '<') { /* opening or closing container tag */
ptr++; ptr++;
if (*ptr == '/') { if (*ptr == '/') {
@ -536,7 +532,7 @@ _cfuconf_parse_list(cfulist_t *lines, char **error) {
this_hash = cfuhash_new_with_flags(CFUHASH_IGNORE_CASE); this_hash = cfuhash_new_with_flags(CFUHASH_IGNORE_CASE);
cfuhash_put(cur_conf->containers, name, (void *)this_hash); cfuhash_put(cur_conf->containers, name, (void *)this_hash);
} }
if ( !(new_conf = cfuhash_get(this_hash, value)) ) { if ( !(new_conf = cfuhash_get(this_hash, value)) ) {
new_conf = cfuconf_new(); new_conf = cfuconf_new();
new_conf->container_type = name; new_conf->container_type = name;
@ -546,7 +542,7 @@ _cfuconf_parse_list(cfulist_t *lines, char **error) {
free(name); name = NULL; free(name); name = NULL;
free(value); value = NULL; free(value); value = NULL;
} }
cfulist_push(stack, (void *)cur_conf); cfulist_push(stack, (void *)cur_conf);
cur_conf = new_conf; cur_conf = new_conf;
@ -568,10 +564,10 @@ _cfuconf_parse_list(cfulist_t *lines, char **error) {
cfuhash_put(cur_conf->directives, name, (void *)list); cfuhash_put(cur_conf->directives, name, (void *)list);
} }
free(name); name = NULL; free(name); name = NULL;
val_list = cfulist_new(); val_list = cfulist_new();
cfulist_enqueue(list, (void *)val_list); cfulist_enqueue(list, (void *)val_list);
/* fprintf(stderr, "====> got '%s' =>", name); */ /* fprintf(stderr, "====> got '%s' =>", name); */
while ( (value = _get_next_value(&ptr) ) ) { while ( (value = _get_next_value(&ptr) ) ) {
/* fprintf(stderr, " '%s'", value); */ /* fprintf(stderr, " '%s'", value); */
@ -608,7 +604,7 @@ cfuconf_parse_file(char *file_path, cfuconf_t **ret_conf, char **error) {
lines = _slurp_file_from_fp(fp); lines = _slurp_file_from_fp(fp);
fclose(fp); fp = NULL; fclose(fp); fp = NULL;
if (!lines) return -1; if (!lines) return -1;
conf = _cfuconf_parse_list(lines, error); conf = _cfuconf_parse_list(lines, error);
cfulist_destroy(lines); cfulist_destroy(lines);
*ret_conf = conf; *ret_conf = conf;
@ -628,11 +624,11 @@ cfuconf_parse_buffer(char *buffer, cfuconf_t **ret_conf, char **error) {
strings = cfustring_c_str_split(buffer, &num_strings, 0, "\r\n", "\n", NULL); strings = cfustring_c_str_split(buffer, &num_strings, 0, "\r\n", "\n", NULL);
if (!strings) return -1; if (!strings) return -1;
for (i = 0; i < num_strings; i++) { for (i = 0; i < num_strings; i++) {
cfulist_push_string(lines, strings[i]); cfulist_push_string(lines, strings[i]);
} }
conf = _cfuconf_parse_list(lines, error); conf = _cfuconf_parse_list(lines, error);
cfulist_destroy(lines); cfulist_destroy(lines);
*ret_conf = conf; *ret_conf = conf;
@ -640,7 +636,7 @@ cfuconf_parse_buffer(char *buffer, cfuconf_t **ret_conf, char **error) {
free(strings); free(strings);
if (conf) return 0; if (conf) return 0;
return -1; return -1;
} }
@ -699,7 +695,7 @@ print_container(cfuhash_table_t *conf_hash, size_t depth) {
container = cfuhash_get(ht, container_name); container = cfuhash_get(ht, container_name);
print_container(container, depth + 1); print_container(container, depth + 1);
} }
free(container_names); free(container_names);
} }
free(keys[i]); free(keys[i]);
@ -752,7 +748,7 @@ print_directive_list_foreach_fn(void *data, size_t data_size, void *arg) {
cfulist_t *val_list = (cfulist_t *)data; cfulist_t *val_list = (cfulist_t *)data;
directive_foreach_ds *ds = (directive_foreach_ds *)arg; directive_foreach_ds *ds = (directive_foreach_ds *)arg;
char *str = NULL; char *str = NULL;
data_size = data_size; data_size = data_size;
if (!val_list) return 0; if (!val_list) return 0;
assert(cfu_is_list(val_list)); assert(cfu_is_list(val_list));
@ -771,14 +767,14 @@ print_conf_foreach_directive(void *name, size_t key_size, void *data, size_t dat
key_size = key_size; key_size = key_size;
data_size = data_size; data_size = data_size;
new_ds->fp = ds->fp; new_ds->fp = ds->fp;
new_ds->depth = ds->depth; new_ds->depth = ds->depth;
new_ds->name = name; new_ds->name = name;
assert(cfu_is_list(this_directive_list)); assert(cfu_is_list(this_directive_list));
cfulist_foreach(this_directive_list, print_directive_list_foreach_fn, new_ds); cfulist_foreach(this_directive_list, print_directive_list_foreach_fn, new_ds);
free(new_ds); free(new_ds);
return 0; return 0;
} }

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-07-08 22:24:03 /*
* Authors: Don * cfuconf.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CFU_CONF_H_ #ifndef _CFU_CONF_H_
#define _CFU_CONF_H_ #define _CFU_CONF_H_
@ -48,72 +45,72 @@
CFU_BEGIN_DECLS CFU_BEGIN_DECLS
struct cfuconf; struct cfuconf;
typedef struct cfuconf cfuconf_t; typedef struct cfuconf cfuconf_t;
/* Apache-style conf files contain directives and containers.
Directives are simple one line specifications with or without
arguments, e.g.,
Doit /* Apache-style conf files contain directives and containers.
Expires On Directives are simple one line specifications with or without
LoadModule my_mod modules/my_mod.so arguments, e.g.,
Containers have a type and a name associated with them and they Doit
in turn contain directives and/or containers, e.g., Expires On
LoadModule my_mod modules/my_mod.so
<MyContainer test1> Containers have a type and a name associated with them and they
Expires Off in turn contain directives and/or containers, e.g.,
<DB devdb>
DBHost db.example.com
DBUser test_user
</DB>
</MyContainer>
Values may be quoted, e.g. <MyContainer test1>
Expires Off
<DB devdb>
DBHost db.example.com
DBUser test_user
</DB>
</MyContainer>
DBUser "test user" Values may be quoted, e.g.
But must be specified on a single line. To escape quotes DBUser "test user"
within a quoted string, use the '\' character.
*/ But must be specified on a single line. To escape quotes
within a quoted string, use the '\' character.
/* Parse the apache-like conf file specified by file_path, */
* returning a pointer to a cfuconf_t structure in conf. Returns
* zero on success, less than zero on error. If an error occurs
* and error is not NULL, it will be set to an error message
* (which must be free()'d by the caller).
*/
extern int cfuconf_parse_file(char *file_path, cfuconf_t **conf, char **error);
/* Same as cfuconf_parse_file(), except assume the contents of the
* file are already in buffer.
*/
extern int cfuconf_parse_buffer(char *buffer, cfuconf_t **conf, char **error);
/* Free all resources used by the cfuconf_t structure */ /* Parse the apache-like conf file specified by file_path,
extern void cfuconf_destroy(cfuconf_t *conf); * returning a pointer to a cfuconf_t structure in conf. Returns
* zero on success, less than zero on error. If an error occurs
* and error is not NULL, it will be set to an error message
* (which must be free()'d by the caller).
*/
extern int cfuconf_parse_file(char *file_path, cfuconf_t **conf, char **error);
/* Get a hash of containers at the top level of conf */ /* Same as cfuconf_parse_file(), except assume the contents of the
extern cfuhash_table_t * cfuconf_get_containers(cfuconf_t *conf); * file are already in buffer.
*/
extern int cfuconf_parse_buffer(char *buffer, cfuconf_t **conf, char **error);
/* Get a hash of directives at the to level */ /* Free all resources used by the cfuconf_t structure */
extern cfuhash_table_t * cfuconf_get_directives(cfuconf_t *conf); extern void cfuconf_destroy(cfuconf_t *conf);
/* Get the value of the given directive, assuming there is only one argument */ /* Get a hash of containers at the top level of conf */
extern int cfuconf_get_directive_one_arg(cfuconf_t *conf, char *directive, char **rvalue); extern cfuhash_table_t * cfuconf_get_containers(cfuconf_t *conf);
/* Get the value of the given directive, assuming there are two arguments */ /* Get a hash of directives at the to level */
extern int cfuconf_get_directive_two_args(cfuconf_t *conf, char *directive, char **rvalue, extern cfuhash_table_t * cfuconf_get_directives(cfuconf_t *conf);
char **rvalue2);
/* Get the value of the given directives, with n arguments */ /* Get the value of the given directive, assuming there is only one argument */
extern int cfuconf_get_directive_n_args(cfuconf_t *conf, char *directive, size_t n, ...); extern int cfuconf_get_directive_one_arg(cfuconf_t *conf, char *directive, char **rvalue);
/* Print out a representation of the parsed configuration */ /* Get the value of the given directive, assuming there are two arguments */
extern void cfuconf_pretty_print_conf(cfuconf_t *conf, FILE *fp, size_t indent_level); extern int cfuconf_get_directive_two_args(cfuconf_t *conf, char *directive, char **rvalue,
char **rvalue2);
/* Get the value of the given directives, with n arguments */
extern int cfuconf_get_directive_n_args(cfuconf_t *conf, char *directive, size_t n, ...);
/* Print out a representation of the parsed configuration */
extern void cfuconf_pretty_print_conf(cfuconf_t *conf, FILE *fp, size_t indent_level);
CFU_END_DECLS CFU_END_DECLS

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-06-24 21:22:40 /*
* Authors: Don * cfuhash.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
@ -155,7 +152,7 @@ hash_value(cfuhash_table_t *ht, const void *key, size_t key_size, size_t num_buc
static cfuhash_table_t * static cfuhash_table_t *
_cfuhash_new(size_t size, u_int32_t flags) { _cfuhash_new(size_t size, u_int32_t flags) {
cfuhash_table_t *ht; cfuhash_table_t *ht;
size = hash_size(size); size = hash_size(size);
ht = (cfuhash_table_t *)malloc(sizeof(cfuhash_table_t)); ht = (cfuhash_table_t *)malloc(sizeof(cfuhash_table_t));
memset(ht, '\000', sizeof(cfuhash_table_t)); memset(ht, '\000', sizeof(cfuhash_table_t));
@ -169,11 +166,11 @@ _cfuhash_new(size_t size, u_int32_t flags) {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
pthread_mutex_init(&ht->mutex, NULL); pthread_mutex_init(&ht->mutex, NULL);
#endif #endif
ht->hash_func = hash_func; ht->hash_func = hash_func;
ht->high = 0.75; ht->high = 0.75;
ht->low = 0.25; ht->low = 0.25;
return ht; return ht;
} }
@ -231,7 +228,7 @@ cfuhash_merge(cfuhash_table_t *ht1, cfuhash_table_t *ht2, u_int32_t flags) {
new_ht = _cfuhash_new(cfuhash_num_entries(ht1) + cfuhash_num_entries(ht2), flags); new_ht = _cfuhash_new(cfuhash_num_entries(ht1) + cfuhash_num_entries(ht2), flags);
if (ht1) cfuhash_copy(ht1, new_ht); if (ht1) cfuhash_copy(ht1, new_ht);
if (ht2) cfuhash_copy(ht2, new_ht); if (ht2) cfuhash_copy(ht2, new_ht);
return new_ht; return new_ht;
} }
@ -274,7 +271,7 @@ extern int
cfuhash_set_hash_function(cfuhash_table_t *ht, cfuhash_function_t hf) { cfuhash_set_hash_function(cfuhash_table_t *ht, cfuhash_function_t hf) {
/* can't allow changing the hash function if the hash already contains entries */ /* can't allow changing the hash function if the hash already contains entries */
if (ht->entries) return -1; if (ht->entries) return -1;
ht->hash_func = hf ? hf : hash_func; ht->hash_func = hf ? hf : hash_func;
return 0; return 0;
} }
@ -368,7 +365,7 @@ cfuhash_get_data(cfuhash_table_t *ht, const void *key, size_t key_size, void **r
if (key_size == (size_t)(-1)) { if (key_size == (size_t)(-1)) {
if (key) key_size = strlen(key) + 1; if (key) key_size = strlen(key) + 1;
else key_size = 0; else key_size = 0;
} }
lock_hash(ht); lock_hash(ht);
@ -386,7 +383,7 @@ cfuhash_get_data(cfuhash_table_t *ht, const void *key, size_t key_size, void **r
} }
unlock_hash(ht); unlock_hash(ht);
return (hr ? 1 : 0); return (hr ? 1 : 0);
} }
@ -397,7 +394,7 @@ extern void *
cfuhash_get(cfuhash_table_t *ht, const char *key) { cfuhash_get(cfuhash_table_t *ht, const char *key) {
void *r = NULL; void *r = NULL;
int rv = 0; int rv = 0;
rv = cfuhash_get_data(ht, (const void *)key, -1, &r, NULL); rv = cfuhash_get_data(ht, (const void *)key, -1, &r, NULL);
if (rv) return r; /* found */ if (rv) return r; /* found */
return NULL; return NULL;
@ -430,7 +427,7 @@ cfuhash_put_data(cfuhash_table_t *ht, const void *key, size_t key_size, void *da
u_int hv = 0; u_int hv = 0;
cfuhash_entry *he = NULL; cfuhash_entry *he = NULL;
int added_an_entry = 0; int added_an_entry = 0;
if (key_size == (size_t)(-1)) { if (key_size == (size_t)(-1)) {
if (key) key_size = strlen(key) + 1; if (key) key_size = strlen(key) + 1;
else key_size = 0; else key_size = 0;
@ -438,7 +435,7 @@ cfuhash_put_data(cfuhash_table_t *ht, const void *key, size_t key_size, void *da
if (data_size == (size_t)(-1)) { if (data_size == (size_t)(-1)) {
if (data) data_size = strlen(data) + 1; if (data) data_size = strlen(data) + 1;
else data_size = 0; else data_size = 0;
} }
lock_hash(ht); lock_hash(ht);
@ -461,7 +458,7 @@ cfuhash_put_data(cfuhash_table_t *ht, const void *key, size_t key_size, void *da
added_an_entry = 1; added_an_entry = 1;
} }
unlock_hash(ht); unlock_hash(ht);
if (added_an_entry && !(ht->flags & CFUHASH_FROZEN)) { if (added_an_entry && !(ht->flags & CFUHASH_FROZEN)) {
if ( (float)ht->entries/(float)ht->num_buckets > ht->high ) cfuhash_rehash(ht); if ( (float)ht->entries/(float)ht->num_buckets > ht->high ) cfuhash_rehash(ht);
@ -579,7 +576,7 @@ cfuhash_keys_data(cfuhash_table_t *ht, size_t *num_keys, size_t **key_sizes, int
if (key_sizes) key_lengths = (size_t *)calloc(ht->entries, sizeof(size_t)); if (key_sizes) key_lengths = (size_t *)calloc(ht->entries, sizeof(size_t));
keys = (void **)calloc(ht->entries, sizeof(void *)); keys = (void **)calloc(ht->entries, sizeof(void *));
for (bucket = 0; bucket < ht->num_buckets; bucket++) { for (bucket = 0; bucket < ht->num_buckets; bucket++) {
if ( (he = ht->buckets[bucket]) ) { if ( (he = ht->buckets[bucket]) ) {
for (; he; he = he->next, entry_index++) { for (; he; he = he->next, entry_index++) {
@ -624,7 +621,7 @@ cfuhash_each_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data
extern int extern int
cfuhash_next_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data, cfuhash_next_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data,
size_t *data_size) { size_t *data_size) {
if (ht->each_chain_entry && ht->each_chain_entry->next) { if (ht->each_chain_entry && ht->each_chain_entry->next) {
ht->each_chain_entry = ht->each_chain_entry->next; ht->each_chain_entry = ht->each_chain_entry->next;
} else { } else {
@ -672,7 +669,7 @@ cfuhash_foreach_remove(cfuhash_table_t *ht, cfuhash_remove_fn_t r_fn, cfuhash_fr
size_t num_removed = 0; size_t num_removed = 0;
cfuhash_entry **buckets = NULL; cfuhash_entry **buckets = NULL;
size_t num_buckets = 0; size_t num_buckets = 0;
if (!ht) return 0; if (!ht) return 0;
lock_hash(ht); lock_hash(ht);
@ -716,7 +713,7 @@ cfuhash_foreach(cfuhash_table_t *ht, cfuhash_foreach_fn_t fe_fn, void *arg) {
cfuhash_entry **buckets = NULL; cfuhash_entry **buckets = NULL;
size_t num_buckets = 0; size_t num_buckets = 0;
int rv = 0; int rv = 0;
if (!ht) return 0; if (!ht) return 0;
lock_hash(ht); lock_hash(ht);
@ -803,7 +800,7 @@ cfuhash_pretty_print(cfuhash_table_t *ht, FILE *fp) {
parg.count = 0; parg.count = 0;
rv += fprintf(fp, "{\n"); rv += fprintf(fp, "{\n");
cfuhash_foreach(ht, _pretty_print_foreach, (void *)&parg); cfuhash_foreach(ht, _pretty_print_foreach, (void *)&parg);
rv += parg.count; rv += parg.count;

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-06-24 21:22:09 /*
* Authors: Don * cfuhash.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CFU_HASH_H_ #ifndef _CFU_HASH_H_
#define _CFU_HASH_H_ #define _CFU_HASH_H_
@ -47,215 +44,215 @@
CFU_BEGIN_DECLS CFU_BEGIN_DECLS
/* The hash table itself. */ /* The hash table itself. */
struct cfuhash_table; struct cfuhash_table;
typedef struct cfuhash_table cfuhash_table_t; typedef struct cfuhash_table cfuhash_table_t;
/* Prototype for a pointer to a hashing function. */ /* Prototype for a pointer to a hashing function. */
typedef u_int32_t (*cfuhash_function_t)(const void *key, size_t length); typedef u_int32_t (*cfuhash_function_t)(const void *key, size_t length);
/* Prototype for a pointer to a free function. */
typedef void (*cfuhash_free_fn_t)(void *data);
/* Prototype for a pointer to a function that determines whether
* or not to remove an entry from the hash.
*/
typedef int (*cfuhash_remove_fn_t)(void *key, size_t key_size, void *data, size_t data_size,
void *arg);
/* Prototype for a pointer to a function to be called foreach /* Prototype for a pointer to a free function. */
* key/value pair in the hash by cfuhash_foreach(). Iteration typedef void (*cfuhash_free_fn_t)(void *data);
* stops if a non-zero value is returned.
*/
typedef int (*cfuhash_foreach_fn_t)(void *key, size_t key_size, void *data, size_t data_size,
void *arg);
/* Creates a new hash table. */
extern cfuhash_table_t * cfuhash_new();
/* Creates a new hash table with the specified size (number of /* Prototype for a pointer to a function that determines whether
* buckets). * or not to remove an entry from the hash.
*/ */
extern cfuhash_table_t * cfuhash_new_with_initial_size(size_t size); typedef int (*cfuhash_remove_fn_t)(void *key, size_t key_size, void *data, size_t data_size,
void *arg);
/* Creates a new hash table with the specified flags. Pass zero /* Prototype for a pointer to a function to be called foreach
* for flags if you want the defaults. * key/value pair in the hash by cfuhash_foreach(). Iteration
*/ * stops if a non-zero value is returned.
extern cfuhash_table_t * cfuhash_new_with_flags(u_int32_t flags); */
typedef int (*cfuhash_foreach_fn_t)(void *key, size_t key_size, void *data, size_t data_size,
/* Same as cfuhash_new() except automatically calls cfuhash_set_free_fn(). */ void *arg);
extern cfuhash_table_t * cfuhash_new_with_free_fn(cfuhash_free_fn_t ff);
/* Copies entries in src to dst */ /* Creates a new hash table. */
extern int cfuhash_copy(cfuhash_table_t *src, cfuhash_table_t *dst); extern cfuhash_table_t * cfuhash_new();
/* Returns a new hash containing entries from both hash tables. /* Creates a new hash table with the specified size (number of
* For any entries with the same key, the one from ht2 wins. * buckets).
*/ */
extern cfuhash_table_t * cfuhash_merge(cfuhash_table_t *ht1, cfuhash_table_t *ht2, extern cfuhash_table_t * cfuhash_new_with_initial_size(size_t size);
u_int32_t flags);
/* Sets the hashing function to use when computing which bucket to add /* Creates a new hash table with the specified flags. Pass zero
* entries to. It should return a 32-bit unsigned integer. By * for flags if you want the defaults.
* default, Perl's hashing algorithm is used. */
*/ extern cfuhash_table_t * cfuhash_new_with_flags(u_int32_t flags);
extern int cfuhash_set_hash_function(cfuhash_table_t *ht, cfuhash_function_t hf);
/* Sets the thresholds for when to rehash. The ratio /* Same as cfuhash_new() except automatically calls cfuhash_set_free_fn(). */
* num_entries/buckets is compared against low and high. If it is extern cfuhash_table_t * cfuhash_new_with_free_fn(cfuhash_free_fn_t ff);
* below 'low' or above 'high', the hash will shrink or grow,
* respectively, unless the flags say to do otherwise.
*/
extern int cfuhash_set_thresholds(cfuhash_table_t *ht, float low, float high);
/* Sets the function to use when removing an entry from the hash, /* Copies entries in src to dst */
* i.e., when replacing an existing entry, deleting an entry, or extern int cfuhash_copy(cfuhash_table_t *src, cfuhash_table_t *dst);
* clearing the hash. It is passed the value of the entry as a
* void *.
*/
extern int cfuhash_set_free_function(cfuhash_table_t * ht, cfuhash_free_fn_t ff);
/* Returns the hash's flags. See below for flag definitions. */ /* Returns a new hash containing entries from both hash tables.
extern u_int32_t cfuhash_get_flags(cfuhash_table_t *ht); * For any entries with the same key, the one from ht2 wins.
*/
extern cfuhash_table_t * cfuhash_merge(cfuhash_table_t *ht1, cfuhash_table_t *ht2,
u_int32_t flags);
/* Sets a flag. */ /* Sets the hashing function to use when computing which bucket to add
extern u_int32_t cfuhash_set_flag(cfuhash_table_t *ht, u_int32_t flag); * entries to. It should return a 32-bit unsigned integer. By
* default, Perl's hashing algorithm is used.
*/
extern int cfuhash_set_hash_function(cfuhash_table_t *ht, cfuhash_function_t hf);
/* Clears a flag. */ /* Sets the thresholds for when to rehash. The ratio
extern u_int32_t cfuhash_clear_flag(cfuhash_table_t *ht, u_int32_t new_flag); * num_entries/buckets is compared against low and high. If it is
* below 'low' or above 'high', the hash will shrink or grow,
* respectively, unless the flags say to do otherwise.
*/
extern int cfuhash_set_thresholds(cfuhash_table_t *ht, float low, float high);
/* Returns the value for the entry with given key. If key_size is -1, /* Sets the function to use when removing an entry from the hash,
* key is assumed to be a null-terminated string. If data_size is not * i.e., when replacing an existing entry, deleting an entry, or
* NULL, the size of the value is placed into data_size. * clearing the hash. It is passed the value of the entry as a
*/ * void *.
extern int cfuhash_get_data(cfuhash_table_t *ht, const void *key, size_t key_size, */
void **data, size_t *data_size); extern int cfuhash_set_free_function(cfuhash_table_t * ht, cfuhash_free_fn_t ff);
/* Returns 1 if an entry with the given key exists in the hash, 0 otherwise. */ /* Returns the hash's flags. See below for flag definitions. */
extern int cfuhash_exists_data(cfuhash_table_t *ht, const void *key, size_t key_size); extern u_int32_t cfuhash_get_flags(cfuhash_table_t *ht);
/* Inserts the given data value into the hash and associates it with /* Sets a flag. */
* key. If key_size is -1, key is assumed to be a null-terminated extern u_int32_t cfuhash_set_flag(cfuhash_table_t *ht, u_int32_t flag);
* string. If data_size is -1, it is assumed to be a null-terminated
* string (it's length will be calculated using strlen). If
* data_size is zero, it will be returned as zero when the value is
* requested.
*/
extern int cfuhash_put_data(cfuhash_table_t *ht, const void *key, size_t key_size, void *data,
size_t data_size, void **r);
/* Clears the hash table (deletes all entries). */ /* Clears a flag. */
extern void cfuhash_clear(cfuhash_table_t *ht); extern u_int32_t cfuhash_clear_flag(cfuhash_table_t *ht, u_int32_t new_flag);
/* Deletes the entry in the hash associated with key. If the entry /* Returns the value for the entry with given key. If key_size is -1,
* existed, it's value will be returned. * key is assumed to be a null-terminated string. If data_size is not
*/ * NULL, the size of the value is placed into data_size.
extern void * cfuhash_delete_data(cfuhash_table_t *ht, const void *key, size_t key_size); */
extern int cfuhash_get_data(cfuhash_table_t *ht, const void *key, size_t key_size,
void **data, size_t *data_size);
/* Returns all the keys from the hash. The number of keys is placed /* Returns 1 if an entry with the given key exists in the hash, 0 otherwise. */
* into the value pointed to by num_keys. If key_sizes is not NULL, extern int cfuhash_exists_data(cfuhash_table_t *ht, const void *key, size_t key_size);
* it will be set to an array of key sizes. If fast is zero, copies
* of the keys are returned. Otherwise, pointers to the real keys
* will be returned.
*/
extern void **cfuhash_keys_data(cfuhash_table_t *ht, size_t *num_keys, size_t **key_sizes,
int fast);
/* Initializes a loop over all the key/value pairs in the hash. It /* Inserts the given data value into the hash and associates it with
* returns the first key/value pair (see cfuhash_next_data()). 1 is * key. If key_size is -1, key is assumed to be a null-terminated
* returned if there are any entries in the hash. 0 is returned * string. If data_size is -1, it is assumed to be a null-terminated
* otherwise. * string (it's length will be calculated using strlen). If
*/ * data_size is zero, it will be returned as zero when the value is
extern int cfuhash_each_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data, * requested.
size_t *data_size); */
extern int cfuhash_put_data(cfuhash_table_t *ht, const void *key, size_t key_size, void *data,
size_t data_size, void **r);
/* Gets the next key/value pair from the hash. You must initialize /* Clears the hash table (deletes all entries). */
* the loop using cfuhash_each_data() before calling this function. extern void cfuhash_clear(cfuhash_table_t *ht);
* If a entry is left to return, 1 is returned from the function. 0
* is returned if there are no more entries in the hash.
*/
extern int cfuhash_next_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data,
size_t *data_size);
/* Iterates over the key/value pairs in the hash, passing each one /* Deletes the entry in the hash associated with key. If the entry
* to r_fn, and removes all entries for which r_fn returns true. * existed, it's value will be returned.
* If ff is not NULL, it is the passed the data to be freed. arg */
* is passed to r_fn. extern void * cfuhash_delete_data(cfuhash_table_t *ht, const void *key, size_t key_size);
*/
extern size_t cfuhash_foreach_remove(cfuhash_table_t *ht, cfuhash_remove_fn_t r_fn,
cfuhash_free_fn_t ff, void *arg);
/* Iterates over the key/value pairs in the hash, passing each one /* Returns all the keys from the hash. The number of keys is placed
* to fe_fn, along with arg. This locks the hash, so do not call * into the value pointed to by num_keys. If key_sizes is not NULL,
* any operations on the hash from within fe_fn unless you really * it will be set to an array of key sizes. If fast is zero, copies
* know what you're doing. A non-zero return value from fe_fn() * of the keys are returned. Otherwise, pointers to the real keys
* stops the iteration. * will be returned.
*/ */
extern size_t cfuhash_foreach(cfuhash_table_t *ht, cfuhash_foreach_fn_t fe_fn, void *arg); extern void **cfuhash_keys_data(cfuhash_table_t *ht, size_t *num_keys, size_t **key_sizes,
int fast);
/* Frees all resources allocated by the hash. If ff is not NULL, it /* Initializes a loop over all the key/value pairs in the hash. It
* is called for each hash entry with the value of the entry passed as * returns the first key/value pair (see cfuhash_next_data()). 1 is
* its only argument. If ff is not NULL, it overrides any function * returned if there are any entries in the hash. 0 is returned
* set previously with cfuhash_set_free_function(). * otherwise.
*/ */
extern int cfuhash_destroy(cfuhash_table_t *ht); extern int cfuhash_each_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data,
size_t *data_size);
extern int cfuhash_destroy_with_free_fn(cfuhash_table_t *ht, cfuhash_free_fn_t ff); /* Gets the next key/value pair from the hash. You must initialize
* the loop using cfuhash_each_data() before calling this function.
* If a entry is left to return, 1 is returned from the function. 0
* is returned if there are no more entries in the hash.
*/
extern int cfuhash_next_data(cfuhash_table_t *ht, void **key, size_t *key_size, void **data,
size_t *data_size);
/* Rebuild the hash to better accomodate the number of entries. See /* Iterates over the key/value pairs in the hash, passing each one
* cfuhash_set_thresholds(). * to r_fn, and removes all entries for which r_fn returns true.
*/ * If ff is not NULL, it is the passed the data to be freed. arg
extern int cfuhash_rehash(cfuhash_table_t *ht); * is passed to r_fn.
*/
extern size_t cfuhash_foreach_remove(cfuhash_table_t *ht, cfuhash_remove_fn_t r_fn,
cfuhash_free_fn_t ff, void *arg);
/* Returns the number entries in the hash. */ /* Iterates over the key/value pairs in the hash, passing each one
extern size_t cfuhash_num_entries(cfuhash_table_t *ht); * to fe_fn, along with arg. This locks the hash, so do not call
* any operations on the hash from within fe_fn unless you really
* know what you're doing. A non-zero return value from fe_fn()
* stops the iteration.
*/
extern size_t cfuhash_foreach(cfuhash_table_t *ht, cfuhash_foreach_fn_t fe_fn, void *arg);
/* Returns the number of buckets allocated for the hash. */ /* Frees all resources allocated by the hash. If ff is not NULL, it
extern size_t cfuhash_num_buckets(cfuhash_table_t *ht); * is called for each hash entry with the value of the entry passed as
* its only argument. If ff is not NULL, it overrides any function
* set previously with cfuhash_set_free_function().
*/
extern int cfuhash_destroy(cfuhash_table_t *ht);
/* Returns the number of buckets actually used out of the total number extern int cfuhash_destroy_with_free_fn(cfuhash_table_t *ht, cfuhash_free_fn_t ff);
* allocated for the hash.
*/
extern size_t cfuhash_num_buckets_used(cfuhash_table_t *ht);
/* Assumes all the keys and values are null-terminated strings and /* Rebuild the hash to better accomodate the number of entries. See
* returns a bencoded string representing the hash (see * cfuhash_set_thresholds().
* http://www.bittorrent.com/protocol.html) */
*/ extern int cfuhash_rehash(cfuhash_table_t *ht);
extern char * cfuhash_bencode_strings(cfuhash_table_t *ht);
/* Locks the hash. Use this with the each and next functions for /* Returns the number entries in the hash. */
* concurrency control. Note that the hash is locked automatically extern size_t cfuhash_num_entries(cfuhash_table_t *ht);
* when doing inserts and deletes, so if you lock the hash and then
* try to insert something into it, you may get into a deadlock,
* depending on your system defaults for how mutexes work.
*/
extern int cfuhash_lock(cfuhash_table_t *ht);
/* Unlocks the hash. Use this with the each an next functions for /* Returns the number of buckets allocated for the hash. */
* concurrency control. The caveat for cfuhash_lcok() also applies to extern size_t cfuhash_num_buckets(cfuhash_table_t *ht);
* this function.
*/
extern int cfuhash_unlock(cfuhash_table_t *ht);
/* Pretty print the hash's key/value pairs to the stream fp. It is /* Returns the number of buckets actually used out of the total number
* assumed that all the keys and values are null-terminated strings. * allocated for the hash.
*/ */
extern int cfuhash_pretty_print(cfuhash_table_t *ht, FILE *fp); extern size_t cfuhash_num_buckets_used(cfuhash_table_t *ht);
/* These are like the _data versions of these functions, with the /* Assumes all the keys and values are null-terminated strings and
* following exceptions: * returns a bencoded string representing the hash (see
* 1) They assume that the key provided is a null-terminated string. * http://www.bittorrent.com/protocol.html)
* 2) They don't worry about the size of the data. */
* 3) Returned keys or values are the return value of the function. extern char * cfuhash_bencode_strings(cfuhash_table_t *ht);
*/
extern void * cfuhash_get(cfuhash_table_t *ht, const char *key); /* Locks the hash. Use this with the each and next functions for
extern int cfuhash_exists(cfuhash_table_t *ht, const char *key); * concurrency control. Note that the hash is locked automatically
extern void * cfuhash_put(cfuhash_table_t *ht, const char *key, void *data); * when doing inserts and deletes, so if you lock the hash and then
extern void * cfuhash_delete(cfuhash_table_t *ht, const char *key); * try to insert something into it, you may get into a deadlock,
extern int cfuhash_each(cfuhash_table_t *ht, char **key, void **data); * depending on your system defaults for how mutexes work.
extern int cfuhash_next(cfuhash_table_t *ht, char **key, void **data); */
extern void **cfuhash_keys(cfuhash_table_t *ht, size_t *num_keys, int fast); extern int cfuhash_lock(cfuhash_table_t *ht);
/* Unlocks the hash. Use this with the each an next functions for
* concurrency control. The caveat for cfuhash_lcok() also applies to
* this function.
*/
extern int cfuhash_unlock(cfuhash_table_t *ht);
/* Pretty print the hash's key/value pairs to the stream fp. It is
* assumed that all the keys and values are null-terminated strings.
*/
extern int cfuhash_pretty_print(cfuhash_table_t *ht, FILE *fp);
/* These are like the _data versions of these functions, with the
* following exceptions:
* 1) They assume that the key provided is a null-terminated string.
* 2) They don't worry about the size of the data.
* 3) Returned keys or values are the return value of the function.
*/
extern void * cfuhash_get(cfuhash_table_t *ht, const char *key);
extern int cfuhash_exists(cfuhash_table_t *ht, const char *key);
extern void * cfuhash_put(cfuhash_table_t *ht, const char *key, void *data);
extern void * cfuhash_delete(cfuhash_table_t *ht, const char *key);
extern int cfuhash_each(cfuhash_table_t *ht, char **key, void **data);
extern int cfuhash_next(cfuhash_table_t *ht, char **key, void **data);
extern void **cfuhash_keys(cfuhash_table_t *ht, size_t *num_keys, int fast);
/* hash table flags */ /* hash table flags */

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-07-02 22:25:39 /*
* Authors: Don * cfulist.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
@ -199,7 +196,7 @@ cfulist_unshift_data(cfulist_t *list, void *data, size_t data_size) {
list->tail = list->entries = entry; list->tail = list->entries = entry;
} }
list->num_entries++; list->num_entries++;
unlock_list(list); unlock_list(list);
return 1; return 1;
@ -488,7 +485,7 @@ typedef struct _join_foreach_struct {
static int static int
_join_foreach_fn(void *data, size_t data_size, void *arg) { _join_foreach_fn(void *data, size_t data_size, void *arg) {
_join_foreach_struct *stuff = (_join_foreach_struct *)arg; _join_foreach_struct *stuff = (_join_foreach_struct *)arg;
data_size = data_size; data_size = data_size;
if (stuff->count) cfustring_append(stuff->string, stuff->delimiter); if (stuff->count) cfustring_append(stuff->string, stuff->delimiter);
stuff->count++; stuff->count++;

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-07-02 22:25:10 /*
* Authors: Don * cfulist.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CFU_LIST_ #ifndef _CFU_LIST_
#define _CFU_LIST_ #define _CFU_LIST_
@ -46,113 +43,113 @@
CFU_BEGIN_DECLS CFU_BEGIN_DECLS
/* The list itself. */ /* The list itself. */
struct cfulist; struct cfulist;
typedef struct cfulist cfulist_t; typedef struct cfulist cfulist_t;
/* Function called for each element in the list when passed to /* Function called for each element in the list when passed to
* cfulist_foreach(). A non-zero return value means to stop * cfulist_foreach(). A non-zero return value means to stop
* iteration. * iteration.
*/ */
typedef int (*cfulist_foreach_fn_t)(void *data, size_t data_size, void *arg); typedef int (*cfulist_foreach_fn_t)(void *data, size_t data_size, void *arg);
/* Function called for each element in the list when passed to /* Function called for each element in the list when passed to
* cfulist_map(). The return value is used to build a new * cfulist_map(). The return value is used to build a new
* list. * list.
*/ */
typedef void * (*cfulist_map_fn_t)(void *data, size_t data_size, void *arg, typedef void * (*cfulist_map_fn_t)(void *data, size_t data_size, void *arg,
size_t *new_data_size); size_t *new_data_size);
/* Function called to free the data in an element. */ /* Function called to free the data in an element. */
typedef void (*cfulist_free_fn_t)(void *data); typedef void (*cfulist_free_fn_t)(void *data);
/* Returns a new list. */ /* Returns a new list. */
extern cfulist_t * cfulist_new(); extern cfulist_t * cfulist_new();
/* Same as cfulist_new(), but set a function to be called on each /* Same as cfulist_new(), but set a function to be called on each
* element when the list is destroyed. * element when the list is destroyed.
*/ */
extern cfulist_t * cfulist_new_with_free_fn(cfulist_free_fn_t free_fn); extern cfulist_t * cfulist_new_with_free_fn(cfulist_free_fn_t free_fn);
/* Returns the number of entries in the list. */ /* Returns the number of entries in the list. */
extern size_t cfulist_num_entries(cfulist_t *list); extern size_t cfulist_num_entries(cfulist_t *list);
/* Manipulating list entries */ /* Manipulating list entries */
/* Push a value onto the end of the list. */ /* Push a value onto the end of the list. */
extern int cfulist_push_data(cfulist_t *list, void *data, size_t data_size); extern int cfulist_push_data(cfulist_t *list, void *data, size_t data_size);
/* Pop a value from the end of the list. */ /* Pop a value from the end of the list. */
extern int cfulist_pop_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_pop_data(cfulist_t *list, void **data, size_t *data_size);
/* Add a value at the beginning of the list. */ /* Add a value at the beginning of the list. */
extern int cfulist_unshift_data(cfulist_t *list, void *data, size_t data_size); extern int cfulist_unshift_data(cfulist_t *list, void *data, size_t data_size);
/* Shift a value off the beginning of the list. */ /* Shift a value off the beginning of the list. */
extern int cfulist_shift_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_shift_data(cfulist_t *list, void **data, size_t *data_size);
/* Add a value at the end of the queue (equivalent to push) */ /* Add a value at the end of the queue (equivalent to push) */
extern int cfulist_enqueue_data(cfulist_t *list, void *data, size_t data_size); extern int cfulist_enqueue_data(cfulist_t *list, void *data, size_t data_size);
/* Remove the value at the beginning of the list (equivalent to shift). */ /* Remove the value at the beginning of the list (equivalent to shift). */
extern int cfulist_dequeue_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_dequeue_data(cfulist_t *list, void **data, size_t *data_size);
/* Return the last entry from the list (without removing it from /* Return the last entry from the list (without removing it from
* the list). * the list).
*/ */
extern int cfulist_first_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_first_data(cfulist_t *list, void **data, size_t *data_size);
/* Return the last entry from the list (without removing it from /* Return the last entry from the list (without removing it from
* the list). * the list).
*/ */
extern int cfulist_last_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_last_data(cfulist_t *list, void **data, size_t *data_size);
/* Return the nth entry from the list (without removing it from /* Return the nth entry from the list (without removing it from
* the list). n starts at zero. * the list). n starts at zero.
*/ */
extern int cfulist_nth_data(cfulist_t *list, void **data, size_t *data_size, size_t n); extern int cfulist_nth_data(cfulist_t *list, void **data, size_t *data_size, size_t n);
extern void cfulist_reset_each(cfulist_t *list); extern void cfulist_reset_each(cfulist_t *list);
extern int cfulist_each_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_each_data(cfulist_t *list, void **data, size_t *data_size);
extern int cfulist_next_data(cfulist_t *list, void **data, size_t *data_size); extern int cfulist_next_data(cfulist_t *list, void **data, size_t *data_size);
/* Calls fe_fn() for each element in the list. Also passes arg on /* Calls fe_fn() for each element in the list. Also passes arg on
* each call. If fe_fn() returns a non-zero value, the iteration * each call. If fe_fn() returns a non-zero value, the iteration
* over the elements stops. * over the elements stops.
*/ */
extern size_t cfulist_foreach(cfulist_t *list, cfulist_foreach_fn_t fe_fn, void *arg); extern size_t cfulist_foreach(cfulist_t *list, cfulist_foreach_fn_t fe_fn, void *arg);
/* Creates a new list from the list passed in. Calls map_fn() on /* Creates a new list from the list passed in. Calls map_fn() on
* each element in the list. The return value is placed in the * each element in the list. The return value is placed in the
* corresponding position in the new list. * corresponding position in the new list.
*/ */
extern cfulist_t *cfulist_map(cfulist_t *list, cfulist_map_fn_t map_fn, void *arg); extern cfulist_t *cfulist_map(cfulist_t *list, cfulist_map_fn_t map_fn, void *arg);
/* Free all resources used by the list. */ /* Free all resources used by the list. */
extern void cfulist_destroy(cfulist_t *list); extern void cfulist_destroy(cfulist_t *list);
extern void cfulist_destroy_with_free_fn(cfulist_t *list, cfulist_free_fn_t free_fn); extern void cfulist_destroy_with_free_fn(cfulist_t *list, cfulist_free_fn_t free_fn);
/* When you don't care about the size of the data */ /* When you don't care about the size of the data */
extern int cfulist_push(cfulist_t *list, void *data); extern int cfulist_push(cfulist_t *list, void *data);
extern void * cfulist_pop(cfulist_t *list); extern void * cfulist_pop(cfulist_t *list);
extern int cfulist_unshift(cfulist_t *list, void *data); extern int cfulist_unshift(cfulist_t *list, void *data);
extern void * cfulist_shift(cfulist_t *list); extern void * cfulist_shift(cfulist_t *list);
extern int cfulist_enqueue(cfulist_t *list, void *data); extern int cfulist_enqueue(cfulist_t *list, void *data);
extern void *cfulist_dequeue(cfulist_t *list); extern void *cfulist_dequeue(cfulist_t *list);
/* Strings -- assume data is a null-terminated string -- size is /* Strings -- assume data is a null-terminated string -- size is
* calculated by strlen(data) + 1 * calculated by strlen(data) + 1
*/ */
extern int cfulist_push_string(cfulist_t *list, char *data); extern int cfulist_push_string(cfulist_t *list, char *data);
extern char * cfulist_pop_string(cfulist_t *list); extern char * cfulist_pop_string(cfulist_t *list);
extern int cfulist_unshift_string(cfulist_t *list, char *data); extern int cfulist_unshift_string(cfulist_t *list, char *data);
extern char * cfulist_shift_string(cfulist_t *list); extern char * cfulist_shift_string(cfulist_t *list);
extern int cfulist_enqueue_string(cfulist_t *list, char *data); extern int cfulist_enqueue_string(cfulist_t *list, char *data);
extern char *cfulist_dequeue_string(cfulist_t *list); extern char *cfulist_dequeue_string(cfulist_t *list);
extern char *cfulist_join(cfulist_t *list, const char *delimiter); extern char *cfulist_join(cfulist_t *list, const char *delimiter);
CFU_END_DECLS CFU_END_DECLS

View File

@ -1,6 +1,38 @@
/* Creation date: 2005-09-04 12:57:25 /*
* Authors: Don * cfuopt.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "cfu.h" #include "cfu.h"
@ -160,7 +192,7 @@ _add_to_option_map(void *data, size_t data_size, void *arg) {
data_size = data_size; data_size = data_size;
cfuhash_put(es->context->option_map, (char *)data, (void *)es->entry); cfuhash_put(es->context->option_map, (char *)data, (void *)es->entry);
return 0; return 0;
} }
@ -183,7 +215,7 @@ cfuopt_add_entry(cfuopt_t *context, const char *opt_str, void *arg_data,
entry->param_names = param_list; entry->param_names = param_list;
cfulist_push(context->option_list, (void *)entry); cfulist_push(context->option_list, (void *)entry);
entry_struct.entry = entry; entry_struct.entry = entry;
entry_struct.context = context; entry_struct.context = context;
@ -204,7 +236,7 @@ check_arg(const char *arg, int *is_long, int *is_short, int *is_data, int *is_en
*value = NULL; *value = NULL;
if (!ptr || !*ptr) return; if (!ptr || !*ptr) return;
if (*ptr != '-') { if (*ptr != '-') {
*is_data = 1; *is_data = 1;
*parsed_arg = cfustring_dup_c_str(ptr); *parsed_arg = cfustring_dup_c_str(ptr);
@ -295,7 +327,7 @@ cfuopt_parse(cfuopt_t *context, int *argc, char ***argv, char **error) {
if (*argc < 1) return; if (*argc < 1) return;
context->progname = cfustring_dup_c_str(args[0]); context->progname = cfustring_dup_c_str(args[0]);
if (*argc < 2) return; if (*argc < 2) return;
for (i = 1; i < *argc; i++) { for (i = 1; i < *argc; i++) {
@ -305,7 +337,7 @@ cfuopt_parse(cfuopt_t *context, int *argc, char ***argv, char **error) {
if (parsed_arg) free(parsed_arg); if (parsed_arg) free(parsed_arg);
parsed_arg = NULL; parsed_arg = NULL;
check_arg(cur_arg, &is_long_opt, &is_short_opt, &is_data, &is_end_of_opt, &parsed_arg, check_arg(cur_arg, &is_long_opt, &is_short_opt, &is_data, &is_end_of_opt, &parsed_arg,
&value); &value);
if (is_long_opt || is_short_opt) { if (is_long_opt || is_short_opt) {
@ -367,7 +399,7 @@ cfuopt_parse(cfuopt_t *context, int *argc, char ***argv, char **error) {
default: default:
break; break;
} }
} }
extra_count = cfulist_num_entries(context->extra); extra_count = cfulist_num_entries(context->extra);
@ -435,7 +467,7 @@ _cfuopt_pretty_print_foreach(void *key, size_t key_size, void *data, size_t data
arg = arg; arg = arg;
ARG_TYPE_TO_STR(list_entry->arg_type, str); ARG_TYPE_TO_STR(list_entry->arg_type, str);
printf("%s=%p (%s - %s) => %s, \"%s\"\n", name, (void *)list_entry, (list_entry->required ? "required" : "optional"), str, list_entry->description, list_entry->arg_description); printf("%s=%p (%s - %s) => %s, \"%s\"\n", name, (void *)list_entry, (list_entry->required ? "required" : "optional"), str, list_entry->description, list_entry->arg_description);
return 0; return 0;
} }
@ -506,7 +538,7 @@ _find_foreach_fn(void *data, size_t data_size, void *arg) {
desc = cfulist_join(param_full_list, ", "); desc = cfulist_join(param_full_list, ", ");
data_size = data_size; data_size = data_size;
cfulist_destroy_with_free_fn(param_full_list, _simple_list_free_fn); cfulist_destroy_with_free_fn(param_full_list, _simple_list_free_fn);
desc_ds->desc = desc; desc_ds->desc = desc;
@ -527,7 +559,7 @@ _find_longest_help_desc(cfuopt_t *context, cfulist_t **desc_list) {
cfulist_foreach(context->option_list, _find_foreach_fn, (void *)&ds); cfulist_foreach(context->option_list, _find_foreach_fn, (void *)&ds);
*desc_list = ds.desc_list; *desc_list = ds.desc_list;
return ds.max_size; return ds.max_size;
} }
@ -548,7 +580,7 @@ _get_help_lines(void *data, size_t data_size, void *arg) {
data_size = data_size; data_size = data_size;
left_col = desc_ds->desc; left_col = desc_ds->desc;
if (!left_col) return 0; if (!left_col) return 0;
desc = desc_ds->entry->description; desc = desc_ds->entry->description;
@ -558,7 +590,7 @@ _get_help_lines(void *data, size_t data_size, void *arg) {
cfulist_push(ds->list, (void *)line); cfulist_push(ds->list, (void *)line);
return 0; return 0;
} }
static void static void
@ -577,7 +609,7 @@ cfuopt_get_help_str(cfuopt_t *context) {
char *help_str = NULL; char *help_str = NULL;
max_width = _find_longest_help_desc(context, &desc_list); max_width = _find_longest_help_desc(context, &desc_list);
fmt = cfustring_sprintf_c_str(" %%-%us %%s\n", max_width); fmt = cfustring_sprintf_c_str(" %%-%us %%s\n", max_width);
ds.fmt = fmt; ds.fmt = fmt;
ds.list = cfulist_new(); ds.list = cfulist_new();

View File

@ -1,6 +1,38 @@
/* Creation date: 2005-09-04 12:54:41 /*
* Authors: Don * cfuopt.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <cfu.h> #include <cfu.h>

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-06-26 19:59:10 /*
* Authors: Don * cfustring.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cfu.h" #include "cfu.h"
#include "cfustring.h" #include "cfustring.h"
@ -167,7 +164,7 @@ extern char *
cfustring_get_buffer_copy(cfustring_t *cfu_str) { cfustring_get_buffer_copy(cfustring_t *cfu_str) {
char *buffer = NULL; char *buffer = NULL;
if (!cfu_str->str) return NULL; if (!cfu_str->str) return NULL;
buffer = (char *)calloc(cfu_str->used_size, 1); buffer = (char *)calloc(cfu_str->used_size, 1);
memcpy(buffer, cfu_str->str, cfu_str->used_size); memcpy(buffer, cfu_str->str, cfu_str->used_size);
return buffer; return buffer;
@ -222,7 +219,7 @@ _check_sep(char **start, char **seps, size_t num_seps, char **sep_chk_ptrs, int
} }
return NULL; return NULL;
} }
for (end = *start; *end; end++) { for (end = *start; *end; end++) {
for (i = 0; i < num_seps; i++) { for (i = 0; i < num_seps; i++) {
if (*sep_chk_ptrs[i] == *end) { if (*sep_chk_ptrs[i] == *end) {
@ -287,7 +284,7 @@ __cfustring_split_to_raw(cfustring_t *cfu_str, size_t *num_strings, size_t num_s
free(sep_array); free(sep_array);
return NULL; return NULL;
} }
while ( (next_str = _check_sep(&end, sep_array, num_seps, sep_chk_ptrs, last)) ) { while ( (next_str = _check_sep(&end, sep_array, num_seps, sep_chk_ptrs, last)) ) {
if (used_ret_strings == max_ret_strings) { if (used_ret_strings == max_ret_strings) {
/* allocate more space */ /* allocate more space */
@ -377,7 +374,7 @@ cfustring_sprintf_c_str(const char *fmt, ...) {
char *str = NULL; char *str = NULL;
cfustring_t *cfu_str = cfustring_new(); cfustring_t *cfu_str = cfustring_new();
va_start(ap, fmt); va_start(ap, fmt);
cfustring_vsprintf(cfu_str, fmt, ap); cfustring_vsprintf(cfu_str, fmt, ap);
va_end(ap); va_end(ap);
str = cfustring_get_buffer_copy(cfu_str); str = cfustring_get_buffer_copy(cfu_str);
@ -569,7 +566,7 @@ cfustring_vsprintf(cfustring_t *cfu_str, const char *fmt_in, va_list ap) {
start = end = fmt; start = end = fmt;
continue; continue;
} }
} else { } else {
byte_count++; byte_count++;
end = fmt; end = fmt;
@ -618,5 +615,5 @@ cfustring_c_str_split(const char *c_str, size_t *num_strings, size_t limit, ...)
cfustring_destroy(cfu_str); cfustring_destroy(cfu_str);
return rv; return rv;
} }

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-06-26 19:56:34 /*
* Authors: Don * cfustring.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CFU_STRING_H_ #ifndef _CFU_STRING_H_
#define _CFU_STRING_H_ #define _CFU_STRING_H_
@ -47,74 +44,74 @@
CFU_BEGIN_DECLS CFU_BEGIN_DECLS
struct cfustring; struct cfustring;
typedef struct cfustring cfustring_t; typedef struct cfustring cfustring_t;
/* Returns a new String. */ /* Returns a new String. */
extern cfustring_t * cfustring_new(); extern cfustring_t * cfustring_new();
/* Returns a new String, but preallocates a buffer of the given size. */ /* Returns a new String, but preallocates a buffer of the given size. */
extern cfustring_t * cfustring_new_with_initial_size(size_t initial_size); extern cfustring_t * cfustring_new_with_initial_size(size_t initial_size);
/* Returns a new String initalized with the given string. */ /* Returns a new String initalized with the given string. */
extern cfustring_t * cfustring_new_from_string(const char *string); extern cfustring_t * cfustring_new_from_string(const char *string);
/* Overwrite anything currently in cfu_str with string. */ /* Overwrite anything currently in cfu_str with string. */
extern int cfustring_dup(cfustring_t *cfu_str, const char *string); extern int cfustring_dup(cfustring_t *cfu_str, const char *string);
/* Truncate the string. */ /* Truncate the string. */
extern int cfustring_clear(cfustring_t *cfu_str); extern int cfustring_clear(cfustring_t *cfu_str);
/* Append str to the end of the buffer in cfu_str. */ /* Append str to the end of the buffer in cfu_str. */
extern int cfustring_append(cfustring_t *cfu_str, const char *str); extern int cfustring_append(cfustring_t *cfu_str, const char *str);
/* Get the buffer used to hold the string. Do not free() it, as it is /* Get the buffer used to hold the string. Do not free() it, as it is
* used directly by cfustring and will be destroyed when * used directly by cfustring and will be destroyed when
* cfustring_destroy() is called. * cfustring_destroy() is called.
*/ */
extern char * cfustring_get_buffer(cfustring_t *cfu_str); extern char * cfustring_get_buffer(cfustring_t *cfu_str);
/* Same as cfustring_get_buffer(), except return a copy of the string. /* Same as cfustring_get_buffer(), except return a copy of the string.
* Caller is responsible for deallocating the buffer with free(). * Caller is responsible for deallocating the buffer with free().
*/ */
extern char * cfustring_get_buffer_copy(cfustring_t *cfu_str); extern char * cfustring_get_buffer_copy(cfustring_t *cfu_str);
/* Split cfu_str on one or more delimiting strings, e.g., /* Split cfu_str on one or more delimiting strings, e.g.,
* cfustring_split(cfu_str, 2, 0, "\r\n", "\n"). Use a limit > 0 if * cfustring_split(cfu_str, 2, 0, "\r\n", "\n"). Use a limit > 0 if
* you want to only get back a certain number of strings and ignore * you want to only get back a certain number of strings and ignore
* any extra delimiters. * any extra delimiters.
*/ */
extern cfustring_t ** cfustring_split(cfustring_t *cfu_str, size_t *num_strings, extern cfustring_t ** cfustring_split(cfustring_t *cfu_str, size_t *num_strings,
size_t limit, ...); size_t limit, ...);
/* Same as cfustring_split(), except return an array of C-strings. /* Same as cfustring_split(), except return an array of C-strings.
* Caller is responsible for deallocating the buffers. * Caller is responsible for deallocating the buffers.
*/ */
extern char ** cfustring_split_to_c_str(cfustring_t *cfu_str, size_t *num_strings, extern char ** cfustring_split_to_c_str(cfustring_t *cfu_str, size_t *num_strings,
size_t limit, ...); size_t limit, ...);
/* Free all resources allocated by cfu_str. */ /* Free all resources allocated by cfu_str. */
extern int cfustring_destroy(cfustring_t *cfu_str); extern int cfustring_destroy(cfustring_t *cfu_str);
/* Duplicate the C string str. Caller must free with free(). */ /* Duplicate the C string str. Caller must free with free(). */
extern char * cfustring_dup_c_str(const char *str); extern char * cfustring_dup_c_str(const char *str);
/* Same as cfustring_dup_c_str(), but only copy at most n chars */
extern char * cfustring_dup_c_str_n(const char *str, size_t n);
/* Like sprintf(), but writes to a self-extending string. */ /* Same as cfustring_dup_c_str(), but only copy at most n chars */
extern size_t cfustring_sprintf(cfustring_t *cfu_str, const char *fmt, ...); extern char * cfustring_dup_c_str_n(const char *str, size_t n);
/* Like vsprintf(), but writes to a self-extending string. */ /* Like sprintf(), but writes to a self-extending string. */
extern size_t cfustring_vsprintf(cfustring_t *cfu_str, const char *fmt, va_list ap); extern size_t cfustring_sprintf(cfustring_t *cfu_str, const char *fmt, ...);
/* Similar to sprintf(), but allocates a C string of the /* Like vsprintf(), but writes to a self-extending string. */
* appropriate size for you and returns it. extern size_t cfustring_vsprintf(cfustring_t *cfu_str, const char *fmt, va_list ap);
*/
extern char * cfustring_sprintf_c_str(const char *fmt, ...);
/* Like cfustring_split_to_c_str(), but split a char * instead of a cfustring_t *. */ /* Similar to sprintf(), but allocates a C string of the
extern char ** cfustring_c_str_split(const char *c_str, size_t *num_strings, size_t limit, ...); * appropriate size for you and returns it.
*/
extern char * cfustring_sprintf_c_str(const char *fmt, ...);
/* Like cfustring_split_to_c_str(), but split a char * instead of a cfustring_t *. */
extern char ** cfustring_c_str_split(const char *c_str, size_t *num_strings, size_t limit, ...);
CFU_END_DECLS CFU_END_DECLS

View File

@ -1,8 +1,38 @@
/* Creation date: 2005-07-26 08:20:59 /*
* cfuthread_queue.c - This file is part of the libcfu library
* Authors: Don *
* Change log: * Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "cfuthread_queue.h" #include "cfuthread_queue.h"
@ -59,13 +89,13 @@ _run_queue(void *arg) {
} }
pthread_cleanup_push((void *)tq->cleanup_fn, tq->cleanup_arg); pthread_cleanup_push((void *)tq->cleanup_fn, tq->cleanup_arg);
while (1) { while (1) {
pthread_mutex_lock(&tq->mutex); pthread_mutex_lock(&tq->mutex);
while (cfulist_num_entries(tq->request_queue) == 0) { while (cfulist_num_entries(tq->request_queue) == 0) {
pthread_cond_wait(&tq->cv, &tq->mutex); pthread_cond_wait(&tq->cv, &tq->mutex);
} }
request = (cfuthread_queue_entry *)cfulist_dequeue(tq->request_queue); request = (cfuthread_queue_entry *)cfulist_dequeue(tq->request_queue);
pthread_mutex_unlock(&tq->mutex); pthread_mutex_unlock(&tq->mutex);
if (!request) continue; if (!request) continue;
@ -101,7 +131,7 @@ cfuthread_queue_new_with_cleanup(cfuthread_queue_fn_t fn, cfuthread_queue_init_t
if ( (0 != pthread_create(&tq->thread, NULL, _run_queue, (void *)tq)) ) { if ( (0 != pthread_create(&tq->thread, NULL, _run_queue, (void *)tq)) ) {
return NULL; return NULL;
} }
return tq; return tq;
} }

View File

@ -1,44 +1,40 @@
/* Creation date: 2005-07-26 08:19:33 /*
* Authors: Don * cfuthread_queue.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CFUTHREAD_QUEUE_H #ifndef _CFUTHREAD_QUEUE_H
#define _CFUTHREAD_QUEUE_H #define _CFUTHREAD_QUEUE_H
@ -46,49 +42,49 @@
CFU_BEGIN_DECLS CFU_BEGIN_DECLS
/* cfuthread_queue provides a way to serialize requests for a /* cfuthread_queue provides a way to serialize requests for a
* resource where you want the resource to be accessed from a * resource where you want the resource to be accessed from a
* single thread only. For instance, for a database connection * single thread only. For instance, for a database connection
* where making calls in separate threads does not work properly, * where making calls in separate threads does not work properly,
* you can use cfuthread_queue. cfuthread_queue_new() creates a * you can use cfuthread_queue. cfuthread_queue_new() creates a
* new thread that waits for something to be added to the queue. * new thread that waits for something to be added to the queue.
* Once something is added, the thread will process the data by * Once something is added, the thread will process the data by
* calling the function you pass as an argument to the * calling the function you pass as an argument to the
* cfuthread_queue_new() function. * cfuthread_queue_new() function.
*/ */
struct cfuthread_queue; struct cfuthread_queue;
typedef struct cfuthread_queue cfuthread_queue_t; typedef struct cfuthread_queue cfuthread_queue_t;
typedef void * (*cfuthread_queue_fn_t)(void *arg); typedef void * (*cfuthread_queue_fn_t)(void *arg);
typedef void (*cfuthread_queue_init_t)(void *arg); typedef void (*cfuthread_queue_init_t)(void *arg);
typedef void (*cfuthread_queue_cleanup_t)(void *arg); typedef void (*cfuthread_queue_cleanup_t)(void *arg);
/* Creates a new thread queue structure that will run the given /* Creates a new thread queue structure that will run the given
* function when a request is received. * function when a request is received.
*/ */
extern cfuthread_queue_t * cfuthread_queue_new(cfuthread_queue_fn_t fn); extern cfuthread_queue_t * cfuthread_queue_new(cfuthread_queue_fn_t fn);
/* Same as cfuthread_queue_new(), but with an initialization /* Same as cfuthread_queue_new(), but with an initialization
* function that gets called with the argument init_arg when the * function that gets called with the argument init_arg when the
* thread is created, and a cleanup function that gets called with * thread is created, and a cleanup function that gets called with
* the argument cleanup_arg when the thread exits, e.g., when * the argument cleanup_arg when the thread exits, e.g., when
* cfuthread_queue_destroy() is called. * cfuthread_queue_destroy() is called.
*/ */
extern cfuthread_queue_t * cfuthread_queue_new_with_cleanup(cfuthread_queue_fn_t fn, extern cfuthread_queue_t * cfuthread_queue_new_with_cleanup(cfuthread_queue_fn_t fn,
cfuthread_queue_init_t init_fn, void *init_arg, cfuthread_queue_cleanup_t cleanup_fn, cfuthread_queue_init_t init_fn, void *init_arg, cfuthread_queue_cleanup_t cleanup_fn,
void *cleanup_arg); void *cleanup_arg);
/* Add a request to the queue. data will get passed to the /* Add a request to the queue. data will get passed to the
* function fn given to cfuthread_queue_new when it reaches the * function fn given to cfuthread_queue_new when it reaches the
* front of the queue. * front of the queue.
*/ */
extern void * cfuthread_queue_make_request(cfuthread_queue_t * tq, void *data); extern void * cfuthread_queue_make_request(cfuthread_queue_t * tq, void *data);
/* Free up resources used by the queue, in addition to canceling /* Free up resources used by the queue, in addition to canceling
* the thread. * the thread.
*/ */
extern void cfuthread_queue_destroy(cfuthread_queue_t *); extern void cfuthread_queue_destroy(cfuthread_queue_t *);
CFU_END_DECLS CFU_END_DECLS

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-06-26 18:11:40 /*
* Authors: Don * cfutime.c - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cfu.h" #include "cfu.h"
#include "cfutime.h" #include "cfutime.h"

View File

@ -1,43 +1,40 @@
/* Creation date: 2005-06-26 18:09:46 /*
* Authors: Don * cfutime.h - This file is part of the libcfu library
* Change log: *
* Copyright (c) 2005 Don Owens. All rights reserved.
*
* This code is released under the BSD license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of the author nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* Copyright (c) 2005 Don Owens
All rights reserved.
This code is released under the BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _CFU_TIME_H_ #ifndef _CFU_TIME_H_
#define _CFU_TIME_H_ #define _CFU_TIME_H_
@ -45,23 +42,23 @@
CFU_BEGIN_DECLS CFU_BEGIN_DECLS
struct cfutime; struct cfutime;
typedef struct cfutime cfutime_t; typedef struct cfutime cfutime_t;
/* Return a new cfutime structure. */ /* Return a new cfutime structure. */
extern cfutime_t *cfutime_new(); extern cfutime_t *cfutime_new();
/* Start the timer. */ /* Start the timer. */
extern void cfutime_begin(cfutime_t *time); extern void cfutime_begin(cfutime_t *time);
/* Stop the timer. */ /* Stop the timer. */
extern void cfutime_end(cfutime_t *time); extern void cfutime_end(cfutime_t *time);
/* Return the number of seconds elapsed as a double. */ /* Return the number of seconds elapsed as a double. */
extern double cfutime_elapsed(cfutime_t *time); extern double cfutime_elapsed(cfutime_t *time);
/* Deallocate resources allocated for time. */ /* Deallocate resources allocated for time. */
extern void cfutime_free(cfutime_t *time); extern void cfutime_free(cfutime_t *time);
CFU_END_DECLS CFU_END_DECLS