Usermode - IRC Client
authorJohn Hodge <[email protected]>
Thu, 16 Jun 2011 10:58:10 +0000 (18:58 +0800)
committerJohn Hodge <[email protected]>
Thu, 16 Jun 2011 10:58:10 +0000 (18:58 +0800)
- Changed Readline behavior to not print a newline when recieving one
- Cleaning up and fixing display bugs
- Implemented atexit() in libc

Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/irc_src/main.c
Usermode/Libraries/libc.so_src/stdlib.c
Usermode/Libraries/libreadline.so_src/main.c

index 33907ee..af81782 100644 (file)
@@ -94,6 +94,7 @@ int main(int argc, char *argv[], char *envp[])
                // Read Command line\r
                #if USE_READLINE\r
                sCommandStr = Readline( readline_state );\r
+               printf("\n");\r
                length = strlen(sCommandStr);\r
                #else\r
                sCommandStr = ReadCommandLine( &length );\r
index 24919aa..e5f14b2 100644 (file)
@@ -59,6 +59,7 @@ enum eMessageTypes
  int   ParseUserCommand(char *String);\r
 // --- \r
 tServer        *Server_Connect(const char *Name, const char *AddressString, short PortNumber);\r
+tMessage       *Message_AppendF(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message, ...);\r
 tMessage       *Message_Append(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message);\r
 tWindow        *Window_Create(tServer *Server, const char *Name);\r
 \r
@@ -89,6 +90,7 @@ tWindow       *gpCurrentWindow = &gWindow_Status;
 void ExitHandler(void)\r
 {\r
        printf("\x1B[?1047l");\r
+       printf("Quit\n");\r
 }\r
 \r
 int main(int argc, const char *argv[], const char *envp[])\r
@@ -107,6 +109,9 @@ int main(int argc, const char *argv[], const char *envp[])
        printf("\x1B[?1047h");\r
        printf("\x1B[%i;%ir", 0, giTerminal_Height-1);\r
        \r
+       SetCursorPos(giTerminal_Height-1, 0);\r
+       printf("[(status)] ");\r
+       \r
        // HACK: Static server entry\r
        // UCC (University [of Western Australia] Computer Club) IRC Server\r
        gWindow_Status.Server = Server_Connect( "UCC", "130.95.13.18", 6667 );\r
@@ -114,10 +119,9 @@ int main(int argc, const char *argv[], const char *envp[])
        if( !gWindow_Status.Server )\r
                return -1;\r
        \r
-       readline_info = Readline_Init(1);\r
-       \r
        SetCursorPos(giTerminal_Height-1, 0);\r
        printf("[(status)] ");\r
+       readline_info = Readline_Init(1);\r
        \r
        for( ;; )\r
        {\r
@@ -154,6 +158,7 @@ int main(int argc, const char *argv[], const char *envp[])
                                free(cmd);\r
                                // Prompt\r
                                SetCursorPos(giTerminal_Height-1, 0);\r
+                               printf("\x1B[K");       // Clear line\r
                                if( gpCurrentWindow->Name[0] )\r
                                        printf("[%s:%s] ", gpCurrentWindow->Server->Name, gpCurrentWindow->Name);\r
                                else\r
@@ -218,7 +223,7 @@ int ParseUserCommand(char *String)
                }\r
                else if( strcmp(command, "/quit") == 0 )\r
                {\r
-                       char    *quit_message = GetValue(String, &pos);\r
+                       char    *quit_message = String + pos;\r
                        tServer *srv;\r
                        \r
                        if( quit_message == NULL || quit_message[0] == '\0' )\r
@@ -253,18 +258,20 @@ int ParseUserCommand(char *String)
                                window_num = 1;\r
                                for( win = gpWindows; win; win = win->Next, window_num ++ )\r
                                {\r
-                                       char tmp[snprintf(NULL, 1000, "%i: %s/%s", window_num, win->Server->Name, win->Name)+1];\r
-                                       snprintf(tmp, 1000, "%i: %s/%s", window_num, win->Server->Name, win->Name);\r
-                                       Message_Append(NULL, MSG_TYPE_SERVER, "client", "", tmp);\r
+                                       if( win->Name[0] ) {\r
+                                               Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "",\r
+                                                       "%i: %s/%s", window_num, win->Server->Name, win->Name);\r
+                                       }\r
+                                       else {\r
+                                               Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "",\r
+                                                       "%i: (status)", window_num);\r
+                                       }\r
                                }\r
                        }\r
                }\r
                else\r
                {\r
-                        int    len = snprintf(NULL, 0, "Unknown command %s", command);\r
-                       char    buf[len+1];\r
-                       snprintf(buf, len+1, "Unknown command %s", command);\r
-                       Message_Append(NULL, MSG_TYPE_SERVER, "client", "", buf);\r
+                       Message_AppendF(NULL, MSG_TYPE_SERVER, "client", "", "Unknown command %s", command);\r
                }\r
        }\r
        else\r
@@ -273,6 +280,8 @@ int ParseUserCommand(char *String)
                // - Only send if server is valid and window name is non-empty\r
                if( gpCurrentWindow->Server && gpCurrentWindow->Name[0] )\r
                {\r
+                       Message_Append(gpCurrentWindow->Server, MSG_TYPE_STANDARD,\r
+                               gsNickname, gpCurrentWindow->Name, String);\r
                        writef(gpCurrentWindow->Server->FD,\r
                                "PRIVMSG %s :%s\n", gpCurrentWindow->Name,\r
                                String\r
@@ -306,17 +315,31 @@ tServer *Server_Connect(const char *Name, const char *AddressString, short PortN
        gpServers = ret;\r
        \r
        // Read some initial data\r
-       printf("%s: Connection opened\n", Name);\r
+       Message_Append(NULL, MSG_TYPE_SERVER, Name, "", "Connection opened");\r
        ProcessIncoming(ret);\r
        \r
        // Identify\r
        writef(ret->FD, "USER %s %s %s : %s\n", gsUsername, gsHostname, AddressString, gsRealName);\r
        writef(ret->FD, "NICK %s\n", gsNickname);\r
-       printf("%s: Identified\n", Name);\r
+       Message_Append(NULL, MSG_TYPE_SERVER, Name, "", "Identified");\r
+       //printf("%s: Identified\n", Name);\r
        \r
        return ret;\r
 }\r
 \r
+tMessage *Message_AppendF(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message, ...)\r
+{\r
+       va_list args;\r
+        int    len;\r
+       va_start(args, Message);\r
+       len = vsnprintf(NULL, 1000, Message, args);\r
+       {\r
+               char    buf[len+1];\r
+               vsnprintf(buf, len+1, Message, args);\r
+               return Message_Append(Server, Type, Source, Dest, buf);\r
+       }\r
+}\r
+\r
 tMessage *Message_Append(tServer *Server, int Type, const char *Source, const char *Dest, const char *Message)\r
 {\r
        tMessage        *ret;\r
@@ -324,7 +347,7 @@ tMessage *Message_Append(tServer *Server, int Type, const char *Source, const ch
         int    msgLen = strlen(Message);\r
        \r
        // NULL servers are internal messages\r
-       if( Server == NULL )\r
+       if( Server == NULL || Source[0] == '\0' )\r
        {\r
                win = &gWindow_Status;\r
        }\r
@@ -397,9 +420,9 @@ tMessage *Message_Append(tServer *Server, int Type, const char *Source, const ch
        \r
        {\r
                int pos = SetCursorPos(giTerminal_Height-2, 0);\r
-               printf("\x1B[T");       // Scroll down 1 (free space below)\r
                #if 1\r
                if( win == gpCurrentWindow ) {\r
+                       printf("\x1B[T");       // Scroll down 1 (free space below)\r
                        printf("[%s] %s\n", Source, Message);\r
                }\r
                #else\r
@@ -527,7 +550,7 @@ void ParseServerLine(tServer *Server, char *Line)
                }\r
                else\r
                {\r
-                       printf("Unknown message %s (%s)\n", cmd, Line+pos);\r
+                       Message_AppendF(Server, MSG_TYPE_SERVER, "", "", "Unknown message %s (%s)\n", cmd, Line+pos);\r
                }\r
        }\r
        else {\r
index 733cb91..94d9d1d 100644 (file)
@@ -32,6 +32,8 @@ void atexit(void (*__func)(void))
  */\r
 EXPORT void exit(int status)\r
 {\r
+       if( g_stdlib_exithandler )\r
+               g_stdlib_exithandler();\r
        _exit(status);\r
 }\r
 \r
index 4bc0fc5..a07b052 100644 (file)
@@ -159,7 +159,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
        
        if(ch == '\n')
        {
-               printf("\n");
+//             printf("\n");
                if(Info->CurBuffer)
                {       
                        // Cap String

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