Usermode/Telnet - Use _SysSelect instead of select (removes libposix requirement)
[tpg/acess2.git] / Usermode / Applications / CLIShell_src / main.c
index 501359a..6de92df 100644 (file)
@@ -8,6 +8,8 @@
 #include <string.h>\r
 #include "header.h"\r
 #include <readline.h>\r
+#include <errno.h>\r
+#include <acess/devices/pty.h>\r
 \r
 #define _stdin 0\r
 #define _stdout        1\r
@@ -31,11 +33,11 @@ struct      {
        {"help", Command_Help}, {"clear", Command_Clear},\r
        {"cd", Command_Cd}, {"dir", Command_Dir}\r
 };\r
-static char    *cDEFAULT_PATH[] = {"/Acess/Bin"};\r
+static char    *cDEFAULT_PATH[] = {"/Acess/Bin","/Acess/SBin"};\r
 #define        BUILTIN_COUNT   (sizeof(cBUILTINS)/sizeof(cBUILTINS[0]))\r
 \r
 // ==== LOCAL VARIABLES ====\r
- int   giNumPathDirs = 1;\r
+ int   giNumPathDirs = 2;\r
 char   **gasPathDirs = cDEFAULT_PATH;\r
 char   **gasEnvironment;\r
 char   gsCommandBuffer[1024];\r
@@ -55,7 +57,7 @@ int main(int argc, char *argv[], char **envp)
        \r
        gasEnvironment = envp;\r
        \r
-       Command_Clear(0, NULL);\r
+//     Command_Clear(0, NULL);\r
        \r
        {\r
                char    *tmp = getenv("CWD");\r
@@ -80,6 +82,10 @@ int main(int argc, char *argv[], char **envp)
                // Read Command line\r
                sCommandStr = Readline( readline_state );\r
                printf("\n");\r
+               if( !sCommandStr ) {\r
+                       perror("Readline");\r
+                       return 1;\r
+               }\r
                \r
                // Parse Command Line into arguments\r
                iArgCount = Parse_Args(sCommandStr, saArgs);\r
@@ -208,14 +214,28 @@ void CallCommand(char **Args)
        \r
        // Create new process\r
        int fds[] = {0, 1, 2};\r
+        int    status;\r
        pid = _SysSpawn(sTmpBuffer, (const char **)Args, (const char **)gasEnvironment, 3, fds, NULL);\r
        if(pid <= 0) {\r
                printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message\r
+               status = 0;\r
        }\r
        else {\r
-                int    status;\r
+               _SysIOCtl(0, PTY_IOCTL_SETPGRP, &pid);\r
                _SysWaitTID(pid, &status);\r
        }\r
+       \r
+       // Return terminal to a sane state\r
+       {\r
+               int zero = 0;\r
+               _SysIOCtl(0, PTY_IOCTL_SETPGRP, &zero);\r
+               printf("\x1b[0m");\r
+       }\r
+       // Print a status message if termination was non-clean\r
+       if( status )\r
+       {\r
+               printf("[%i] exited %i\n", pid, status);\r
+       }\r
 }\r
 \r
 /**\r

UCC git Repository :: git.ucc.asn.au