/* Description- parses a .string directive. GET- line (lineInfo *). (IC, DC). */ void parseStringDirc(lineInfo *line, int *IC, int *DC) { /* Make the label a data label (is there is one) */ if (line->label) { line->label->isData = TRUE; line->label->address = FIRST_ADDRESS + *DC; } trimStr(&line->lineStr); if (isLegalStringParam(&line->lineStr, line->lineNum)) { if (!addStringToData(line->lineStr, IC, DC, line->lineNum)) { /* Not enough memory */ printf("ERR:\t Not enough memory.\n"); ERROR = TRUE; } } else { /* Illegal string */ printf("ERR:\tIllegal string. line: %d\n",line->lineNum); ERROR = TRUE; } }
void readPhenotypeGenesFromFile(const char* filename, vector<int>* phenotypeGeneIdsUpDown, map<string, int>* geneSymbolToId){ ifstream inFile; inFile.open(filename, ifstream::in); int totalGenes = geneSymbolToId->size(); if (inFile.is_open()) { //read the output from the while (inFile.good()) { string line; if (!getline(inFile, line)) break; istringstream lineStream(line); int i = 0; string geneSym; bool isPhenotype = false; while (lineStream) { //for each column (parameter) string token; if (!getline(lineStream, token, '\t')) break; if(i == 0){ //gene symbol geneSym = token; }else if(i == 7){ //phenotype status if(token.compare("Y") == 0){ isPhenotype = true; } } if(isPhenotype){ size_t foundUp = geneSym.find("UP"); size_t foundDown = geneSym.find("DOWN"); trimStr(geneSym, "_"); map<string, int>::iterator it = geneSymbolToId->find(geneSym); if (foundUp!=std::string::npos){ //the gene is upregulated phenotypeGeneIdsUpDown->push_back(it->second); } if (foundDown!=std::string::npos){ //the gene is downregulated phenotypeGeneIdsUpDown->push_back(it->second + totalGenes); } } i++; } } inFile.close(); } else { cerr << "Error opening file of explained and phenotype gene list \n"; } }
int PermutationScorer::getNumberWords (const string& text) const { int count = 0; string line = trimStr(text); if (line.length()>0) { int pos = line.find(" "); while (pos!=int(string::npos)) { count++; pos = line.find(" ",pos+1); } count++; } return count; }
/* Description- Parses a .extern directive. GET- line (lineInfo *). */ void parseExternDirc(lineInfo *line) { /* check if we use in labelInfo if not i can delete it.*/ labelInfo label = { 0 }, *labelPointer; /* If there is a label in the line, remove the it from labelArr */ if (line->label) { removeLastLabel(line->lineNum); } trimStr(&line->lineStr); labelPointer = addLabelToArr(label, line); }
void checkStr(char *s) { int i; if (setMaxStrLen(s, MAX_STRING_LENGTH)) { trimStr(s); fprintf(stderr, "WARNING(%i): String shortened to '%s'\n", nline, s); nwarn++; } if (i = mkPrintStr(s, '?')) { fprintf(stderr, "WARNING(%i): %i bad char(s) replaced: '%s'\n", nline, i, s); nwarn++; } }
void readGenesListUpDown(const char* filename, vector<int>* geneIdsUpDown, map<string, int>* geneSymbolToId){ ifstream inFile; inFile.open(filename, std::ifstream::in); int totalGenes = geneSymbolToId->size(); if (inFile.is_open()) { //read the output from the while (inFile.good()) { string s; if (!getline(inFile, s)) break; istringstream ss(s); size_t foundUp = s.find("UP"); size_t foundDown = s.find("DOWN"); trimStr(s, "_"); string currentGeneName = s; map<string, int>::iterator it = geneSymbolToId->find(currentGeneName); if (foundUp!=std::string::npos){ //the gene is upregulated geneIdsUpDown->push_back(it->second); } if (foundDown!=std::string::npos){ //the gene is downregulated geneIdsUpDown->push_back(it->second + totalGenes); } } inFile.close(); } else { cerr << "Error opening file\n"; } }
void myEditMountImpl::slotFinish() { myDataPartition dataM; QString opt, tmp; dataM.part = namePart->text(); dataM.FS_fstab = selectType->currentText(); dataM.MntPnt = selectMP->currentText(); if(dataM.FS_fstab.isEmpty()) { selectType->setFocus(); return; } if(dataM.MntPnt.isEmpty()) { selectMP->setFocus(); return; } if(checkSync->isChecked ()) opt+=",sync"; if(checkNoatime->isChecked()) opt+=",noatime"; if(checkRo->isChecked()) opt+=",ro"; if(checkNoSuid->isChecked()) opt+=",nosuid"; if(checkUmask22->isChecked()) opt+=",umask=0002"; if(checkUser->isChecked()) opt+=",user"; if(checkNoExec->isChecked()) opt+=",noexec"; if(checkNodev->isChecked()) opt+=",nodev"; tmp = editOther->text(); if(!tmp.isEmpty()) opt+=","+tmp; tmp = editCharSet->currentText(); if(!tmp.isEmpty()) opt+=",iocharset="+tmp; tmp = editCodePage->currentText(); if(!tmp.isEmpty()) opt+=",codepage="+tmp; trimStr(opt, ","); dataM.Parameter=opt; if(dataM.fileSystem=="ext3") { dataM.freq="1"; dataM.passno="2"; } else { dataM.freq="0"; dataM.passno="0"; } accept(); emit sendData(dataM); }
/*! \fn myEditMountImpl::loadData(myDataPartition& data) */ void myEditMountImpl::loadData(myDataPartition data) { namePart->setText(data.Device); selectType->setCurrentText(data.FS_fstab); //selectMP->insertItem(data.MntPnt); selectMP->setCurrentText(data.MntPnt); editCharSet->setCurrentText(""); editCodePage->setCurrentText(""); namePart->setText(data.part); nameType->setText(data.fileSystem);; nameSize->setText(data.Size); int n,i,j; QString s = data.Parameter; QString tmp,t; QString cmdL; i=n=0; while(i!=-1) { i = s.find(","); if(i==-1) { tmp = s; } tmp = s.mid(0,i); //tmp.remove(i,1); s.remove(0,i+1); if(tmp.find("iocharset=")!=-1) { j = tmp.find("="); t = tmp.mid(j+1,tmp.length()-j); editCharSet->insertItem(t); editCharSet->setCurrentText(t); } else if(tmp.find("codepage=")!=-1) { j = tmp.find("="); t = tmp.mid(j+1,tmp.length()-j); editCodePage->insertItem(t); editCodePage->setCurrentText(t); } else if(tmp=="sync") checkSync->setChecked(true); else if(tmp=="noatime") checkNoatime->setChecked(true); else if(tmp=="ro") checkRo->setChecked(true); else if(tmp=="nosuid") checkNoSuid->setChecked(true); else if(tmp=="umask=0022") checkUmask22->setChecked(true); else if(tmp=="user") checkUser->setChecked(true); else if(tmp=="noexec") checkNoExec->setChecked(true); else if(tmp=="nodev") checkNodev->setChecked(true); else{ cmdL+=tmp+","; }//,iocharset=koi8-u,codepage=866,noauto,ro,exec,users } trimStr(cmdL, ","); editOther->setText(cmdL); }
QVariant JSONReader::parseJSON(QString str) { //---- Trim String str = trimStr(str); //qDebug() << endl << "Str:" << str ; //---- Start Testing String if(str.toLower() == "true") { //---- Return bool true //qDebug() << "---- Return: QVariant(true)" << endl; return QVariant(true); } else if (str.toLower() == "false") { //---- Return bool false //qDebug() << "---- Return: QVariant(false)" << endl; return QVariant(false); } else if (str.toLower() == "null") { //---- Return null //qDebug() << "---- Return: QVariant()" << endl; return QVariant(QVariant::String); } else { if (isNumeric(str)) { //---- Return int/float number if(str.toFloat() == str.toInt()) { //---- Return int //qDebug() << "---- Return: QVariant(int)" << endl; return QVariant(str.toInt()); } else { //---- Return float //qDebug() << "---- Return: QVariant(float)" << endl; return QVariant(str.toFloat()); } } else { //qDebug() << "-- is a String, Object, Array"; QRegExp rxString("^(\"|').*(\\1)$"); QRegExp rxArray("^\\[.*\\]$"); QRegExp rxObject("^\\{.*\\}$"); if (rxString.exactMatch(str) == true) { //---- Return string str = reduceStr(str); //qDebug() << "---- Return: QString()" << endl; return QVariant(str); } else if ((rxObject.exactMatch(str) == true) || (rxArray.exactMatch(str) == true)) { int type; QList<QVariant> array; QMap<QString,QVariant> object; if (rxObject.exactMatch(str) == true) { //qDebug() << "Object...."; type = JSON_IN_OBJ; } else if (rxArray.exactMatch(str) == true) { //qDebug() << "Array...."; type = JSON_IN_ARR; } //---- Setup "Stack" QVector< QMap<QString, QVariant> > stack; QMap<QString, QVariant> newStack; newStack["what"] = QVariant(JSON_SLICE); newStack["where"] = QVariant(0); newStack["delim"] = QVariant(0); stack.append(newStack); //---- Trim String and remove first&last characters str = trimStr(str); str = reduceStr(str); //---- If object is empty if (strLength(str) == 0) { return QVariant(); } //---- Find name:value or "name":value pairs for (int c=0; c<=strLength(str); c++) { //---- Get last entered "stack" value QMap<QString, QVariant> top = stack.last(); QString substr_c_2(subStr(str, c, 2)); if ((c == strLength(str)) || ((str[c] == ',') && (top["what"].toInt() == JSON_SLICE))) { //---- Found a comma that is not inside a string, array, etc., //---- OR we've reached the end of the character list QString slice(subStr(str, top["where"].toInt(), (c-top["where"].toInt()))); newStack["what"] = QVariant(JSON_SLICE); newStack["where"] = QVariant(c+1); newStack["delim"] = QVariant(0); stack.append(newStack); if (c != strLength(str)) { //qDebug() << "-- Found ',' at" << c << ":" << slice << endl; } else { //qDebug() << "-- Found End at" << c << endl; } if (type == JSON_IN_ARR) { //---- If we are in array mode just append value to list array.append(parseJSON(slice)); } else if (type == JSON_IN_OBJ) { //---- We are in an object. So get property name and set element in a QMap QRegExp rxString("^\\s*([\"|'].*[^\\\\][\"|'])\\s*:.*"); rxString.setMinimal(true); if (rxString.indexIn(slice) >= 0) { //---- Is in quotes QString key = parseJSON(rxString.cap(1)).toString(); QVariant val = parseJSON(subStr(slice,strLength(rxString.cap(1))+1)); object[key] = val; } else { QRegExp rxString("^\\s*(\\w+)\\s*:.*"); rxString.setMinimal(true); //---- Not in quotes QString key = parseJSON(rxString.cap(1)).toString(); QVariant val = parseJSON(subStr(slice,strLength(rxString.cap(1))+1)); object[key] = val; } } } else if (((str[c] == '"') || (str[c] == '\'')) && (top["what"].toInt() != JSON_IN_STR) ) { //---- Found a quote, and we are not inside a string newStack["what"] = QVariant(JSON_IN_STR); newStack["where"] = QVariant(c); newStack["delim"] = QVariant(str[c]); stack.append(newStack); } else if ((str[c] == top["delim"].toChar()) && (top["what"].toInt() == JSON_IN_STR) && ((strLength(subStr(str,0,c))-strLength(subStr(str,0,c).replace(QRegExp("\\\\$"),""))) % 2 != 1) ) { /*--- Found a quote, we're in a string, and it's not escaped we know that it's not escaped becase there is not an odd number of backslashes at the end of the string so far */ stack.remove(stack.count()-1); //qDebug() << "-- Found a Quote at" << c << ":" << subStr(str,top["where"].toInt(),(1+1-top["where"].toInt())); } else if ((str[c] == '[') && ((top["what"].toInt() == JSON_SLICE) || (top["what"].toInt() == JSON_IN_ARR) || (top["what"].toInt() == JSON_IN_OBJ) ) ) { //---- Found a left-bracket '[', and we are in an array, object, or slice newStack["what"] = QVariant(JSON_IN_ARR); newStack["where"] = QVariant(c); newStack["delim"] = QVariant(0); stack.append(newStack); } else if ((str[c] == ']') && (top["what"].toInt() == JSON_IN_ARR) ) { //---- Found a right-bracket ']', and we're in an array stack.remove(stack.count()-1); } else if ((str[c] == '{') && ((top["what"].toInt() == JSON_SLICE) || (top["what"].toInt() == JSON_IN_ARR) || (top["what"].toInt() == JSON_IN_OBJ) ) ) { //---- Found a left-brace '{', and we are in an array, object, or slice newStack["what"] = QVariant(JSON_IN_OBJ); newStack["where"] = QVariant(c); newStack["delim"] = QVariant(0); stack.append(newStack); //qDebug() << "-- Found '{' at" << c ; } else if ((str[c] == '}') && (top["what"].toInt() == JSON_IN_OBJ) ) { stack.remove(stack.count()-1); //qDebug() << "-- Found '}' at" << c << ":" << subStr(str,top["where"].toInt(),(1+c-top["where"].toInt())); } } //---- Return Object if (type == JSON_IN_ARR) { //---- Return Array return QVariant(array); } else if (type == JSON_IN_OBJ) { //---- Return Object return QVariant(object); } } } } return QVariant(QVariant::String); }
QString get_disk_statistic() { QString cmd, s, msg; int i=0; cmd = QString("df 2>&1"); FILE *fdisk=popen(cmd, "r"); char *buf=(char *) malloc(1024); QString dev; while(fgets(buf, 1024, fdisk)) { if(strlen(buf)<=1) continue; if(strncmp("/dev/", buf, 5)==0) { //while(isspace(*buf)) strcpy(buf, buf+1); while(strchr(buf, '\t')) *strchr(buf, '\t')=' ';//replease all symbol \n in space // Get the device *strchr(buf, ' ')=0; //mid first string s = buf;//device msg +="<tr bgcolor=\"#EEF6FF\"><td>"+s+"</td>"; strcpy(buf, buf+strlen(buf)+1); //step next word while(isspace(*buf)) strcpy(buf, buf+1); *strchr(buf, ' ')=0; s = buf; i = s.toInt(); msg +="<td>"+convert_size_disk(i)+"</td>";//size strcpy(buf, buf+strlen(buf)+1); while(isspace(*buf)) strcpy(buf, buf+1); strcpy(buf, strchr(buf, ' ')); // skip used while(isspace(*buf)) strcpy(buf, buf+1); *strchr(buf, ' ')=0; s = buf;//Available i = s.toInt(); msg +="<td>"+convert_size_disk(i)+"</td>"; strcpy(buf, buf+strlen(buf)+1); while(isspace(*buf)) strcpy(buf, buf+1); strcpy(buf, strchr(buf, ' ')); // skip procent while(isspace(*buf)) strcpy(buf, buf+1); //*strchr(buf, ' ')=0; s = buf; trimStr(s,"\n"); msg +="<td>"+s+"</td></tr>";//mounted } } pclose(fdisk); free(buf); QString font = "<font size=+1 color=\"blue\"><b>%1</b> : </font><br><br><br>"; QString s_msg = font.arg(QObject::tr("Disk's statistic")); s_msg += "<table border=0 width=100%>"; s_msg += QString("<tr bgcolor=\"lightGray\"><th>%1</th><th>%2</th><th>%3</th><th>%4</th></tr>") .arg(QObject::tr("Device")).arg(QObject::tr("Size")).arg(QObject::tr("Available")).arg(QObject::tr("Mounted to")); s_msg += msg; s_msg += "</table>"; return s_msg; }
AST *frontend(char *txt, u32 txtlen) { char *s = NULL; u32 *code = NULL; u32 i = 0; u32 slen; int tokcur, tokexp = TOK_GAME_TITLE; AST *tree = (AST*) malloc(sizeof(AST)); memset(tree, 0, sizeof(AST)); // Text MUST contain a new line char at the end if (txt[txtlen - 1] != '\n') { txt = (char*) realloc(txt, ++txtlen); txt[txtlen - 1] = '\n'; } printf("*** Compiler front end ***\n"); printf("Parsing...\n"); /*** Scanner ***/ while (i < txtlen) { slen = indexOfChr(&txt[i], '\n'); if (!_isEmptyStr(&txt[i], slen)) { s = &txt[i]; s[slen] = NUL; /*** Screener ***/ remCmtFromStr(s); trimStr(s); if (strlen(s) > 0) { /*** Parser ***/ tokcur = getToken(s); if (!(tokexp & tokcur)) { fprintf(stderr, "ERROR(%i): '%s' : ", nline, s); if (tokexp & TOK_CHEAT_DESC) { fprintf(stderr, "Cheat description expected\n"); tokexp = TOK_ALL; } else /* if (tokexp & TOK_GAME_TITLE) */ { fprintf(stderr, "Game title expected\n"); tokexp = TOK_GAME_TITLE | TOK_CHEAT_DESC; } nerr++; } else switch (tokcur) { case TOK_GAME_TITLE: s = getGameTitle(s); if (*s == NUL) { fprintf(stderr, "ERROR(%i): Empty game title\n", nline); nerr++; } else { checkStr(s); if (!nerr && addGameToTree(tree, s) < 0) { fprintf(stderr, "ERROR(%i): '%s' : Cannot add more games\n", nline, s); nerr++; } } tokexp = TOK_GAME_TITLE | TOK_CHEAT_DESC; break; case TOK_CHEAT_DESC: checkStr(s); if (!nerr && addCheatToTree(tree, s) < 0) { fprintf(stderr, "ERROR(%i): '%s' : Cannot add more cheats\n", nline, s); nerr++; } tokexp = TOK_ALL; break; case TOK_CHEAT_CODE: code = getCheatCode(s); if (!nerr && addCodeToTree(tree, code) < 0) { fprintf(stderr, "ERROR(%i): %08X %08X : Cannot add more codes\n", nline, code[0], code[1]); nerr++; } tokexp = TOK_ALL; break; } } } nline++; i += slen + 1; } printf("Parsing done: %i error(s), %i warning(s)\n", nerr, nwarn); if (nerr) { fprintf(stderr, "Error(s) occurred during parsing.\n"); freeTree(tree); return NULL; } else if (!tree->ngames) { fprintf(stderr, "Nothing parsed.\n"); freeTree(tree); return NULL; } printf("Stats: %u game(s), %u cheat(s), %u code(s)\n", tree->ngames, tree->nallcheats, tree->nallcodes); return tree; }