From c5d4075db5b5b17cbfd36250d6e86cb9ad4e6f66 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 5 Aug 2008 19:58:21 +0000 Subject: [PATCH] Oops, move the definition of the now-static function formatScriptOutput to above where it's used. --- output.cc | 84 +++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/output.cc b/output.cc index cf142dd88..b19a53186 100644 --- a/output.cc +++ b/output.cc @@ -473,6 +473,48 @@ static void getNmapServiceName(struct serviceDeductions *sd, int state, *namebuf = '\0'; } +#ifndef NOLUA +static char* formatScriptOutput(ScriptResult sr) { + std::string result = std::string(), output = sr.get_output(); + string::size_type pos; + char *c_result, *c_output = new char[output.length()+1]; + strncpy(c_output, output.c_str(), output.length()+1); + int line = 0; +#ifdef WIN32 + const char* sep = "\r\n"; +#else + const char* sep = "\n"; +#endif + std::string line_prfx = "| "; + + char* token = strtok(c_output, sep); + + result += line_prfx + sr.get_id() + ": "; + + while(token != NULL) { + if(line > 0) + result += line_prfx; + result += std::string(token) + sep; + token = strtok(NULL, sep); + line++; + } + + // fix the last line + pos = result.rfind(line_prfx); + result.replace(pos, 3, "|_ "); + + // delete the unwanted trailing newline + pos = result.rfind(sep); + if(pos!=std::string::npos){ + result.erase(pos, strlen(sep)); + } + c_result = strdup(result.c_str()); + + delete[] c_output; + return c_result; +} +#endif /* NOLUA */ + /* Prints the familiar Nmap tabular output showing the "interesting" ports found on the machine. It also handles the Machine/Greppable output and the XML output. It is pretty ugly -- in particular I @@ -835,48 +877,6 @@ log_write(LOG_PLAIN, "%d service%s unrecognized despite returning data. If you k log_flush_all(); } -#ifndef NOLUA -static char* formatScriptOutput(ScriptResult sr) { - std::string result = std::string(), output = sr.get_output(); - string::size_type pos; - char *c_result, *c_output = new char[output.length()+1]; - strncpy(c_output, output.c_str(), output.length()+1); - int line = 0; -#ifdef WIN32 - const char* sep = "\r\n"; -#else - const char* sep = "\n"; -#endif - std::string line_prfx = "| "; - - char* token = strtok(c_output, sep); - - result += line_prfx + sr.get_id() + ": "; - - while(token != NULL) { - if(line > 0) - result += line_prfx; - result += std::string(token) + sep; - token = strtok(NULL, sep); - line++; - } - - // fix the last line - pos = result.rfind(line_prfx); - result.replace(pos, 3, "|_ "); - - // delete the unwanted trailing newline - pos = result.rfind(sep); - if(pos!=std::string::npos){ - result.erase(pos, strlen(sep)); - } - c_result = strdup(result.c_str()); - - delete[] c_output; - return c_result; -} -#endif /* NOLUA */ - /* Note that this escapes newlines, which is generally needed in attributes to avoid parser normalization, but might not be needed