From d50caad446038d3e022da403a619bad29315baf5 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 9 Feb 2005 14:46:25 +0000 Subject: [PATCH] headers for libjson git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@34 9efc2488-bf62-4759-914b-345cdb29e865 --- include/libjson/arraylist.h | 52 +++++ include/libjson/bits.h | 38 ++++ include/libjson/debug.h | 33 +++ include/libjson/json.h | 30 +++ include/libjson/json_object.h | 301 ++++++++++++++++++++++++++ include/libjson/json_object_private.h | 25 +++ include/libjson/json_tokener.h | 70 ++++++ include/libjson/json_util.h | 13 ++ include/libjson/linkhash.h | 270 +++++++++++++++++++++++ include/libjson/printbuf.h | 43 ++++ 10 files changed, 875 insertions(+) create mode 100644 include/libjson/arraylist.h create mode 100644 include/libjson/bits.h create mode 100644 include/libjson/debug.h create mode 100644 include/libjson/json.h create mode 100644 include/libjson/json_object.h create mode 100644 include/libjson/json_object_private.h create mode 100644 include/libjson/json_tokener.h create mode 100644 include/libjson/json_util.h create mode 100644 include/libjson/linkhash.h create mode 100644 include/libjson/printbuf.h diff --git a/include/libjson/arraylist.h b/include/libjson/arraylist.h new file mode 100644 index 0000000..b137e16 --- /dev/null +++ b/include/libjson/arraylist.h @@ -0,0 +1,52 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _arraylist_h_ +#define _arraylist_h_ + +#define ARRAY_LIST_DEFAULT_SIZE 32 + +typedef void (array_list_free_fn) (void *data); + +struct array_list +{ + void **array; + int length; + int size; + array_list_free_fn *free_fn; +}; + +extern struct array_list* +array_list_new(array_list_free_fn *free_fn); + +extern void +array_list_free(struct array_list *this); + +extern void* +array_list_get_idx(struct array_list *this, int i); + +extern int +array_list_put_idx(struct array_list *this, int i, void *data); + +extern int +array_list_add(struct array_list *this, void *data); + +extern int +array_list_length(struct array_list *this); + +#endif diff --git a/include/libjson/bits.h b/include/libjson/bits.h new file mode 100644 index 0000000..b9d1b88 --- /dev/null +++ b/include/libjson/bits.h @@ -0,0 +1,38 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _bits_h_ +#define _bits_h_ + +#define min(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x < _y ? _x : _y; }) + +#define max(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; }) + +#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) +#define error_ptr(error) ((void*)error) +#define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L) + +#endif diff --git a/include/libjson/debug.h b/include/libjson/debug.h new file mode 100644 index 0000000..7d8d10b --- /dev/null +++ b/include/libjson/debug.h @@ -0,0 +1,33 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#define errstr strerror(errno) + +extern void mc_set_debug(int debug); +extern int mc_get_debug(); + +extern void mc_set_syslog(int syslog); +extern void mc_abort(const char *msg, ...); +extern void mc_debug(const char *msg, ...); +extern void mc_error(const char *msg, ...); +extern void mc_info(const char *msg, ...); + +#endif diff --git a/include/libjson/json.h b/include/libjson/json.h new file mode 100644 index 0000000..b2787c1 --- /dev/null +++ b/include/libjson/json.h @@ -0,0 +1,30 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _json_h_ +#define _json_h_ + +#include "libjson/bits.h" +#include "libjson/debug.h" +#include "libjson/linkhash.h" +#include "libjson/arraylist.h" +#include "libjson/json_util.h" +#include "libjson/json_object.h" +#include "libjson/json_tokener.h" + +#endif diff --git a/include/libjson/json_object.h b/include/libjson/json_object.h new file mode 100644 index 0000000..a4e4ff3 --- /dev/null +++ b/include/libjson/json_object.h @@ -0,0 +1,301 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _json_object_h_ +#define _json_object_h_ + +#define JSON_OBJECT_DEF_HASH_ENTIRES 16 + +#undef FALSE +#define FALSE ((boolean)0) + +#undef TRUE +#define TRUE ((boolean)1) + +extern char *json_number_chars; +extern char *json_hex_chars; + +/* forward structure definitions */ + +typedef int boolean; +struct printbuf; +struct lh_table; +struct array_list; +struct json_object; +typedef struct json_object json; + +/* supported object types */ + +enum json_type { + json_type_null, + json_type_boolean, + json_type_double, + json_type_int, + json_type_object, + json_type_array, + json_type_string, +}; + +/* reference counting functions */ + +/** + * Increment the reference count of json_object + * @param this the json_object instance + */ +extern struct json_object* json_object_get(struct json_object *this); + +/** + * Decrement the reference count of json_object and free if it reaches zero + * @param this the json_object instance + */ +extern void json_object_put(struct json_object *this); + + +/** + * Check if the json_object is of a given type + * @param this the json_object instance + * @param type one of: + json_type_boolean, + json_type_double, + json_type_int, + json_type_object, + json_type_array, + json_type_string, + */ +extern int json_object_is_type(struct json_object *this, enum json_type type); + +/** + * Get the type of the json_object + * @param this the json_object instance + * @returns type being one of: + json_type_boolean, + json_type_double, + json_type_int, + json_type_object, + json_type_array, + json_type_string, + */ +extern enum json_type json_object_get_type(struct json_object *this); + + +/** Stringify object to json format + * @param this the json_object instance + * @returns a string in JSON format + */ +extern char* json_object_to_json_string(struct json_object *this); + + +/* object type methods */ + +/** Create a new empty object + * @returns a json_object of type json_type_object + */ +extern struct json_object* json_object_new_object(); + +/** Get the hashtable of a json_object of type json_type_object + * @param this the json_object instance + * @returns a linkhash + */ +extern struct lh_table* json_object_get_object(struct json_object *this); + +/** Add an object field to a json_object of type json_type_object + * + * The reference count will *not* be incremented. This is to make adding + * fields to objects in code more compact. If you want to retain a reference + * to an added object you must wrap the passed object with json_object_get + * + * @param this the json_object instance + * @param key the object field name (a private copy will be duplicated) + * @param val a json_object or NULL member to associate with the given field + */ +extern void json_object_object_add(struct json_object* this, char *key, + struct json_object *val); + +/** Get the json_object associate with a given object field + * @param this the json_object instance + * @param key the object field name + * @returns the json_object associated with the given field name + */ +extern struct json_object* json_object_object_get(struct json_object* this, + char *key); + +/** Delete the given json_object field + * + * The reference count will be decremented for the deleted object + * + * @param this the json_object instance + * @param key the object field name + */ +extern void json_object_object_del(struct json_object* this, char *key); + +/** Iterate through all keys and values of an object + * @param this the json_object instance + * @param key the local name for the char* key variable defined in the body + * @param val the local name for the json_object* object variable defined in the body + */ +#define json_object_object_foreach(obj,key,val) \ +char *key; struct json_object *val; \ +for(struct lh_entry *entry = json_object_get_object(obj)->head; ({ if(entry) { key = (char*)entry->k; val = (struct json_object*)entry->v; } ; entry; }); entry = entry->next ) + + +/* Array type methods */ + +/** Create a new empty json_object of type json_type_array + * @returns a json_object of type json_type_array + */ +extern struct json_object* json_object_new_array(); + +/** Get the arraylist of a json_object of type json_type_array + * @param this the json_object instance + * @returns an arraylist + */ +extern struct array_list* json_object_get_array(struct json_object *this); + +/** Get the length of a json_object of type json_type_array + * @param this the json_object instance + * @returns an int + */ +extern int json_object_array_length(struct json_object *this); + +/** Add an element to the end of a json_object of type json_type_array + * + * The reference count will *not* be incremented. This is to make adding + * fields to objects in code more compact. If you want to retain a reference + * to an added object you must wrap the passed object with json_object_get + * + * @param this the json_object instance + * @param val the json_object to be added + */ +extern int json_object_array_add(struct json_object *this, + struct json_object *val); + +/** Insert or replace an element at a specified index in an array (a json_object of type json_type_array) + * + * The reference count will *not* be incremented. This is to make adding + * fields to objects in code more compact. If you want to retain a reference + * to an added object you must wrap the passed object with json_object_get + * + * The reference count of a replaced object will be decremented. + * + * The array size will be automatically be expanded to the size of the + * index if the index is larger than the current size. + * + * @param this the json_object instance + * @param idx the index to insert the element at + * @param val the json_object to be added + */ +extern int json_object_array_put_idx(struct json_object *this, int idx, + struct json_object *val); + +/** Get the element at specificed index of the array (a json_object of type json_type_array) + * @param this the json_object instance + * @param idx the index to get the element at + * @returns the json_object at the specified index (or NULL) + */ +extern struct json_object* json_object_array_get_idx(struct json_object *this, + int idx); + +/* boolean type methods */ + +/** Create a new empty json_object of type json_type_boolean + * @param b a boolean TRUE or FALSE (0 or 1) + * @returns a json_object of type json_type_boolean + */ +extern struct json_object* json_object_new_boolean(boolean b); + +/** Get the boolean value of a json_object + * + * The type is coerced to a boolean if the passed object is not a boolean. + * integer and double objects will return FALSE if there value is zero + * or TRUE otherwise. If the passed object is a string it will return + * TRUE if it has a non zero length. If any other object type is passed + * TRUE will be returned if the object is not NULL. + * + * @param this the json_object instance + * @returns a boolean + */ +extern boolean json_object_get_boolean(struct json_object *this); + + +/* int type methods */ + +/** Create a new empty json_object of type json_type_int + * @param i the integer + * @returns a json_object of type json_type_int + */ +extern struct json_object* json_object_new_int(int i); + +/** Get the int value of a json_object + * + * The type is coerced to a int if the passed object is not a int. + * double objects will return their integer conversion. Strings will be + * parsed as an integer. If no conversion exists then 0 is returned. + * + * @param this the json_object instance + * @returns an int + */ +extern int json_object_get_int(struct json_object *this); + + +/* double type methods */ + +/** Create a new empty json_object of type json_type_double + * @param d the double + * @returns a json_object of type json_type_double + */ +extern struct json_object* json_object_new_double(double d); + +/** Get the double value of a json_object + * + * The type is coerced to a double if the passed object is not a double. + * integer objects will return their dboule conversion. Strings will be + * parsed as a double. If no conversion exists then 0.0 is returned. + * + * @param this the json_object instance + * @returns an double + */ +extern double json_object_get_double(struct json_object *this); + + +/* string type methods */ + +/** Create a new empty json_object of type json_type_string + * + * A copy of the string is made and the memory is managed by the json_object + * + * @param s the string + * @returns a json_object of type json_type_string + */ +extern struct json_object* json_object_new_string(char *s); + +extern struct json_object* json_object_new_string_len(char *s, int len); + +/** Get the string value of a json_object + * + * If the passed object is not of type json_type_string then the JSON + * representation of the object is returned. + * + * The returned string memory is managed by the json_object and will + * be freed when the reference count of the json_object drops to zero. + * + * @param this the json_object instance + * @returns a string + */ +extern char* json_object_get_string(struct json_object *this); + +#endif diff --git a/include/libjson/json_object_private.h b/include/libjson/json_object_private.h new file mode 100644 index 0000000..91ce99c --- /dev/null +++ b/include/libjson/json_object_private.h @@ -0,0 +1,25 @@ +#ifndef _json_object_private_h_ +#define _json_object_private_h_ + +typedef void (json_object_delete_fn)(struct json_object *o); +typedef int (json_object_to_json_string_fn)(struct json_object *o, + struct printbuf *pb); + +struct json_object +{ + enum json_type o_type; + json_object_delete_fn *_delete; + json_object_to_json_string_fn *_to_json_string; + int _ref_count; + struct printbuf *_pb; + union data { + boolean c_boolean; + double c_double; + int c_int; + struct lh_table *c_object; + struct array_list *c_array; + char *c_string; + } o; +}; + +#endif diff --git a/include/libjson/json_tokener.h b/include/libjson/json_tokener.h new file mode 100644 index 0000000..7ab2156 --- /dev/null +++ b/include/libjson/json_tokener.h @@ -0,0 +1,70 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _json_tokener_h_ +#define _json_tokener_h_ + +#include "libjson/json_object.h" + +enum json_tokener_error { + json_tokener_success, + json_tokener_error_parse_unexpected, + json_tokener_error_parse_null, + json_tokener_error_parse_boolean, + json_tokener_error_parse_number, + json_tokener_error_parse_array, + json_tokener_error_parse_object, + json_tokener_error_parse_string, + json_tokener_error_parse_comment, + json_tokener_error_parse_eof, +}; + +enum json_tokener_state { + json_tokener_state_eatws, + json_tokener_state_start, + json_tokener_state_finish, + json_tokener_state_null, + json_tokener_state_comment_start, + json_tokener_state_comment, + json_tokener_state_comment_eol, + json_tokener_state_comment_end, + json_tokener_state_string, + json_tokener_state_string_escape, + json_tokener_state_escape_unicode, + json_tokener_state_boolean, + json_tokener_state_number, + json_tokener_state_array, + json_tokener_state_array_sep, + json_tokener_state_object, + json_tokener_state_object_field_start, + json_tokener_state_object_field, + json_tokener_state_object_field_end, + json_tokener_state_object_value, + json_tokener_state_object_sep, +}; + +struct json_tokener +{ + char *source; + int pos; + struct printbuf *pb; +}; + +extern struct json_object* json_tokener_parse(char *s); + +#endif diff --git a/include/libjson/json_util.h b/include/libjson/json_util.h new file mode 100644 index 0000000..7627fb2 --- /dev/null +++ b/include/libjson/json_util.h @@ -0,0 +1,13 @@ +#ifndef _json_util_h_ +#define _json_util_h_ + +#include "libjson/json_object.h" + + +#define JSON_FILE_BUF_SIZE 4096 + +/* utlitiy functions */ +extern struct json_object* json_object_from_file(char *filename); +extern int json_object_to_file(char *filename, struct json_object *obj); + +#endif diff --git a/include/libjson/linkhash.h b/include/libjson/linkhash.h new file mode 100644 index 0000000..3439894 --- /dev/null +++ b/include/libjson/linkhash.h @@ -0,0 +1,270 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _linkhash_h_ +#define _linkhash_h_ + +/** + * golden prime used in hash functions + */ +#define LH_PRIME 0x9e370001UL + +/** + * sentinel pointer value for empty slots + */ +#define LH_EMPTY (void*)-1 + +/** + * sentinel pointer value for freed slots + */ +#define LH_FREED (void*)-2 + + +struct lh_entry; + + +/** + * callback function prototypes + */ +typedef void (lh_entry_free_fn) (struct lh_entry *e); +/** + * callback function prototypes + */ +typedef unsigned long (lh_hash_fn) (void *k); +/** + * callback function prototypes + */ +typedef int (lh_equal_fn) (void *k1, void *k2); + +/** + * An entry in the hash table + */ +struct lh_entry { + /** + * The key. + */ + void *k; + /** + * The value. + */ + void *v; + /** + * The next entry + */ + struct lh_entry *next; + /** + * The previous entry. + */ + struct lh_entry *prev; +}; + + +/** + * The hash table structure. + */ +struct lh_table { + /** + * Size of our hash. + */ + int size; + /** + * Numbers of entries. + */ + int count; + + /** + * Number of collisions. + */ + int collisions; + + /** + * Number of resizes. + */ + int resizes; + + /** + * Number of lookups. + */ + int lookups; + + /** + * Number of inserts. + */ + int inserts; + + /** + * Number of deletes. + */ + int deletes; + + /** + * Name of the hash table. + */ + char *name; + + /** + * The first entry. + */ + struct lh_entry *head; + + /** + * The last entry. + */ + struct lh_entry *tail; + + struct lh_entry *table; + + /** + * A pointer onto the function responsible for freeing an entry. + */ + lh_entry_free_fn *free_fn; + lh_hash_fn *hash_fn; + lh_equal_fn *equal_fn; +}; + + +/** + * Pre-defined hash and equality functions + */ +extern unsigned long lh_ptr_hash(void *k); +extern int lh_ptr_equal(void *k1, void *k2); + +extern unsigned long lh_char_hash(void *k); +extern int lh_char_equal(void *k1, void *k2); + + +/** + * Convenience list iterator. + */ +#define lh_foreach(table, entry) \ +for(entry = table->head; entry; entry = entry->next) + +/** + * lh_foreach_safe allows calling of deletion routine while iterating. + */ +#define lh_foreach_safe(table, entry, tmp) \ +for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp) + + + +/** + * Create a new linkhash table. + * @param size initial table size. The table is automatically resized + * although this incurs a performance penalty. + * @param name the table name. + * @param free_fn callback function used to free memory for entries + * when lh_table_free or lh_table_delete is called. + * If NULL is provided, then memory for keys and values + * must be freed by the caller. + * @param hash_fn function used to hash keys. 2 standard ones are defined: + * lh_ptr_hash and lh_char_hash for hashing pointer values + * and C strings respectively. + * @param equal_fn comparison function to compare keys. 2 standard ones defined: + * lh_ptr_hash and lh_char_hash for comparing pointer values + * and C strings respectively. + * @return a pointer onto the linkhash table. + */ +extern struct lh_table* lh_table_new(int size, char *name, + lh_entry_free_fn *free_fn, + lh_hash_fn *hash_fn, + lh_equal_fn *equal_fn); + +/** + * Convenience function to create a new linkhash + * table with char keys. + * @param size initial table size. + * @param name table name. + * @param free_fn callback function used to free memory for entries. + * @return a pointer onto the linkhash table. + */ +extern struct lh_table* lh_kchar_table_new(int size, char *name, + lh_entry_free_fn *free_fn); + + +/** + * Convenience function to create a new linkhash + * table with ptr keys. + * @param size initial table size. + * @param name table name. + * @param free_fn callback function used to free memory for entries. + * @return a pointer onto the linkhash table. + */ +extern struct lh_table* lh_kptr_table_new(int size, char *name, + lh_entry_free_fn *free_fn); + + +/** + * Free a linkhash table. + * If a callback free function is provided then it is called for all + * entries in the table. + * @param t table to free. + */ +extern void lh_table_free(struct lh_table *t); + + +/** + * Insert a record into the table. + * @param t the table to insert into. + * @param k a pointer to the key to insert. + * @param v a pointer to the value to insert. + */ +extern int lh_table_insert(struct lh_table *t, void *k, void *v); + + +/** + * Lookup a record into the table. + * @param t the table to lookup + * @param k a pointer to the key to lookup + * @return a pointer to the record structure of the value or NULL if it does not exist. + */ +extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k); + +/** + * Lookup a record into the table + * @param t the table to lookup + * @param k a pointer to the key to lookup + * @return a pointer to the found value or NULL if it does not exist. + */ +extern void* lh_table_lookup(struct lh_table *t, void *k); + + +/** + * Delete a record from the table. + * If a callback free function is provided then it is called for the + * for the item being deleted. + * @param t the table to delete from. + * @param e a pointer to the entry to delete. + * @return 0 if the item was deleted. + * @return -1 if it was not found. + */ +extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e); + + +/** + * Delete a record from the table. + * If a callback free function is provided then it is called for the + * for the item being deleted. + * @param t the table to delete from. + * @param k a pointer to the key to delete. + * @return 0 if the item was deleted. + * @return -1 if it was not found. + */ +extern int lh_table_delete(struct lh_table *t, void *k); + + +#endif diff --git a/include/libjson/printbuf.h b/include/libjson/printbuf.h new file mode 100644 index 0000000..0eacdb1 --- /dev/null +++ b/include/libjson/printbuf.h @@ -0,0 +1,43 @@ +/* + * $Id$ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#ifndef _printbuf_h_ +#define _printbuf_h_ + +struct printbuf { + char *buf; + int bpos; + int size; +}; + +extern struct printbuf* +printbuf_new(); + +extern int +printbuf_memappend(struct printbuf *p, char *buf, int size); + +extern int +sprintbuf(struct printbuf *p, const char *msg, ...); + +extern void +printbuf_reset(struct printbuf *p); + +extern void +printbuf_free(struct printbuf *p); + +#endif -- 2.43.2