fix indenting
This commit is contained in:
parent
3947d443fa
commit
ab4514d1e5
|
@ -134,11 +134,11 @@
|
|||
* mpool_resize only.
|
||||
*/
|
||||
typedef void (*mpool_log_func_t)(const void *mp_p,
|
||||
const int func_id,
|
||||
const unsigned long byte_size,
|
||||
const unsigned long ele_n,
|
||||
const void *old_addr, const void *new_addr,
|
||||
const unsigned long old_byte_size);
|
||||
const int func_id,
|
||||
const unsigned long byte_size,
|
||||
const unsigned long ele_n,
|
||||
const void *old_addr, const void *new_addr,
|
||||
const unsigned long old_byte_size);
|
||||
|
||||
#ifdef MPOOL_MAIN
|
||||
|
||||
|
@ -183,7 +183,7 @@ typedef void mpool_t;
|
|||
*/
|
||||
extern
|
||||
mpool_t *mpool_open(const unsigned int flags, const unsigned int page_size,
|
||||
void *start_addr, int *error_p);
|
||||
void *start_addr, int *error_p);
|
||||
|
||||
/*
|
||||
* int mpool_close
|
||||
|
@ -251,7 +251,7 @@ int mpool_clear(mpool_t *mp_p);
|
|||
*/
|
||||
extern
|
||||
void *mpool_alloc(mpool_t *mp_p, const unsigned long byte_size,
|
||||
int *error_p);
|
||||
int *error_p);
|
||||
|
||||
/*
|
||||
* void *mpool_calloc
|
||||
|
@ -281,7 +281,7 @@ void *mpool_alloc(mpool_t *mp_p, const unsigned long byte_size,
|
|||
*/
|
||||
extern
|
||||
void *mpool_calloc(mpool_t *mp_p, const unsigned long ele_n,
|
||||
const unsigned long ele_size, int *error_p);
|
||||
const unsigned long ele_size, int *error_p);
|
||||
|
||||
/*
|
||||
* int mpool_free
|
||||
|
@ -341,9 +341,9 @@ int mpool_free(mpool_t *mp_p, void *addr, const unsigned long size);
|
|||
*/
|
||||
extern
|
||||
void *mpool_resize(mpool_t *mp_p, void *old_addr,
|
||||
const unsigned long old_byte_size,
|
||||
const unsigned long new_byte_size,
|
||||
int *error_p);
|
||||
const unsigned long old_byte_size,
|
||||
const unsigned long new_byte_size,
|
||||
int *error_p);
|
||||
|
||||
/*
|
||||
* int mpool_stats
|
||||
|
@ -381,10 +381,10 @@ void *mpool_resize(mpool_t *mp_p, void *old_addr,
|
|||
*/
|
||||
extern
|
||||
int mpool_stats(const mpool_t *mp_p, unsigned int *page_size_p,
|
||||
unsigned long *num_alloced_p,
|
||||
unsigned long *user_alloced_p,
|
||||
unsigned long *max_alloced_p,
|
||||
unsigned long *tot_alloced_p);
|
||||
unsigned long *num_alloced_p,
|
||||
unsigned long *user_alloced_p,
|
||||
unsigned long *max_alloced_p,
|
||||
unsigned long *tot_alloced_p);
|
||||
|
||||
/*
|
||||
* int mpool_set_log_func
|
||||
|
@ -461,3 +461,14 @@ const char *mpool_strerror(const int error);
|
|||
/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
|
||||
|
||||
#endif /* ! __MPOOL_H__ */
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -83,25 +83,25 @@
|
|||
* were about 2^68 hashes to choose from. I only tested about a
|
||||
* billion of those.
|
||||
*/
|
||||
#define HASH_MIX(a, b, c) \
|
||||
do { \
|
||||
a -= b; a -= c; a ^= (c >> 13); \
|
||||
b -= c; b -= a; b ^= (a << 8); \
|
||||
c -= a; c -= b; c ^= (b >> 13); \
|
||||
a -= b; a -= c; a ^= (c >> 12); \
|
||||
b -= c; b -= a; b ^= (a << 16); \
|
||||
c -= a; c -= b; c ^= (b >> 5); \
|
||||
a -= b; a -= c; a ^= (c >> 3); \
|
||||
b -= c; b -= a; b ^= (a << 10); \
|
||||
c -= a; c -= b; c ^= (b >> 15); \
|
||||
} while(0)
|
||||
#define HASH_MIX(a, b, c) \
|
||||
do { \
|
||||
a -= b; a -= c; a ^= (c >> 13); \
|
||||
b -= c; b -= a; b ^= (a << 8); \
|
||||
c -= a; c -= b; c ^= (b >> 13); \
|
||||
a -= b; a -= c; a ^= (c >> 12); \
|
||||
b -= c; b -= a; b ^= (a << 16); \
|
||||
c -= a; c -= b; c ^= (b >> 5); \
|
||||
a -= b; a -= c; a ^= (c >> 3); \
|
||||
b -= c; b -= a; b ^= (a << 10); \
|
||||
c -= a; c -= b; c ^= (b >> 15); \
|
||||
} while(0)
|
||||
|
||||
#define SET_POINTER(pnt, val) \
|
||||
do { \
|
||||
if ((pnt) != NULL) { \
|
||||
(*(pnt)) = (val); \
|
||||
} \
|
||||
} while(0)
|
||||
#define SET_POINTER(pnt, val) \
|
||||
do { \
|
||||
if ((pnt) != NULL) { \
|
||||
(*(pnt)) = (val); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/*
|
||||
* The following macros take care of the mmap case. When we are
|
||||
|
@ -117,9 +117,9 @@
|
|||
|
||||
#else
|
||||
|
||||
#define TABLE_POINTER(tab_p, type, pnt) \
|
||||
((tab_p)->ta_mmap == NULL || (pnt) == NULL ? (pnt) : \
|
||||
(type)((char *)((tab_p)->ta_mmap) + (long)(pnt)))
|
||||
#define TABLE_POINTER(tab_p, type, pnt) \
|
||||
((tab_p)->ta_mmap == NULL || (pnt) == NULL ? (pnt) : \
|
||||
(type)((char *)((tab_p)->ta_mmap) + (long)(pnt)))
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -127,8 +127,8 @@
|
|||
* Macros to get at the key and the data pointers
|
||||
*/
|
||||
#define ENTRY_KEY_BUF(entry_p) ((entry_p)->te_key_buf)
|
||||
#define ENTRY_DATA_BUF(tab_p, entry_p) \
|
||||
(ENTRY_KEY_BUF(entry_p) + (entry_p)->te_key_size)
|
||||
#define ENTRY_DATA_BUF(tab_p, entry_p) \
|
||||
(ENTRY_KEY_BUF(entry_p) + (entry_p)->te_key_size)
|
||||
|
||||
/*
|
||||
* Table structures...
|
||||
|
@ -142,10 +142,10 @@
|
|||
* faster.
|
||||
*/
|
||||
typedef struct table_shell_st {
|
||||
unsigned int te_key_size; /* size of data */
|
||||
unsigned int te_data_size; /* size of data */
|
||||
struct table_shell_st *te_next_p; /* pointer to next in the list */
|
||||
/* NOTE: this does not have the te_key_buf field here */
|
||||
unsigned int te_key_size; /* size of data */
|
||||
unsigned int te_data_size; /* size of data */
|
||||
struct table_shell_st *te_next_p; /* pointer to next in the list */
|
||||
/* NOTE: this does not have the te_key_buf field here */
|
||||
} table_shell_t;
|
||||
|
||||
/*
|
||||
|
@ -157,10 +157,10 @@ typedef struct table_shell_st {
|
|||
* changed to match.
|
||||
*/
|
||||
typedef struct table_entry_st {
|
||||
unsigned int te_key_size; /* size of data */
|
||||
unsigned int te_data_size; /* size of data */
|
||||
struct table_entry_st *te_next_p; /* pointer to next in the list */
|
||||
unsigned char te_key_buf[1]; /* 1st byte of key buf */
|
||||
unsigned int te_key_size; /* size of data */
|
||||
unsigned int te_data_size; /* size of data */
|
||||
struct table_entry_st *te_next_p; /* pointer to next in the list */
|
||||
unsigned char te_key_buf[1]; /* 1st byte of key buf */
|
||||
} table_entry_t;
|
||||
|
||||
/* external structure for debuggers be able to see void */
|
||||
|
@ -168,20 +168,20 @@ typedef table_entry_t table_entry_ext_t;
|
|||
|
||||
/* main table structure */
|
||||
typedef struct table_st {
|
||||
unsigned int ta_magic; /* magic number */
|
||||
unsigned int ta_flags; /* table's flags defined in table.h */
|
||||
unsigned int ta_bucket_n; /* num of buckets, should be 2^X */
|
||||
unsigned int ta_entry_n; /* num of entries in all buckets */
|
||||
unsigned int ta_data_align; /* data alignment value */
|
||||
table_entry_t **ta_buckets; /* array of linked lists */
|
||||
table_linear_t ta_linear; /* linear tracking */
|
||||
struct table_st *ta_mmap; /* mmaped table */
|
||||
unsigned long ta_file_size; /* size of on-disk space */
|
||||
unsigned int ta_magic; /* magic number */
|
||||
unsigned int ta_flags; /* table's flags defined in table.h */
|
||||
unsigned int ta_bucket_n; /* num of buckets, should be 2^X */
|
||||
unsigned int ta_entry_n; /* num of entries in all buckets */
|
||||
unsigned int ta_data_align; /* data alignment value */
|
||||
table_entry_t **ta_buckets; /* array of linked lists */
|
||||
table_linear_t ta_linear; /* linear tracking */
|
||||
struct table_st *ta_mmap; /* mmaped table */
|
||||
unsigned long ta_file_size; /* size of on-disk space */
|
||||
|
||||
void *ta_mem_pool; /* pointer to some memory pool */
|
||||
table_mem_alloc_t ta_alloc_func; /* memory allocation function */
|
||||
table_mem_resize_t ta_resize_func; /* memory resize function */
|
||||
table_mem_free_t ta_free_func; /* memory free function */
|
||||
void *ta_mem_pool; /* pointer to some memory pool */
|
||||
table_mem_alloc_t ta_alloc_func; /* memory allocation function */
|
||||
table_mem_resize_t ta_resize_func; /* memory resize function */
|
||||
table_mem_free_t ta_free_func; /* memory free function */
|
||||
} table_t;
|
||||
|
||||
/* external table structure for debuggers */
|
||||
|
@ -189,41 +189,53 @@ typedef table_t table_ext_t;
|
|||
|
||||
/* local comparison functions */
|
||||
typedef int (*compare_t)(const void *element1_p, const void *element2_p,
|
||||
table_compare_t user_compare,
|
||||
const table_t *table_p, int *err_bp);
|
||||
table_compare_t user_compare,
|
||||
const table_t *table_p, int *err_bp);
|
||||
|
||||
/*
|
||||
* to map error to string
|
||||
*/
|
||||
typedef struct {
|
||||
int es_error; /* error number */
|
||||
char *es_string; /* assocaited string */
|
||||
int es_error; /* error number */
|
||||
char *es_string; /* assocaited string */
|
||||
} error_str_t;
|
||||
|
||||
static error_str_t errors[] = {
|
||||
{ TABLE_ERROR_NONE, "no error" },
|
||||
{ TABLE_ERROR_PNT, "invalid table pointer" },
|
||||
{ TABLE_ERROR_ARG_NULL, "buffer argument is null" },
|
||||
{ TABLE_ERROR_SIZE, "incorrect size argument" },
|
||||
{ TABLE_ERROR_OVERWRITE, "key exists and no overwrite" },
|
||||
{ TABLE_ERROR_NOT_FOUND, "key does not exist" },
|
||||
{ TABLE_ERROR_ALLOC, "error allocating memory" },
|
||||
{ TABLE_ERROR_LINEAR, "linear access not in progress" },
|
||||
{ TABLE_ERROR_OPEN, "could not open file" },
|
||||
{ TABLE_ERROR_SEEK, "could not seek to position in file" },
|
||||
{ TABLE_ERROR_READ, "could not read from file" },
|
||||
{ TABLE_ERROR_WRITE, "could not write to file" },
|
||||
{ TABLE_ERROR_MMAP_NONE, "no mmap support compiled in library" },
|
||||
{ TABLE_ERROR_MMAP, "could not mmap the file" },
|
||||
{ TABLE_ERROR_MMAP_OP, "operation not valid on mmap files" },
|
||||
{ TABLE_ERROR_EMPTY, "table is empty" },
|
||||
{ TABLE_ERROR_NOT_EMPTY, "table contains data" },
|
||||
{ TABLE_ERROR_ALIGNMENT, "invalid alignment value" },
|
||||
{ TABLE_ERROR_COMPARE, "problems with internal comparison" },
|
||||
{ TABLE_ERROR_FREE, "memory free error" },
|
||||
{ 0 }
|
||||
{ TABLE_ERROR_NONE, "no error" },
|
||||
{ TABLE_ERROR_PNT, "invalid table pointer" },
|
||||
{ TABLE_ERROR_ARG_NULL, "buffer argument is null" },
|
||||
{ TABLE_ERROR_SIZE, "incorrect size argument" },
|
||||
{ TABLE_ERROR_OVERWRITE, "key exists and no overwrite" },
|
||||
{ TABLE_ERROR_NOT_FOUND, "key does not exist" },
|
||||
{ TABLE_ERROR_ALLOC, "error allocating memory" },
|
||||
{ TABLE_ERROR_LINEAR, "linear access not in progress" },
|
||||
{ TABLE_ERROR_OPEN, "could not open file" },
|
||||
{ TABLE_ERROR_SEEK, "could not seek to position in file" },
|
||||
{ TABLE_ERROR_READ, "could not read from file" },
|
||||
{ TABLE_ERROR_WRITE, "could not write to file" },
|
||||
{ TABLE_ERROR_MMAP_NONE, "no mmap support compiled in library" },
|
||||
{ TABLE_ERROR_MMAP, "could not mmap the file" },
|
||||
{ TABLE_ERROR_MMAP_OP, "operation not valid on mmap files" },
|
||||
{ TABLE_ERROR_EMPTY, "table is empty" },
|
||||
{ TABLE_ERROR_NOT_EMPTY, "table contains data" },
|
||||
{ TABLE_ERROR_ALIGNMENT, "invalid alignment value" },
|
||||
{ TABLE_ERROR_COMPARE, "problems with internal comparison" },
|
||||
{ TABLE_ERROR_FREE, "memory free error" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
#define INVALID_ERROR "invalid error code"
|
||||
|
||||
#endif /* ! __TABLE_LOC_H__ */
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,12 +26,12 @@
|
|||
#include <errno.h> /* for setting errno */
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
/* not in Windows! */
|
||||
/* not in Windows! */
|
||||
# include <unistd.h>
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#ifndef SIMCLIST_NO_DUMPRESTORE
|
||||
/* includes for dump/restore */
|
||||
/* includes for dump/restore */
|
||||
# include <time.h>
|
||||
# include <sys/uio.h> /* for READ_ERRCHECK() and write() */
|
||||
# include <fcntl.h> /* for open() etc */
|
||||
|
@ -88,31 +88,31 @@ typedef INT64 int64_t;
|
|||
/* define some commodity macros for Dump/Restore functionality */
|
||||
#ifndef SIMCLIST_NO_DUMPRESTORE
|
||||
/* write() decorated with error checking logic */
|
||||
#define WRITE_ERRCHECK(fd, msgbuf, msglen) do { \
|
||||
if (write(fd, msgbuf, msglen) < 0) return -1; \
|
||||
} while (0);
|
||||
#define WRITE_ERRCHECK(fd, msgbuf, msglen) do { \
|
||||
if (write(fd, msgbuf, msglen) < 0) return -1; \
|
||||
} while (0);
|
||||
/* READ_ERRCHECK() decorated with error checking logic */
|
||||
#define READ_ERRCHECK(fd, msgbuf, msglen) do { \
|
||||
if (read(fd, msgbuf, msglen) != msglen) { \
|
||||
/*errno = EPROTO;*/ \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0);
|
||||
#define READ_ERRCHECK(fd, msgbuf, msglen) do { \
|
||||
if (read(fd, msgbuf, msglen) != msglen) { \
|
||||
/*errno = EPROTO;*/ \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
/* convert 64bit integers from host to network format */
|
||||
#define hton64(x) (\
|
||||
htons(1) == 1 ? \
|
||||
(uint64_t)x /* big endian */ \
|
||||
: /* little endian */ \
|
||||
((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \
|
||||
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
|
||||
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
|
||||
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
|
||||
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
|
||||
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
|
||||
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
|
||||
(((uint64_t)(x) & 0x00000000000000ffULL) << 56))) \
|
||||
)
|
||||
#define hton64(x) ( \
|
||||
htons(1) == 1 ? \
|
||||
(uint64_t)x /* big endian */ \
|
||||
: /* little endian */ \
|
||||
((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \
|
||||
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
|
||||
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
|
||||
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
|
||||
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
|
||||
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
|
||||
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
|
||||
(((uint64_t)(x) & 0x00000000000000ffULL) << 56))) \
|
||||
)
|
||||
|
||||
/* convert 64bit integers from network to host format */
|
||||
#define ntoh64(x) (hton64(x))
|
||||
|
@ -206,12 +206,12 @@ static int list_attrOk(const list_t *restrict l);
|
|||
|
||||
/* do not inline, this is recursive */
|
||||
static void list_sort_quicksort(list_t *restrict l, int versus,
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel);
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel);
|
||||
|
||||
static inline void list_sort_selectionsort(list_t *restrict l, int versus,
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel);
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel);
|
||||
|
||||
static void *list_get_minmax(const list_t *restrict l, int versus);
|
||||
|
||||
|
@ -792,8 +792,8 @@ static void *list_sort_quicksort_threadwrapper(void *wrapped_params) {
|
|||
#endif
|
||||
|
||||
static inline void list_sort_selectionsort(list_t *restrict l, int versus,
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel) {
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel) {
|
||||
struct list_entry_s *cursor, *toswap, *firstunsorted;
|
||||
void *tmpdata;
|
||||
|
||||
|
@ -813,8 +813,8 @@ static inline void list_sort_selectionsort(list_t *restrict l, int versus,
|
|||
}
|
||||
|
||||
static void list_sort_quicksort(list_t *restrict l, int versus,
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel) {
|
||||
unsigned int first, struct list_entry_s *fel,
|
||||
unsigned int last, struct list_entry_s *lel) {
|
||||
unsigned int pivotid;
|
||||
unsigned int i;
|
||||
register struct list_entry_s *pivot;
|
||||
|
@ -1094,15 +1094,15 @@ int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict
|
|||
|
||||
/**** DUMP FORMAT ****
|
||||
|
||||
[ ver timestamp | totlen numels elemlen hash | DATA ]
|
||||
[ ver timestamp | totlen numels elemlen hash | DATA ]
|
||||
|
||||
where DATA can be:
|
||||
@ for constant-size list (element size is constant; elemlen > 0)
|
||||
[ elem elem ... elem ]
|
||||
@ for other lists (element size dictated by element_meter each time; elemlen <= 0)
|
||||
[ size elem size elem ... size elem ]
|
||||
where DATA can be:
|
||||
@ for constant-size list (element size is constant; elemlen > 0)
|
||||
[ elem elem ... elem ]
|
||||
@ for other lists (element size dictated by element_meter each time; elemlen <= 0)
|
||||
[ size elem size elem ... size elem ]
|
||||
|
||||
all integers are encoded in NETWORK BYTE FORMAT
|
||||
all integers are encoded in NETWORK BYTE FORMAT
|
||||
*****/
|
||||
|
||||
|
||||
|
@ -1327,10 +1327,10 @@ int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len
|
|||
/* possibly verify the list consistency */
|
||||
/* wrt hash */
|
||||
/* don't do that
|
||||
if (header.listhash != 0 && header.listhash != list_hash(l)) {
|
||||
errno = ECANCELED;
|
||||
return -1;
|
||||
}
|
||||
if (header.listhash != 0 && header.listhash != list_hash(l)) {
|
||||
errno = ECANCELED;
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
/* wrt header */
|
||||
|
@ -1487,14 +1487,14 @@ static int list_repOk(const list_t *restrict l) {
|
|||
struct list_entry_s *s;
|
||||
|
||||
ok = (l != NULL) && (
|
||||
/* head/tail checks */
|
||||
(l->head_sentinel != NULL && l->tail_sentinel != NULL) &&
|
||||
(l->head_sentinel != l->tail_sentinel) && (l->head_sentinel->prev == NULL && l->tail_sentinel->next == NULL) &&
|
||||
/* empty list */
|
||||
(l->numels > 0 || (l->mid == NULL && l->head_sentinel->next == l->tail_sentinel && l->tail_sentinel->prev == l->head_sentinel)) &&
|
||||
/* spare elements checks */
|
||||
l->spareelsnum <= SIMCLIST_MAX_SPARE_ELEMS
|
||||
);
|
||||
/* head/tail checks */
|
||||
(l->head_sentinel != NULL && l->tail_sentinel != NULL) &&
|
||||
(l->head_sentinel != l->tail_sentinel) && (l->head_sentinel->prev == NULL && l->tail_sentinel->next == NULL) &&
|
||||
/* empty list */
|
||||
(l->numels > 0 || (l->mid == NULL && l->head_sentinel->next == l->tail_sentinel && l->tail_sentinel->prev == l->head_sentinel)) &&
|
||||
/* spare elements checks */
|
||||
l->spareelsnum <= SIMCLIST_MAX_SPARE_ELEMS
|
||||
);
|
||||
|
||||
if (!ok) return 0;
|
||||
|
||||
|
@ -1523,3 +1523,13 @@ static int list_attrOk(const list_t *restrict l) {
|
|||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -28,7 +28,7 @@
|
|||
#include "table.h"
|
||||
|
||||
static char *rcs_id =
|
||||
"$Id: table_util.c,v 1.5 2000/03/09 03:30:42 gray Exp $";
|
||||
"$Id: table_util.c,v 1.5 2000/03/09 03:30:42 gray Exp $";
|
||||
|
||||
#define WRITE_MODE 0640 /* mode to write out table */
|
||||
#define SPECIAL_CHARS "e\033^^\"\"''\\\\n\nr\rt\tb\bf\fa\007"
|
||||
|
@ -61,67 +61,67 @@ static char *rcs_id =
|
|||
* out_size - size of the output buffer.
|
||||
*/
|
||||
int expand_chars(const void *buf, const int buf_size,
|
||||
char *out, const int out_size)
|
||||
char *out, const int out_size)
|
||||
{
|
||||
int buf_c;
|
||||
const unsigned char *buf_p, *spec_p;
|
||||
char *max_p, *out_p = out;
|
||||
int buf_c;
|
||||
const unsigned char *buf_p, *spec_p;
|
||||
char *max_p, *out_p = out;
|
||||
|
||||
/* setup our max pointer */
|
||||
max_p = out + out_size;
|
||||
/* setup our max pointer */
|
||||
max_p = out + out_size;
|
||||
|
||||
/* run through the input buffer, counting the characters as we go */
|
||||
for (buf_c = 0, buf_p = (const unsigned char *)buf;; buf_c++, buf_p++) {
|
||||
/* run through the input buffer, counting the characters as we go */
|
||||
for (buf_c = 0, buf_p = (const unsigned char *)buf;; buf_c++, buf_p++) {
|
||||
|
||||
/* did we reach the end of the buffer? */
|
||||
if (buf_size < 0) {
|
||||
if (*buf_p == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (buf_c >= buf_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* did we reach the end of the buffer? */
|
||||
if (buf_size < 0) {
|
||||
if (*buf_p == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (buf_c >= buf_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* search for special characters */
|
||||
for (spec_p = (unsigned char *)SPECIAL_CHARS + 1;
|
||||
*(spec_p - 1) != '\0';
|
||||
spec_p += 2) {
|
||||
if (*spec_p == *buf_p) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* search for special characters */
|
||||
for (spec_p = (unsigned char *)SPECIAL_CHARS + 1;
|
||||
*(spec_p - 1) != '\0';
|
||||
spec_p += 2) {
|
||||
if (*spec_p == *buf_p) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* did we find one? */
|
||||
if (*(spec_p - 1) != '\0') {
|
||||
if (out_p + 2 >= max_p) {
|
||||
break;
|
||||
}
|
||||
(void)sprintf(out_p, "\\%c", *(spec_p - 1));
|
||||
out_p += 2;
|
||||
continue;
|
||||
}
|
||||
/* did we find one? */
|
||||
if (*(spec_p - 1) != '\0') {
|
||||
if (out_p + 2 >= max_p) {
|
||||
break;
|
||||
}
|
||||
(void)sprintf(out_p, "\\%c", *(spec_p - 1));
|
||||
out_p += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* print out any 7-bit printable characters */
|
||||
if (*buf_p < 128 && isprint(*buf_p)) {
|
||||
if (out_p + 1 >= max_p) {
|
||||
break;
|
||||
}
|
||||
*out_p = *(char *)buf_p;
|
||||
out_p += 1;
|
||||
}
|
||||
else {
|
||||
if (out_p + 4 >= max_p) {
|
||||
break;
|
||||
}
|
||||
(void)sprintf(out_p, "\\%03o", *buf_p);
|
||||
out_p += 4;
|
||||
}
|
||||
}
|
||||
/* print out any 7-bit printable characters */
|
||||
if (*buf_p < 128 && isprint(*buf_p)) {
|
||||
if (out_p + 1 >= max_p) {
|
||||
break;
|
||||
}
|
||||
*out_p = *(char *)buf_p;
|
||||
out_p += 1;
|
||||
}
|
||||
else {
|
||||
if (out_p + 4 >= max_p) {
|
||||
break;
|
||||
}
|
||||
(void)sprintf(out_p, "\\%03o", *buf_p);
|
||||
out_p += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return out_p - out;
|
||||
return out_p - out;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -141,22 +141,22 @@ int expand_chars(const void *buf, const int buf_size,
|
|||
*/
|
||||
static void dump_table(table_t *tab_p)
|
||||
{
|
||||
char buf[10240];
|
||||
void *key_p, *data_p;
|
||||
int ret, key_size, data_size, len, entry_c;
|
||||
char buf[10240];
|
||||
void *key_p, *data_p;
|
||||
int ret, key_size, data_size, len, entry_c;
|
||||
|
||||
for (ret = table_first(tab_p, (void **)&key_p, &key_size,
|
||||
(void **)&data_p, &data_size), entry_c = 0;
|
||||
ret == TABLE_ERROR_NONE;
|
||||
ret = table_next(tab_p, (void **)&key_p, &key_size,
|
||||
(void **)&data_p, &data_size), entry_c++) {
|
||||
/* expand the key */
|
||||
len = expand_chars(key_p, key_size, buf, sizeof(buf));
|
||||
(void)printf("%d: key '%.*s' (%d), ", entry_c, len, buf, len);
|
||||
/* now dump the data */
|
||||
len = expand_chars(data_p, data_size, buf, sizeof(buf));
|
||||
(void)printf("data '%.*s' (%d)\n", len, buf, len);
|
||||
}
|
||||
for (ret = table_first(tab_p, (void **)&key_p, &key_size,
|
||||
(void **)&data_p, &data_size), entry_c = 0;
|
||||
ret == TABLE_ERROR_NONE;
|
||||
ret = table_next(tab_p, (void **)&key_p, &key_size,
|
||||
(void **)&data_p, &data_size), entry_c++) {
|
||||
/* expand the key */
|
||||
len = expand_chars(key_p, key_size, buf, sizeof(buf));
|
||||
(void)printf("%d: key '%.*s' (%d), ", entry_c, len, buf, len);
|
||||
/* now dump the data */
|
||||
len = expand_chars(data_p, data_size, buf, sizeof(buf));
|
||||
(void)printf("data '%.*s' (%d)\n", len, buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -176,120 +176,131 @@ static void dump_table(table_t *tab_p)
|
|||
*/
|
||||
static void usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"Usage: table_util\n"
|
||||
" [-b number] or --buckets num buckets to adjust table\n"
|
||||
" [-o file] or --out-file output filename\n"
|
||||
" [-v] or --verbose verbose messages\n"
|
||||
" file input table filename\n");
|
||||
exit(1);
|
||||
(void)fprintf(stderr,
|
||||
"Usage: table_util\n"
|
||||
" [-b number] or --buckets num buckets to adjust table\n"
|
||||
" [-o file] or --out-file output filename\n"
|
||||
" [-v] or --verbose verbose messages\n"
|
||||
" file input table filename\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
table_t *tab_p;
|
||||
char do_write = 0, verbose = 0;
|
||||
char *out_file = NULL, *in_file;
|
||||
int ret, entry_n, bucket_n, num_buckets = 0;
|
||||
table_t *tab_p;
|
||||
char do_write = 0, verbose = 0;
|
||||
char *out_file = NULL, *in_file;
|
||||
int ret, entry_n, bucket_n, num_buckets = 0;
|
||||
|
||||
/* process the args */
|
||||
for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++) {
|
||||
/* process the args */
|
||||
for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++) {
|
||||
|
||||
switch (*(*argv + 1)) {
|
||||
switch (*(*argv + 1)) {
|
||||
|
||||
case 'b':
|
||||
argc--, argv++;
|
||||
if (argc == 0) {
|
||||
usage();
|
||||
}
|
||||
num_buckets = atoi(*argv);
|
||||
break;
|
||||
case 'b':
|
||||
argc--, argv++;
|
||||
if (argc == 0) {
|
||||
usage();
|
||||
}
|
||||
num_buckets = atoi(*argv);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
argc--, argv++;
|
||||
if (argc == 0) {
|
||||
usage();
|
||||
}
|
||||
out_file = *argv;
|
||||
break;
|
||||
case 'o':
|
||||
argc--, argv++;
|
||||
if (argc == 0) {
|
||||
usage();
|
||||
}
|
||||
out_file = *argv;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc != 1) {
|
||||
usage();
|
||||
}
|
||||
if (argc != 1) {
|
||||
usage();
|
||||
}
|
||||
|
||||
/* take the last argument as the input file */
|
||||
in_file = *argv;
|
||||
/* take the last argument as the input file */
|
||||
in_file = *argv;
|
||||
|
||||
/* read in the table from disk */
|
||||
tab_p = table_read(in_file, &ret);
|
||||
if (tab_p == NULL) {
|
||||
(void)fprintf(stderr, "table_util: unable to table_read from '%s': %s\n",
|
||||
in_file, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
/* read in the table from disk */
|
||||
tab_p = table_read(in_file, &ret);
|
||||
if (tab_p == NULL) {
|
||||
(void)fprintf(stderr, "table_util: unable to table_read from '%s': %s\n",
|
||||
in_file, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* get info about the table */
|
||||
ret = table_info(tab_p, &bucket_n, &entry_n);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr,
|
||||
"table_util: unable to get info on table in '%s': %s\n",
|
||||
in_file, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
/* get info about the table */
|
||||
ret = table_info(tab_p, &bucket_n, &entry_n);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr,
|
||||
"table_util: unable to get info on table in '%s': %s\n",
|
||||
in_file, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
(void)printf("Read table of %d buckets and %d entries from '%s'\n",
|
||||
bucket_n, entry_n, in_file);
|
||||
(void)printf("Read table of %d buckets and %d entries from '%s'\n",
|
||||
bucket_n, entry_n, in_file);
|
||||
|
||||
if (verbose) {
|
||||
dump_table(tab_p);
|
||||
}
|
||||
if (verbose) {
|
||||
dump_table(tab_p);
|
||||
}
|
||||
|
||||
if (num_buckets > 0) {
|
||||
/* adjust the table's buckets */
|
||||
ret = table_adjust(tab_p, num_buckets);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr,
|
||||
"table_util: unable to adjust table to %d buckets: %s\n",
|
||||
num_buckets, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
do_write = 1;
|
||||
}
|
||||
if (num_buckets > 0) {
|
||||
/* adjust the table's buckets */
|
||||
ret = table_adjust(tab_p, num_buckets);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr,
|
||||
"table_util: unable to adjust table to %d buckets: %s\n",
|
||||
num_buckets, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
do_write = 1;
|
||||
}
|
||||
|
||||
/* did we modify the table at all */
|
||||
if (do_write) {
|
||||
if (out_file == NULL) {
|
||||
out_file = in_file;
|
||||
}
|
||||
/* did we modify the table at all */
|
||||
if (do_write) {
|
||||
if (out_file == NULL) {
|
||||
out_file = in_file;
|
||||
}
|
||||
|
||||
/* write out our table */
|
||||
ret = table_write(tab_p, out_file, WRITE_MODE);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr, "table_util: unable to write table to '%s': %s\n",
|
||||
out_file, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
/* write out our table */
|
||||
ret = table_write(tab_p, out_file, WRITE_MODE);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr, "table_util: unable to write table to '%s': %s\n",
|
||||
out_file, table_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
(void)printf("Wrote table to '%s'\n", out_file);
|
||||
}
|
||||
(void)printf("Wrote table to '%s'\n", out_file);
|
||||
}
|
||||
|
||||
/* free the table */
|
||||
ret = table_free(tab_p);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr, "table_util: unable to free table: %s\n",
|
||||
table_strerror(ret));
|
||||
/* NOTE: not a critical error */
|
||||
}
|
||||
/* free the table */
|
||||
ret = table_free(tab_p);
|
||||
if (ret != TABLE_ERROR_NONE) {
|
||||
(void)fprintf(stderr, "table_util: unable to free table: %s\n",
|
||||
table_strerror(ret));
|
||||
/* NOTE: not a critical error */
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue