/** * Searches in the "name" directory for the "find" file, * if file is found and the user wanted to find that filetype * the path is added to a list that will be printed at the end. * Also puts all directories found in a list for it to be * searched. */ bool searchForFile(char* name, char *find, int t, struct Node* list) { DIR *dir; struct dirent *ent; struct stat f_info; bool foundFile = false; if (openDir(&dir, name, &ent)) { do { if ((lstat(ent->d_name, &f_info)) < 0) { fprintf(stderr, "lstat error: "); perror(ent->d_name); } else { if (t == 0 && compareName(ent->d_name, find)) { foundFile = true; } else if (checkDir(t, f_info, ent->d_name, find)) { foundFile = true; } else if (checkReg(t, f_info, ent->d_name, find)) { foundFile = true; } else if (checkLink(t, f_info, ent->d_name, find)) { foundFile = true; } if (checkDirAndRights(f_info) && !isDot(ent->d_name)) { int l = strlen(name) + strlen(ent->d_name); char *str = calloc(1, sizeof(char[l + 2])); strcpy(str, name); strcat(str, "/"); strcat(str, ent->d_name); insert(list, str); } } } while ((ent = readdir(dir))); } closedir(dir); return foundFile; }
QVector<Instruction> Parser::parseFile(QFile &instFile) { QVector <Instruction> instMem; //to be returned Instruction temp; //current instruction that is being formed QString line; //current line being proccessed QTextStream fileStream(&instFile); //the stream of the file QRegExp inst_3Op("\\s*(ADD|ADDI|XOR|SLT|BLE)\\s+\\$(\\d+)\\s*,\\s*\\$(\\d+)\\s*,\\s*(\\$?\\d+)\\s*"); //to check for instruction with three operands QRegExp inst_2Op("\\s*(LW|SW)\\s+\\$(\\d+)\\s*,\\s*(\\d+)\\s*\\(\\s*\\$(\\d+)\\s*\\)\\s*"); //to check for instructions with two operands QRegExp inst_1Op ("\\s*(J|JAL|JR|JUMP_PROCEDURE)\\s+(\\$?\\d+)\\s*"); //to check for instruction with 1 operand QRegExp inst_0Op ("^\\s*(RETURN_PROCEDURE)\\s*$"); QRegExp empty("^(\\s*)$"); //to check for any white char QString fileError = "An Error Occurred, Problem with the File"; //to be thrown if an error occurred when openning the file QString invalidSyntaxError = "An Error Occurred, Invalid Instruction Syntax at Line: "; //to be thrown if invalid syntax found QString RegIndexError = "An Error Occurred, Register Index Out of Bounds at Line: "; //to be thrown if register index is out of bound if(instFile.open(QFile::ReadOnly)) { //todo : open file in read only format while(!fileStream.atEnd()) { line = fileStream.readLine(); lineNumber++; if(inst_3Op.indexIn(line) != -1) { //match 3operands instruction temp.inst = inst_3Op.cap(0); temp.instType = inst_3Op.cap(1); temp.jAddress = 0; if (temp.instType == "ADDI" || temp.instType == "BLE" ){ // I-Format if (inst_3Op.cap(4).at(0) == '$') throw (invalidSyntaxError + QString::number(lineNumber)); temp.rd = 0; temp.rt = atoi( inst_3Op.cap(2).toStdString().c_str() ); temp.rs = atoi( inst_3Op.cap(3).toStdString().c_str() ); temp.imm = atoi( inst_3Op.cap(4).toStdString().c_str() ); if ( !checkReg(temp.rs) || !checkReg(temp.rt) ) throw (RegIndexError + QString::number(lineNumber)); } else { //R-Format if (inst_3Op.cap(4).at(0) != '$') throw (invalidSyntaxError + QString::number(lineNumber)); temp.imm = 0; temp.rd = atoi( inst_3Op.cap(2).toStdString().c_str() ); temp.rs = atoi( inst_3Op.cap(3).toStdString().c_str() ); temp.rt = atoi( inst_3Op.cap(4).toStdString().substr(1).c_str() ); if (!checkReg(temp.rs) || !checkReg(temp.rt) || !checkReg(temp.rd) ) throw (RegIndexError + QString::number(lineNumber)); } } else if(inst_2Op.indexIn(line) != -1) { //match 2operands instructtion temp.inst = inst_2Op.cap(0); temp.instType = inst_2Op.cap(1); temp.rd = 0; temp.jAddress = 0; temp.rt = atoi( inst_2Op.cap(2).toStdString().c_str() ); temp.imm = atoi( inst_2Op.cap(3).toStdString().c_str() ); temp.rs = atoi( inst_2Op.cap(4).toStdString().c_str() ); if ( !checkReg(temp.rs) || !checkReg(temp.rt) ) throw (RegIndexError + QString::number(lineNumber)); } else if (inst_1Op.indexIn(line) != -1) { //match 1operand instruction temp.inst = inst_1Op.cap(0); temp.instType = inst_1Op.cap(1); temp.rt = 0; temp.rd = 0; temp.imm = 0; if(temp.instType == "JR") { //JR if (inst_1Op.cap(2).at(0) != '$') throw (invalidSyntaxError + QString::number(lineNumber)); temp.jAddress = 0; temp.rs = atoi( inst_1Op.cap(2).toStdString().substr(1).c_str() ); if ( !checkReg(temp.rs) ) throw (RegIndexError + QString::number(lineNumber)); } else { // J/JAL/JUMP_PROCEDURE if (inst_1Op.cap(2).at(0) == '$') throw (invalidSyntaxError + QString::number(lineNumber)); temp.rs = 0; temp.jAddress = atoi( inst_1Op.cap(2).toStdString().c_str() ); } } else if(inst_0Op.indexIn(line) != -1) { //RETURN_PROCEDURE temp.inst = inst_0Op.cap(0); temp.instType = inst_1Op.cap(1); temp.rs = temp.rt = temp.rd = temp.imm = temp.jAddress = 0; } else if (empty.indexIn(line) != -1) { //match white char continue; } else { //invalid instruction throw (invalidSyntaxError + QString::number(lineNumber)); } instMem.push_back(temp); //end of line parsing } instFile.close(); } else throw (fileError); //QString Error return instMem; //end of parsing file }
WLogin::WLogin(QWidget *parent) : QDialog(parent) { //main widget setup installEventFilter(this); this->setWindowFlags(Qt::FramelessWindowHint); this->setAttribute( Qt::WA_TranslucentBackground, true); this->setObjectName("LoginWindow"); //components new loginBgLabel = new QLabel(this); regBgLabel = new QLabel(this); userName = new QLineEdit(this); password = new QLineEdit(this); passwordConfirm = new QLineEdit(this); idCard = new QLineEdit(this); cardNum = new QLineEdit(this); mobile = new QLineEdit(this); email = new QLineEdit(this); address = new QLineEdit(this); zipcode = new QLineEdit(this); notice = new QLabel(this); closeBtn = new QPushButton(this); regBtn = new QPushButton(tr("Register"), this); loginBtn = new QPushButton(tr("Login"), this); registerBtn = new QPushButton(tr("Register"), this); backBtn = new QPushButton(tr("Go Back"), this); //set object name loginBgLabel->setObjectName("LogInBG"); regBgLabel->setObjectName("RegBG"); userName->setObjectName("LogInUser"); password->setObjectName("LogInPW"); passwordConfirm->setObjectName("RegPWConfirm"); idCard->setObjectName("RegIDCard"); cardNum->setObjectName("RegCardNum"); mobile->setObjectName("RegMobile"); email->setObjectName("RegEmail"); address->setObjectName("RegAddress"); zipcode->setObjectName("RegZipcode"); notice->setObjectName("LogInNotice"); closeBtn->setObjectName("LogInClose"); regBtn->setObjectName("LogInReg"); loginBtn->setObjectName("LogInLogIn"); registerBtn->setObjectName("RegRegister"); backBtn->setObjectName("RegBack"); //set position and size loginBgLabel->setGeometry(QRect(0, 0, 400, 678)); regBgLabel->setGeometry(QRect(0, 0, 400, 678)); userName->setGeometry(QRect(41, 198, 200, 36)); password->setGeometry(QRect(41, 246, 200, 36)); passwordConfirm->setGeometry(QRect(41, 286, 318, 36)); idCard->setGeometry(QRect(41, 334, 318, 36)); cardNum->setGeometry(QRect(41, 384, 318, 36)); mobile->setGeometry(QRect(41, 430, 318, 36)); email->setGeometry(QRect(41, 478, 318, 36)); address->setGeometry(QRect(41, 526, 318, 36)); zipcode->setGeometry(QRect(41, 574, 318, 36)); notice->setGeometry(QRect(41, 182, 294, 16)); closeBtn->setGeometry(QRect(375, 12, 10, 15)); regBtn->setGeometry(QRect(263, 202, 96, 36)); loginBtn->setGeometry(QRect(263, 244, 96, 36)); registerBtn->setGeometry(QRect(263, 626, 96, 36)); backBtn->setGeometry(QRect(167, 626, 96, 36)); //hide the registration buttons loginBgLabel->setVisible(true); regBgLabel->setVisible(false); regBtn->setVisible(true); loginBtn->setVisible(true); passwordConfirm->setVisible(false); idCard->setVisible(false); cardNum->setVisible(false); mobile->setVisible(false); email->setVisible(false); address->setVisible(false); zipcode->setVisible(false); registerBtn->setVisible(false); backBtn->setVisible(false); //set place holder text userName->setPlaceholderText(tr("Username")); password->setPlaceholderText(tr("Password")); idCard->setPlaceholderText(tr("ID Number")); passwordConfirm->setPlaceholderText(tr("Confirm Password")); cardNum->setPlaceholderText(tr("Card Number")); mobile->setPlaceholderText(tr("Mobile")); email->setPlaceholderText(tr("E-mail")); address->setPlaceholderText(tr("Address")); zipcode->setPlaceholderText(tr("Zipcode")); //set format notice->setAlignment(Qt::AlignCenter); password->setEchoMode(QLineEdit::Password); passwordConfirm->setEchoMode(QLineEdit::Password); userName->setFocus(); //set connections connect(password, SIGNAL(returnPressed()), this, SLOT(checkLogin())); connect(zipcode, SIGNAL(returnPressed()), this, SLOT(checkReg())); connect(registerBtn, SIGNAL(clicked(bool)), this, SLOT(checkReg())); connect(closeBtn, SIGNAL(clicked(bool)), this, SLOT(reject())); connect(regBtn, SIGNAL(clicked(bool)), this, SLOT(changeToReg())); connect(loginBtn, SIGNAL(clicked(bool)), this, SLOT(checkLogin())); connect(backBtn, SIGNAL(clicked(bool)), this, SLOT(changeToLogin())); //start opening animation openWindow(); }