summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-19 16:07:22 +0100
committerHaru <haru@dotalux.com>2016-01-29 10:59:18 +0100
commit84a16afc56aa5a93dae2c83a9b1482ab52e90c31 (patch)
tree86c67a5cb2b0e13fb1624b51136d309be8dc3228 /src/plugins
parent8121e1d12dca0c85892ad45f0bb765e7eba770aa (diff)
downloadhercules-84a16afc56aa5a93dae2c83a9b1482ab52e90c31.tar.gz
hercules-84a16afc56aa5a93dae2c83a9b1482ab52e90c31.tar.bz2
hercules-84a16afc56aa5a93dae2c83a9b1482ab52e90c31.tar.xz
hercules-84a16afc56aa5a93dae2c83a9b1482ab52e90c31.zip
Removed duplicate code from the db2sql plugin
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/db2sql.c60
1 files changed, 24 insertions, 36 deletions
diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c
index 5b5d79bac..abbb42ee0 100644
--- a/src/plugins/db2sql.c
+++ b/src/plugins/db2sql.c
@@ -49,7 +49,7 @@ struct {
char *p;
size_t len;
} buf[4];
- char *db_name;
+ const char *db_name;
} tosql;
bool torun = false;
@@ -328,53 +328,41 @@ void totable(void) {
") ENGINE=MyISAM;\n"
"\n", year, tosql.db_name,tosql.db_name,tosql.db_name);
}
-void do_db2sql(void) {
+void do_db2sql(void)
+{
+ int i;
+ struct convert_db_files {
+ const char *name;
+ const char *source;
+ const char *destination;
+ } files[] = {
+ {"item_db", "re/item_db.conf", "sql-files/item_db_re.sql"},
+ {"item_db", "pre-re/item_db.conf", "sql-files/item_db.sql"},
+ {"item_db2", "item_db2.conf", "sql-files/item_db2.sql"},
+ };
+
/* link */
itemdb_readdb_libconfig_sub = itemdb->readdb_libconfig_sub;
itemdb->readdb_libconfig_sub = db2sql;
/* */
- if ((tosql.fp = fopen("sql-files/item_db_re.sql", "wt+")) == NULL) {
- ShowError("itemdb_tosql: File not found \"%s\".\n", "sql-files/item_db_re.sql");
- return;
- }
-
- tosql.db_name = "item_db";
- totable();
-
- memset(&tosql.buf, 0, sizeof(tosql.buf) );
-
+ memset(&tosql.buf, 0, sizeof(tosql.buf));
itemdb->clear(false);
- itemdb->readdb_libconfig("re/item_db.conf");
- fclose(tosql.fp);
-
- if ((tosql.fp = fopen("sql-files/item_db.sql", "wt+")) == NULL) {
- ShowError("itemdb_tosql: File not found \"%s\".\n", "sql-files/item_db.sql");
- return;
- }
-
- tosql.db_name = "item_db";
- totable();
+ for (i = 0; i < ARRAYLENGTH(files); i++) {
+ if ((tosql.fp = fopen(files[i].destination, "wt+")) == NULL) {
+ ShowError("itemdb_tosql: File not found \"%s\".\n", files[i].destination);
+ return;
+ }
- itemdb->clear(false);
- itemdb->readdb_libconfig("pre-re/item_db.conf");
+ tosql.db_name = files[i].name;
+ totable();
- fclose(tosql.fp);
+ itemdb->readdb_libconfig(files[i].source);
- if ((tosql.fp = fopen("sql-files/item_db2.sql", "wt+")) == NULL) {
- ShowError("itemdb_tosql: File not found \"%s\".\n", "sql-files/item_db2.sql");
- return;
+ fclose(tosql.fp);
}
- tosql.db_name = "item_db2";
- totable();
-
- itemdb->clear(false);
- itemdb->readdb_libconfig("item_db2.conf");
-
- fclose(tosql.fp);
-
/* unlink */
itemdb->readdb_libconfig_sub = itemdb_readdb_libconfig_sub;