/* Function Name: checkLine * Purpose: Determines validity of a line of YAS * * Parameters: char * to a line of YAS * Returns: -1 : all spaces in line or instruction. * 0 : invalid line * 1 : valid line * Modifies: - */ int checkLine(char * line) { if(isSpaces(line, 0, 21) && line[22] == '|') return -1; //The case of an empty line else{ if(!isSpaces(line, 0, 1)) //Check initial spaces return 0; if(!isAddress(line)) //Check for address return 0; if(!(line[7] == ':' && line[8] == ' ' && line[21] == ' ' && line[22] == '|')) //Check particular spots return 0; if(!(isData(line))) //Check for data { //If no data... if(!isSpaces(line, 9, 20))//Check if only spaces return 0; //If not spaces OR valid data else return -1; //If just spaces } return 1; } }
void removeExtraLines(const QFileInfo& file) { //to string list QStringList fileList; int countOfEmptyLines = 0; const QString& path = file.absoluteFilePath(); QFile readfile(path); if(!readfile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QString outpath=path; if(testmode) outpath+=".test"; while(!readfile.atEnd()) { QByteArray data=readfile.readLine(); if(data.length() && data.at(data.length()-1)=='\n') data.resize(data.size()-1); if(data.length() && data.at(data.length()-1)=='\r') data.resize(data.size()-1); QString str(data); fileList += str; } //new file without empty lines QFile outfile(outpath); if(outfile.open(QIODevice::WriteOnly | QIODevice::Text)) { for (int i = 0; i < fileList.size(); ++i) { if (fileList.at(i).isEmpty() || isSpaces(fileList.at(i))) { countOfEmptyLines++; } else { countOfEmptyLines = 0; } if (countOfEmptyLines <= maxEmptyLines) { outfile.write(fileList.at(i).toAscii()); outfile.write("\n"); } } outfile.close(); } }
/* Function Name: isData * Purpose: Determines if there is data in the line after the address * * Parameters: line - input record to check * Returns: bool indicating whether the line contains data or not * Modifies: none */ bool isData(char* line){ if(!isSpaces(line, 9, 10)){ //checks for spaces where data should be int i; int count = 0; for(i = 9; i <= 20; i++){ if(line[i] == ' ') break; else count++; } bool check = checkHex(line, 9, 8+count); count = count%2; bool a = (check && !count); return (a); } return FALSE; //return false if only spaces in record }
void Shell::start() { std::string commandWithArgs; out << PROMPT; while(std::getline(in, commandWithArgs, '\n')) { if (!commandWithArgs.empty() && !isSpaces(commandWithArgs)) { ShellCommand* cmd = commands[getCommandName(commandWithArgs)]; if (cmd == NULL) { out << "command not found" << std::endl; } else { cmd->run(commandWithArgs); if (cmd->getName() == "quit") { break; } } } out << PROMPT; } }
bool checkLine(char * record) { bool validLine = FALSE; if(isAddress(record)) { //If there is an address and there is data if(isData(record)){ if(isSpaces(record,0,1) && isSpaces(record,8,8) && isSpaces(record,21,21)){ if(record[22] == '|'){ validLine =TRUE; } } } //If there is an address and no data else{ if(isSpaces(record,0,1) && isSpaces(record,8,21) && record[22] == '|') validLine = TRUE; } } //If there is no address else{ if(isSpaces(record,0,21) && record[22]== '|') validLine = TRUE; } return validLine; }
void testFunctions(){ printf("inside main\n \n "); printf("\n validFileName tests: \n"); printf("bumba.y should return 0: "); printf("%d\n", validFileName("bumba.y")); printf("noDot should return 0: "); printf("%d\n", validFileName("noDot")); printf("victory.yo should return 1: "); printf("%d\n", validFileName("victory.yo")); printf("\n isAddress tests: \n"); printf(" 0x01H: should return 0:"); printf("%d\n",isAddress(" 0x01H:")); printf(" 1x014: should return 0:"); printf("%d\n",isAddress(" 1x014:")); printf(" 0x014: should return 1:"); printf("%d\n",isAddress(" 0x014:")); printf(" 0x6A4: should return 1:"); printf("%d\n",isAddress(" 0x064:")); //need to add testing for 0x014:00 ... spaces ... | printf("\n isData tests: \n"); printf(" 0x014: 0z should return 0:"); printf("%d\n",isData(" 0x014: 0z")); printf(" 0x014: 00ddxx01daq should return 0:"); printf("%d\n",isData(" 0x014: 00ddxx01da0q")); printf(" 0x014: 00345dzqa000 should return 0:"); printf("%d\n",isData(" 0x014: 000345dzqa000")); printf(" 0x014: 00ddd0000000 should return 1:"); printf("%d\n",isData(" 0x014: 00ddd0000000 ")); printf(" 0x014: 00000000001 should return 1: "); printf("%d\n",isData(" 0x014: 000000000001")); printf(" 0x014: 01 should return 1: "); printf("%d\n",isData(" 0x014: 01")); printf("\n isSpaces tests: \n"); printf("should return 0: wxrHtl-jhplzsk"); printf("%d\n",isSpaces("wxrHtl-jhplzsk",0,14)); printf("%d\n",isSpaces("wxrHtl-jhplzsk",0,14)); printf("isSpaces should return 1: "); printf("%d\n",isSpaces(" ",0,14)); printf("isSpaces should return 1: "); printf("%d\n",isSpaces(" ",0,2)); printf("isSpaces should return 0: "); printf("%d\n",isSpaces("d ",0,2)); printf("checkHex tests: \n"); printf("abcdzf0123456789 should return 0: "); printf("%d\n",checkHex("abcdzf0123456789",0,15)); printf("abcdef0123456789 should return 1: "); printf("%d\n",checkHex("abcdef0123456789",0,15)); printf("grabAddress tests: \n"); printf(" 0x01a should return 0x01a: "); printf("%x\n",grabAddress(" 0x01a")); printf(" 0x014 should return 0x014: "); printf("%x\n",grabAddress(" 0x014")); printf("grabDataByte tests: \n"); printf(" 01a402, 4 should return 02: "); printf("%x\n", grabDataByte("01a402",4)); printf(" 01a402, 2 should return a4: "); printf("%x\n", grabDataByte("01a402",2)); printf(" 01, 0 should return 01: "); printf("%x\n", grabDataByte("01",0)); printf("countBytes tests: \n"); printf(" 0x014: 00000000001 should return 5: "); printf("%x\n", countBytes(" 0x014: 0000000001 ")); printf(" 0x014: 0201 should return 2: "); printf("%x\n", countBytes(" 0x014: 0201")); printf(" 0x014: 020100 should return 3: "); printf("%x\n", countBytes(" 0x014: 020100")); printf(" 0x014: should return 0: "); printf("%x\n", countBytes(" 0x014: ")); printf("checkLine tests: \n"); printf(" 0x014 000000000001 |comments should return 0: "); printf("%d\n", checkLine(" 0x014 000000000001 |comments\n")); printf("0x014: 000000000001 |comments should return 0: "); printf("%d\n", checkLine("0x014: 000000000001 |comments\n")); printf(" 0x014: 000000000001 |comments should return 1: "); printf("%d\n", checkLine(" 0x014: 000000000001 |comments\n")); //printf(" 01a402, 2 should return a4: "); //printf("%x\n", grabDataByte("01a402",2)); //printf(" 01, 0 should return 01: "); /* printf("discardRest should return 0: \n"); printf("%d\n",discardRest("",0,15)); printf("discardRest should return 1: \n"); printf("%d\n",discardRest("",0,15)); */ }