23 #include <glibmm/optioncontext.h> 24 #include <gtkmm/application.h> 26 #include <sys/signal.h> 34 #include "../../libs/rapidjson/document.h" 43 const Glib::RefPtr<Gio::ApplicationCommandLine>&,
44 const Glib::RefPtr<Gtk::Application>& app);
46 GIOCondition condition,
71 std::string
manual =
"https://github.com/LawrenceWarren/KoMo2#user-manual";
76 std::string
help =
"Please view the user manual (" +
manual +
") for help.";
94 int main(
int argc,
char* argv[]) {
96 auto app = Gtk::Application::create(argc, argv,
"uon.cs.KoMo2",
97 Gio::APPLICATION_HANDLES_COMMAND_LINE);
105 app->signal_command_line().connect(
118 auto exit = app->run(koMo2Window);
131 std::cout <<
"A pipe error ocurred." << std::endl;
140 g_io_add_watch(fd, G_IO_IN, f, mainModel);
156 std::cout <<
"A pipe error ocurred." << std::endl;
176 auto jimulatorPath = argv0.append(
"/bin/jimulator").c_str();
177 execlp(jimulatorPath,
"", (
char*)0);
190 auto buf = realpath(arg, NULL);
191 const std::string argv0(buf);
194 return argv0.substr(0, argv0.size() - 7);
204 std::ifstream variablesFile(argv0 +
"/variables.json");
205 std::stringstream ss;
208 if (variablesFile.is_open()) {
209 while (getline(variablesFile, s)) {
218 variablesFile.close();
222 rapidjson::Document d;
223 d.Parse(ss.str().c_str());
225 if (not d.IsObject()) {
226 std::cout <<
"Can't read variables.json, using defaults." << std::endl;
230 if (d.HasMember(
"version")) {
231 version = std::string(d[
"version"].GetString());
234 if (d.HasMember(
"manual")) {
235 manual = std::string(d[
"manual"].GetString());
238 if (d.HasMember(
"help")) {
239 help = std::string(d[
"help"].GetString());
241 help =
"Please view the user manual (" +
manual +
") for help.";
244 if (d.HasMember(
"refresh")) {
245 refresh = d[
"refresh"].GetInt();
258 const bool isMnemonics) {
260 static_cast<KoMo2Model*
>(
model)->getDisassemblyModel()->setEnglishMnemonic(
265 std::cout <<
version << std::endl;
270 std::cout <<
help << std::endl;
288 const Glib::RefPtr<Gio::ApplicationCommandLine>& cmd,
289 const Glib::RefPtr<Gtk::Application>& app) {
290 Glib::OptionGroup group(
"options",
"main options");
291 bool isVersion =
false, isHelp =
false,
296 version.set_long_name(
"version");
297 version.set_short_name(
'v');
298 version.set_description(
"Display version information.");
299 group.add_entry(version, isVersion);
302 help.set_long_name(
"help");
303 help.set_short_name(
'h');
304 help.set_description(
"Display a help message.");
305 group.add_entry(help, isHelp);
307 mnemonics.set_long_name(
"english");
308 mnemonics.set_short_name(
'e');
309 mnemonics.set_description(
310 "Play ARM mnemonics in English if using a screenreader.");
311 group.add_entry(mnemonics, isMnemonics);
313 Glib::OptionContext context;
314 context.add_group(group);
317 Glib::OptionGroup gtkgroup(gtk_get_option_group(
true));
318 context.add_group(gtkgroup);
320 char** argv = cmd->get_arguments(argc);
321 context.parse(argc, argv);
350 GIOCondition condition,
361 std::cout <<
"Error reading from compiler communcation pipe." << std::endl;
370 p->getTerminalModel()->appendTextToTextView(buff);
int communicationFromJimulator[2]
The pipe which will be used by KoMo2 to read from Jimulator (i.e. Jimulator will write to it...
int writeToJimulator
Stores the file descriptor used for writing to Jimulator.
std::string manual
Manual information read from variables.json is stored here.
void initCompilerPipes(KoMo2Model *const mainModel)
Initialises the communication pipes between the compiler process & the main KoMo2 GUI...
int readFromJimulator
Stores the file descriptor used for reading from Jimulator.
void readProgramVariables(const std::string argv0)
Reads the program variables from the "variables.json" file and populates global variables with the va...
int communicationToJimulator[2]
The pipe which will be used by KoMo2 to write to Jimulator (i.e. Jimulator will read from it...
const int initialiseCommandLine(const Glib::RefPtr< Gio::ApplicationCommandLine > &, const Glib::RefPtr< Gtk::Application > &app)
Sets up and parses custom command line arguments. To add more command line arguments, create a new boolean and a new Glib::OptionEntry object, and then add a longname, shortname, and description, then add it to the group. Then pass the boolean into the handleCommandLine function.
const bool receivedCompilerOutput(GIOChannel *source, GIOCondition condition, gpointer data)
This callback function is called when the compiler communication pipe receives a change in state (mea...
void initJimulator(const std::string argv0)
Initialises Jimulator in a separate child process.
std::string help
Help information read from variables.json is stored here.
The class definition of the main window of the program. This main window is the mater view of the pro...
int emulator_PID
This variable will store the PID of the Jimulator process.
sourceFile source
The source file that is currently loaded into Jimulator.
A file containing the definition of the KoMo2Model class.
int compilerCommunication[2]
The pipe that handles communication between the compiler process and KoMo2.
int refresh
Refresh rate information read from variables.json is stored here.
The logical model of the entire application. All other models should be member variables of this mode...
std::string version
Version information read from variables.json is stored here.
const int handleCommandLine(const bool isVersion, const bool isHelp, const bool isMnemonics)
Handles if a command line flag is set.
void * model
Used as a reference to the master KoMo2Model.
A class declaration for the MainWindowView class, which inherits from GTK::Window.
const std::string getAbsolutePathToRootDirectory(const char *const arg)
get the absolute path to the directory of the binary.
int main(int argc, char *argv[])
The program entry point.