/*! * @brief Reads a script file parsing the commands as it goes * * @param[in] filename - name of the script file * * @author J. Peterson * @date 06/22/2014 */ bool CTestScript::readScriptFile(const char *filename) { // // Clear out the current list of tests and commands // m_testList.clear(); m_commandList.clear(); m_version.clear(); // // If no file name was given then we are done // if ((filename == NULL) || (filename[0] == '\0')) { return(false); } // // Open the file // FILE *fp = fopen(filename, "r"); if (fp == NULL) { QMessageBox msgBox; msgBox.setText("Could not open script file."); msgBox.exec(); return(false); } // // Read each line of the script file and parse it. while (!feof(fp)) { char lineBuffer[1024]; if (fgets(lineBuffer, sizeof(lineBuffer), fp)) { // // create the new command // m_commandList.push_back(CCommand()); int i = m_commandList.size() - 1; CCommand *pCommand = &m_commandList[i]; pCommand->parse(lineBuffer, i); if (pCommand->m_type == CCommand::CMD_UNKNOWN) { QString title = QFileInfo( QCoreApplication::applicationFilePath() ).fileName(); QString msg = "<html><head/><body><p><span style=\" font-size:10pt; font-weight:600; color:#F00000;\"><pre>Poorly formed command on line "; QString lineNum; lineNum.setNum(i+1, 10); msg.append(lineNum); msg.append(":\n\n "); msg.append(lineBuffer); msg.append("\n</pre></span></p></body></html>"); QMessageBox::warning(NULL, title, msg); } if (pCommand->m_type == CCommand::CMD_VERSION) { if (!m_version.isEmpty()) { QString title = QFileInfo( QCoreApplication::applicationFilePath() ).fileName(); QString msg = "<html><head/><body><p><span style=\" font-size:10pt; font-weight:600; color:#F00000;\"><pre>Re-declaration of Version on line: "; QString lineNum; lineNum.setNum(i, 10); msg.append(lineNum); msg.append(":\n\n "); msg.append(lineBuffer); msg.append("\n</pre></span></p></body></html>"); QMessageBox::warning(NULL, title, msg); } m_version = pCommand->m_scriptVersion; } if (pCommand->m_type == CCommand::CMD_TEST) { m_testList.push_back(i); } } } fclose(fp); return(true); }