mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
remove Windows/ICC support
This commit is contained in:
committed by
Konstantinos Margaritis
parent
8cff876962
commit
08357a096c
@@ -38,10 +38,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
@@ -52,7 +50,6 @@
|
||||
*/
|
||||
static inline
|
||||
std::string inferExpressionPath(const std::string &sigFile) {
|
||||
#ifndef _WIN32
|
||||
// POSIX variant.
|
||||
|
||||
// dirname() may modify its argument, so we must make a copy.
|
||||
@@ -60,25 +57,11 @@ std::string inferExpressionPath(const std::string &sigFile) {
|
||||
path.push_back(0); // ensure null termination.
|
||||
|
||||
std::string rv = dirname(path.data());
|
||||
#else
|
||||
// Windows variant.
|
||||
if (sigFile.size() >= _MAX_DIR) {
|
||||
return std::string();
|
||||
}
|
||||
char path[_MAX_DIR];
|
||||
_splitpath(sigFile.c_str(), nullptr, path, nullptr, nullptr);
|
||||
std::string rv(path);
|
||||
#endif
|
||||
|
||||
rv += "/../pcre";
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define stat _stat
|
||||
#define S_IFREG _S_IFREG
|
||||
#endif
|
||||
|
||||
static inline
|
||||
bool isDir(const std::string &filename) {
|
||||
struct stat s;
|
||||
|
@@ -40,14 +40,9 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
// Windows support is probably very fragile
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
|
||||
@@ -98,11 +93,6 @@ void processLine(string &line, unsigned lineNum,
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define stat _stat
|
||||
#define S_ISDIR(st_m) (_S_IFDIR & (st_m))
|
||||
#define S_ISREG(st_m) (_S_IFREG & (st_m))
|
||||
#endif
|
||||
void HS_CDECL loadExpressionsFromFile(const string &fname, ExpressionMap &exprMap) {
|
||||
struct stat st;
|
||||
if (stat(fname.c_str(), &st) != 0) {
|
||||
@@ -143,7 +133,6 @@ bool isIgnorable(const std::string &f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
||||
// Is our input path a file or a directory?
|
||||
struct stat st;
|
||||
@@ -197,62 +186,6 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#else // windows TODO: improve
|
||||
void HS_CDECL loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
||||
// Is our input path a file or a directory?
|
||||
struct stat st;
|
||||
if (stat(inPath.c_str(), &st) != 0) {
|
||||
cerr << "Can't stat path: '" << inPath << "'" << endl;
|
||||
exit(1);
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
// process file
|
||||
try {
|
||||
loadExpressionsFromFile(inPath, exprMap);
|
||||
} catch (runtime_error &e) {
|
||||
cerr << e.what() << ": '" << inPath << "'" << endl;
|
||||
exit(1);
|
||||
}
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
WIN32_FIND_DATA ffd;
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
string glob = inPath + "/*";
|
||||
hFind = FindFirstFile(glob.c_str(), &ffd);
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
cerr << "Can't open directory: '" << inPath << "'" << endl;
|
||||
exit(1);
|
||||
}
|
||||
do {
|
||||
string basename(ffd.cFileName);
|
||||
string fname(inPath);
|
||||
fname.push_back('/');
|
||||
fname.append(basename);
|
||||
|
||||
// Ignore '.' and '..'
|
||||
if (basename == "." || basename == "..") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip emacs backup files, dotfiles (such as VIM swap).
|
||||
if (isIgnorable(basename)) {
|
||||
cerr << "Ignoring signature file " << fname << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
loadExpressionsFromFile(fname, exprMap);
|
||||
} catch (runtime_error &e) {
|
||||
cerr << e.what() << ": '" << fname << "'" << endl;
|
||||
exit(1);
|
||||
}
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
FindClose(hFind);
|
||||
} else {
|
||||
cerr << "Can't stat path: '" << inPath << "'" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void HS_CDECL loadSignatureList(const string &inFile,
|
||||
SignatureSet &signatures) {
|
||||
|
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef WIN_GETOPT_H
|
||||
#define WIN_GETOPT_H
|
||||
|
||||
#include <windows.h>
|
||||
#define ILLEGAL (int)'?'
|
||||
#define END -1
|
||||
#define SPECIAL_OPT 1
|
||||
|
||||
int optind = 0;
|
||||
char *optarg;
|
||||
static char EMPT[] = "";
|
||||
static char *ptr = EMPT;
|
||||
static int no_argument = 0;
|
||||
static int required_argument = 1;
|
||||
static const char no_arg[] = "option doesn't take an argument --%.*s";
|
||||
static const char non_opt_string[] = "not an option : %s";
|
||||
static const char ill_shortopt_char[] = "unknown option -%c";
|
||||
static const char ill_longopt_string[] = "unknown option --%s";
|
||||
static const char req_arg_string[] = "option requires an argument --%s";
|
||||
static const char req_arg_char[] = "option requires an argument -%c";
|
||||
|
||||
struct option {
|
||||
const char *name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int value;
|
||||
};
|
||||
|
||||
static
|
||||
void warn(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stdout, fmt, args);
|
||||
fprintf(stdout, "\n");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
int getopt_long(int nargc, char *const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx) {
|
||||
char *check, *equal;
|
||||
size_t current_opt_len;
|
||||
bool all_flag = false;
|
||||
int match = -1;
|
||||
// illegal
|
||||
if (options == NULL) {
|
||||
return ILLEGAL;
|
||||
}
|
||||
if (optind == 0) {
|
||||
optind = 1;
|
||||
}
|
||||
if (optind >= nargc) {
|
||||
return END;
|
||||
}
|
||||
if (*options == '-') {
|
||||
all_flag = true;
|
||||
++options;
|
||||
}
|
||||
optarg = NULL;
|
||||
// illegal
|
||||
if (*(ptr = nargv[optind]) != '-') {
|
||||
ptr = EMPT;
|
||||
if (all_flag) {
|
||||
optarg = nargv[optind++];
|
||||
return SPECIAL_OPT;
|
||||
} else {
|
||||
warn(non_opt_string, nargv[optind]);
|
||||
return ILLEGAL;
|
||||
}
|
||||
}
|
||||
// likely a short option ?
|
||||
if (ptr[1] != '\0' && *++ptr != '-' && ptr[1] == '\0') {
|
||||
char opt_char = *ptr;
|
||||
ptr = EMPT;
|
||||
// really short option ?
|
||||
if ((check = (char *)strchr(options, opt_char)) != NULL) {
|
||||
if (check[1] == ':') {
|
||||
++optind;
|
||||
if (optind >= nargc) {
|
||||
warn(req_arg_char, opt_char);
|
||||
return ILLEGAL;
|
||||
} else {
|
||||
optarg = nargv[optind];
|
||||
}
|
||||
}
|
||||
++optind;
|
||||
return opt_char;
|
||||
} else { // illegal
|
||||
warn(ill_shortopt_char, opt_char);
|
||||
return ILLEGAL;
|
||||
}
|
||||
}
|
||||
// we meet '--'
|
||||
if (*ptr == '-' && ptr[1] == '\0') {
|
||||
ptr = EMPT;
|
||||
return END;
|
||||
}
|
||||
// we meet '--foo' , long option
|
||||
if (long_options != NULL && *ptr == '-' && ptr[1] != '\0') {
|
||||
++ptr;
|
||||
if ((equal = strchr(ptr, '=')) != NULL) {
|
||||
// found --option=arg
|
||||
current_opt_len = equal - ptr;
|
||||
++equal;
|
||||
} else {
|
||||
current_opt_len = strlen(ptr);
|
||||
}
|
||||
for (int i = 0; long_options[i].name; i++) {
|
||||
if (!strcmp(ptr, long_options[i].name )) {
|
||||
match = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == -1) { // don't match
|
||||
warn(ill_longopt_string, ptr);
|
||||
ptr = EMPT;
|
||||
return ILLEGAL;
|
||||
} else {
|
||||
++optind;
|
||||
if (long_options[match].has_arg == required_argument) {
|
||||
if (equal) {
|
||||
optarg = equal;
|
||||
} else if (optind < nargc) {
|
||||
optarg = nargv[optind++];
|
||||
} else {
|
||||
warn(req_arg_string, ptr);
|
||||
ptr = EMPT;
|
||||
return ILLEGAL;
|
||||
}
|
||||
}
|
||||
if (long_options[match].has_arg == no_argument && equal) {
|
||||
warn(no_arg, (int)current_opt_len, ptr);
|
||||
ptr = EMPT;
|
||||
return ILLEGAL;
|
||||
}
|
||||
ptr = EMPT;
|
||||
if (long_options[match].flag) {
|
||||
*long_options[match].flag = long_options[match].value;
|
||||
return 0;
|
||||
} else {
|
||||
return (long_options[match].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
warn(non_opt_string, ptr);
|
||||
ptr = EMPT;
|
||||
return ILLEGAL;
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user