Commit d0cf9fe0 authored by Michael Smith's avatar Michael Smith

Brendan was getting pissed off about inconsistent indentation styles.

Convert all tabs to 4 spaces. All code must now use 4 space indents.

svn path=/trunk/avl/; revision=4492
parent 6198c728
This diff is collapsed.
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 by Sam Rushing <rushing@nightmare.com>
*/
/* $Id: avl.h,v 1.5 2003/03/09 22:56:46 karl Exp $ */
/* $Id: avl.h,v 1.6 2003/03/15 02:10:18 msmith Exp $ */
#ifndef __AVL_H
#define __AVL_H
......@@ -22,24 +22,24 @@ extern "C" {
#endif
typedef struct avl_node_tag {
void * key;
struct avl_node_tag * left;
struct avl_node_tag * right;
struct avl_node_tag * parent;
void * key;
struct avl_node_tag * left;
struct avl_node_tag * right;
struct avl_node_tag * parent;
/*
* The lower 2 bits of <rank_and_balance> specify the balance
* factor: 00==-1, 01==0, 10==+1.
* The rest of the bits are used for <rank>
*/
unsigned long rank_and_balance;
unsigned long rank_and_balance;
#ifndef NO_THREAD
rwlock_t rwlock;
#endif
} avl_node;
#define AVL_GET_BALANCE(n) ((int)(((n)->rank_and_balance & 3) - 1))
#define AVL_GET_BALANCE(n) ((int)(((n)->rank_and_balance & 3) - 1))
#define AVL_GET_RANK(n) (((n)->rank_and_balance >> 2))
#define AVL_GET_RANK(n) (((n)->rank_and_balance >> 2))
#define AVL_SET_BALANCE(n,b) \
((n)->rank_and_balance) = \
......@@ -51,11 +51,11 @@ typedef struct avl_node_tag {
struct _avl_tree;
typedef int (*avl_key_compare_fun_type) (void * compare_arg, void * a, void * b);
typedef int (*avl_iter_fun_type) (void * key, void * iter_arg);
typedef int (*avl_iter_index_fun_type) (unsigned long index, void * key, void * iter_arg);
typedef int (*avl_free_key_fun_type) (void * key);
typedef int (*avl_key_printer_fun_type) (char *, void *);
typedef int (*avl_key_compare_fun_type) (void * compare_arg, void * a, void * b);
typedef int (*avl_iter_fun_type) (void * key, void * iter_arg);
typedef int (*avl_iter_index_fun_type) (unsigned long index, void * key, void * iter_arg);
typedef int (*avl_free_key_fun_type) (void * key);
typedef int (*avl_key_printer_fun_type) (char *, void *);
/*
* <compare_fun> and <compare_arg> let us associate a particular compare
......@@ -63,11 +63,11 @@ typedef int (*avl_key_printer_fun_type) (char *, void *);
*/
typedef struct _avl_tree {
avl_node * root;
unsigned long height;
unsigned long length;
avl_key_compare_fun_type compare_fun;
void * compare_arg;
avl_node * root;
unsigned long height;
unsigned long length;
avl_key_compare_fun_type compare_fun;
void * compare_arg;
#ifndef NO_THREAD
rwlock_t rwlock;
#endif
......@@ -77,66 +77,66 @@ avl_tree * avl_tree_new (avl_key_compare_fun_type compare_fun, void * compare_ar
avl_node * avl_node_new (void * key, avl_node * parent);
void avl_tree_free (
avl_tree * tree,
avl_free_key_fun_type free_key_fun
avl_tree * tree,
avl_free_key_fun_type free_key_fun
);
int avl_insert (
avl_tree * ob,
void * key
avl_tree * ob,
void * key
);
int avl_delete (
avl_tree * tree,
void * key,
avl_free_key_fun_type free_key_fun
avl_tree * tree,
void * key,
avl_free_key_fun_type free_key_fun
);
int avl_get_by_index (
avl_tree * tree,
unsigned long index,
void ** value_address
avl_tree * tree,
unsigned long index,
void ** value_address
);
int avl_get_by_key (
avl_tree * tree,
void * key,
void ** value_address
avl_tree * tree,
void * key,
void ** value_address
);
int avl_iterate_inorder (
avl_tree * tree,
avl_iter_fun_type iter_fun,
void * iter_arg
avl_tree * tree,
avl_iter_fun_type iter_fun,
void * iter_arg
);
int avl_iterate_index_range (
avl_tree * tree,
avl_tree * tree,
avl_iter_index_fun_type iter_fun,
unsigned long low,
unsigned long high,
void * iter_arg
unsigned long low,
unsigned long high,
void * iter_arg
);
int avl_get_span_by_key (
avl_tree * tree,
void * key,
unsigned long * low,
unsigned long * high
avl_tree * tree,
void * key,
unsigned long * low,
unsigned long * high
);
int avl_get_span_by_two_keys (
avl_tree * tree,
void * key_a,
void * key_b,
unsigned long * low,
unsigned long * high
avl_tree * tree,
void * key_a,
void * key_b,
unsigned long * low,
unsigned long * high
);
int avl_verify (avl_tree * tree);
void avl_print_tree (
avl_tree * tree,
avl_tree * tree,
avl_key_printer_fun_type key_printer
);
......@@ -149,15 +149,15 @@ avl_node *avl_get_next(avl_node * node);
/* These two are from David Ascher <david_ascher@brown.edu> */
int avl_get_item_by_key_most (
avl_tree * tree,
void * key,
void ** value_address
avl_tree * tree,
void * key,
void ** value_address
);
int avl_get_item_by_key_least (
avl_tree * tree,
void * key,
void ** value_address
avl_tree * tree,
void * key,
void ** value_address
);
/* optional locking stuff */
......
......@@ -11,75 +11,75 @@ int _printer(char *buff, void *key);
int main(int argc, char **argv)
{
int i, max_nodes;
avl_tree *tree;
avl_node *node;
max_nodes = 25;
if (argc == 2) {
max_nodes = atoi(argv[1]);
if (max_nodes == 0)
max_nodes = 10;
}
printf("avl test... max_nodes = %d...\n", max_nodes);
tree = avl_tree_new(_compare, NULL);
printf("Filling tree...\n");
for (i = 0; i < max_nodes; i++) {
avl_insert(tree, (void *)rand());
}
printf("Traversing tree...\n");
node = avl_get_first(tree);
while (node) {
i = (int)node->key;
printf("...%5d\n", i);
node = avl_get_next(node);
}
printf("Trying to go backwards...\n");
node = tree->root->right;
while (node) {
i = (int)node->key;
printf("...%5d\n", i);
node = avl_get_prev(node);
}
printf("Printing tree...\n");
avl_print_tree(tree, _printer);
avl_tree_free(tree, _free);
return 0;
int i, max_nodes;
avl_tree *tree;
avl_node *node;
max_nodes = 25;
if (argc == 2) {
max_nodes = atoi(argv[1]);
if (max_nodes == 0)
max_nodes = 10;
}
printf("avl test... max_nodes = %d...\n", max_nodes);
tree = avl_tree_new(_compare, NULL);
printf("Filling tree...\n");
for (i = 0; i < max_nodes; i++) {
avl_insert(tree, (void *)rand());
}
printf("Traversing tree...\n");
node = avl_get_first(tree);
while (node) {
i = (int)node->key;
printf("...%5d\n", i);
node = avl_get_next(node);
}
printf("Trying to go backwards...\n");
node = tree->root->right;
while (node) {
i = (int)node->key;
printf("...%5d\n", i);
node = avl_get_prev(node);
}
printf("Printing tree...\n");
avl_print_tree(tree, _printer);
avl_tree_free(tree, _free);
return 0;
}
int _compare(void *compare_arg, void *a, void *b)
{
int i, j;
int i, j;
i = (int)a;
j = (int)b;
i = (int)a;
j = (int)b;
if (i > j)
return 1;
if (j > i)
return -1;
return 0;
if (i > j)
return 1;
if (j > i)
return -1;
return 0;
}
int _free(void *key)
{
return 1;
return 1;
}
int _printer(char *buff, void *key)
{
return snprintf(buff, 25, "%d", (int)key);
return snprintf(buff, 25, "%d", (int)key);
}
......
This diff is collapsed.
......@@ -17,25 +17,25 @@
#define HTTPP_VAR_ICYPASSWORD "__icy_password"
typedef enum httpp_request_type_tag {
httpp_req_none, httpp_req_get, httpp_req_post, httpp_req_head,
httpp_req_source, httpp_req_play, httpp_req_stats, httpp_req_unknown
httpp_req_none, httpp_req_get, httpp_req_post, httpp_req_head,
httpp_req_source, httpp_req_play, httpp_req_stats, httpp_req_unknown
} httpp_request_type_e;
typedef struct http_var_tag {
char *name;
char *value;
char *name;
char *value;
} http_var_t;
typedef struct http_varlist_tag {
http_var_t var;
struct http_varlist_tag *next;
http_var_t var;
struct http_varlist_tag *next;
} http_varlist_t;
typedef struct http_parser_tag {
httpp_request_type_e req_type;
char *uri;
avl_tree *vars;
avl_tree *queryvars;
httpp_request_type_e req_type;
char *uri;
avl_tree *vars;
avl_tree *queryvars;
} http_parser_t;
http_parser_t *httpp_create_parser(void);
......
......@@ -6,54 +6,54 @@
int main(int argc, char **argv)
{
char buff[8192];
int readed;
http_parser_t parser;
avl_node *node;
http_var_t *var;
httpp_initialize(&parser, NULL);
readed = fread(buff, 1, 8192, stdin);
if (httpp_parse(&parser, buff, readed)) {
printf("Parse succeeded...\n\n");
printf("Request was ");
switch (parser.req_type) {
case httpp_req_none:
printf(" none\n");
break;
case httpp_req_unknown:
printf(" unknown\n");
break;
case httpp_req_get:
printf(" get\n");
break;
case httpp_req_post:
printf(" post\n");
break;
case httpp_req_head:
printf(" head\n");
break;
}
printf("Version was 1.%d\n", parser.version);
node = avl_get_first(parser.vars);
while (node) {
var = (http_var_t *)node->key;
if (var)
printf("Iterating variable(s): %s = %s\n", var->name, var->value);
node = avl_get_next(node);
}
} else {
printf("Parse failed...\n");
}
printf("Destroying parser...\n");
httpp_destroy(&parser);
return 0;
char buff[8192];
int readed;
http_parser_t parser;
avl_node *node;
http_var_t *var;
httpp_initialize(&parser, NULL);
readed = fread(buff, 1, 8192, stdin);
if (httpp_parse(&parser, buff, readed)) {
printf("Parse succeeded...\n\n");
printf("Request was ");
switch (parser.req_type) {
case httpp_req_none:
printf(" none\n");
break;
case httpp_req_unknown:
printf(" unknown\n");
break;
case httpp_req_get:
printf(" get\n");
break;
case httpp_req_post:
printf(" post\n");
break;
case httpp_req_head:
printf(" head\n");
break;
}
printf("Version was 1.%d\n", parser.version);
node = avl_get_first(parser.vars);
while (node) {
var = (http_var_t *)node->key;
if (var)
printf("Iterating variable(s): %s = %s\n", var->name, var->value);
node = avl_get_next(node);
}
} else {
printf("Parse failed...\n");
}
printf("Destroying parser...\n");
httpp_destroy(&parser);
return 0;
}
......@@ -28,13 +28,13 @@ static int _initialized = 0;
typedef struct log_tag
{
int in_use;
int in_use;
int level;
int level;
char *filename;
FILE *logfile;
char *filename;
FILE *logfile;
char *buffer;
} log_t;
......@@ -47,26 +47,26 @@ static void _unlock_logger();
void log_initialize()
{
int i;
int i;
if (_initialized) return;
if (_initialized) return;
for (i = 0; i < LOG_MAXLOGS; i++) {
loglist[i].in_use = 0;
loglist[i].level = 2;
loglist[i].filename = NULL;
loglist[i].logfile = NULL;
loglist[i].buffer = NULL;
}
for (i = 0; i < LOG_MAXLOGS; i++) {
loglist[i].in_use = 0;
loglist[i].level = 2;
loglist[i].filename = NULL;
loglist[i].logfile = NULL;
loglist[i].buffer = NULL;
}
/* initialize mutexes */
/* initialize mutexes */
#ifndef _WIN32
pthread_mutex_init(&_logger_mutex, NULL);
pthread_mutex_init(&_logger_mutex, NULL);
#else
InitializeCriticalSection(&_logger_mutex);
InitializeCriticalSection(&_logger_mutex);
#endif
_initialized = 1;
_initialized = 1;
}
int log_open_file(FILE *file)
......@@ -75,34 +75,34 @@ int log_open_file(FILE *file)
if(file == NULL) return LOG_EINSANE;
log_id = _get_log_id();
if (log_id < 0) return LOG_ENOMORELOGS;
log_id = _get_log_id();
if (log_id < 0) return LOG_ENOMORELOGS;
loglist[log_id].logfile = file;
if (loglist[log_id].logfile != NULL) {
loglist[log_id].filename = NULL;
} else {
_release_log_id(log_id);
return LOG_ECANTOPEN;
}
loglist[log_id].logfile = file;
if (loglist[log_id].logfile != NULL) {
loglist[log_id].filename = NULL;
} else {
_release_log_id(log_id);
return LOG_ECANTOPEN;
}
return log_id;
return log_id;
}
int log_open(const char *filename)
{
int ret;
int ret;
FILE *file;
if (filename == NULL) return LOG_EINSANE;
if (strcmp(filename, "") == 0) return LOG_EINSANE;
if (filename == NULL) return LOG_EINSANE;
if (strcmp(filename, "") == 0) return LOG_EINSANE;
file = fopen(filename, "a");
ret = log_open_file(file);
if(ret >= 0)
if(ret >= 0)
setvbuf(file, NULL, IO_BUFFER_TYPE, 0);
return ret;
......@@ -110,152 +110,152 @@ int log_open(const char *filename)
int log_open_with_buffer(const char *filename, int size)
{
/* not implemented */
return LOG_ENOTIMPL;
/* not implemented */
return LOG_ENOTIMPL;
}
void log_set_level(int log_id, int level)
{
if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
if (loglist[log_id].in_use == 0) return;
if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
if (loglist[log_id].in_use == 0) return;
loglist[log_id].level = level;
loglist[log_id].level = level;
}
void log_flush(int log_id)
{
if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
if (loglist[log_id].in_use == 0) return;
if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
if (loglist[log_id].in_use == 0) return;
fflush(loglist[log_id].logfile);
fflush(loglist[log_id].logfile);
}
void log_reopen(int log_id)
{
/* not implemented yet */
/* not implemented yet */
}
void log_close(int log_id)
{
if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
if (loglist[log_id].in_use == 0) return;
loglist[log_id].in_use = 0;
loglist[log_id].level = 2;
if (loglist[log_id].filename) free(loglist[log_id].filename);
if (loglist[log_id].buffer) free(loglist[log_id].buffer);
fclose(loglist[log_id].logfile);
loglist[log_id].logfile = NULL;
if (log_id < 0 || log_id >= LOG_MAXLOGS) return;
if (loglist[log_id].in_use == 0) return;
loglist[log_id].in_use = 0;
loglist[log_id].level = 2;
if (loglist[log_id].filename) free(loglist[log_id].filename);
if (loglist[log_id].buffer) free(loglist[log_id].buffer);
fclose(loglist[log_id].logfile);
loglist[log_id].logfile = NULL;
}
void log_shutdown()
{
/* destroy mutexes */
/* destroy mutexes */
#ifndef _WIN32
pthread_mutex_destroy(&_logger_mutex);
pthread_mutex_destroy(&_logger_mutex);
#else
DeleteCriticalSection(&_logger_mutex);
DeleteCriticalSection(&_logger_mutex);
#endif
_initialized = 0;
_initialized = 0;
}
void log_write(int log_id, int priority, const char *cat, const char *func,
const char *fmt, ...)
{
static char prior[4][5] = { "EROR\0", "WARN\0", "INFO\0", "DBUG\0" };