/** run selection dialog and run selected file */ void spqrMainWindow::openFile() { QFileDialog d(this, tr("Open Prolog file"), lastDir, Prolog_Exts()); if (d.exec()) { lastDir = d.directory().path(); openSourceFile(d.selectedFiles()[0]); } }
/** GUI setup */ spqrMainWindow::spqrMainWindow(int argc, char *argv[], QWidget *parent) : QMainWindow(parent), MruHelper("spqr") { statusBar()->showMessage(tr("spqr Setup")); lqPreferences p; p.loadGeometry(this); con = new ConsoleEdit(argc, argv); connect(con, SIGNAL(engine_ready()), this, SLOT(engineReady())); make_tabs(); QMenu *m = menuBar()->addMenu(tr("&File")); m->setStatusTip(tr("Show File operations")); m->addAction(tr("&New..."), this, SLOT(newFile()), QKeySequence::New)->setStatusTip(tr("Create a new file")); m->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence::Open)->setStatusTip(tr("Open an existing file")); m->addMenu(mruMenu = new QMenu(tr("Recent &Files...")))->setStatusTip(tr("List recently opened files")); loadMru(p, this); m->addSeparator(); m->addAction(tr("&Save"), this, SLOT(saveFile()), QKeySequence::Save)->setStatusTip(tr("Save the document to disk")); m->addAction(tr("Save &As..."), this, SLOT(saveFileAs()), QKeySequence::SaveAs)->setStatusTip(tr("Save the document under a new name")); m->addSeparator(); m->addAction(tr("&Quit"), qApp, SLOT(quit()), QKeySequence::Quit)->setStatusTip(tr("Exit the application")); // detach the background processor to avoid a random GPF exiting the program connect(qApp, &QApplication::aboutToQuit, []() { SwiPrologEngine::quit_request(); }); menuBar()->addSeparator(); menuBar()->addAction("&Exec", this, SLOT(execSource()))->setStatusTip(tr("Run Prolog Source code")); menuBar()->addAction("&Source", this, SLOT(viewSource()))->setStatusTip(tr("Show the Prolog source window")); menuBar()->addAction("&Console", this, SLOT(viewConsole()))->setStatusTip(tr("Show the SWI-Prolog console")); menuBar()->addAction("&Help", this, SLOT(viewHelp()))->setStatusTip(tr("Show SWI-Prolog helpDoc")); lastDir = p.value("lastDir").toString(); QString currFile = p.value("fileSource").toString(); if (argc >= 2) currFile = argv[1]; if (currFile.length()) openSourceFile(currFile); }
int main(int argc, char *argv[]){ openSourceFile(argv[1]); createOutputFile(argv[1]); strcpy(sourceFileName, argv[1]); while(!sourceEOF){ TokenType currentToken = getToken(); if(strcmp(tokenTypeStr[currentToken], "OTHER") != 0 && strcmp(tokenTypeStr[currentToken], "ERROR") != 0){ if(currentToken == KEYWORD || currentToken == OPERATOR || currentToken == DELIMITER) fprintf(outputFile, "%d %s\n", lineNo, tokenString); else fprintf(outputFile, "%d %s %s\n", lineNo, tokenTypeStr[currentToken], tokenString); //printf("%d %s %s\n", lineNo, tokenTypeStr[currentToken], tokenString); } } fclose(source); fclose(outputFile); diffTest(argv[1]); return 0; }
void languageDirective(void) { DumbGetCharOn = true; getChar(); char directive[32]; int32_t directiveLength = 0; while ((curChar != ' ') && (curChar != '\n') && (curChar != '\r') && (directiveLength < 31)) { directive[directiveLength++] = curChar; getChar(); } directive[directiveLength] = nullptr; _strlwr(directive); if (strcmp(directive, "include") == 0) { //--------------------- // INCLUDE directive... getChar(); if (curChar == '"') { getChar(); char fileName[128]; int32_t fileNameLength = 0; while ((curChar != '"') && (fileNameLength < 127)) { fileName[fileNameLength++] = curChar; getChar(); } fileName[fileNameLength] = nullptr; //----------------------------------------------------------------------- // The language directive should be on a line by itself, since // everything after the directive on this line is ignored... DumbGetCharOn = false; //---------------------------------------------------- // Now that we have the file name, let's include it... int32_t openErr = ABL_NO_ERR; if ((openErr = openSourceFile(fileName)) != ABL_NO_ERR) { syntaxError(ABL_ERR_SYNTAX_SOURCE_FILE_OPEN); curToken = TKN_ERROR; } } else { syntaxError(ABL_ERR_SYNTAX_BAD_LANGUAGE_DIRECTIVE_USAGE); curToken = TKN_ERROR; } } else if (strcmp(directive, "include_") == 0) { //--------------------- // INCLUDE directive... getChar(); if (curChar == '"') { getChar(); char fileName[128]; int32_t fileNameLength = 0; while ((curChar != '"') && (fileNameLength < 127)) { fileName[fileNameLength++] = curChar; getChar(); } fileName[fileNameLength] = nullptr; //----------------------------------------------------------------------- // The language directive should be on a line by itself, since // everything after the directive on this line is ignored... DumbGetCharOn = false; //---------------------------------------------------- // Now that we have the file name, let's include it... int32_t openErr = ABL_NO_ERR; //--------------------------------------- // What's the current module's directory? char fullPath[255]; int32_t curChar = strlen(SourceFiles[0]); while ((curChar > -1) && (SourceFiles[0][curChar] != '\\')) curChar--; if (curChar == -1) strcpy(fullPath, fileName); else { strcpy(fullPath, SourceFiles[0]); fullPath[curChar + 1] = nullptr; strcat(fullPath, fileName); } if ((openErr = openSourceFile(fullPath)) != ABL_NO_ERR) { syntaxError(ABL_ERR_SYNTAX_SOURCE_FILE_OPEN); curToken = TKN_ERROR; } } else { syntaxError(ABL_ERR_SYNTAX_BAD_LANGUAGE_DIRECTIVE_USAGE); curToken = TKN_ERROR; } } else if (strcmp(directive, "assert_on") == 0) { DumbGetCharOn = false; curChar = ' '; AssertEnabled = true; } else if (strcmp(directive, "assert_off") == 0) { DumbGetCharOn = false; curChar = ' '; AssertEnabled = false; } else if (strcmp(directive, "print_on") == 0) { DumbGetCharOn = false; curChar = ' '; PrintEnabled = true; } else if (strcmp(directive, "print_off") == 0) { DumbGetCharOn = false; curChar = ' '; PrintEnabled = false; } else if (strcmp(directive, "stringfuncs_on") == 0) { DumbGetCharOn = false; curChar = ' '; StringFunctionsEnabled = true; } else if (strcmp(directive, "stringfuncs_off") == 0) { DumbGetCharOn = false; curChar = ' '; StringFunctionsEnabled = false; } else if (strcmp(directive, "debug_on") == 0) { DumbGetCharOn = false; curChar = ' '; DebugCodeEnabled = true; } else if (strcmp(directive, "debug_off") == 0) { DumbGetCharOn = false; curChar = ' '; DebugCodeEnabled = false; } else if (strcmp(directive, "debug_start") == 0) { bool stillCutting = true; if (!DebugCodeEnabled) { int32_t nestedLevel = 1; getChar(); // getChar(); do { while ((curChar != '#') && (curChar != CHR_EOF)) getChar(); if (curChar == '#') { char directive2[32]; int32_t directiveLength = 0; while ((curChar != ' ') && (curChar != '\n') && (curChar != '\r') && (directiveLength < 31)) { directive2[directiveLength++] = curChar; getChar(); } directive2[directiveLength] = nullptr; _strlwr(directive2); if (strcmp(directive2, "#debug_start") == 0) nestedLevel++; else if (strcmp(directive2, "#debug_end") == 0) { nestedLevel--; if (nestedLevel == 0) stillCutting = false; } } else if (curChar == CHR_EOF) { syntaxError(ABL_ERR_SYNTAX_UNEXPECTED_EOF); curToken = TKN_ERROR; } else getChar(); } while (stillCutting); } curChar = ' '; DumbGetCharOn = false; } else if (strcmp(directive, "debug_end") == 0) { curChar = ' '; DumbGetCharOn = false; } else { syntaxError(ABL_ERR_SYNTAX_UNKNOWN_LANGUAGE_DIRECTIVE); curToken = TKN_ERROR; } }
void MainWindow::createActions() { m_newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); m_newAct->setShortcut(tr("Ctrl+N")); m_newAct->setStatusTip(tr("Create a new file")); connect(m_newAct, SIGNAL(triggered()), this, SLOT(newFile())); m_openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); m_openAct->setShortcut(tr("Ctrl+O")); m_openAct->setStatusTip(tr("Open a file from disk")); connect(m_openAct, SIGNAL(triggered()), this, SLOT(open())); m_saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); m_saveAct->setShortcut(tr("Ctrl+S")); m_saveAct->setStatusTip(tr("Save the document to disk")); connect(m_saveAct, SIGNAL(triggered()), this, SLOT(save())); m_saveAsAct = new QAction(tr("Save &As..."), this); m_saveAsAct->setStatusTip(tr("Save the document under a new name")); connect(m_saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); m_closeAct = new QAction(tr("&Close..."), this); m_closeAct->setShortcut(tr("Ctrl+W")); m_closeAct->setStatusTip(tr("Close the document")); connect(m_closeAct, SIGNAL(triggered()), this, SLOT(close())); m_openSourceFile = new QAction(tr("&Open Source File"), this); m_openSourceFile->setShortcut(tr("Ctrl+Alt+J")); m_openSourceFile->setStatusTip(tr("Open a file from the source directory")); connect(m_openSourceFile, SIGNAL(triggered()), this, SLOT(openSourceFile())); m_openBuildFile = new QAction(tr("&Open Build File"), this); m_openBuildFile->setShortcut(tr("Ctrl+Alt+K")); m_openBuildFile->setStatusTip(tr("Open a file from the build directory")); connect(m_openBuildFile, SIGNAL(triggered()), this, SLOT(openBuildFile())); m_selectOpenedFile = new QAction(tr("&Select Opened File"), this); m_selectOpenedFile->setShortcut(tr("Ctrl+Space")); m_selectOpenedFile->setStatusTip(tr("Select an already opened file")); connect(m_selectOpenedFile, SIGNAL(triggered()), this, SLOT(selectOpenedFile())); m_exitAct = new QAction(tr("E&xit"), this); m_exitAct->setShortcut(tr("Ctrl+Q")); m_exitAct->setStatusTip(tr("Exit the application")); connect(m_exitAct, SIGNAL(triggered()), this, SLOT(close())); m_cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); m_cutAct->setShortcut(tr("Ctrl+X")); m_cutAct->setStatusTip(tr("Cut the current selection's contents to the " "clipboard")); connect(m_cutAct, SIGNAL(triggered()), m_fileStack, SLOT(cut())); m_copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this); m_copyAct->setShortcut(tr("Ctrl+C")); m_copyAct->setStatusTip(tr("Copy the current selection's contents to the " "clipboard")); connect(m_copyAct, SIGNAL(triggered()), m_fileStack, SLOT(copy())); m_pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this); m_pasteAct->setShortcut(tr("Ctrl+V")); m_pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current " "selection")); connect(m_pasteAct, SIGNAL(triggered()), m_fileStack, SLOT(paste())); m_splitVertical = new QAction(tr("Split &Vertical"), this); m_splitVertical->setShortcut(tr("Ctrl+Alt+V")); m_splitVertical->setStatusTip(tr("Split the focused file view vertically")); connect(m_splitVertical, SIGNAL(triggered()), this, SLOT(splitVertical())); m_splitHorizontal = new QAction(tr("Split &Horizontal"), this); m_splitHorizontal->setShortcut(tr("Ctrl+Alt+H")); m_splitHorizontal->setStatusTip(tr("Split the focused file view horizontally")); connect(m_splitHorizontal, SIGNAL(triggered()), this, SLOT(splitHorizontal())); m_newProjectAct = new QAction(QIcon(":/images/new.png"), tr("&New Project"), this); m_newProjectAct->setStatusTip(tr("Create a new project")); connect(m_newProjectAct, SIGNAL(triggered()), this, SLOT(newProject())); m_openProjectAct = new QAction(QIcon(":/images/open.png"), tr("&Open Project..."), this); m_openProjectAct->setStatusTip(tr("Open an existing project")); connect(m_openProjectAct, SIGNAL(triggered()), this, SLOT(openProject())); m_importProjectAct = new QAction(tr("&Import Project"), this); m_importProjectAct->setStatusTip(tr("Import an existing project")); connect(m_importProjectAct, SIGNAL(triggered()), this, SLOT(importProject())); m_closeProjectAct = new QAction(tr("&Close Project..."), this); m_closeProjectAct->setStatusTip(tr("Close the project")); connect(m_closeProjectAct, SIGNAL(triggered()), this, SLOT(closeProject())); m_openSettingsAct = new QAction(tr("&Configure..."), this); m_openSettingsAct->setStatusTip(tr("Configure settings")); connect(m_openSettingsAct, SIGNAL(triggered()), this, SLOT(openSettings())); m_aboutAct = new QAction(tr("&About"), this); m_aboutAct->setStatusTip(tr("Show the application's About box")); connect(m_aboutAct, SIGNAL(triggered()), this, SLOT(about())); m_aboutQtAct = new QAction(tr("About &Qt"), this); m_aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); connect(m_aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); m_cutAct->setEnabled(false); m_copyAct->setEnabled(false); connect(m_fileStack, SIGNAL(copyAvailable(bool)), m_cutAct, SLOT(setEnabled(bool))); connect(m_fileStack, SIGNAL(copyAvailable(bool)), m_copyAct, SLOT(setEnabled(bool))); }
/** this is default as required by MruHelper */ void spqrMainWindow::openFileIndex(int i) { openSourceFile(files[i]); }