void Connection::processNext(const char *data) { if (m_commandName.isNull()) { m_commandName = data; m_argumentsExpected = -1; } else { processArgument(data); } }
static void cd(const int& fd, const std::string& argu, WorkingDirectory& wd) { const std::string nargu = processArgument(argu); std::string ret = wd.changeDir(nargu); char buffer[maxn]; cleanBuffer(buffer); sprintf(buffer, "%s", ret.c_str()); birdWrite(fd, buffer); }
static bool d(const int& fd, const std::string& argu, const WorkingDirectory& wd) { const std::string nargu = processArgument(argu); char buffer[maxn]; cleanBuffer(buffer); sprintf(buffer, "d %s", argu.c_str()); birdWrite(fd, buffer); cleanBuffer(buffer); birdRead(fd, buffer); if (std::string(buffer) == "UNEXPECTED_ERROR") { fprintf(stderr, "Unexpected Error\n"); return false; } else if (std::string(buffer) == "PERMISSION_DENIED") { fprintf(stderr, "%s: Permission denied\n", nargu.c_str()); return false; } else if (std::string(buffer) == "FILE_NOT_EXIST") { fprintf(stderr, "%s: No such file or directory\n", nargu.c_str()); return false; } else if (std::string(buffer) == "IS_DIR") { fprintf(stderr, "%s is a directory\n", nargu.c_str()); return false; } else if (std::string(buffer) == "NOT_REGULAR_FILE") { fprintf(stderr, "%s is not a regular file\n", nargu.c_str()); return false; } std::string filename = getFileName(nargu); if (wd.getStartupPath().back() == '/') { filename = wd.getStartupPath() + "Download/" + filename; } else { filename = wd.getStartupPath() + "/Download/" + filename; } FILE* fp = fopen(filename.c_str(), "wb"); if (!fp) { fprintf(stderr, "%s: File Open Error\n", filename.c_str()); cleanBuffer(buffer); sprintf(buffer, "ERROR_OPEN_FILE"); birdWrite(fd, buffer); return false; } cleanBuffer(buffer); sprintf(buffer, "OK"); birdWrite(fd, buffer); printf("Download File \"%s\"\n", getFileName(nargu).c_str()); unsigned long fileSize; birdRead(fd, buffer); sscanf(buffer, "%*s%*s%lu", &fileSize); printf("File size: %lu bytes\n", fileSize); birdReadFile(fd, fp, fileSize); printf("Download File \"%s\" Completed\n", getFileName(nargu).c_str()); fclose(fp); return true; }
void Config::processEnvArguments() { size_t len = strlen(ENV_PREFIX); for (int i=0; ::environ[i] != 0; i++) { const char* envarg = ::environ[i]; if (strlen(envarg) <= len+1) continue; if (memcmp(ENV_PREFIX, envarg, len) != 0) continue; const char* arg = envarg + len; processArgument(arg); } }
static bool u(const int& fd, const std::string& argu) { const std::string nargu = processArgument(argu); int chk = isExist(nargu); if (chk == -2) { fprintf(stderr, "%s: Unexpected Error\n", nargu.c_str()); return false; } else if (chk == -1) { fprintf(stderr, "%s: Permission denied\n", nargu.c_str()); return false; } else if (chk == 0) { fprintf(stderr, "%s: No such file or directory\n", nargu.c_str()); return false; } else if (chk == 2) { fprintf(stderr, "%s is a directory\n", nargu.c_str()); return false; } else if (chk == 3) { fprintf(stderr, "%s is not a regular file\n", nargu.c_str()); return false; } FILE* fp = fopen(nargu.c_str(), "rb"); if (!fp) { fprintf(stderr, "%s: Unexpected Error\n", nargu.c_str()); return false; } unsigned long fileSize; struct stat st; stat(nargu.c_str(), &st); fileSize = st.st_size; char buffer[maxn]; cleanBuffer(buffer); sprintf(buffer, "u %s", argu.c_str()); birdWrite(fd, buffer); cleanBuffer(buffer); birdRead(fd, buffer); if (std::string(buffer) == "ERROR_OPEN_FILE") { fprintf(stderr, "Cannot open file \"%s\" on Remote Server\n", getFileName(argu.c_str()).c_str()); fclose(fp); return false; } printf("Upload File \"%s\"\n", getFileName(nargu).c_str()); cleanBuffer(buffer); sprintf(buffer, "filesize = %lu", fileSize); birdWrite(fd, buffer); printf("File size: %lu bytes\n", fileSize); birdWriteFile(fd, fp, fileSize); printf("Upload File \"%s\" Completed\n", getFileName(nargu).c_str()); fclose(fp); return true; }
static void u(const int& fd, const std::string& argu, const WorkingDirectory& wd) { const std::string nargu = processArgument(argu); char buffer[maxn]; std::string filename = getFileName(nargu); FILE* fp = fopen(filename.c_str(), "wb"); if (!fp) { cleanBuffer(buffer); sprintf(buffer, "ERROR_OPEN_FILE"); birdWrite(fd, buffer); return; } else { cleanBuffer(buffer); sprintf(buffer, "OK"); birdWrite(fd, buffer); } unsigned long fileSize; birdRead(fd, buffer); sscanf(buffer, "%*s%*s%lu", &fileSize); birdReadFile(fd, fp, fileSize); fclose(fp); }
int main(int argc, const char* argv[]) { initialize(); LCPP_SCOPE_EXIT { shutdown(); }; // parse settings for(int i = 1; i < argc; ++i) { processArgument(argv[i]); } auto& testManager = cut::IUnitTestManager::instance(); testManager.run("StackPtr", "Basics"); testManager.run("GarbageCollection", "Basics"); testManager.run("Object", "AllTypes"); // The code below runs only the tests Test_01-Test_80 from the ThautTests group. //ezStringBuilder sTest; //for(int i = 1; i < 80 + 1; ++i) //{ // sTest.Format("Test_%.2d", i); // testManager.run("ThautTests", sTest.GetData()); //} testManager.runAll(); testManager.printStatistics(); auto& stats = testManager.statistics(); if(g_pauseBeforeExit && stats.testsFailed > 0) { system("pause"); } return 0; }
void Config::process(int argc, char* argv[]) { processCommandLineArguments(argc-1, argv+1); if (isSet("config")) { string path; get("config", path); ifstream f(path.c_str()); if (!f) { cerr << "Failed to open config file " << path << endl; return; } while (f) { string str; getline(f, str); boost::trim(str); if (str[0] == '#') continue; if (str.empty()) continue; processArgument(str.c_str()); } } processEnvArguments(); }
int loggerGccParserCollectActions( const char* prog_, const char* toolName_, const char* const argv_[], LoggerVector* actions_) { size_t i; /* Position of the last include path + 1 */ size_t lastIncPos = 1; GccArgsState state = Normal; LoggerAction* action = loggerActionNew(toolName_); loggerVectorAdd(&action->arguments, loggerStrDup(toolName_)); for (i = 1; argv_[i]; ++i) { state = processArgument(state, argv_[i], action); if (argv_[i][0] == '-' && argv_[i][1] == 'I') { if (argv_[i][2]) { /* -I with path argument */ lastIncPos = action->arguments.size; } else { /* The path should be the next argument */ lastIncPos = action->arguments.size + 1; } } } if (!getenv("CC_LOGGER_NO_DEF_DIRS")) { LoggerVector defIncludes; loggerVectorInit(&defIncludes); getDefaultArguments(prog_, &defIncludes); if (defIncludes.size) { loggerVectorAddFrom(&action->arguments, &defIncludes, &lastIncPos, (LoggerDupFuc) &loggerStrDup); } loggerVectorClear(&defIncludes); } /* * Workaround for -MT and friends: if the source set contains the output, * then we have to remove it from the set. */ i = loggerVectorFind(&action->sources, action->output.path, (LoggerCmpFuc) &strcmp); if (i != SIZE_MAX) { loggerVectorErase(&action->sources, i); } loggerVectorAdd(actions_, action); return 1; }
void Config::processCommandLineArguments(int argc, char* argv[]) { for (int i=0; i < argc; i++) { processArgument(argv[i]); } }
int loggerGccParserCollectActions( const char* prog_, const char* toolName_, const char* const argv_[], LoggerVector* actions_) { enum Language { C, CPP, OBJC } lang = CPP; size_t i; /* Position of the last include path + 1 */ char full_prog_path[PATH_MAX+1]; char *path_ptr; size_t lastIncPos = 1; size_t lastSysIncPos = 1; GccArgsState state = Normal; LoggerAction* action = loggerActionNew(toolName_); char* keepLinkVar = getenv("CC_LOGGER_KEEP_LINK"); int keepLink = keepLinkVar && strcmp(keepLinkVar, "true") == 0; /* If prog_ is a relative path we try to * convert it to absolute path. */ path_ptr = realpath(prog_, full_prog_path); /* If we cannot convert it, we try to find the * executable in the PATH. */ if (!path_ptr) path_ptr = findFullPath(toolName_, full_prog_path); if (path_ptr) /* Log compiler with full path. */ loggerVectorAdd(&action->arguments, loggerStrDup(full_prog_path)); else /* Compiler was not found in path, log the binary name only. */ loggerVectorAdd(&action->arguments, loggerStrDup(toolName_)); /* Determine programming language based on compiler name. */ for (i = 0; cCompiler[i]; ++i) if (strstr(toolName_, cCompiler[i])) lang = C; for (i = 0; cppCompiler[i]; ++i) if (strstr(toolName_, cppCompiler[i])) lang = CPP; for (i = 1; argv_[i]; ++i) { const char* current = argv_[i]; state = processArgument(state, current, action); if (current[0] == '-') { /* Determine the position of the last -I and -isystem flags. * Depending on whether the parameter of -I or -isystem is separated * from the flag by a space character. * 2 == strlen("-I") && 8 == strlen("-isystem") */ if (current[1] == 'I') lastIncPos = action->arguments.size + (current[2] ? 0 : 1); else if (strstr(current, "-isystem") == current) lastSysIncPos = action->arguments.size + (current[8] ? 0 : 1); /* Determine the programming language based on -x flag. */ else if (strcmp(current, "-x") == 0) { /* TODO: The language value after -x can be others too. See the man * page of GCC. * TODO: According to a GCC warning the -x flag has no effect when it * is placed after the last input file to be compiled. */ const char* l = argv_[i + 1]; if (strcmp(l, "c") == 0 || strcmp(l, "c-header") == 0) lang = C; else if (strcmp(l, "c++") == 0 || strcmp(l, "c++-header") == 0) lang = CPP; } } } if (getenv("CC_LOGGER_DEF_DIRS")) { LoggerVector defIncludes; loggerVectorInit(&defIncludes); getDefaultArguments(prog_, &defIncludes); if (defIncludes.size) { loggerVectorAddFrom(&action->arguments, &defIncludes, &lastIncPos, (LoggerDupFuc) &loggerStrDup); if (lastSysIncPos > lastIncPos) lastSysIncPos += defIncludes.size; lastIncPos += defIncludes.size; } loggerVectorClear(&defIncludes); } if (getenv("CPATH")) { LoggerVector includes; loggerVectorInit(&includes); getPathsFromEnvVar(&includes, "CPATH", "-I"); if (includes.size) { loggerVectorAddFrom(&action->arguments, &includes, &lastIncPos, (LoggerDupFuc) &loggerStrDup); if (lastSysIncPos > lastIncPos) lastSysIncPos += includes.size; lastIncPos += includes.size; } loggerVectorClear(&includes); } if (lang == CPP && getenv("CPLUS_INCLUDE_PATH")) { LoggerVector includes; loggerVectorInit(&includes); getPathsFromEnvVar(&includes, "CPLUS_INCLUDE_PATH", "-isystem"); if (includes.size) { loggerVectorAddFrom(&action->arguments, &includes, &lastSysIncPos, (LoggerDupFuc) &loggerStrDup); } loggerVectorClear(&includes); } else if (lang == C && getenv("C_INCLUDE_PATH")) { LoggerVector includes; loggerVectorInit(&includes); getPathsFromEnvVar(&includes, "C_INCLUDE_PATH", "-isystem"); if (includes.size) { loggerVectorAddFrom(&action->arguments, &includes, &lastSysIncPos, (LoggerDupFuc) &loggerStrDup); } loggerVectorClear(&includes); } /* * Workaround for -MT and friends: if the source set contains the output, * then we have to remove it from the set. */ i = loggerVectorFind(&action->sources, action->output.path, (LoggerCmpFuc) &strcmp); if (i != SIZE_MAX) { loggerVectorErase(&action->sources, i); } if (!keepLink) do { i = loggerVectorFindIf(&action->sources, (LoggerPredFuc) &isObjectFile); loggerVectorErase(&action->sources, i); } while (i != SIZE_MAX); if (action->sources.size != 0) loggerVectorAdd(actions_, action); return 1; }
int main(int argc, char** argv) { clang::CompilerInstance compiler; #ifndef _WIN32 compiler.createDiagnostics(); #else compiler.createDiagnostics(argc, argv); #endif compiler.createFileManager(); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-qual" ProcessArguments processArgument(argc, argv); if (argc == 1) { processArgument.printUsage(std::cout); return 0; }; if (!processArgument.isValid()) { processArgument.printUsage(std::cout); return 0; }; if (processArgument.isVersion()) return 0; int clang_argc = argc; llvm::MutableArrayRef<const char*> Argv((const char**)argv, clang_argc+1); for (int i = 0; i<argc; i++) Argv[i] = argv[i]; #pragma GCC diagnostic pop Argv[clang_argc]="-Qunused-arguments"; llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> Diag(&compiler.getDiagnostics()); clang::CompilerInvocation* invocation = clang::createInvocationFromCommandLine(Argv,Diag); if (!invocation) { std::cerr << "Could not create clang invocation; Aborting"; exit(2); } invocation->getLangOpts()->CPlusPlus = true; invocation->getLangOpts()->Bool = true; invocation->getLangOpts()->WChar = true; invocation->getLangOpts()->Exceptions = true; invocation->getLangOpts()->CXXExceptions = true; invocation->getLangOpts()->EmitAllDecls = true; invocation->getLangOpts()->GNUInline = true; invocation->getLangOpts()->Deprecated = true; invocation->getLangOpts()->ShortWChar = true; invocation->getLangOpts()->ImplicitInt = false; // equivalent command-line option: callers -std=c++11 // enable to analyze C++11 source code like clang version 3.7.0 (trunk 240320) //invocation->getLangOpts()->CPlusPlus11 = true; //invocation->getLangOpts()->CPlusPlus11 = false; invocation->getFrontendOpts().ProgramAction = clang::frontend::ParseSyntaxOnly; compiler.setInvocation(invocation); CallersAction callersAction(processArgument.getOutputFile(), compiler); if (processArgument.doesGenerateImplicitMethods()) callersAction.setGenerateImplicitMethods(); compiler.ExecuteAction(callersAction); return 0; }
static void d(const int& fd, const std::string& argu) { const std::string nargu = processArgument(argu); char buffer[maxn]; int chk = isExist(nargu); if (chk == -2) { cleanBuffer(buffer); sprintf(buffer, "UNEXPECTED_ERROR"); birdWrite(fd, buffer); return; } else if (chk == -1) { cleanBuffer(buffer); sprintf(buffer, "PERMISSION_DENIED"); birdWrite(fd, buffer); return; } else if (chk == 0) { cleanBuffer(buffer); sprintf(buffer, "FILE_NOT_EXIST"); birdWrite(fd, buffer); return; } else if (chk == 2) { cleanBuffer(buffer); sprintf(buffer, "IS_DIR"); birdWrite(fd, buffer); return; } else if (chk == 3) { cleanBuffer(buffer); sprintf(buffer, "NOT_REGULAR_FILE"); birdWrite(fd, buffer); return; } FILE* fp = fopen(nargu.c_str(), "rb"); if (!fp) { cleanBuffer(buffer); sprintf(buffer, "UNEXPECTED_ERROR"); birdWrite(fd, buffer); return; } else { cleanBuffer(buffer); sprintf(buffer, "FILE_EXISTS"); birdWrite(fd, buffer); } cleanBuffer(buffer); birdRead(fd, buffer); if (std::string(buffer) == "ERROR_OPEN_FILE") { fclose(fp); return; } unsigned long fileSize; struct stat st; stat(nargu.c_str(), &st); fileSize = st.st_size; cleanBuffer(buffer); sprintf(buffer, "filesize = %lu", fileSize); birdWrite(fd, buffer); birdWriteFile(fd, fp, fileSize); fclose(fp); return; }