From 3d5aca66b9712758aecb2e80bc5b2fb3df6256a4 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Wed, 16 Dec 2009 18:22:58 +0100 Subject: New model, object-oriented, for applications --- Source/Applications/PaperWork/Makefile | 2 +- Source/Applications/PaperWork/PaperWork.cpp | 64 +++++++++++++++++++++++++++++ Source/Applications/PaperWork/main.cpp | 57 ------------------------- 3 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 Source/Applications/PaperWork/PaperWork.cpp delete mode 100644 Source/Applications/PaperWork/main.cpp (limited to 'Source/Applications/PaperWork') diff --git a/Source/Applications/PaperWork/Makefile b/Source/Applications/PaperWork/Makefile index fe8d564..d3203cf 100644 --- a/Source/Applications/PaperWork/Makefile +++ b/Source/Applications/PaperWork/Makefile @@ -6,7 +6,7 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I . LD = ld LDFLAGS = -T ../../Library/Link.ld -L ../../Library -Objects = main.o +Objects = PaperWork.o OutFile = PaperWork all: $(OutFile) diff --git a/Source/Applications/PaperWork/PaperWork.cpp b/Source/Applications/PaperWork/PaperWork.cpp new file mode 100644 index 0000000..0d6a821 --- /dev/null +++ b/Source/Applications/PaperWork/PaperWork.cpp @@ -0,0 +1,64 @@ +#include + +#define DEFAULT_SHELL "/Applications/Shell/Shell.app" + +class PaperWork : public ShellApp { + public: + PaperWork() : ShellApp() {} + int run(); +}; + +APP(PaperWork); + +int PaperWork::run() { + String act = "init"; + if (args.size() == 2) { + if (args[1] == "login") { + act = "login"; + } else if (args[1] == "init") { + act = "init"; + } + } + + if (act == "init") { + while (1) { + Process p = Process::run("/System/Applications/PaperWork.app"); + if (p.valid()) { + p.setInVT(invt); + p.setOutVT(outvt); + p.pushArg("login"); + p.start(); + p.wait(); + } else { + return 1; + } + } + } else if (act == "login") { + outvt << "Logging in to Melon\n"; + String user, pw; + while (1) { + outvt << "Username: "; + user = invt.readLine(); + outvt << "Password: "; + pw = invt.readLine(false); + if (!Process::get().authenticatePW(user, pw)) { + outvt << "Authentication failed.\n\n"; + continue; + } + outvt << "What shell to run [" << DEFAULT_SHELL << "]? "; + String sh = invt.readLine(); + if (sh == "") sh = DEFAULT_SHELL; + Process p = Process::run(sh); + if (p.valid()) { + p.setInVT(invt); + p.setOutVT(outvt); + p.start(); + p.wait(); + outvt << "\n\n"; + } else { + return 1; + } + return 0; + } + } +} diff --git a/Source/Applications/PaperWork/main.cpp b/Source/Applications/PaperWork/main.cpp deleted file mode 100644 index 2fb40df..0000000 --- a/Source/Applications/PaperWork/main.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#define DEFAULT_SHELL "/Applications/Shell/Shell.app" - -int main(Vector args) { - String act = "init"; - if (args.size() == 2) { - if (args[1] == "login") { - act = "login"; - } else if (args[1] == "init") { - act = "init"; - } - } - - if (act == "init") { - while (1) { - Process p = Process::run("/System/Applications/PaperWork.app"); - if (p.valid()) { - p.setInVT(invt); - p.setOutVT(outvt); - p.pushArg("login"); - p.start(); - p.wait(); - } else { - return 1; - } - } - } else if (act == "login") { - outvt << "Logging in to Melon\n"; - String user, pw; - while (1) { - outvt << "Username: "; - user = invt.readLine(); - outvt << "Password: "; - pw = invt.readLine(false); - if (!Process::get().authenticatePW(user, pw)) { - outvt << "Authentication failed.\n\n"; - continue; - } - outvt << "What shell to run [" << DEFAULT_SHELL << "]? "; - String sh = invt.readLine(); - if (sh == "") sh = DEFAULT_SHELL; - Process p = Process::run(sh); - if (p.valid()) { - p.setInVT(invt); - p.setOutVT(outvt); - p.start(); - p.wait(); - outvt << "\n\n"; - } else { - return 1; - } - return 0; - } - } -} -- cgit v1.2.3 From 4f9078c0f06e0cf0cb7bb164fc72fb9918c68e6a Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Thu, 17 Dec 2009 11:18:19 +0100 Subject: Added some option handling featurs to the default ShellApp class --- Source/Applications/PaperWork/PaperWork.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'Source/Applications/PaperWork') diff --git a/Source/Applications/PaperWork/PaperWork.cpp b/Source/Applications/PaperWork/PaperWork.cpp index 0d6a821..4f9cb0e 100644 --- a/Source/Applications/PaperWork/PaperWork.cpp +++ b/Source/Applications/PaperWork/PaperWork.cpp @@ -4,7 +4,11 @@ class PaperWork : public ShellApp { public: - PaperWork() : ShellApp() {} + PaperWork() : ShellApp("PaperWork.app", "Melon's init/login manager") { + addFlag("s", "shell", "Define the default shell to launch", FT_STR, DEFAULT_SHELL); + addFlag("l", "login", "Act as a login manager"); + addFlag("i", "init", "Act as a init manager", FT_BOOL, "on"); + } int run(); }; @@ -12,13 +16,7 @@ APP(PaperWork); int PaperWork::run() { String act = "init"; - if (args.size() == 2) { - if (args[1] == "login") { - act = "login"; - } else if (args[1] == "init") { - act = "init"; - } - } + if (bFlag("login")) act = "login"; if (act == "init") { while (1) { @@ -26,7 +24,7 @@ int PaperWork::run() { if (p.valid()) { p.setInVT(invt); p.setOutVT(outvt); - p.pushArg("login"); + p.pushArg("--login"); p.start(); p.wait(); } else { @@ -45,9 +43,9 @@ int PaperWork::run() { outvt << "Authentication failed.\n\n"; continue; } - outvt << "What shell to run [" << DEFAULT_SHELL << "]? "; + outvt << "What shell to run [" << sFlag("shell") << "]? "; String sh = invt.readLine(); - if (sh == "") sh = DEFAULT_SHELL; + if (sh == "") sh = sFlag("shell"); Process p = Process::run(sh); if (p.valid()) { p.setInVT(invt); -- cgit v1.2.3