summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.cpp48
-rw-r--r--src/common/core.hpp4
-rw-r--r--src/common/db.cpp126
-rw-r--r--src/common/db.hpp30
-rw-r--r--src/common/grfio.cpp84
-rw-r--r--src/common/grfio.hpp6
-rw-r--r--src/common/lock.cpp18
-rw-r--r--src/common/lock.hpp4
-rw-r--r--src/common/md5calc.cpp2
-rw-r--r--src/common/md5calc.hpp8
-rw-r--r--src/common/mmo.hpp44
-rw-r--r--src/common/mt_rand.cpp16
-rw-r--r--src/common/mt_rand.hpp4
-rw-r--r--src/common/nullpo.cpp38
-rw-r--r--src/common/nullpo.hpp12
-rw-r--r--src/common/socket.cpp202
-rw-r--r--src/common/socket.hpp32
-rw-r--r--src/common/timer.cpp76
-rw-r--r--src/common/timer.hpp18
-rw-r--r--src/common/utils.cpp38
-rw-r--r--src/common/utils.hpp8
21 files changed, 409 insertions, 409 deletions
diff --git a/src/common/core.cpp b/src/common/core.cpp
index db26e31..9d1d8e7 100644
--- a/src/common/core.cpp
+++ b/src/common/core.cpp
@@ -17,13 +17,13 @@
// (sigaction() is POSIX; signal() is not.) Taken from Stevens' _Advanced
// Programming in the UNIX Environment_.
//
-typedef void (*sigfunc)(int);
-static sigfunc compat_signal (int signo, sigfunc func)
+typedef void(*sigfunc)(int);
+static sigfunc compat_signal(int signo, sigfunc func)
{
struct sigaction sact, oact;
sact.sa_handler = func;
- sigfillset (&sact.sa_mask);
+ sigfillset(&sact.sa_mask);
sigdelset(&sact.sa_mask, SIGSEGV);
sigdelset(&sact.sa_mask, SIGBUS);
sigdelset(&sact.sa_mask, SIGTRAP);
@@ -31,22 +31,22 @@ static sigfunc compat_signal (int signo, sigfunc func)
sigdelset(&sact.sa_mask, SIGFPE);
sact.sa_flags = 0;
- if (sigaction (signo, &sact, &oact) < 0)
+ if (sigaction(signo, &sact, &oact) < 0)
return SIG_ERR;
return oact.sa_handler;
}
-static void chld_proc (int UNUSED)
+static void chld_proc(int UNUSED)
{
wait(NULL);
}
-static void sig_proc (int UNUSED)
+static void sig_proc(int UNUSED)
{
for (int i = 1; i < 31; ++i)
compat_signal(i, SIG_IGN);
- term_func ();
- _exit (0);
+ term_func();
+ _exit(0);
}
bool runflag = true;
@@ -60,34 +60,34 @@ bool runflag = true;
Unless you use SA_SIGINFO and *carefully* check the origin,
that means they must be SIG_DFL.
*/
-int main (int argc, char **argv)
+int main(int argc, char **argv)
{
/// Note that getpid() and getppid() may be very close
- mt_seed (time (NULL) ^ (getpid () << 16) ^ (getppid () << 8));
+ mt_seed(time(NULL) ^ (getpid() << 16) ^ (getppid() << 8));
- do_socket ();
+ do_socket();
- do_init (argc, argv);
+ do_init(argc, argv);
// set up exit handlers *after* the initialization has happened.
// This is because term_func is likely to depend on successful init.
- compat_signal (SIGPIPE, SIG_IGN);
- compat_signal (SIGTERM, sig_proc);
- compat_signal (SIGINT, sig_proc);
- compat_signal (SIGCHLD, chld_proc);
+ compat_signal(SIGPIPE, SIG_IGN);
+ compat_signal(SIGTERM, sig_proc);
+ compat_signal(SIGINT, sig_proc);
+ compat_signal(SIGCHLD, chld_proc);
// Signal to create coredumps by system when necessary (crash)
- compat_signal (SIGSEGV, SIG_DFL);
- compat_signal (SIGBUS, SIG_DFL);
- compat_signal (SIGTRAP, SIG_DFL);
- compat_signal (SIGILL, SIG_DFL);
- compat_signal (SIGFPE, SIG_DFL);
+ compat_signal(SIGSEGV, SIG_DFL);
+ compat_signal(SIGBUS, SIG_DFL);
+ compat_signal(SIGTRAP, SIG_DFL);
+ compat_signal(SIGILL, SIG_DFL);
+ compat_signal(SIGFPE, SIG_DFL);
- atexit (term_func);
+ atexit(term_func);
while (runflag)
{
- do_sendrecv (do_timer (gettick_nocache ()));
- do_parsepacket ();
+ do_sendrecv(do_timer(gettick_nocache()));
+ do_parsepacket();
}
}
diff --git a/src/common/core.hpp b/src/common/core.hpp
index 8a52c55..14dc61d 100644
--- a/src/common/core.hpp
+++ b/src/common/core.hpp
@@ -10,10 +10,10 @@ extern bool runflag;
/// This is an external function defined by each server
/// This function must register stuff for the parse loop
-extern int do_init (int, char **);
+extern int do_init(int, char **);
/// Cleanup function called whenever a signal kills us
/// or when if we manage to exit() gracefully.
-extern void term_func (void);
+extern void term_func(void);
#endif // CORE_HPP
diff --git a/src/common/db.cpp b/src/common/db.cpp
index 21a3597..e04b7d0 100644
--- a/src/common/db.cpp
+++ b/src/common/db.cpp
@@ -8,14 +8,14 @@
#define ROOT_SIZE 4096
-static int strdb_cmp (struct dbt *table, const char *a, const char* b)
+static int strdb_cmp(struct dbt *table, const char *a, const char* b)
{
if (table->maxlen)
- return strncmp (a, b, table->maxlen);
- return strcmp (a, b);
+ return strncmp(a, b, table->maxlen);
+ return strcmp(a, b);
}
-static hash_t strdb_hash (struct dbt *table, const char *a)
+static hash_t strdb_hash(struct dbt *table, const char *a)
{
size_t i = table->maxlen;
if (i == 0)
@@ -29,16 +29,16 @@ static hash_t strdb_hash (struct dbt *table, const char *a)
return h;
}
-struct dbt *strdb_init (size_t maxlen)
+struct dbt *strdb_init(size_t maxlen)
{
struct dbt *table;
- CREATE (table, struct dbt, 1);
+ CREATE(table, struct dbt, 1);
table->type = DB_STRING;
table->maxlen = maxlen;
return table;
}
-static int numdb_cmp (numdb_key_t a, numdb_key_t b)
+static int numdb_cmp(numdb_key_t a, numdb_key_t b)
{
if (a == b)
return 0;
@@ -47,47 +47,47 @@ static int numdb_cmp (numdb_key_t a, numdb_key_t b)
return 1;
}
-static hash_t numdb_hash (numdb_key_t a)
+static hash_t numdb_hash(numdb_key_t a)
{
return (hash_t) a;
}
-struct dbt *numdb_init (void)
+struct dbt *numdb_init(void)
{
struct dbt *table;
- CREATE (table, struct dbt, 1);
+ CREATE(table, struct dbt, 1);
table->type = DB_NUMBER;
return table;
}
-static int table_cmp (struct dbt *table, db_key_t a, db_key_t b)
+static int table_cmp(struct dbt *table, db_key_t a, db_key_t b)
{
- switch(table->type)
+ switch (table->type)
{
- case DB_NUMBER: return numdb_cmp (a.i, b.i);
- case DB_STRING: return strdb_cmp (table, a.s, b.s);
+ case DB_NUMBER: return numdb_cmp(a.i, b.i);
+ case DB_STRING: return strdb_cmp(table, a.s, b.s);
}
abort();
}
-static hash_t table_hash (struct dbt *table, db_key_t key)
+static hash_t table_hash(struct dbt *table, db_key_t key)
{
- switch(table->type)
+ switch (table->type)
{
- case DB_NUMBER: return numdb_hash (key.i);
- case DB_STRING: return strdb_hash (table, key.s);
+ case DB_NUMBER: return numdb_hash(key.i);
+ case DB_STRING: return strdb_hash(table, key.s);
}
abort();
}
/// Search for a node with the given key
-db_val_t db_search (struct dbt *table, db_key_t key)
+db_val_t db_search(struct dbt *table, db_key_t key)
{
- struct dbn *p = table->ht[table_hash (table, key) % HASH_SIZE];
+ struct dbn *p = table->ht[table_hash(table, key) % HASH_SIZE];
while (p)
{
- int c = table_cmp (table, key, p->key);
+ int c = table_cmp(table, key, p->key);
if (c == 0)
return p->data;
if (c < 0)
@@ -99,7 +99,7 @@ db_val_t db_search (struct dbt *table, db_key_t key)
}
// Tree maintainance methods
-static void db_rotate_left (struct dbn *p, struct dbn **root)
+static void db_rotate_left(struct dbn *p, struct dbn **root)
{
struct dbn *y = p->right;
p->right = y->left;
@@ -117,7 +117,7 @@ static void db_rotate_left (struct dbn *p, struct dbn **root)
p->parent = y;
}
-static void db_rotate_right (struct dbn *p, struct dbn **root)
+static void db_rotate_right(struct dbn *p, struct dbn **root)
{
struct dbn *y = p->left;
p->left = y->right;
@@ -135,7 +135,7 @@ static void db_rotate_right (struct dbn *p, struct dbn **root)
p->parent = y;
}
-static void db_rebalance (struct dbn *p, struct dbn **root)
+static void db_rebalance(struct dbn *p, struct dbn **root)
{
p->color = RED;
while (p != *root && p->parent->color == RED)
@@ -155,11 +155,11 @@ static void db_rebalance (struct dbn *p, struct dbn **root)
if (p == p->parent->right)
{
p = p->parent;
- db_rotate_left (p, root);
+ db_rotate_left(p, root);
}
p->parent->color = BLACK;
p->parent->parent->color = RED;
- db_rotate_right (p->parent->parent, root);
+ db_rotate_right(p->parent->parent, root);
}
}
else
@@ -177,11 +177,11 @@ static void db_rebalance (struct dbn *p, struct dbn **root)
if (p == p->parent->left)
{
p = p->parent;
- db_rotate_right (p, root);
+ db_rotate_right(p, root);
}
p->parent->color = BLACK;
p->parent->parent->color = RED;
- db_rotate_left (p->parent->parent, root);
+ db_rotate_left(p->parent->parent, root);
}
}
}
@@ -189,7 +189,7 @@ static void db_rebalance (struct dbn *p, struct dbn **root)
}
// param z = node to remove
-static void db_rebalance_erase (struct dbn *z, struct dbn **root)
+static void db_rebalance_erase(struct dbn *z, struct dbn **root)
{
struct dbn *y = z;
struct dbn *x = NULL;
@@ -257,7 +257,7 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root)
{
w->color = BLACK;
x_parent->color = RED;
- db_rotate_left (x_parent, root);
+ db_rotate_left(x_parent, root);
w = x_parent->right;
}
if ((!w->left || w->left->color == BLACK) &&
@@ -274,14 +274,14 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root)
if (w->left)
w->left->color = BLACK;
w->color = RED;
- db_rotate_right (w, root);
+ db_rotate_right(w, root);
w = x_parent->right;
}
w->color = x_parent->color;
x_parent->color = BLACK;
if (w->right)
w->right->color = BLACK;
- db_rotate_left (x_parent, root);
+ db_rotate_left(x_parent, root);
break;
}
}
@@ -293,7 +293,7 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root)
{
w->color = BLACK;
x_parent->color = RED;
- db_rotate_right (x_parent, root);
+ db_rotate_right(x_parent, root);
w = x_parent->left;
}
if ((!w->right || w->right->color == BLACK) &&
@@ -310,14 +310,14 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root)
if (w->right)
w->right->color = BLACK;
w->color = RED;
- db_rotate_left (w, root);
+ db_rotate_left(w, root);
w = x_parent->left;
}
w->color = x_parent->color;
x_parent->color = BLACK;
if (w->left)
w->left->color = BLACK;
- db_rotate_right (x_parent, root);
+ db_rotate_right(x_parent, root);
break;
}
}
@@ -326,21 +326,21 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root)
}
}
-struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data)
+struct dbn *db_insert(struct dbt *table, db_key_t key, db_val_t data)
{
- hash_t hash = table_hash (table, key) % HASH_SIZE;
+ hash_t hash = table_hash(table, key) % HASH_SIZE;
int c = 0;
struct dbn *prev = NULL;
struct dbn *p = table->ht[hash];
while (p)
{
- c = table_cmp (table, key, p->key);
+ c = table_cmp(table, key, p->key);
if (c == 0)
{
// key found in table, replace
// Tell the user of the table to free the key and value
if (table->release)
- table->release (p->key, p->data);
+ table->release(p->key, p->data);
p->data = data;
p->key = key;
return p;
@@ -352,7 +352,7 @@ struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data)
else
p = p->right;
}
- CREATE (p, struct dbn, 1);
+ CREATE(p, struct dbn, 1);
p->key = key;
p->data = data;
p->color = RED;
@@ -370,18 +370,18 @@ struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data)
if (prev->color == RED)
{
// must rebalance
- db_rebalance (p, &table->ht[hash]);
+ db_rebalance(p, &table->ht[hash]);
}
return p;
}
-db_val_t db_erase (struct dbt *table, db_key_t key)
+db_val_t db_erase(struct dbt *table, db_key_t key)
{
- hash_t hash = table_hash (table, key) % HASH_SIZE;
+ hash_t hash = table_hash(table, key) % HASH_SIZE;
struct dbn *p = table->ht[hash];
while (p)
{
- int c = table_cmp (table, key, p->key);
+ int c = table_cmp(table, key, p->key);
if (c == 0)
break;
if (c < 0)
@@ -392,12 +392,12 @@ db_val_t db_erase (struct dbt *table, db_key_t key)
if (!p)
return NULL;
db_val_t data = p->data;
- db_rebalance_erase (p, &table->ht[hash]);
- free (p);
+ db_rebalance_erase(p, &table->ht[hash]);
+ free(p);
return data;
}
#ifdef SMART_WALK_TREE
-static inline void db_walk_tree (bool dealloc, struct dbn* p, db_func_t func, va_list ap)
+static inline void db_walk_tree(bool dealloc, struct dbn* p, db_func_t func, va_list ap)
{
if (!p)
return;
@@ -415,7 +415,7 @@ static inline void db_walk_tree (bool dealloc, struct dbn* p, db_func_t func, va
{
// apply_func loop
if (func)
- func (p->key, p->data, ap);
+ func(p->key, p->data, ap);
if (p->left)
{
// continue descending
@@ -434,7 +434,7 @@ static inline void db_walk_tree (bool dealloc, struct dbn* p, db_func_t func, va
if (!p->parent)
{
if (dealloc)
- free (p);
+ free(p);
// if we have already done both children, there is no more to do
return;
}
@@ -443,7 +443,7 @@ static inline void db_walk_tree (bool dealloc, struct dbn* p, db_func_t func, va
// finished the left tree, now walk the right tree
p = p->parent->right;
if (dealloc)
- free (p->parent->left);
+ free(p->parent->left);
break; //goto apply_func;
}
// p->parent->right == p
@@ -451,21 +451,21 @@ static inline void db_walk_tree (bool dealloc, struct dbn* p, db_func_t func, va
// keep backtracking
p = p->parent;
if (dealloc)
- free (p->right?:p->left);
+ free(p->right?:p->left);
} //backtrack loop
} // apply_func loop
}
#endif // SMART_WALK_TREE
-void db_foreach (struct dbt *table, db_func_t func, ...)
+void db_foreach(struct dbt *table, db_func_t func, ...)
{
va_list ap;
- va_start (ap, func);
+ va_start(ap, func);
for (int i = 0; i < HASH_SIZE; i++)
{
#ifdef SMART_WALK_TREE
- db_walk_tree (false, table->ht[i], func, ap);
+ db_walk_tree(false, table->ht[i], func, ap);
#else
struct dbn *p = table->ht[i];
if (!p)
@@ -474,7 +474,7 @@ void db_foreach (struct dbt *table, db_func_t func, ...)
int sp = 0;
while (1)
{
- func (p->key, p->data, ap);
+ func(p->key, p->data, ap);
struct dbn *pn = p->left;
if (pn)
{
@@ -496,19 +496,19 @@ void db_foreach (struct dbt *table, db_func_t func, ...)
} // while true
#endif // else ! SMART_WALK_TREE
} // for i
- va_end (ap);
+ va_end(ap);
}
// This function is suspiciously similar to the previous
-void db_final (struct dbt *table, db_func_t func, ...)
+void db_final(struct dbt *table, db_func_t func, ...)
{
va_list ap;
- va_start (ap, func);
+ va_start(ap, func);
for (int i = 0; i < HASH_SIZE; i++)
{
#ifdef SMART_WALK_TREE
- db_walk_tree (true, table->ht[i], func, ap);
+ db_walk_tree(true, table->ht[i], func, ap);
#else
struct dbn *p = table->ht[i];
if (!p)
@@ -518,7 +518,7 @@ void db_final (struct dbt *table, db_func_t func, ...)
while (1)
{
if (func)
- func (p->key, p->data, ap);
+ func(p->key, p->data, ap);
struct dbn *pn = p->left;
if (pn)
{
@@ -536,11 +536,11 @@ void db_final (struct dbt *table, db_func_t func, ...)
pn = stack[--sp];
}
} // if pn else if !pn
- free (p);
+ free(p);
p = pn;
} // while true
#endif // else ! SMART_WALK_TREE
} // for i
- free (table);
- va_end (ap);
+ free(table);
+ va_end(ap);
}
diff --git a/src/common/db.hpp b/src/common/db.hpp
index 62125d8..313ba3a 100644
--- a/src/common/db.hpp
+++ b/src/common/db.hpp
@@ -28,7 +28,7 @@ typedef union db_key_t
} db_key_t;
typedef void* db_val_t;
typedef uint32_t hash_t;
-typedef void (*db_func_t)(db_key_t, db_val_t, va_list);
+typedef void(*db_func_t)(db_key_t, db_val_t, va_list);
/// DataBase Node
struct dbn
@@ -51,40 +51,40 @@ struct dbt
dbt_type type;
/// Note, before replacement, key/values to be replaced
// TODO refactor to decrease/eliminate the uses of this?
- void (*release) (db_key_t, db_val_t) __attribute__((deprecated));
+ void(*release)(db_key_t, db_val_t) __attribute__((deprecated));
/// Maximum length of a string key - TODO refactor to ensure all strings are NUL-terminated
size_t maxlen __attribute__((deprecated));
/// The root trees
struct dbn *ht[HASH_SIZE];
};
-# define strdb_search(t,k) db_search((t),(db_key_t)(k))
-# define strdb_insert(t,k,d) db_insert((t),(db_key_t)(k),(db_val_t)(d))
-# define strdb_erase(t,k) db_erase ((t),(db_key_t)(k))
+# define strdb_search(t,k) db_search((t), (db_key_t)(k))
+# define strdb_insert(t,k,d) db_insert((t), (db_key_t)(k), (db_val_t)(d))
+# define strdb_erase(t,k) db_erase((t), (db_key_t)(k))
# define strdb_foreach db_foreach
# define strdb_final db_final
-# define numdb_search(t,k) db_search((t),(db_key_t)(k))
-# define numdb_insert(t,k,d) db_insert((t),(db_key_t)(k),(db_val_t)(d))
-# define numdb_erase(t,k) db_erase ((t),(db_key_t)(k))
+# define numdb_search(t,k) db_search((t), (db_key_t)(k))
+# define numdb_insert(t,k,d) db_insert((t), (db_key_t)(k), (db_val_t)(d))
+# define numdb_erase(t,k) db_erase((t), (db_key_t)(k))
# define numdb_foreach db_foreach
# define numdb_final db_final
/// Create a map from char* to void*, with strings possibly not null-terminated
-struct dbt *strdb_init (size_t maxlen);
+struct dbt *strdb_init(size_t maxlen);
/// Create a map from int to void*
-struct dbt *numdb_init (void);
+struct dbt *numdb_init(void);
/// Return the value corresponding to the key, or NULL if not found
-db_val_t db_search (struct dbt *table, db_key_t key);
+db_val_t db_search(struct dbt *table, db_key_t key);
/// Add or replace table[key] = data
// if it was already there, call release
-struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data);
+struct dbn *db_insert(struct dbt *table, db_key_t key, db_val_t data);
/// Remove a key from the table, returning the data
-db_val_t db_erase (struct dbt *table, db_key_t key);
+db_val_t db_erase(struct dbt *table, db_key_t key);
/// Execute a function for every element, in unspecified order
-void db_foreach (struct dbt *, db_func_t, ...);
+void db_foreach(struct dbt *, db_func_t, ...);
// opposite of init? Calls release for every element and frees memory
// This probably isn't really needed: we don't have to free memory while exiting
-void db_final (struct dbt *, db_func_t, ...) __attribute__((deprecated));
+void db_final(struct dbt *, db_func_t, ...) __attribute__((deprecated));
#endif
diff --git a/src/common/grfio.cpp b/src/common/grfio.cpp
index dd1e707..042de85 100644
--- a/src/common/grfio.cpp
+++ b/src/common/grfio.cpp
@@ -34,7 +34,7 @@ static int16_t filelist_hash[256] = {l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l};
#undef l
/// Hash a filename
-static uint8_t filehash (const char *fname)
+static uint8_t filehash(const char *fname)
{
// Larger than the return type - upper bits are used in the process
uint32_t hash = 0;
@@ -48,12 +48,12 @@ static uint8_t filehash (const char *fname)
/// Find the filelist entry for the given filename, or NULL if it is not
static
-FILELIST *filelist_find (const char *fname)
+FILELIST *filelist_find(const char *fname)
{
- int16_t index = filelist_hash[filehash (fname)];
+ int16_t index = filelist_hash[filehash(fname)];
while (index >= 0)
{
- if (strcmp (filelist[index].fn, fname) == 0)
+ if (strcmp(filelist[index].fn, fname) == 0)
return &filelist[index];
index = filelist[index].next;
}
@@ -61,24 +61,24 @@ FILELIST *filelist_find (const char *fname)
}
/// Copy a temporary entry into the hash map
-static FILELIST *filelist_add (FILELIST * entry)
+static FILELIST *filelist_add(FILELIST * entry)
{
if (filelist_entrys >= FILELIST_LIMIT)
{
- fprintf (stderr, "filelist limit : filelist_add\n");
- exit (1);
+ fprintf(stderr, "filelist limit : filelist_add\n");
+ exit(1);
}
if (filelist_entrys >= filelist_maxentry)
{
RECREATE(filelist, FILELIST, filelist_maxentry + FILELIST_ADDS);
- memset (filelist + filelist_maxentry, '\0',
- FILELIST_ADDS * sizeof (FILELIST));
+ memset(filelist + filelist_maxentry, '\0',
+ FILELIST_ADDS * sizeof(FILELIST));
filelist_maxentry += FILELIST_ADDS;
}
uint16_t new_index = filelist_entrys++;
- uint8_t hash = filehash (entry->fn);
+ uint8_t hash = filehash(entry->fn);
entry->next = filelist_hash[hash];
filelist_hash[hash] = new_index;
@@ -87,26 +87,26 @@ static FILELIST *filelist_add (FILELIST * entry)
return &filelist[new_index];
}
-static FILELIST *filelist_modify (FILELIST * entry)
+static FILELIST *filelist_modify(FILELIST * entry)
{
- FILELIST *fentry = filelist_find (entry->fn);
+ FILELIST *fentry = filelist_find(entry->fn);
if (fentry)
{
entry->next = fentry->next;
*fentry = *entry;
return fentry;
}
- return filelist_add (entry);
+ return filelist_add(entry);
}
/// Change fname data/*.gat to lfname data/*.wlk
// TODO even if the file exists, don't keep reopening it every time one loads
static
-void grfio_resnametable (const char *fname, char *lfname)
+void grfio_resnametable(const char *fname, char *lfname)
{
char restable[] = "data/resnametable.txt";
- FILE *fp = fopen_ (restable, "rb");
+ FILE *fp = fopen_(restable, "rb");
if (fp == NULL)
{
fprintf(stderr, "No resnametable, can't look for %s\n", fname);
@@ -118,23 +118,23 @@ void grfio_resnametable (const char *fname, char *lfname)
}
char line[512];
- while (fgets (line, sizeof (line), fp))
+ while (fgets(line, sizeof(line), fp))
{
char w1[256], w2[256];
if (
// line is of the form foo.gat#foo.wlk#
- (sscanf (line, "%[^#]#%[^#]#", w1, w2) == 2)
+ (sscanf(line, "%[^#]#%[^#]#", w1, w2) == 2)
// strip data/ from foo.gat before comparing
- && (!strcmp (w1, fname + 5)))
+ && (!strcmp(w1, fname + 5)))
{
- strcpy (lfname, "data/");
- strcpy (lfname + 5, w2);
- fclose_ (fp);
+ strcpy(lfname, "data/");
+ strcpy(lfname + 5, w2);
+ fclose_(fp);
return;
}
}
fprintf(stderr, "Unable to find resource: %s\n", fname);
- fclose_ (fp);
+ fclose_(fp);
strcpy(lfname, fname);
char* ext = lfname + strlen(lfname) - 4;
@@ -144,9 +144,9 @@ void grfio_resnametable (const char *fname, char *lfname)
}
/// Size of resource
-size_t grfio_size (const char *fname)
+size_t grfio_size(const char *fname)
{
- FILELIST *entry = filelist_find (fname);
+ FILELIST *entry = filelist_find(fname);
if (entry)
return entry->declen;
@@ -154,60 +154,60 @@ size_t grfio_size (const char *fname)
FILELIST lentry;
struct stat st;
- grfio_resnametable (fname, lfname);
+ grfio_resnametable(fname, lfname);
for (char *p = lfname; *p; p++)
if (*p == '\\')
*p = '/';
- if (stat (lfname, &st) == 0)
+ if (stat(lfname, &st) == 0)
{
- strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1);
+ strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
lentry.declen = st.st_size;
- entry = filelist_modify (&lentry);
+ entry = filelist_modify(&lentry);
}
else
{
- printf ("%s not found\n", fname);
+ printf("%s not found\n", fname);
return 0;
}
return entry->declen;
}
-void *grfio_reads (const char *fname, size_t *size)
+void *grfio_reads(const char *fname, size_t *size)
{
char lfname[256];
- grfio_resnametable (fname, lfname);
+ grfio_resnametable(fname, lfname);
for (char *p = &lfname[0]; *p != 0; p++)
if (*p == '\\')
*p = '/'; // * At the time of Unix
- FILE *in = fopen_ (lfname, "rb");
+ FILE *in = fopen_(lfname, "rb");
if (!in)
{
- fprintf (stderr, "%s not found\n", fname);
+ fprintf(stderr, "%s not found\n", fname);
return NULL;
}
FILELIST lentry;
- FILELIST *entry = filelist_find (fname);
+ FILELIST *entry = filelist_find(fname);
if (entry)
{
lentry.declen = entry->declen;
}
else
{
- fseek (in, 0, SEEK_END);
- lentry.declen = ftell (in);
- fseek (in, 0, SEEK_SET);
- strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1);
- entry = filelist_modify (&lentry);
+ fseek(in, 0, SEEK_END);
+ lentry.declen = ftell(in);
+ fseek(in, 0, SEEK_SET);
+ strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
+ entry = filelist_modify(&lentry);
}
uint8_t *buf2;
- CREATE (buf2, uint8_t, lentry.declen + 1024);
- if (fread (buf2, 1, lentry.declen, in) != lentry.declen)
+ CREATE(buf2, uint8_t, lentry.declen + 1024);
+ if (fread(buf2, 1, lentry.declen, in) != lentry.declen)
exit(1);
- fclose_ (in);
+ fclose_(in);
in = NULL;
if (size)
diff --git a/src/common/grfio.hpp b/src/common/grfio.hpp
index 3485904..f418ac3 100644
--- a/src/common/grfio.hpp
+++ b/src/common/grfio.hpp
@@ -6,12 +6,12 @@
#define GRFIO_HPP
/// Load file into memory
-# define grfio_read(resourcename) grfio_reads (resourcename, NULL)
+# define grfio_read(resourcename) grfio_reads(resourcename, NULL)
/// Load file into memory and possibly record length
// For some reason, this allocates an extra 1024 bytes at the end
-void *grfio_reads (const char *resourcename, size_t *size);
+void *grfio_reads(const char *resourcename, size_t *size);
/// Get size of file
// This is only called once, and that is to check the existence of a file.
-size_t grfio_size (const char *resourcename) __attribute__((deprecated));
+size_t grfio_size(const char *resourcename) __attribute__((deprecated));
#endif // GRFIO_HPP
diff --git a/src/common/lock.cpp b/src/common/lock.cpp
index 2ba9a0a..13a99c5 100644
--- a/src/common/lock.cpp
+++ b/src/common/lock.cpp
@@ -7,30 +7,30 @@
/// (Until the file is closed, it keeps the old file)
// Start writing a tmpfile
-FILE *lock_fopen (const char *filename, int *info)
+FILE *lock_fopen(const char *filename, int *info)
{
char newfile[512];
FILE *fp;
- int no = getpid ();
+ int no = getpid();
// Get a filename that doesn't already exist
do
{
- sprintf (newfile, "%s_%d.tmp", filename, no++);
+ sprintf(newfile, "%s_%d.tmp", filename, no++);
}
- while ((fp = fopen_ (newfile, "r")) && (fclose_ (fp), 1));
+ while ((fp = fopen_(newfile, "r")) && (fclose_(fp), 1));
*info = --no;
- return fopen_ (newfile, "w");
+ return fopen_(newfile, "w");
}
// Delete the old file and rename the new file
-void lock_fclose (FILE * fp, const char *filename, int *info)
+void lock_fclose(FILE * fp, const char *filename, int *info)
{
char newfile[512];
if (fp)
{
- fclose_ (fp);
- sprintf (newfile, "%s_%d.tmp", filename, *info);
- rename (newfile, filename);
+ fclose_(fp);
+ sprintf(newfile, "%s_%d.tmp", filename, *info);
+ rename(newfile, filename);
}
}
diff --git a/src/common/lock.hpp b/src/common/lock.hpp
index 19c1302..d6128d8 100644
--- a/src/common/lock.hpp
+++ b/src/common/lock.hpp
@@ -2,7 +2,7 @@
#define LOCK_HPP
/// Locked FILE I/O
// Changes are made in a separate file until lock_fclose
-FILE *lock_fopen (const char *filename, int *info);
-void lock_fclose (FILE * fp, const char *filename, int *info);
+FILE *lock_fopen(const char *filename, int *info);
+void lock_fclose(FILE * fp, const char *filename, int *info);
#endif // LOCK_HPP
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp
index b0f8e5f..9027bc9 100644
--- a/src/common/md5calc.cpp
+++ b/src/common/md5calc.cpp
@@ -193,7 +193,7 @@ MD5_state MD5_from_string(const char* msg, const size_t msglen)
}
// now pad 1-512 bits + the 64-bit length - may be two blocks
uint8_t buf[0x40] = {};
- memcpy (buf, msg, rem);
+ memcpy(buf, msg, rem);
buf[rem] = 0x80; // a single one bit
if (64 - rem > 8)
{
diff --git a/src/common/md5calc.hpp b/src/common/md5calc.hpp
index 2dfaecb..2aed0bc 100644
--- a/src/common/md5calc.hpp
+++ b/src/common/md5calc.hpp
@@ -37,13 +37,13 @@ MD5_state MD5_from_FILE(FILE* in);
/// Output in ASCII - with lowercase hex digits, null-terminated
// these may overlap safely
-static void MD5_String (const char *string, char output[33]) __attribute__((deprecated));
-static inline void MD5_String (const char *string, char output[33]) {
+static void MD5_String(const char *string, char output[33]) __attribute__((deprecated));
+static inline void MD5_String(const char *string, char output[33]) {
MD5_to_str(MD5_from_cstring(string), output);
}
/// Output in binary
-static void MD5_String2binary (const char *string, uint8_t output[16]) __attribute__((deprecated));
-static inline void MD5_String2binary (const char *string, uint8_t output[16]) {
+static void MD5_String2binary(const char *string, uint8_t output[16]) __attribute__((deprecated));
+static inline void MD5_String2binary(const char *string, uint8_t output[16]) {
MD5_to_bin(MD5_from_cstring(string), output);
}
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index 45f86cf..7441a16 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -51,7 +51,7 @@
struct item
{
- int id;
+ int id;
short nameid;
short amount;
unsigned short equip;
@@ -76,23 +76,23 @@ struct skill
struct global_reg
{
char str[32];
- int value;
+ int value;
};
struct mmo_charstatus
{
- int char_id;
- int account_id;
- int partner_id;
+ int char_id;
+ int account_id;
+ int partner_id;
- int base_exp, job_exp, zeny;
+ int base_exp, job_exp, zeny;
short pc_class;
short status_point, skill_point;
- int hp, max_hp, sp, max_sp;
+ int hp, max_hp, sp, max_sp;
short option, karma, manner;
short hair, hair_color, clothes_color;
- int party_id;
+ int party_id;
short weapon, shield;
short head_top, head_mid, head_bottom;
@@ -108,18 +108,18 @@ struct mmo_charstatus
struct point last_point, save_point, memo_point[10];
struct item inventory[MAX_INVENTORY], cart[MAX_CART];
struct skill skill[MAX_SKILL];
- int global_reg_num;
+ int global_reg_num;
struct global_reg global_reg[GLOBAL_REG_NUM];
- int account_reg_num;
+ int account_reg_num;
struct global_reg account_reg[ACCOUNT_REG_NUM];
- int account_reg2_num;
+ int account_reg2_num;
struct global_reg account_reg2[ACCOUNT_REG2_NUM];
};
struct storage
{
- int dirty;
- int account_id;
+ int dirty;
+ int account_id;
short storage_status;
short storage_amount;
struct item storage_[MAX_STORAGE];
@@ -129,31 +129,31 @@ struct map_session_data;
struct gm_account
{
- int account_id;
- int level;
+ int account_id;
+ int level;
};
struct party_member
{
- int account_id;
+ int account_id;
char name[24], map[24];
- int leader, online, lv;
+ int leader, online, lv;
struct map_session_data *sd;
};
struct party
{
- int party_id;
+ int party_id;
char name[24];
- int exp;
- int item;
+ int exp;
+ int item;
struct party_member member[MAX_PARTY];
};
struct square
{
- int val1[5];
- int val2[5];
+ int val1[5];
+ int val2[5];
};
#endif // MMO_HPP
diff --git a/src/common/mt_rand.cpp b/src/common/mt_rand.cpp
index 676eca1..91ae2e4 100644
--- a/src/common/mt_rand.cpp
+++ b/src/common/mt_rand.cpp
@@ -61,7 +61,7 @@ static uint32_t state[N+1]; // state vector the +1 is needed due to the coding
static uint32_t *next; // next random value is computed from here
static int left = -1; // can *next++ this many times before reloading
-void mt_seed (uint32_t seed)
+void mt_seed(uint32_t seed)
{
uint32_t x = seed | 1U;
uint32_t *s = state;
@@ -71,11 +71,11 @@ void mt_seed (uint32_t seed)
}
static
-void mt_reload (void)
+void mt_reload(void)
{
// if mt_seed has never been called
if (left < -1)
- mt_seed (time (NULL));
+ mt_seed(time(NULL));
// conceptually, these are indices into the state that wrap
uint32_t *p0 = state;
@@ -87,27 +87,27 @@ void mt_reload (void)
// regenerate the lower N-M elements of the state
for (int j = N-M+1; --j != 0; s0 = s1, s1 = *p2++)
- *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U);
+ *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
pM = state;
// regenerate the next M-1 elements of the state
// note that s1 is set to state[N] at the end, but discarded
for (int j = M; --j != 0; s0 = s1, s1 = *p2++)
- *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U);
+ *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
// regenerate the last 1 element of the state
s1 = state[0];
- *p0 = *pM ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U);
+ *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
// ready for the normal mt_random algorithm
left = N;
next = state;
}
-uint32_t mt_random (void)
+uint32_t mt_random(void)
{
if (--left < 0)
- mt_reload ();
+ mt_reload();
uint32_t y = *next++;
y ^= (y >> 11);
diff --git a/src/common/mt_rand.hpp b/src/common/mt_rand.hpp
index c7bae4e..ae5986b 100644
--- a/src/common/mt_rand.hpp
+++ b/src/common/mt_rand.hpp
@@ -4,9 +4,9 @@
# include "sanity.hpp"
/// Initialize the generator (called automatically with time() if you don't)
-void mt_seed (uint32_t seed);
+void mt_seed(uint32_t seed);
/// Get a random number
-uint32_t mt_random (void);
+uint32_t mt_random(void);
/**
* ModuloRand and ModuloPlusRand
diff --git a/src/common/nullpo.cpp b/src/common/nullpo.cpp
index 67c839f..ad52009 100644
--- a/src/common/nullpo.cpp
+++ b/src/common/nullpo.cpp
@@ -3,13 +3,13 @@
#include <string.h>
#include "nullpo.hpp"
-static void nullpo_info_core (const char *file, int line, const char *func);
+static void nullpo_info_core(const char *file, int line, const char *func);
__attribute__((format(printf, 4, 0)))
-static void nullpo_info_core (const char *file, int line, const char *func,
+static void nullpo_info_core(const char *file, int line, const char *func,
const char *fmt, va_list ap);
/// Null check and print format
-bool nullpo_chk_f (const char *file, int line, const char *func,
+bool nullpo_chk_f(const char *file, int line, const char *func,
const void *target, const char *fmt, ...)
{
va_list ap;
@@ -17,55 +17,55 @@ bool nullpo_chk_f (const char *file, int line, const char *func,
if (target)
return 0;
- va_start (ap, fmt);
- nullpo_info_core (file, line, func, fmt, ap);
- va_end (ap);
+ va_start(ap, fmt);
+ nullpo_info_core(file, line, func, fmt, ap);
+ va_end(ap);
return 1;
}
-bool nullpo_chk (const char *file, int line, const char *func,
+bool nullpo_chk(const char *file, int line, const char *func,
const void *target)
{
if (target)
return 0;
- nullpo_info_core (file, line, func);
+ nullpo_info_core(file, line, func);
return 1;
}
/// External functions
-void nullpo_info_f (const char *file, int line, const char *func,
+void nullpo_info_f(const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list ap;
- va_start (ap, fmt);
- nullpo_info_core (file, line, func, fmt, ap);
- va_end (ap);
+ va_start(ap, fmt);
+ nullpo_info_core(file, line, func, fmt, ap);
+ va_end(ap);
}
-void nullpo_info (const char *file, int line, const char *func)
+void nullpo_info(const char *file, int line, const char *func)
{
- nullpo_info_core (file, line, func);
+ nullpo_info_core(file, line, func);
}
/// Actual output function
-static void nullpo_info_core (const char *file, int line, const char *func)
+static void nullpo_info_core(const char *file, int line, const char *func)
{
if (!file)
file = "??";
if (!func || !*func)
func = "unknown";
- fprintf (stderr, "%s:%d: in func `%s': NULL pointer\n", file, line, func);
+ fprintf(stderr, "%s:%d: in func `%s': NULL pointer\n", file, line, func);
}
-static void nullpo_info_core (const char *file, int line, const char *func,
+static void nullpo_info_core(const char *file, int line, const char *func,
const char *fmt, va_list ap)
{
nullpo_info_core(file, line, func);
if (fmt && *fmt)
{
- vfprintf (stderr, fmt, ap);
- if (fmt[strlen (fmt) - 1] != '\n')
+ vfprintf(stderr, fmt, ap);
+ if (fmt[strlen(fmt) - 1] != '\n')
fputc('\n', stderr);
}
}
diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp
index 7aff691..25ab2b9 100644
--- a/src/common/nullpo.hpp
+++ b/src/common/nullpo.hpp
@@ -42,20 +42,20 @@
# include "sanity.hpp"
/// Used by macros in this header
-bool nullpo_chk (const char *file, int line, const char *func,
+bool nullpo_chk(const char *file, int line, const char *func,
const void *target);
/// Used by macros in this header
-bool nullpo_chk_f (const char *file, int line, const char *func,
+bool nullpo_chk_f(const char *file, int line, const char *func,
const void *target, const char *fmt, ...)
- __attribute__ ((format (printf, 5, 6)));
+ __attribute__((format(printf, 5, 6)));
/// Used only by map/battle.c
-void nullpo_info (const char *file, int line, const char *func);
+void nullpo_info(const char *file, int line, const char *func);
/// Not used
-void nullpo_info_f (const char *file, int line, const char *func,
+void nullpo_info_f(const char *file, int line, const char *func,
const char *fmt, ...)
- __attribute__ ((format (printf, 4, 5)));
+ __attribute__((format(printf, 4, 5)));
#endif // NULLPO_HPP
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index cc6e4b3..fb254dc 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -20,8 +20,8 @@
#include "utils.hpp"
fd_set readfds;
-int fd_max;
-int currentuse;
+int fd_max;
+int currentuse;
const uint32_t RFIFO_SIZE = 65536;
const uint32_t WFIFO_SIZE = 65536;
@@ -29,23 +29,23 @@ const uint32_t WFIFO_SIZE = 65536;
struct socket_data *session[FD_SETSIZE];
/// Discard all input
-static void null_parse (int fd);
+static void null_parse(int fd);
/// Default parser for new connections
-static void (*default_func_parse) (int) = null_parse;
+static void(*default_func_parse)(int) = null_parse;
-void set_defaultparse (void (*defaultparse) (int))
+void set_defaultparse(void(*defaultparse)(int))
{
default_func_parse = defaultparse;
}
/// Read from socket to the queue
-static void recv_to_fifo (int fd)
+static void recv_to_fifo(int fd)
{
if (session[fd]->eof)
return;
- ssize_t len = read (fd, session[fd]->rdata + session[fd]->rdata_size,
- RFIFOSPACE (fd));
+ ssize_t len = read(fd, session[fd]->rdata + session[fd]->rdata_size,
+ RFIFOSPACE(fd));
if (len > 0)
{
@@ -58,19 +58,19 @@ static void recv_to_fifo (int fd)
}
}
-static void send_from_fifo (int fd)
+static void send_from_fifo(int fd)
{
if (session[fd]->eof)
return;
- ssize_t len = write (fd, session[fd]->wdata, session[fd]->wdata_size);
+ ssize_t len = write(fd, session[fd]->wdata, session[fd]->wdata_size);
if (len > 0)
{
session[fd]->wdata_size -= len;
if (len < (ssize_t)session[fd]->wdata_size)
{
- memmove (session[fd]->wdata, session[fd]->wdata + len,
+ memmove(session[fd]->wdata, session[fd]->wdata + len,
session[fd]->wdata_size);
}
session[fd]->connected = 1;
@@ -81,32 +81,32 @@ static void send_from_fifo (int fd)
}
}
-static void null_parse (int fd)
+static void null_parse(int fd)
{
- printf ("null_parse : %d\n", fd);
- RFIFOSKIP (fd, RFIFOREST (fd));
+ printf("null_parse : %d\n", fd);
+ RFIFOSKIP(fd, RFIFOREST(fd));
}
-static void connect_client (int listen_fd)
+static void connect_client(int listen_fd)
{
struct sockaddr_in client_address;
- socklen_t len = sizeof (client_address);
+ socklen_t len = sizeof(client_address);
- int fd = accept (listen_fd, (struct sockaddr *) &client_address, &len);
+ int fd = accept(listen_fd, (struct sockaddr *) &client_address, &len);
if (fd == -1)
{
- perror ("accept");
+ perror("accept");
return;
}
if (fd_max <= fd)
{
fd_max = fd + 1;
}
- if (!free_fds ())
+ if (!free_fds())
{
- fprintf (stderr, "softlimit reached, disconnecting : %d\n", fd);
- delete_session (fd);
+ fprintf(stderr, "softlimit reached, disconnecting : %d\n", fd);
+ delete_session(fd);
return;
}
@@ -114,20 +114,20 @@ static void connect_client (int listen_fd)
/// Allow to bind() again after the server restarts.
// Since the socket is still in the TIME_WAIT, there's a possibility
// that formerly lost packets might be delivered and confuse the server.
- setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
/// Send packets as soon as possible
/// even if the kernel thinks there is too little for it to be worth it!
// I'm not convinced this is a good idea; although in minimizes the
// latency for an individual write, it increases traffic in general.
- setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
- FD_SET (fd, &readfds);
+ FD_SET(fd, &readfds);
- fcntl (fd, F_SETFL, O_NONBLOCK);
+ fcntl(fd, F_SETFL, O_NONBLOCK);
- CREATE (session[fd], struct socket_data, 1);
- CREATE (session[fd]->rdata, uint8_t, RFIFO_SIZE);
- CREATE (session[fd]->wdata, uint8_t, WFIFO_SIZE);
+ CREATE(session[fd], struct socket_data, 1);
+ CREATE(session[fd]->rdata, uint8_t, RFIFO_SIZE);
+ CREATE(session[fd]->wdata, uint8_t, WFIFO_SIZE);
session[fd]->max_rdata = RFIFO_SIZE;
session[fd]->max_wdata = WFIFO_SIZE;
@@ -135,72 +135,72 @@ static void connect_client (int listen_fd)
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
session[fd]->client_addr = client_address;
- session[fd]->created = time (NULL);
+ session[fd]->created = time(NULL);
session[fd]->connected = 0;
currentuse++;
}
-int make_listen_port (uint16_t port)
+int make_listen_port(uint16_t port)
{
struct sockaddr_in server_address;
- int fd = socket (AF_INET, SOCK_STREAM, 0);
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
{
- perror ("socket");
+ perror("socket");
return -1;
}
if (fd_max <= fd)
fd_max = fd + 1;
- fcntl (fd, F_SETFL, O_NONBLOCK);
+ fcntl(fd, F_SETFL, O_NONBLOCK);
const int yes = 1;
/// Allow to bind() again after the server restarts.
// Since the socket is still in the TIME_WAIT, there's a possibility
// that formerly lost packets might be delivered and confuse the server.
- setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
/// Send packets as soon as possible
/// even if the kernel thinks there is too little for it to be worth it!
// I'm not convinced this is a good idea; although in minimizes the
// latency for an individual write, it increases traffic in general.
- setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
server_address.sin_family = AF_INET;
- server_address.sin_addr.s_addr = htonl (INADDR_ANY);
- server_address.sin_port = htons (port);
+ server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+ server_address.sin_port = htons(port);
- if (bind (fd, (struct sockaddr *) &server_address,
- sizeof (server_address)) == -1)
+ if (bind(fd, (struct sockaddr *) &server_address,
+ sizeof(server_address)) == -1)
{
- perror ("bind");
- exit (1);
+ perror("bind");
+ exit(1);
}
- if (listen (fd, 5) == -1)
+ if (listen(fd, 5) == -1)
{ /* error */
- perror ("listen");
- exit (1);
+ perror("listen");
+ exit(1);
}
- FD_SET (fd, &readfds);
+ FD_SET(fd, &readfds);
- CREATE (session[fd], struct socket_data, 1);
+ CREATE(session[fd], struct socket_data, 1);
session[fd]->func_recv = connect_client;
- session[fd]->created = time (NULL);
+ session[fd]->created = time(NULL);
session[fd]->connected = 1;
currentuse++;
return fd;
}
-int make_connection (uint32_t ip, uint16_t port)
+int make_connection(uint32_t ip, uint16_t port)
{
struct sockaddr_in server_address;
- int fd = socket (AF_INET, SOCK_STREAM, 0);
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
{
- perror ("socket");
+ perror("socket");
return -1;
}
if (fd_max <= fd)
@@ -210,43 +210,43 @@ int make_connection (uint32_t ip, uint16_t port)
/// Allow to bind() again after the server restarts.
// Since the socket is still in the TIME_WAIT, there's a possibility
// that formerly lost packets might be delivered and confuse the server.
- setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
/// Send packets as soon as possible
/// even if the kernel thinks there is too little for it to be worth it!
// I'm not convinced this is a good idea; although in minimizes the
// latency for an individual write, it increases traffic in general.
- setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = ip;
- server_address.sin_port = htons (port);
+ server_address.sin_port = htons(port);
- fcntl (fd, F_SETFL, O_NONBLOCK);
+ fcntl(fd, F_SETFL, O_NONBLOCK);
/// Errors not caught - we must not block
/// Let the main select() loop detect when we know the state
- connect (fd, (struct sockaddr *) &server_address,
- sizeof (struct sockaddr_in));
+ connect(fd, (struct sockaddr *) &server_address,
+ sizeof(struct sockaddr_in));
- FD_SET (fd, &readfds);
+ FD_SET(fd, &readfds);
- CREATE (session[fd], struct socket_data, 1);
- CREATE (session[fd]->rdata, uint8_t, RFIFO_SIZE);
- CREATE (session[fd]->wdata, uint8_t, WFIFO_SIZE);
+ CREATE(session[fd], struct socket_data, 1);
+ CREATE(session[fd]->rdata, uint8_t, RFIFO_SIZE);
+ CREATE(session[fd]->wdata, uint8_t, WFIFO_SIZE);
session[fd]->max_rdata = RFIFO_SIZE;
session[fd]->max_wdata = WFIFO_SIZE;
session[fd]->func_recv = recv_to_fifo;
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
- session[fd]->created = time (NULL);
+ session[fd]->created = time(NULL);
session[fd]->connected = 1;
currentuse++;
return fd;
}
-void delete_session (int fd)
+void delete_session(int fd)
{
if (fd < 0 || fd >= FD_SETSIZE)
return;
@@ -255,151 +255,151 @@ void delete_session (int fd)
// but this is cheap and good enough for the typical case
if (fd == fd_max - 1)
fd_max--;
- FD_CLR (fd, &readfds);
+ FD_CLR(fd, &readfds);
if (session[fd])
{
- free (session[fd]->rdata);
- free (session[fd]->wdata);
- free (session[fd]->session_data);
- free (session[fd]);
+ free(session[fd]->rdata);
+ free(session[fd]->wdata);
+ free(session[fd]->session_data);
+ free(session[fd]);
}
session[fd] = NULL;
// just close() would try to keep sending buffers
- shutdown (fd, SHUT_RDWR);
- close (fd);
+ shutdown(fd, SHUT_RDWR);
+ close(fd);
currentuse--;
if (currentuse < 0)
{
- fprintf (stderr, "delete_session: current sessions negative!\n");
+ fprintf(stderr, "delete_session: current sessions negative!\n");
currentuse = 0;
}
return;
}
-void realloc_fifo (int fd, size_t rfifo_size, size_t wfifo_size)
+void realloc_fifo(int fd, size_t rfifo_size, size_t wfifo_size)
{
struct socket_data *s = session[fd];
if (s->max_rdata != rfifo_size && s->rdata_size < rfifo_size)
{
- RECREATE (s->rdata, uint8_t, rfifo_size);
+ RECREATE(s->rdata, uint8_t, rfifo_size);
s->max_rdata = rfifo_size;
}
if (s->max_wdata != wfifo_size && s->wdata_size < wfifo_size)
{
- RECREATE (s->wdata, uint8_t, wfifo_size);
+ RECREATE(s->wdata, uint8_t, wfifo_size);
s->max_wdata = wfifo_size;
}
}
-void WFIFOSET (int fd, size_t len)
+void WFIFOSET(int fd, size_t len)
{
struct socket_data *s = session[fd];
if (s->wdata_size + len + 16384 > s->max_wdata)
{
- realloc_fifo (fd, s->max_rdata, s->max_wdata << 1);
- printf ("socket: %d wdata expanded to %d bytes.\n", fd, s->max_wdata);
+ realloc_fifo(fd, s->max_rdata, s->max_wdata << 1);
+ printf("socket: %d wdata expanded to %d bytes.\n", fd, s->max_wdata);
}
if (s->wdata_size + len + 2048 < s->max_wdata)
s->wdata_size += len;
else
- fprintf (stderr, "socket: %d wdata lost !!\n", fd), abort ();
+ fprintf(stderr, "socket: %d wdata lost !!\n", fd), abort();
}
-void do_sendrecv (uint32_t next)
+void do_sendrecv(uint32_t next)
{
fd_set rfd = readfds, wfd;
- FD_ZERO (&wfd);
+ FD_ZERO(&wfd);
for (int i = 0; i < fd_max; i++)
{
if (session[i] && session[i]->wdata_size)
- FD_SET (i, &wfd);
+ FD_SET(i, &wfd);
}
struct timeval timeout;
timeout.tv_sec = next / 1000;
timeout.tv_usec = next % 1000 * 1000;
- if (select (fd_max, &rfd, &wfd, NULL, &timeout) <= 0)
+ if (select(fd_max, &rfd, &wfd, NULL, &timeout) <= 0)
return;
for (int i = 0; i < fd_max; i++)
{
if (!session[i])
continue;
- if (FD_ISSET (i, &wfd))
+ if (FD_ISSET(i, &wfd))
{
if (session[i]->func_send)
//send_from_fifo(i);
- session[i]->func_send (i);
+ session[i]->func_send(i);
}
- if (FD_ISSET (i, &rfd))
+ if (FD_ISSET(i, &rfd))
{
if (session[i]->func_recv)
//recv_to_fifo(i);
//or connect_client(i);
- session[i]->func_recv (i);
+ session[i]->func_recv(i);
}
}
}
-void do_parsepacket (void)
+void do_parsepacket(void)
{
for (int i = 0; i < fd_max; i++)
{
if (!session[i])
continue;
if (!session[i]->connected
- && time (NULL) - session[i]->created > CONNECT_TIMEOUT)
+ && time(NULL) - session[i]->created > CONNECT_TIMEOUT)
{
- printf ("Session #%d timed out\n", i);
+ printf("Session #%d timed out\n", i);
session[i]->eof = 1;
}
if (!session[i]->rdata_size && !session[i]->eof)
continue;
if (session[i]->func_parse)
{
- session[i]->func_parse (i);
+ session[i]->func_parse(i);
/// some func_parse may call delete_session
if (!session[i])
continue;
}
/// Reclaim buffer space for what was read
- RFIFOFLUSH (i);
+ RFIFOFLUSH(i);
}
}
-void do_socket (void)
+void do_socket(void)
{
- FD_ZERO (&readfds);
+ FD_ZERO(&readfds);
currentuse = 3;
}
-void RFIFOSKIP (int fd, size_t len)
+void RFIFOSKIP(int fd, size_t len)
{
struct socket_data *s = session[fd];
s->rdata_pos += len;
if (s->rdata_size < s->rdata_pos)
{
- fprintf (stderr, "too many skip\n");
- abort ();
+ fprintf(stderr, "too many skip\n");
+ abort();
}
}
-void fclose_ (FILE * fp)
+void fclose_(FILE * fp)
{
- if (fclose (fp))
- perror ("fclose"), abort ();
+ if (fclose(fp))
+ perror("fclose"), abort();
currentuse--;
}
-FILE *fopen_ (const char *path, const char *mode)
+FILE *fopen_(const char *path, const char *mode)
{
- FILE *f = fopen (path, mode);
+ FILE *f = fopen(path, mode);
if (f)
currentuse++;
return f;
}
-bool free_fds (void)
+bool free_fds(void)
{
return currentuse < SOFT_LIMIT;
}
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index 00f2df0..b2ef119 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -19,7 +19,7 @@
# define RFIFOW(fd,pos) (*(uint16_t*)(RFIFOP(fd, pos)))
# define RFIFOL(fd,pos) (*(uint32_t*)(RFIFOP(fd, pos)))
/// Done reading
-void RFIFOSKIP (int fd, size_t len);
+void RFIFOSKIP(int fd, size_t len);
/// Internal - clean up by discarding handled bytes
// Atm this is also called in char/char.c, but that is unnecessary
# define RFIFOFLUSH(fd) (memmove(session[fd]->rdata,RFIFOP(fd,0),RFIFOREST(fd)),\
@@ -45,7 +45,7 @@ session[fd]->rdata_pos=0)
# define WFIFOW(fd,pos) (*(uint16_t*)(WFIFOP(fd,pos)))
# define WFIFOL(fd,pos) (*(uint32_t*)(WFIFOP(fd,pos)))
/// Finish writing
-void WFIFOSET (int fd, size_t len);
+void WFIFOSET(int fd, size_t len);
/// Write to an arbitrary buffer
#define WBUFP(p,pos) (((uint8_t*)(p))+(pos))
@@ -80,13 +80,13 @@ struct socket_data
/// Only called when select() indicates the socket is ready
/// If, after that, nothing is read, it sets eof
// These could probably be hard-coded with a little work
- void (*func_recv) (int);
- void (*func_send) (int);
+ void(*func_recv)(int);
+ void(*func_send)(int);
/// This is the important one
/// Set to different functions depending on whether the connection
/// is a player or a server/ladmin
/// Can be set explicitly or via set_defaultparse
- void (*func_parse) (int);
+ void(*func_parse)(int);
/// Server-specific data type
void *session_data;
};
@@ -106,30 +106,30 @@ extern int fd_max;
/// open a socket, bind, and listen. Return an fd, or -1 if socket() fails,
/// but exit if bind() or listen() fails
-int make_listen_port (uint16_t port);
+int make_listen_port(uint16_t port);
/// Connect to an address, return a connected socket or -1
// FIXME - this is IPv4 only!
-int make_connection (uint32_t ip, uint16_t port);
+int make_connection(uint32_t ip, uint16_t port);
/// free() the structure and close() the fd
-void delete_session (int);
+void delete_session(int);
/// Make a the internal queues bigger
-void realloc_fifo (int fd, size_t rfifo_size, size_t wfifo_size);
+void realloc_fifo(int fd, size_t rfifo_size, size_t wfifo_size);
/// Update all sockets that can be read/written from the queues
-void do_sendrecv (uint32_t next);
+void do_sendrecv(uint32_t next);
/// Call the parser function for every socket that has read data
-void do_parsepacket (void);
+void do_parsepacket(void);
/// An init function
-void do_socket (void);
+void do_socket(void);
/// Change the default parser for newly connected clients
// typically called once per server, but individual clients may identify
// themselves as servers
-void set_defaultparse (void (*defaultparse) (int));
+void set_defaultparse(void(*defaultparse)(int));
/// Wrappers to track number of free FDs
-void fclose_ (FILE * fp);
-FILE *fopen_ (const char *path, const char *mode);
-bool free_fds (void);
+void fclose_(FILE * fp);
+FILE *fopen_(const char *path, const char *mode);
+bool free_fds(void);
#endif // SOCKET_HPP
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index 66aaa9b..8a12d19 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -29,30 +29,30 @@ static timer_id *timer_heap = NULL;
static uint32_t gettick_cache;
static uint8_t gettick_count = 0;
-uint32_t gettick_nocache (void)
+uint32_t gettick_nocache(void)
{
struct timeval tval;
// BUG: This will cause strange behavior if the system clock is changed!
// it should be reimplemented in terms of clock_gettime(CLOCK_MONOTONIC, )
- gettimeofday (&tval, NULL);
+ gettimeofday(&tval, NULL);
gettick_count = 255;
return gettick_cache = tval.tv_sec * 1000 + tval.tv_usec / 1000;
}
-uint32_t gettick (void)
+uint32_t gettick(void)
{
if (gettick_count--)
return gettick_cache;
- return gettick_nocache ();
+ return gettick_nocache();
}
-static void push_timer_heap (timer_id index)
+static void push_timer_heap(timer_id index)
{
if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max)
{
timer_heap_max += 256;
- RECREATE (timer_heap, timer_id, timer_heap_max);
- memset (timer_heap + (timer_heap_max - 256), 0, sizeof (timer_id) * 256);
+ RECREATE(timer_heap, timer_id, timer_heap_max);
+ memset(timer_heap + (timer_heap_max - 256), 0, sizeof(timer_id) * 256);
}
// timer_heap[0] is the greatest index into the heap, which increases
timer_heap[0]++;
@@ -71,14 +71,14 @@ static void push_timer_heap (timer_id index)
timer_heap[h + 1] = index;
}
-static timer_id top_timer_heap (void)
+static timer_id top_timer_heap(void)
{
if (!timer_heap || !timer_heap[0])
return -1;
return timer_heap[1];
}
-static timer_id pop_timer_heap (void)
+static timer_id pop_timer_heap(void)
{
if (!timer_heap || !timer_heap[0])
return -1;
@@ -99,7 +99,7 @@ static timer_id pop_timer_heap (void)
uint32_t i = (h - 1) / 2;
while (h)
{
- if (DIFF_TICK (timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0)
+ if (DIFF_TICK(timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0)
break;
timer_heap[h + 1] = timer_heap[i + 1];
h = i;
@@ -110,7 +110,7 @@ static timer_id pop_timer_heap (void)
return ret;
}
-timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t data)
+timer_id add_timer(tick_t tick, timer_func func, custom_id_t id, custom_data_t data)
{
timer_id i;
@@ -136,14 +136,14 @@ timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t
if (timer_data_max == 0)
{
timer_data_max = 256;
- CREATE (timer_data, struct TimerData, timer_data_max);
+ CREATE(timer_data, struct TimerData, timer_data_max);
}
else
{
timer_data_max += 256;
- RECREATE (timer_data, struct TimerData, timer_data_max);
- memset (timer_data + (timer_data_max - 256), 0,
- sizeof (struct TimerData) * 256);
+ RECREATE(timer_data, struct TimerData, timer_data_max);
+ memset(timer_data + (timer_data_max - 256), 0,
+ sizeof(struct TimerData) * 256);
}
}
timer_data[i].tick = tick;
@@ -152,32 +152,32 @@ timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t
timer_data[i].data = data;
timer_data[i].type = TIMER_ONCE_AUTODEL;
timer_data[i].interval = 1000;
- push_timer_heap (i);
+ push_timer_heap(i);
if (i >= timer_data_num)
timer_data_num = i + 1;
return i;
}
-timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id,
+timer_id add_timer_interval(tick_t tick, timer_func func, custom_id_t id,
custom_data_t data, interval_t interval)
{
- timer_id tid = add_timer (tick, func, id, data);
+ timer_id tid = add_timer(tick, func, id, data);
timer_data[tid].type = TIMER_INTERVAL;
timer_data[tid].interval = interval;
return tid;
}
-void delete_timer (timer_id id, timer_func func)
+void delete_timer(timer_id id, timer_func func)
{
if (id == 0 || id >= timer_data_num)
{
- fprintf (stderr, "delete_timer error : no such timer %d\n", id);
- abort ();
+ fprintf(stderr, "delete_timer error : no such timer %d\n", id);
+ abort();
}
if (timer_data[id].func != func)
{
- fprintf (stderr, "Timer mismatch\n");
- abort ();
+ fprintf(stderr, "Timer mismatch\n");
+ abort();
}
// "to let them disappear" - is this just in case?
timer_data[id].func = NULL;
@@ -185,43 +185,43 @@ void delete_timer (timer_id id, timer_func func)
timer_data[id].tick -= 60 * 60 * 1000;
}
-tick_t addtick_timer (timer_id tid, interval_t tick)
+tick_t addtick_timer(timer_id tid, interval_t tick)
{
return timer_data[tid].tick += tick;
}
-struct TimerData *get_timer (timer_id tid)
+struct TimerData *get_timer(timer_id tid)
{
return &timer_data[tid];
}
-interval_t do_timer (tick_t tick)
+interval_t do_timer(tick_t tick)
{
timer_id i;
/// Number of milliseconds until it calls this again
// this says to wait 1 sec if all timers get popped
interval_t nextmin = 1000;
- while ((i = top_timer_heap ()) != (timer_id)-1)
+ while ((i = top_timer_heap()) != (timer_id)-1)
{
// while the heap is not empty and
- if (DIFF_TICK (timer_data[i].tick, tick) > 0)
+ if (DIFF_TICK(timer_data[i].tick, tick) > 0)
{
/// Return the time until the next timer needs to goes off
- nextmin = DIFF_TICK (timer_data[i].tick, tick);
+ nextmin = DIFF_TICK(timer_data[i].tick, tick);
break;
}
- pop_timer_heap ();
+ pop_timer_heap();
if (timer_data[i].func)
{
- if (DIFF_TICK (timer_data[i].tick, tick) < -1000)
+ if (DIFF_TICK(timer_data[i].tick, tick) < -1000)
{
// If we are too far past the requested tick, call with the current tick instead to fix reregistering problems
- timer_data[i].func (i, tick, timer_data[i].id, timer_data[i].data);
+ timer_data[i].func(i, tick, timer_data[i].id, timer_data[i].data);
}
else
{
- timer_data[i].func (i, timer_data[i].tick, timer_data[i].id, timer_data[i].data);
+ timer_data[i].func(i, timer_data[i].tick, timer_data[i].id, timer_data[i].data);
}
}
switch (timer_data[i].type)
@@ -231,14 +231,14 @@ interval_t do_timer (tick_t tick)
if (free_timer_list_pos >= free_timer_list_max)
{
free_timer_list_max += 256;
- RECREATE (free_timer_list, uint32_t, free_timer_list_max);
- memset (free_timer_list + (free_timer_list_max - 256),
- 0, 256 * sizeof (uint32_t));
+ RECREATE(free_timer_list, uint32_t, free_timer_list_max);
+ memset(free_timer_list + (free_timer_list_max - 256),
+ 0, 256 * sizeof(uint32_t));
}
free_timer_list[free_timer_list_pos++] = i;
break;
case TIMER_INTERVAL:
- if (DIFF_TICK (timer_data[i].tick, tick) < -1000)
+ if (DIFF_TICK(timer_data[i].tick, tick) < -1000)
{
timer_data[i].tick = tick + timer_data[i].interval;
}
@@ -246,7 +246,7 @@ interval_t do_timer (tick_t tick)
{
timer_data[i].tick += timer_data[i].interval;
}
- push_timer_heap (i);
+ push_timer_heap(i);
break;
}
}
diff --git a/src/common/timer.hpp b/src/common/timer.hpp
index fdda344..fc4f8cb 100644
--- a/src/common/timer.hpp
+++ b/src/common/timer.hpp
@@ -19,7 +19,7 @@ typedef uint32_t timer_id;
// BUG: pointers are stored in here
typedef int32_t custom_id_t;
typedef int32_t custom_data_t;
-typedef void (*timer_func) (timer_id, tick_t, custom_id_t, custom_data_t);
+typedef void(*timer_func)(timer_id, tick_t, custom_id_t, custom_data_t);
struct TimerData
{
@@ -41,20 +41,20 @@ struct TimerData
/// but use of 32-bit integers means it wraps every 49 days.
// The only external caller of this function is the core.c main loop, but that makes sense
// in fact, it might make more sense if gettick() ALWAYS returned that cached value
-tick_t gettick_nocache (void);
+tick_t gettick_nocache(void);
/// This function is called enough that it's worth caching the result for
/// the next 255 times
-tick_t gettick (void);
+tick_t gettick(void);
-timer_id add_timer (tick_t, timer_func, custom_id_t, custom_data_t);
-timer_id add_timer_interval (tick_t, timer_func, custom_id_t, custom_data_t, interval_t);
-void delete_timer (timer_id, timer_func);
+timer_id add_timer(tick_t, timer_func, custom_id_t, custom_data_t);
+timer_id add_timer_interval(tick_t, timer_func, custom_id_t, custom_data_t, interval_t);
+void delete_timer(timer_id, timer_func);
-tick_t addtick_timer (timer_id, interval_t);
-struct TimerData *get_timer (timer_id tid);
+tick_t addtick_timer(timer_id, interval_t);
+struct TimerData *get_timer(timer_id tid);
/// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens
-interval_t do_timer (tick_t tick);
+interval_t do_timer(tick_t tick);
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index fbdd87e..732f3b1 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -9,10 +9,10 @@
//-----------------------------------------------------
// Function to suppress control characters in a string.
//-----------------------------------------------------
-int remove_control_chars (char *str)
+int remove_control_chars(char *str)
{
- int i;
- int change = 0;
+ int i;
+ int change = 0;
for (i = 0; str[i]; i++)
{
@@ -29,39 +29,39 @@ int remove_control_chars (char *str)
//---------------------------------------------------
// E-mail check: return 0 (not correct) or 1 (valid).
//---------------------------------------------------
-int e_mail_check (const char *email)
+int e_mail_check(const char *email)
{
char ch;
const char *last_arobas;
// athena limits
- if (strlen (email) < 3 || strlen (email) > 39)
+ if (strlen(email) < 3 || strlen(email) > 39)
return 0;
// part of RFC limits (official reference of e-mail description)
- if (strchr (email, '@') == NULL || email[strlen (email) - 1] == '@')
+ if (strchr(email, '@') == NULL || email[strlen(email) - 1] == '@')
return 0;
- if (email[strlen (email) - 1] == '.')
+ if (email[strlen(email) - 1] == '.')
return 0;
- last_arobas = strrchr (email, '@');
+ last_arobas = strrchr(email, '@');
- if (strstr (last_arobas, "@.") != NULL ||
- strstr (last_arobas, "..") != NULL)
+ if (strstr(last_arobas, "@.") != NULL ||
+ strstr(last_arobas, "..") != NULL)
return 0;
for (ch = 1; ch < 32; ch++)
{
- if (strchr (last_arobas, ch) != NULL)
+ if (strchr(last_arobas, ch) != NULL)
{
return 0;
break;
}
}
- if (strchr (last_arobas, ' ') != NULL ||
- strchr (last_arobas, ';') != NULL)
+ if (strchr(last_arobas, ' ') != NULL ||
+ strchr(last_arobas, ';') != NULL)
return 0;
// all correct
@@ -74,15 +74,15 @@ int e_mail_check (const char *email)
//-------------------------------------------------
int config_switch (const char *str)
{
- if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0
- || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0
- || strcasecmp (str, "si") == 0)
+ if (strcasecmp(str, "on") == 0 || strcasecmp(str, "yes") == 0
+ || strcasecmp(str, "oui") == 0 || strcasecmp(str, "ja") == 0
+ || strcasecmp(str, "si") == 0)
return 1;
- if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0
- || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0)
+ if (strcasecmp(str, "off") == 0 || strcasecmp(str, "no") == 0
+ || strcasecmp(str, "non") == 0 || strcasecmp(str, "nein") == 0)
return 0;
- return atoi (str);
+ return atoi(str);
}
const char *ip2str(struct in_addr ip, bool extra_dot)
diff --git a/src/common/utils.hpp b/src/common/utils.hpp
index 1097bf7..fdd9d40 100644
--- a/src/common/utils.hpp
+++ b/src/common/utils.hpp
@@ -11,15 +11,15 @@ I deleted malloc.{h,c} because it was redundant;
future calls should either use this or depend on the coming segfault.
*/
# define CREATE(result, type, number) \
- if (!((result) = (type *) calloc ((number), sizeof(type)))) \
+ if (!((result) = (type *) calloc((number), sizeof(type)))) \
{ perror("SYSERR: malloc failure"); abort(); } else (void)0
# define RECREATE(result,type,number) \
- if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\
+ if (!((result) = (type *) realloc((result), sizeof(type) * (number))))\
{ perror("SYSERR: realloc failure"); abort(); } else (void)0
-int remove_control_chars (char *str);
-int e_mail_check (const char *email);
+int remove_control_chars(char *str);
+int e_mail_check(const char *email);
int config_switch (const char *str);
const char *ip2str(struct in_addr ip, bool extra_dot = false);