summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/const_array.hpp1
-rw-r--r--src/common/core.cpp4
-rw-r--r--src/common/core.hpp2
-rw-r--r--src/common/cxxstdio.cpp33
-rw-r--r--src/common/cxxstdio.hpp16
-rw-r--r--src/common/db.cpp1
-rw-r--r--src/common/db.hpp1
-rw-r--r--src/common/extract.cpp68
-rw-r--r--src/common/extract.hpp60
-rw-r--r--src/common/grfio.cpp2
-rw-r--r--src/common/lock.hpp4
-rw-r--r--src/common/mmo.hpp2
-rw-r--r--src/common/nullpo.cpp1
-rw-r--r--src/common/nullpo.hpp2
-rw-r--r--src/common/socket.cpp10
-rw-r--r--src/common/socket.hpp3
-rw-r--r--src/common/timer.cpp4
-rw-r--r--src/common/utils.cpp4
-rw-r--r--src/common/utils2.hpp2
19 files changed, 132 insertions, 88 deletions
diff --git a/src/common/const_array.hpp b/src/common/const_array.hpp
index db8416d..93ae337 100644
--- a/src/common/const_array.hpp
+++ b/src/common/const_array.hpp
@@ -33,6 +33,7 @@
# define constexpr /* nothing */
#endif
+// TODO see if I ever actually use this, and not the subclass
template<class T>
class const_array
{
diff --git a/src/common/core.cpp b/src/common/core.cpp
index 7da1b27..300f1cc 100644
--- a/src/common/core.cpp
+++ b/src/common/core.cpp
@@ -5,14 +5,12 @@
#include <unistd.h>
#include <csignal>
-#include <cstdio>
#include <cstdlib>
+#include <ctime>
#include "mt_rand.hpp"
-#include "nullpo.hpp"
#include "socket.hpp"
#include "timer.hpp"
-#include "version.hpp"
#include "../poison.hpp"
diff --git a/src/common/core.hpp b/src/common/core.hpp
index 2d68eaf..0c11efb 100644
--- a/src/common/core.hpp
+++ b/src/common/core.hpp
@@ -1,6 +1,8 @@
#ifndef CORE_HPP
#define CORE_HPP
+#include "sanity.hpp"
+
/// core.c contains a server-independent main() function
/// and then runs a do_sendrecv loop
diff --git a/src/common/cxxstdio.cpp b/src/common/cxxstdio.cpp
new file mode 100644
index 0000000..8f4001f
--- /dev/null
+++ b/src/common/cxxstdio.cpp
@@ -0,0 +1,33 @@
+#include "cxxstdio.hpp"
+// cxxstdio.cpp - pass C++ types through scanf/printf
+//
+// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <cstdlib>
+
+namespace cxxstdio
+{
+StringConverter::~StringConverter()
+{
+ if (mid)
+ {
+ out = mid;
+ free(mid);
+ }
+}
+} // namespace cxxstdio
diff --git a/src/common/cxxstdio.hpp b/src/common/cxxstdio.hpp
index 866947c..96c3ca2 100644
--- a/src/common/cxxstdio.hpp
+++ b/src/common/cxxstdio.hpp
@@ -2,7 +2,7 @@
#define CXXSTDIO_HPP
// cxxstdio.hpp - pass C++ types through scanf/printf
//
-// Copyright © 2011-2012 Ben Longbons <b.r.longbons@gmail.com>
+// Copyright © 2011-2013 Ben Longbons <b.r.longbons@gmail.com>
//
// This file is part of The Mana World (Athena server)
//
@@ -19,15 +19,16 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "utils2.hpp"
+#include "sanity.hpp"
#include <cstdarg>
#include <cstdio>
-#include <cstdlib>
#include <string>
#include "const_array.hpp"
+#include "utils2.hpp"
+
namespace cxxstdio
{
@@ -213,14 +214,7 @@ namespace cxxstdio
StringConverter(std::string& s)
: out(s), mid(nullptr)
{}
- ~StringConverter()
- {
- if (mid)
- {
- out = mid;
- free(mid);
- }
- }
+ ~StringConverter();
char **operator &()
{
return &mid;
diff --git a/src/common/db.cpp b/src/common/db.cpp
index 6558ed0..970e054 100644
--- a/src/common/db.cpp
+++ b/src/common/db.cpp
@@ -1,6 +1,5 @@
#include "db.hpp"
-#include <cstdio>
#include <cstdlib>
#include <cstring>
diff --git a/src/common/db.hpp b/src/common/db.hpp
index 63ce7fa..d04f318 100644
--- a/src/common/db.hpp
+++ b/src/common/db.hpp
@@ -1,6 +1,7 @@
// WARNING: there is a system header by this name
#ifndef DB_HPP
#define DB_HPP
+
# include "sanity.hpp"
# include <functional>
diff --git a/src/common/extract.cpp b/src/common/extract.cpp
new file mode 100644
index 0000000..5e89e19
--- /dev/null
+++ b/src/common/extract.cpp
@@ -0,0 +1,68 @@
+#include "extract.hpp"
+// extract.cpp - a simple, hierarchical, tokenizer
+//
+// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+bool extract(const_string str, const_string *rv)
+{
+ *rv = str;
+ return true;
+}
+
+bool extract(const_string str, std::string *rv)
+{
+ *rv = std::string(str.begin(), str.end());
+ return true;
+}
+
+bool extract(const_string str, struct global_reg *var)
+{
+ return extract(str,
+ record<','>(&var->str, &var->value));
+}
+
+bool extract(const_string str, struct item *it)
+{
+ return extract(str,
+ record<','>(
+ &it->id,
+ &it->nameid,
+ &it->amount,
+ &it->equip,
+ &it->identify,
+ &it->refine,
+ &it->attribute,
+ &it->card[0],
+ &it->card[1],
+ &it->card[2],
+ &it->card[3],
+ &it->broken))
+ || extract(str,
+ record<','>(
+ &it->id,
+ &it->nameid,
+ &it->amount,
+ &it->equip,
+ &it->identify,
+ &it->refine,
+ &it->attribute,
+ &it->card[0],
+ &it->card[1],
+ &it->card[2],
+ &it->card[3]));
+}
diff --git a/src/common/extract.hpp b/src/common/extract.hpp
index 24456be..c60ce2a 100644
--- a/src/common/extract.hpp
+++ b/src/common/extract.hpp
@@ -1,8 +1,8 @@
#ifndef EXTRACT_HPP
#define EXTRACT_HPP
-// extract.hpp - a simple, heirarchail, tokenizer
+// extract.hpp - a simple, hierarchical, tokenizer
//
-// Copyright © 2012 Ben Longbons <b.r.longbons@gmail.com>
+// Copyright © 2012-2013 Ben Longbons <b.r.longbons@gmail.com>
//
// This file is part of The Mana World (Athena server)
//
@@ -19,6 +19,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include "sanity.hpp"
+
#include <algorithm>
#include "const_array.hpp"
@@ -70,19 +72,9 @@ bool extract(const_string str, T *iv)
return true;
}
-inline
-bool extract(const_string str, const_string *rv)
-{
- *rv = str;
- return true;
-}
+bool extract(const_string str, const_string *rv);
-inline
-bool extract(const_string str, std::string *rv)
-{
- *rv = std::string(str.begin(), str.end());
- return true;
-}
+bool extract(const_string str, std::string *rv);
template<size_t N>
__attribute__((deprecated))
@@ -160,42 +152,8 @@ bool extract(const_string str, VRecord<split, T> rec)
&& extract(const_string(s + 1, str.end()), rec);
}
-inline
-bool extract(const_string str, struct global_reg *var)
-{
- return extract(str,
- record<','>(&var->str, &var->value));
-}
+bool extract(const_string str, struct global_reg *var);
+
+bool extract(const_string str, struct item *it);
-inline
-bool extract(const_string str, struct item *it)
-{
- return extract(str,
- record<','>(
- &it->id,
- &it->nameid,
- &it->amount,
- &it->equip,
- &it->identify,
- &it->refine,
- &it->attribute,
- &it->card[0],
- &it->card[1],
- &it->card[2],
- &it->card[3],
- &it->broken))
- || extract(str,
- record<','>(
- &it->id,
- &it->nameid,
- &it->amount,
- &it->equip,
- &it->identify,
- &it->refine,
- &it->attribute,
- &it->card[0],
- &it->card[1],
- &it->card[2],
- &it->card[3]));
-}
#endif // EXTRACT_HPP
diff --git a/src/common/grfio.cpp b/src/common/grfio.cpp
index bbf073a..1ed5c3e 100644
--- a/src/common/grfio.cpp
+++ b/src/common/grfio.cpp
@@ -4,11 +4,9 @@
#include <sys/stat.h>
#include <cstdio>
-#include <cstdlib>
#include <cstring>
#include "cxxstdio.hpp"
-#include "mmo.hpp"
#include "socket.hpp"
#include "utils.hpp"
diff --git a/src/common/lock.hpp b/src/common/lock.hpp
index 8b444f4..f7ce2d8 100644
--- a/src/common/lock.hpp
+++ b/src/common/lock.hpp
@@ -1,8 +1,12 @@
#ifndef LOCK_HPP
#define LOCK_HPP
+#include "sanity.hpp"
+
#include <cstdio>
+// TODO replace with a class
+
/// Locked FILE I/O
// Changes are made in a separate file until lock_fclose
FILE *lock_fopen(const char *filename, int *info);
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index 7ed2548..db150ba 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -2,7 +2,7 @@
#ifndef MMO_HPP
#define MMO_HPP
-# include <ctime>
+# include "sanity.hpp"
# include "utils.hpp"
diff --git a/src/common/nullpo.cpp b/src/common/nullpo.cpp
index c18231a..d7d489c 100644
--- a/src/common/nullpo.cpp
+++ b/src/common/nullpo.cpp
@@ -1,7 +1,6 @@
#include "nullpo.hpp"
#include <cstdio>
-#include <cstring>
#include "../poison.hpp"
diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp
index 7d12033..ad1084a 100644
--- a/src/common/nullpo.hpp
+++ b/src/common/nullpo.hpp
@@ -25,7 +25,7 @@
/// Used by macros in this header
bool nullpo_chk(const char *file, int line, const char *func,
- const void *target);
+ const void *target);
/// Used only by map/battle.c
void nullpo_info(const char *file, int line, const char *func);
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index c877b2b..50c08a0 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -1,21 +1,19 @@
#include "socket.hpp"
-#include <netinet/in.h>
+#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/types.h>
+//#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
-#include <cerrno>
-#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <ctime>
#include "cxxstdio.hpp"
-#include "mmo.hpp"
+//#include "mmo.hpp"
#include "utils.hpp"
#include "../poison.hpp"
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index 975b7f4..b9b80b3 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -4,11 +4,8 @@
# include "sanity.hpp"
# include <netinet/in.h>
-# include <sys/socket.h>
-# include <sys/types.h>
# include <cstdio>
-# include <ctime>
// Struct declaration
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index abc885d..65f04e0 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -1,11 +1,7 @@
#include "timer.hpp"
-#include <sys/socket.h>
#include <sys/time.h>
-#include <sys/types.h>
-#include <cstdio>
-#include <cstdlib>
#include <cstring>
#include "cxxstdio.hpp"
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index 9a19244..bd82180 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -3,10 +3,6 @@
#include <netinet/in.h>
#include <sys/time.h>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-
#include <algorithm>
#include "../poison.hpp"
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp
index 3b652d5..973a445 100644
--- a/src/common/utils2.hpp
+++ b/src/common/utils2.hpp
@@ -1,6 +1,8 @@
#ifndef UTILS2_HPP
#define UTILS2_HPP
+#include "sanity.hpp"
+
#include <iterator>
#include <type_traits>