From d1c69657fed9e9d2d4a674a86032b1b46fabfaa8 Mon Sep 17 00:00:00 2001 From: asmodai Date: Mon, 8 May 2017 23:52:22 +0300 Subject: [PATCH] Refactoring --- metamod/src/callback_jit.cpp | 2 +- metamod/src/dllapi.cpp | 2 +- metamod/src/jitasm.h | 2 +- metamod/src/log_meta.cpp | 2 +- metamod/src/log_meta.h | 2 +- metamod/src/metamod.cpp | 4 +-- metamod/src/mlist.cpp | 2 +- metamod/src/mlist.h | 8 +++--- metamod/src/mplayer.cpp | 4 +-- metamod/src/mplugin.cpp | 50 +++++++++++++++--------------------- 10 files changed, 34 insertions(+), 44 deletions(-) diff --git a/metamod/src/callback_jit.cpp b/metamod/src/callback_jit.cpp index ec96d78..30832fd 100644 --- a/metamod/src/callback_jit.cpp +++ b/metamod/src/callback_jit.cpp @@ -87,7 +87,7 @@ void CForwardCallbackJIT::naked_main() lea(eax, dword_ptr[esp + strbuf_offset]); // buf ptr else mov(eax, esp); - mov(ecx, size_t(vsnprintf)); + mov(ecx, size_t(Q_vsnprintf)); push(edx); push(dword_ptr[ebp + first_arg_offset + (m_jitdata->args_count - 1) * sizeof(int)]); // last arg of pfn (format string) diff --git a/metamod/src/dllapi.cpp b/metamod/src/dllapi.cpp index 0a80724..b214672 100644 --- a/metamod/src/dllapi.cpp +++ b/metamod/src/dllapi.cpp @@ -30,7 +30,7 @@ void MM_PRE_HOOK mm_ClientCommand(edict_t *pEntity) } } -void EXT_FUNC mm_ServerDeactivate(void) +void EXT_FUNC mm_ServerDeactivate() { sFunctionTable_jit.pfnServerDeactivate(); diff --git a/metamod/src/jitasm.h b/metamod/src/jitasm.h index 6562d91..d20f4ab 100644 --- a/metamod/src/jitasm.h +++ b/metamod/src/jitasm.h @@ -117,7 +117,7 @@ #define JITASM_TRACE jitasm::detail::Trace #endif #elif defined(JITASM_GCC) - #define JITASM_TRACE(...) ((void)0) + #define JITASM_TRACE(...) (()0) #else #define JITASM_TRACE __noop #endif diff --git a/metamod/src/log_meta.cpp b/metamod/src/log_meta.cpp index 12d9662..585debd 100644 --- a/metamod/src/log_meta.cpp +++ b/metamod/src/log_meta.cpp @@ -151,7 +151,7 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix, // Flushes the message queue, printing messages to the respective // service. This function doesn't check anymore if the g_engfuncs // jumptable is set. Don't call it if it isn't set. -void flush_ALERT_buffer(void) +void flush_ALERT_buffer() { BufferedMessage *msg = g_messageQueueStart; int dev = (int)CVAR_GET_FLOAT("developer"); diff --git a/metamod/src/log_meta.h b/metamod/src/log_meta.h index fb8da55..8f319d0 100644 --- a/metamod/src/log_meta.h +++ b/metamod/src/log_meta.h @@ -24,4 +24,4 @@ void META_LOG(const char *fmt, ...); void META_DEBUG_(int level, const char* fmt, ...); void META_CLIENT(edict_t *pEntity, const char *fmt, ...); -void flush_ALERT_buffer(void); +void flush_ALERT_buffer(); diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp index d71be2f..d2d8dd3 100644 --- a/metamod/src/metamod.cpp +++ b/metamod/src/metamod.cpp @@ -260,7 +260,7 @@ void metamod_startup() // Set initial GameDLL fields (name, gamedir). // meta_errno values: // - ME_NULLRESULT _getcwd failed -bool meta_init_gamedll(void) +bool meta_init_gamedll() { char gamedir[PATH_MAX]; char *cp; @@ -387,7 +387,7 @@ bool get_function_table_old(const char* ifname, int ifvers_mm, table_t*& table, // - ME_DLOPEN couldn't dlopen game dll file // - ME_DLMISSING couldn't find required routine in game dll // (GiveFnptrsToDll, GetEntityAPI, GetEntityAPI2) -bool meta_load_gamedll(void) +bool meta_load_gamedll() { if (!setup_gamedll(&g_GameDLL)) { diff --git a/metamod/src/mlist.cpp b/metamod/src/mlist.cpp index f480f7d..8ace174 100644 --- a/metamod/src/mlist.cpp +++ b/metamod/src/mlist.cpp @@ -642,7 +642,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now) } // Re-enable any plugins currently paused. -void MPluginList::unpause_all(void) +void MPluginList::unpause_all() { for (int i = 0; i < m_max_loaded_count; i++) { diff --git a/metamod/src/mlist.h b/metamod/src/mlist.h index ca19859..4588b4f 100644 --- a/metamod/src/mlist.h +++ b/metamod/src/mlist.h @@ -31,14 +31,14 @@ public: bool found_child_plugins(int source_index) const; - bool ini_startup(void); // read inifile at startup - bool ini_refresh(void); // re-read inifile + bool ini_startup(); // read inifile at startup + bool ini_refresh(); // re-read inifile bool cmd_addload(const char *args); // load from console command MPlugin *plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now); //load from plugin - bool load(void); // load the list, at startup + bool load(); // load the list, at startup bool refresh(PLUG_LOADTIME now); // update from re-read inifile - void unpause_all(void); // unpause any paused plugins + void unpause_all(); // unpause any paused plugins void retry_all(PLUG_LOADTIME now); // retry any pending plugin actions void show(int source_index = 0); // list plugins to console void show_client(edict_t *pEntity); // list plugins to player client diff --git a/metamod/src/mplayer.cpp b/metamod/src/mplayer.cpp index 8ea0254..120b141 100644 --- a/metamod/src/mplayer.cpp +++ b/metamod/src/mplayer.cpp @@ -32,7 +32,7 @@ void MPlayer::clear_cvar_query(const char *cvar) // Check if a client cvar is queried for this player // Returns NULL if not // or the name of the cvar. -const char *MPlayer::is_querying_cvar(void) const +const char *MPlayer::is_querying_cvar() const { if (m_isQueried) { @@ -60,7 +60,7 @@ void MPlayerList::clear_player_cvar_query(const edict_t *pEntity, const char *cv m_players[indx].clear_cvar_query(cvar); } -void MPlayerList::clear_all_cvar_queries(void) +void MPlayerList::clear_all_cvar_queries() { for (int indx = 1; indx <= gpGlobals->maxClients; indx++) { diff --git a/metamod/src/mplugin.cpp b/metamod/src/mplugin.cpp index a448b34..565da8c 100644 --- a/metamod/src/mplugin.cpp +++ b/metamod/src/mplugin.cpp @@ -129,8 +129,6 @@ bool MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON rea // Parse a filename string from PEXT_LOAD_PLUGIN_BY_ *function into a plugin. bool MPlugin::plugin_parseline(const char *fname, int loader_index) { - char *cp; - m_source_plugin_index = loader_index; Q_strncpy(m_filename, fname, sizeof m_filename - 1); @@ -138,7 +136,7 @@ bool MPlugin::plugin_parseline(const char *fname, int loader_index) NormalizePath(m_filename); //store just name of the actual _file, without path - cp = Q_strrchr(m_filename, '/'); + char* cp = Q_strrchr(m_filename, '/'); if (cp) m_file = cp + 1; else @@ -161,15 +159,13 @@ bool MPlugin::plugin_parseline(const char *fname, int loader_index) bool MPlugin::cmd_parseline(const char *line) { char buf[NAME_MAX + PATH_MAX + MAX_DESC_LEN]; - char *token; char *ptr_token; - char *cp; Q_strncpy(buf, line, sizeof buf - 1); buf[sizeof buf - 1] = '\0'; // remove "load" - token = strtok_r(buf, " \t", &ptr_token); + char* token = strtok_r(buf, " \t", &ptr_token); if (!token) return false; @@ -183,7 +179,7 @@ bool MPlugin::cmd_parseline(const char *line) NormalizePath(m_filename); // store name of just the actual _file_, without dir components - cp = Q_strrchr(m_filename, '/'); + char* cp = Q_strrchr(m_filename, '/'); if (cp) m_file = cp + 1; else @@ -215,7 +211,7 @@ bool MPlugin::cmd_parseline(const char *line) } // Make sure this plugin has the necessary minimal information. -bool MPlugin::check_input(void) +bool MPlugin::check_input() { // doublecheck our input/state if (m_status < PL_VALID) { @@ -254,7 +250,7 @@ bool MPlugin::check_input(void) // Gamedir/dlls/mm_filename_i386.so // Gamedir/dlls/filename_mm_i386.so // Gamedir/dlls/filename_MM_i386.so -bool MPlugin::resolve(void) +bool MPlugin::resolve() { char *found; @@ -341,7 +337,6 @@ char *MPlugin::resolve_dirs(char *path) const char *MPlugin::resolve_prefix(char *path) const { struct stat st; - char *cp, *fname; char dname[PATH_MAX]; static char buf[PATH_MAX]; char *found; @@ -351,12 +346,11 @@ char *MPlugin::resolve_prefix(char *path) const Q_strncpy(dname, path, sizeof dname - 1); dname[sizeof dname - 1] = '\0'; - cp = Q_strrchr(dname, '/'); + char* cp = Q_strrchr(dname, '/'); if (cp) { *cp = '\0'; - fname = cp + 1; - Q_snprintf(buf, sizeof buf, "%s/mm_%s", dname, fname); + Q_snprintf(buf, sizeof buf, "%s/mm_%s", dname, cp + 1); } else { @@ -456,9 +450,6 @@ static bool is_platform_postfix(char *pf) // the part up to the last dot, if one exists. bool MPlugin::platform_match(MPlugin *other) const { - char *end, *other_end; - int prefixlen; - if (m_status == PL_EMPTY || other->m_status == PL_EMPTY) return false; @@ -471,17 +462,18 @@ bool MPlugin::platform_match(MPlugin *other) const if (*m_desc != '\0' && !Q_stricmp(m_desc, other->m_desc)) return true; - end = Q_strrchr(m_file, '_'); - if (!end || !is_platform_postfix(end)) end = Q_strrchr(m_file, '.'); - other_end = Q_strrchr(other->m_file, '_'); - + char* end = Q_strrchr(m_file, '_'); + if (!end || !is_platform_postfix(end)) + end = Q_strrchr(m_file, '.'); + + char* other_end = Q_strrchr(other->m_file, '_'); if (!other_end || !is_platform_postfix(other_end)) other_end = Q_strrchr(other->m_file, '.'); if (!end || !other_end) return false; - prefixlen = end - m_file; + int prefixlen = end - m_file; if (other_end - other->m_file != prefixlen) return false; @@ -581,7 +573,7 @@ bool MPlugin::load(PLUG_LOADTIME now) // Meta_Init (if present) - tell dll it'll be used as a metamod plugin // GiveFnptrsToDll - give engine function ptrs // Meta_Query - say "hi" and get info about plugin -bool MPlugin::query(void) +bool MPlugin::query() { // open the plugin DLL if (!m_sys_module.load(m_pathname)) { @@ -967,7 +959,6 @@ bool MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, PL_UNLOAD_REASO // Inform plugin we're going to unload it. bool MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { - int ret; META_DETACH_FN pfn_detach; // If we have no handle, i.e. no dll loaded, we return true because the @@ -983,7 +974,7 @@ bool MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) return false; } - ret = pfn_detach(now, reason); + int ret = pfn_detach(now, reason); if (ret != TRUE) { META_ERROR("dll: Failed detach plugin '%s': Error from Meta_Detach(): %d", m_desc, ret); @@ -1101,7 +1092,7 @@ bool MPlugin::retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) // Clear a plugin (it failed a previous action and should be // removed from the list, or it's being unloaded). -bool MPlugin::clear(void) +bool MPlugin::clear() { if (m_status != PL_FAILED && m_status != PL_BADFILE && m_status != PL_EMPTY && m_status != PL_OPENED) { @@ -1169,7 +1160,7 @@ void show_table(const char* table_name, table_t* table, info_t* info_begin, bool // List information about plugin to console. void MPlugin::show() { - char *cp, *tstr; + char *cp; const int width = 13; META_CONS("%*s: %s", width, "name", m_info ? m_info->name : "(nil)"); @@ -1191,7 +1182,7 @@ void MPlugin::show() META_CONS("%*s: %s", width, "ifvers", m_info ? m_info->ifvers : "(nil)"); // ctime() includes newline at EOL - tstr = ctime(&m_time_loaded); + char* tstr = ctime(&m_time_loaded); if ((cp = Q_strchr(tstr, '\n'))) *cp = '\0'; @@ -1221,14 +1212,13 @@ void MPlugin::show() bool MPlugin::newer_file() const { struct stat st; - time_t file_time; if (stat(m_pathname, &st) != 0) { META_ERROR("ini: Skipping plugin, couldn't stat file '%s': %s", m_pathname, strerror(errno)); return false; } - file_time = st.st_ctime > st.st_mtime ? st.st_ctime : st.st_mtime; + time_t file_time = st.st_ctime > st.st_mtime ? st.st_ctime : st.st_mtime; META_DEBUG(5, "newer_file? file=%s; load=%d, file=%d; ctime=%d, mtime=%d", m_file, m_time_loaded, file_time, st.st_ctime, st.st_mtime); if (file_time > m_time_loaded) return true; @@ -1247,7 +1237,7 @@ const char *MPlugin::str_status(STR_STATUS fmt) const if (fmt == ST_SHOW) return "empt"; else return "empty"; case PL_VALID: - if (fmt == ST_SHOW) return"info"; + if (fmt == ST_SHOW) return "info"; else return "valid"; case PL_BADFILE: if (fmt == ST_SHOW) return "badf";