static void printQueryData(MaQueue *q) { MaRequest *req; char buf[MPR_MAX_STRING], **keys, *value; int i, numKeys; req = q->conn->request; if (req->parsedUri->query == 0) { return; } mprStrcpy(buf, sizeof(buf), req->parsedUri->query); numKeys = getVars(q, &keys, buf, (int) strlen(buf)); if (numKeys == 0) { maWrite(q, "<H2>No Query Data Found</H2>\r\n"); } else { maWrite(q, "<H2>Decoded Query Data Variables</H2>\r\n"); for (i = 0; i < (numKeys * 2); i += 2) { value = keys[i+1]; maWrite(q, "<p>QVAR %s=%s</p>\r\n", keys[i], value ? value: ""); } } maWrite(q, "\r\n"); mprFree(keys); }
static void printBodyData(MaQueue *q) { MprBuf *buf; char **keys, *value; int i, numKeys; if (q->pair == 0 || q->pair->first == 0) { return; } buf = q->pair->first->content; mprAddNullToBuf(buf); numKeys = getVars(q, &keys, mprGetBufStart(buf), mprGetBufLength(buf)); if (numKeys == 0) { maWrite(q, "<H2>No Body Data Found</H2>\r\n"); } else { maWrite(q, "<H2>Decoded Body Data</H2>\r\n"); for (i = 0; i < (numKeys * 2); i += 2) { value = keys[i+1]; maWrite(q, "<p>PVAR %s=%s</p>\r\n", keys[i], value ? value: ""); } } maWrite(q, "\r\n"); mprFree(keys); mprFree(buf); }
void EntityType::init(void) { size_t varSize; Uint32 *startData; getVars(&varSize, &startData); memset(startData,0,varSize*sizeof(Uint32)); }
/* * Cdi * { */ Cdi::Cdi(const char *path) { streamID = streamOpenRead(path); vlistID = streamInqVlist(streamID); nvars = vlistNvars(vlistID); getTaxes(); getZaxes(); getGrids(); getVars(); }
void EntityType::dump(void) { size_t varSize; Uint32 *startData; const char **tab=getVars(&varSize, &startData); printf("%d Elements :\n", static_cast<unsigned>(varSize)); for (size_t i=0; i<varSize;i++) printf("\t%s = %d\n",tab[i],*(startData+i)); }
/* vector index 0 = lkeys * vector index 1 = lvars * vector index 2 = lops * vector index 3 = llits */ std::vector<std::map<std::string, size_t>> Tokenizer::findTokens(std::string line) { std::vector<std::map<std::string, size_t>> vec; std::map<std::string, size_t> lkeys; std::map<std::string, size_t> lvars; std::map<std::string, size_t> lops; std::map<std::string, size_t> llits; std::string words = seperateWords(line); auto keys = getKeys(words); auto vars = getVars(words); auto ops = getOps(line); // getOps needs non-seperated line auto lits = getLits(words); size_t pos = 0; //for (int i = 0; i < keys.size(); i++) for (auto x : keys) { //pos = line.find(keys[i], pos); pos = line.find(x, pos); //lkeys.insert(std::pair<size_t, std::string>(pos++, keys[i])); lkeys.insert(std::make_pair(x, pos++)); } pos = 0; //for (int i = 0; i < vars.size(); i++) for (auto x : vars) { //pos = line.find(vars[i], pos); pos = line.find(x, pos); //lvars.insert(std::pair<size_t, std::string>(pos++, vars[i])); lvars.insert(std::make_pair(x, pos++)); } pos = 0; //for (int i = 0; i < ops.size(); i++) for (auto x : ops) { //pos = line.find(ops[i], pos); pos = line.find(x, pos); //lops.insert(std::pair<size_t, std::string>(pos++, ops[i])); lops.insert(std::make_pair(x, pos++)); } pos = 0; //for (int i = 0; i < lits.size(); i++) for (auto x : lits) { //pos = line.find(lits[i], pos); pos = line.find(x, pos); //llits.insert(std::pair<size_t, std::string>(pos++, lits[i])); llits.insert(std::make_pair(x, pos++)); } vec.push_back(lkeys); vec.push_back(lvars); vec.push_back(lops); vec.push_back(llits); return vec; }
void EntityType::save(GAGCore::OutputStream *stream) { size_t size; Uint32 *startData; getVars(&size, &startData); for (size_t i=0; i<size; i++) { std::ostringstream oss; oss << "entitytype" << i; stream->writeUint32(startData[i], oss.str().c_str()); } }
void EntityType::load(GAGCore::InputStream *stream) { size_t size; Uint32 *startData; getVars(&size, &startData); for (size_t i=0;i<size;i++) { std::ostringstream oss; oss << "entitytype" << i; startData[i] = stream->readUint32(oss.str()); } }
std::map<int, block_ptr> XML::build(std::istream *is, script::Script &script) { parse(is); node_ptr scriptRoot(root->first_node("scripts")->first_node("script"), null_deleter()); getVars(script.variables_); getPoints(script.points_, script.devices_); std::map<int, block_ptr> startingBlocks; for (int i = 0; scriptRoot; scriptRoot.reset(scriptRoot->next_sibling(), null_deleter()), ++i) { block_ptr b(getChildren(node_ptr(scriptRoot->first_node(), null_deleter()))); startingBlocks.insert(std::pair<int, block_ptr>(i, b)); } return startingBlocks; }
void BashCodeCompletion::cursorPositionChanged() { uint line, col; m_cursorInterface->cursorPositionReal(&line, &col); kdDebug() << "BashCodeCompletion::cursorPositionChanged:" << line << ":" << col << endl; QString lineStr = m_editInterface->textLine(line); if(lineStr.isNull() || lineStr.isEmpty()){ kdDebug() << "No Text..." << endl; return; // nothing to do } // if(m_config->getCodeCompletion()) // { QString restLine = lineStr.mid(col); QString prevText = lineStr.mid(0,col); if(restLine.left(1) != " " && restLine.left(1) != "\t" && !restLine.isNull()) { kdDebug() << "no codecompletion because no empty character after cursor:" << restLine << ":" << endl; return; } QRegExp prevReg("[$][\\d\\w]*\\b$"); int pos = prevReg.search( prevText ); if (pos > -1 ) { // We are in completion mode QString startMatch = prevReg.cap(0); kdDebug() << "Matching: " << startMatch << endl; m_completionBoxShow=true; m_codeInterface->showCompletionBox(getVars(startMatch),2); } else { kdDebug() << "no vars in: " << prevText << endl; return; } // } }
/* If there is a HTTP_SWITCHES argument in the query string, examine that instead of the original argv */ static int getArgv(int *pargc, char ***pargv, int originalArgc, char **originalArgv) { char *switches, *next, sbuf[1024]; int i; *pargc = 0; if (getQueryString(&queryBuf, &queryLen) < 0) { return -1; } numQueryKeys = getVars(&queryKeys, queryBuf, queryLen); switches = 0; for (i = 0; i < numQueryKeys; i += 2) { if (strcmp(queryKeys[i], "HTTP_SWITCHES") == 0) { switches = queryKeys[i+1]; break; } } if (switches == 0) { switches = getenv("HTTP_SWITCHES"); } if (switches) { strncpy(sbuf, switches, sizeof(sbuf) - 1); descape(sbuf); next = strtok(sbuf, " \t\n"); i = 1; for (i = 1; next && i < (MAX_ARGV - 1); i++) { argvList[i] = next; next = strtok(0, " \t\n"); } argvList[0] = originalArgv[0]; *pargv = argvList; *pargc = i; } else { *pargc = originalArgc; *pargv = originalArgv; } return 0; }
bool EntityType::loadText(GAGCore::InputStream *stream) { char temp[256]; char *token; char *varname; int val; size_t varSize; Uint32 *startData; const char **tab=getVars(&varSize, &startData); assert(stream); while (true) { if (!Utilities::gets(temp, 256, stream)) return false; if (temp[0]=='*') return true; token=strtok(temp," \t\n\r=;"); if ((!token) || (strcmp(token,"//")==0)) continue; varname=token; token=strtok(NULL," \t\n\r=;"); if (token) val=atoi(token); else val=0; for (size_t i=0; i<varSize; i++) if (strcmp(tab[i],varname)==0) { *(startData+i)=val; break; } } }
int main(int argc, char **argv, char **envp) #endif { char *cp, *method; int i, j, err; err = 0; outputArgs = outputQuery = outputEnv = outputPost = 0; outputBytes = outputHeaderLines = responseStatus = 0; outputLocation = 0; nonParsedHeader = 0; responseMsg = 0; hasError = 0; timeout = 0; queryBuf = 0; queryLen = 0; numQueryKeys = numPostKeys = 0; originalArgc = argc; originalArgv = argv; #if _WIN32 && !WINCE _setmode(0, O_BINARY); _setmode(1, O_BINARY); _setmode(2, O_BINARY); #endif if (strstr(argv[0], "nph-") != 0) { nonParsedHeader++; } if (getArgv(&argc, &argv, originalArgc, originalArgv) < 0) { error("Can't read CGI input"); } for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } for (cp = &argv[i][1]; *cp; cp++) { switch (*cp) { case 'a': outputArgs++; break; case 'b': if (++i >= argc) { err = __LINE__; } else { outputBytes = atoi(argv[i]); } break; case 'e': outputEnv++; break; case 'h': if (++i >= argc) { err = __LINE__; } else { outputHeaderLines = atoi(argv[i]); nonParsedHeader++; } break; case 'l': if (++i >= argc) { err = __LINE__; } else { outputLocation = argv[i]; if (responseStatus == 0) { responseStatus = 302; } } break; case 'n': nonParsedHeader++; break; case 'p': outputPost++; break; case 'q': outputQuery++; break; case 's': if (++i >= argc) { err = __LINE__; } else { responseStatus = atoi(argv[i]); } break; case 't': if (++i >= argc) { err = __LINE__; } else { timeout = atoi(argv[i]); } break; default: err = __LINE__; break; } } } if (err) { fprintf(stderr, "usage: cgiProgram -aenp [-b bytes] [-h lines]\n" "\t[-l location] [-s status] [-t timeout]\n" "\tor set the HTTP_SWITCHES environment variable\n"); fprintf(stderr, "Error at cgiProgram:%d\n", __LINE__); exit(255); } if ((method = getenv("REQUEST_METHOD")) != 0 && strcmp(method, "POST") == 0) { if (getPostData(&postBuf, &postBufLen) < 0) { error("Can't read CGI input"); } if (strcmp(safeGetenv("CONTENT_TYPE"), "application/x-www-form-urlencoded") == 0) { numPostKeys = getVars(&postKeys, postBuf, postBufLen); } } if (hasError) { if (! nonParsedHeader) { printf("HTTP/1.0 %d %s\r\n\r\n", responseStatus, responseMsg); printf("<HTML><BODY><p>Error: %d -- %s</p></BODY></HTML>\r\n", responseStatus, responseMsg); } fprintf(stderr, "cgiProgram: ERROR: %s\n", responseMsg); exit(2); } if (nonParsedHeader) { if (responseStatus == 0) { printf("HTTP/1.0 200 OK\r\n"); } else { printf("HTTP/1.0 %d %s\r\n", responseStatus, responseMsg ? responseMsg: ""); } printf("Connection: close\r\n"); printf("X-CGI-CustomHeader: Any value at all\r\n"); } printf("Content-type: %s\r\n", "text/html"); if (outputHeaderLines) { for (i = 0; i < outputHeaderLines; i++) { printf("X-CGI-%d: A loooooooooooooooooooooooong string\r\n", i); } } if (outputLocation) { printf("Location: %s\r\n", outputLocation); } if (responseStatus) { printf("Status: %d\r\n", responseStatus); } printf("\r\n"); if ((outputBytes + outputArgs + outputEnv + outputQuery + outputPost + outputLocation + responseStatus) == 0) { outputArgs++; outputEnv++; outputQuery++; outputPost++; } if (outputBytes) { j = 0; for (i = 0; i < outputBytes; i++) { putchar('0' + j); j++; if (j > 9) { if (++outputBytes > 0) { putchar('\r'); } if (++outputBytes > 0) { putchar('\n'); } j = 0; } } } printf("<HTML><TITLE>cgiProgram: Output</TITLE><BODY>\r\n"); if (outputArgs) { #if _WIN32 printf("<P>CommandLine: %s</P>\r\n", GetCommandLine()); #endif printf("<H2>Args</H2>\r\n"); for (i = 0; i < argc; i++) { printf("<P>ARG[%d]=%s</P>\r\n", i, argv[i]); } } printEnv(envp); if (outputQuery) { printQuery(); } if (outputPost) { printPost(postBuf, postBufLen); } printf("</BODY></HTML>\r\n"); #if VXWORKS /* VxWorks pipes need an explicit eof string Must not call exit(0) in Vxworks as that will exit the task before the CGI handler can cleanup. Must use return 0. */ write(1, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN); write(2, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN); #endif fflush(stderr); fflush(stdout); return 0; }
int main(int argc,char** argv) { SgProject* proj = frontend(argc,argv); fixAllPrefixPostfix(proj); initializeScopeInformation(proj); SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDecl->get_definition(); //SageInterface::rebuildSymbolTable(mainDef); StaticCFG::CFG cfg(mainDef); SgIncidenceDirectedGraph *g = cfg.getGraph(); PathCollector* pathCollector = new PathCollector(g,&cfg); std::vector<SgNode*> scopeNodes = NodeQuery::querySubTree(mainDef,V_SgScopeStatement); std::vector<SgGraphNode*> visited; std::vector<SgNode*> nodes = NodeQuery::querySubTree(mainDef,V_SgWhileStmt); std::vector<SgNode*>::iterator node = nodes.begin(); for (; node != nodes.end(); node++) { SgScopeStatement* scopeOfWhile = SageInterface::getEnclosingScope(*node); SgStatementPtrList statementsInScope = scopeOfWhile->getStatementList(); SgStatementPtrList::iterator statPtr = statementsInScope.begin(); std::set<SgPragmaDeclaration*> prdecls; for (; statPtr!=statementsInScope.end();statPtr++) { if (isSgPragmaDeclaration(*statPtr)) { prdecls.insert(isSgPragmaDeclaration(*statPtr)); } } //SgExprStatement* boundingConditionStatement = isSgExprStatement(isSgWhileStmt(*node)->get_condition()); //SgExpression* boundingCondition = boundingConditionStatement->get_expression(); SgStatement* body = (isSgWhileStmt(*node)->get_body()); std::vector<std::vector<SgGraphNode*> > paths = pathCollector->getPaths(); std::cout << getPrelude() << std::endl; SgGraphNode* whileStart = cfg.cfgForBeginning(isSgWhileStmt(*node)); SgGraphNode* whileEnd = cfg.cfgForEnd(isSgWhileStmt(*node)); collectPaths(whileStart,whileEnd, pathCollector); SgGraphNode* whileOut = getWhileEndNode(isSgWhileStmt(*node),pathCollector); SgGraphNode* bodyStart = cfg.cfgForBeginning(isSgWhileStmt(*node)->get_body()); SgGraphNode* bodyEnd = cfg.cfgForEnd(isSgWhileStmt(*node)->get_body()); pathCollector->clearPaths(); collectPaths(bodyStart,whileOut,pathCollector); paths.clear(); paths = pathCollector->getPaths(); std::vector<std::vector<SgGraphNode*> >::iterator i = paths.begin(); std::set<SgVariableSymbol*> vars = getVars(pathCollector); std::string vardecls; std::string initrule; std::vector<std::string> rules= getRules(*node,pathCollector, vars, vardecls,initrule); std::cout << vardecls << std::endl; for (int i = 0; i < rules.size(); i++) { std::cout << rules[i] << std::endl; } std::set<SgPragmaDeclaration*>::iterator pr = prdecls.begin(); for (; pr != prdecls.end(); pr++) { std::set<std::string> variables; std::vector<std::string> s_expressions; std::string prag_str = get_pragma_string(*pr); bool initPrag; /*std::string rhs =*/ translateToS_Expr(prag_str,variables,s_expressions,initPrag); if (s_expressions.size() > 0) { std::string queryResult; if (initPrag) { queryResult = assumptionPragma(s_expressions,initrule); } else { queryResult = queryPragma(s_expressions,initrule); } std::cout << queryResult << std::endl; } } } backend(proj); return 0; }
void* SimulationResultsCmp_compareResults(const char *filename, const char *reffilename, const char *resultfilename, double reltol, double abstol, void *vars) { char **cmpvars=NULL; char **cmpdiffvars=NULL; unsigned int vardiffindx=0; unsigned int ncmpvars = 0; void *allvars,*cmpvar,*res; unsigned int i,size,size_ref,len,oldlen,j,k; char *var,*var1,*var2; DataField time,timeref,data,dataref; DiffDataField ddf; const char *msg[2] = {"",""}; ddf.data=NULL; ddf.n=0; oldlen = 0; len = 1; /* open files */ /* fprintf(stderr, "Open File %s\n", filename); */ if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(filename,&simresglob_c)) return mk_cons(mk_scon("Error Open File!"),mk_nil()); /* fprintf(stderr, "Open File %s\n", reffilename); */ if (UNKNOWN_PLOT == SimulationResultsImpl__openFile(reffilename,&simresglob_ref)) return mk_cons(mk_scon("Error Open RefFile!"),mk_nil()); size = SimulationResultsImpl__readSimulationResultSize(filename,&simresglob_c); /* fprintf(stderr, "Read size of File %s size= %d\n", filename,size); */ size_ref = SimulationResultsImpl__readSimulationResultSize(reffilename,&simresglob_ref); /* fprintf(stderr, "Read size of File %s size= %d\n", reffilename,size_ref); */ /* get vars to compare */ cmpvars = getVars(vars,&ncmpvars); /* if no var compare all vars */ if (ncmpvars==0){ allvars = SimulationResultsImpl__readVars(filename,&simresglob_c); cmpvars = getVars(vars,&ncmpvars); if (ncmpvars==0) return mk_cons(mk_scon("Error Get Vars!"),mk_nil()); } cmpdiffvars = (char**)malloc(sizeof(char*)*(ncmpvars)); /* fprintf(stderr, "Compare Vars:\n"); /* /* for(i=0;i<ncmpvars;i++) fprintf(stderr, "Var: %s\n", cmpvars[i]); */ /* get time */ /* fprintf(stderr, "get time\n"); */ time = getData("time",filename,size,&simresglob_c); if (time.n==0) { time = getData("Time",filename,size,&simresglob_c); if (time.n==0){ /* fprintf(stderr, "Cannot get var time\n"); */ return mk_cons(mk_scon("Error get time!"),mk_nil()); } } /* fprintf(stderr, "get reftime\n"); */ timeref = getData("time",reffilename,size_ref,&simresglob_ref); if (timeref.n==0) { timeref = getData("Time",reffilename,size_ref,&simresglob_ref); if (timeref.n==0){ /* fprintf(stderr, "Cannot get var reftime\n"); */ return mk_cons(mk_scon("Error get ref time!"),mk_nil()); } } var1=NULL; var2=NULL; /* compare vars */ /* fprintf(stderr, "compare vars\n"); */ for (i=0;i<ncmpvars;i++) { var = cmpvars[i]; len = strlen(var); if (oldlen < len) { if (var1) free(var1); var1 = (char*) malloc(len+1); oldlen = len; } memset(var1,0,len); k = 0; for (j=0;j<len;j++) { if (var[j] !='\"' ) { var1[k] = var[j]; k +=1; } } /* fprintf(stderr, "compare var: %s\n",var); */ /* check if in ref_file */ dataref = getData(var1,reffilename,size_ref,&simresglob_ref); if (dataref.n==0) { if (var2) free(var2); var2 = (char*) malloc(len+1); strncpy(var2,var1,len+1); fixDerInName(var2,len); fixCommaInName(&var2,len); dataref = getData(var2,reffilename,size_ref,&simresglob_ref); if (dataref.n==0) { fprintf(stderr, "Get Data of Var %s from file %s failed\n",var,reffilename); c_add_message(-1, ErrorType_scripting, ErrorLevel_warning, "Get Data of Var failed!\n", msg, 0); continue; } } /* check if in file */ data = getData(var1,filename,size,&simresglob_c); if (data.n==0) { fixDerInName(var1,len); fixCommaInName(&var1,len); data = getData(var1,filename,size,&simresglob_c); if (data.n==0) { if (data.data) free(data.data); fprintf(stderr, "Get Data of Var %s from file %s failed\n",var,filename); c_add_message(-1, ErrorType_scripting, ErrorLevel_warning, "Get Data of Var failed!\n", msg, 0); continue; } } /* compare */ vardiffindx = cmpData(var,&time,&timeref,&data,&dataref,reltol,abstol,&ddf,cmpdiffvars,vardiffindx); /* free */ if (dataref.data) free(dataref.data); if (data.data) free(data.data); } if (writeLogFile(resultfilename,&ddf,filename,reffilename,reltol,abstol)) { c_add_message(-1, ErrorType_scripting, ErrorLevel_warning, "Cannot write result file!\n", msg, 0); } if (ddf.n > 0){ /* fprintf(stderr, "diff: %d\n",ddf.n); */ /* for (i=0;i<vardiffindx;i++) fprintf(stderr, "diffVar: %s\n",cmpdiffvars[i]); */ res = mk_nil(); for (i=0;i<vardiffindx;i++){ res = (void*)mk_cons(mk_scon(cmpdiffvars[i]),res); } res = mk_cons(mk_scon("Files not Equal!"),res); c_add_message(-1, ErrorType_scripting, ErrorLevel_warning, "Files not Equal\n", msg, 0); } else res = mk_cons(mk_scon("Files Equal!"),mk_nil()); if (var1) free(var1); if (var2) free(var2); if (ddf.data) free(ddf.data); if(cmpvars) free(cmpvars); if (time.data) free(time.data); if (timeref.data) free(timeref.data); if (cmpdiffvars) free(cmpdiffvars); /* close files */ SimulationResultsImpl__close(&simresglob_c); SimulationResultsImpl__close(&simresglob_ref); return res; }