1. remove all hardcode strings to En.rc
authorMagnus Olsen <magnus@greatlord.com>
Mon, 23 May 2005 16:48:22 +0000 (16:48 +0000)
committerMagnus Olsen <magnus@greatlord.com>
Mon, 23 May 2005 16:48:22 +0000 (16:48 +0000)
2. make it unicode and anis

svn path=/trunk/; revision=15476

reactos/subsys/system/sm/En.rc [new file with mode: 0644]
reactos/subsys/system/sm/resource.h [new file with mode: 0644]
reactos/subsys/system/sm/sm.c
reactos/subsys/system/sm/sm.rc

diff --git a/reactos/subsys/system/sm/En.rc b/reactos/subsys/system/sm/En.rc
new file mode 100644 (file)
index 0000000..af05f47
--- /dev/null
@@ -0,0 +1,57 @@
+#include "resource.h"\r
+/*\r
+ * Moved all hardcoded strings to En.rc.\r
+ * By Magnus Olsen  2005 magnus@itkonsult-olsen.com\r
+ */\r
+\r
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT\r
+STRINGTABLE DISCARDABLE\r
+{\r
+IDS_boot, "boot subsystem_name" \r
+\r
+IDS_help, "help [command]"\r
+\r
+IDS_info, "info [subsystem_id]"\r
+\r
+IDS_reboot, "reboot subsystem_id"\r
+\r
+IDS_shutdown,"shutdown subsystem_id"\r
+\r
+\r
+\r
+IDS_boot_msg, "bootstrap an optional environment subsystem;"\r
+\r
+IDS_help_msg, "print help for command;"\r
+\r
+IDS_info_msg,   "print information about a booted subsystem\n\\r
+if subsystem_id is omitted, a list of booted\n\\r
+environment subsystems is printed."\r
+\r
+IDS_reboot_msg,  "reboot an optional environment subsystem;"\r
+IDS_shutdown_msg, "shutdown an optional environment subsystem;"\r
+\r
+IDS_Unknown, "Unknown command '%s'.\n"\r
+\r
+IDS_Status, "Status 0x%08lx\n"\r
+\r
+IDS_SM1,  "SM SubSystem Directory\n\n\\r
+SSID PID      Flags\n\\r
+---- -------- ------------\n"\r
+\r
+IDS_SM2, "%04x %08lx %04x\n"\r
+\r
+IDS_ID, "SubSystem ID: %d\n\\r
+       Flags: %04x\n\\r
+  Process ID: %ld\n"\r
+\r
+IDS_Not_Imp,  "not implemented\n"\r
+\r
+IDS_Mangers, "ReactOS/Win32 Session Manager Control Tool\n\n"\r
+\r
+IDS_USING, "Usage:\n\\r
+\tsm\n\\r
+\tsm help [command]\n\\r
+\tsm command [arguments]\n\n'sm help' will print the list of valid commands.\n"\r
+\r
+IDS_FAILS_MNG, "Failed to connect to the Session Manager! (Status=0x%08lx)\n"\r
+}\r
diff --git a/reactos/subsys/system/sm/resource.h b/reactos/subsys/system/sm/resource.h
new file mode 100644 (file)
index 0000000..382cf52
--- /dev/null
@@ -0,0 +1,27 @@
+\r
+\r
+\r
+#define RC_STRING_MAX_SIZE                 200\r
+#define IDS_boot                           100\r
+#define IDS_help                           101\r
+#define IDS_info                           102\r
+#define IDS_reboot                         103\r
+#define IDS_shutdown                       104\r
+#define IDS_boot_msg                       205\r
+#define IDS_help_msg                       206\r
+#define IDS_info_msg                       207\r
+#define IDS_reboot_msg                     208\r
+#define IDS_shutdown_msg                   209\r
+\r
+#define IDS_Unknown                        300\r
+#define IDS_Not_Imp                                               301\r
+#define IDS_ID                             302\r
+#define IDS_SM2                            303\r
+#define IDS_SM1                            304\r
+#define IDS_Status                         305\r
+#define IDS_Mangers                        306\r
+#define IDS_USING                          307\r
+#define IDS_FAILS_MNG                      308\r
+\r
+\r
+/* EOF */\r
index 507da33..31a6d88 100644 (file)
@@ -26,6 +26,8 @@
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
+#include <tchar.h>\r
+#include "resource.h"\r
 \r
 #define NTOS_MODE_USER\r
 #include <ntos.h>\r
@@ -39,10 +41,10 @@ HANDLE hSmApiPort = (HANDLE) 0;
 \r
 typedef struct _SM_CMD_DESCRIPTOR\r
 {\r
-       const char * Name;\r
-       int (*EntryPoint)(int,char**);\r
-       const char * Synopsis;\r
-       const char * Description;\r
+       TCHAR Name[RC_STRING_MAX_SIZE];\r
+       int (*EntryPoint)(int,TCHAR**);\r
+       TCHAR Synopsis[RC_STRING_MAX_SIZE];\r
+       TCHAR Description[RC_STRING_MAX_SIZE];\r
        \r
 } SM_CMD_DESCRIPTOR, *PSM_CMD_DESCRIPTOR;\r
 \r
@@ -55,16 +57,19 @@ SM_CMD_DECL(shutdown);
 /* internal commands directory */\r
 SM_CMD_DESCRIPTOR Command [] =\r
 {\r
-       {"boot",     SM_CMD(boot),     "boot subsystem_name",   "bootstrap an optional environment subsystem;"},\r
-       {"help",     SM_CMD(help),     "help [command]",        "print help for command;"},\r
-       {"info",     SM_CMD(info),     "info [subsystem_id]",   "print information about a booted subsystem\n"\r
+       {"boot",     SM_CMD(boot),     _T("boot subsystem_name"),   _T("bootstrap an optional environment subsystem;")},\r
+       {"help",     SM_CMD(help),     _T("help [command]"),        _T("print help for command;")},\r
+       {"info",     SM_CMD(info),     _T("info [subsystem_id]"),   _T("print information about a booted subsystem\n"\r
                                                                "if subsystem_id is omitted, a list of booted\n"\r
-                                                               "environment subsystems is printed."},\r
-       {"reboot",   SM_CMD(reboot),   "reboot subsystem_id",   "reboot an optional environment subsystem;"},\r
-       {"shutdown", SM_CMD(shutdown), "shutdown subsystem_id", "shutdown an optional environment subsystem;"},\r
+                                                               "environment subsystems is printed.")},\r
+       {"reboot",   SM_CMD(reboot),   _T("reboot subsystem_id"),   _T("reboot an optional environment subsystem;")},\r
+       {"shutdown", SM_CMD(shutdown), _T("shutdown subsystem_id"), _T("shutdown an optional environment subsystem;")},\r
 };\r
 \r
-PSM_CMD_DESCRIPTOR LookupCommand (const char * CommandName)\r
+TCHAR UsageMessage[RC_STRING_MAX_SIZE];\r
+void loadlang(PSM_CMD_DESCRIPTOR );\r
+\r
+PSM_CMD_DESCRIPTOR LookupCommand (const TCHAR * CommandName)\r
 {\r
        int i;\r
        const int command_count = (sizeof Command / sizeof Command[0]);\r
@@ -73,14 +78,16 @@ PSM_CMD_DESCRIPTOR LookupCommand (const char * CommandName)
 \r
        for (i=0; (i < command_count); i ++)\r
        {\r
-               if (0 == strcmp(CommandName, Command[i].Name))\r
+               if (0 == _tcscmp(CommandName, Command[i].Name))\r
                {\r
                        break;\r
                }\r
        }\r
        if (i == command_count)\r
        {\r
-               fprintf(stderr, "Unknown command '%s'.\n", CommandName);\r
+               LoadString( GetModuleHandle(NULL), IDS_Unknown, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);\r
+\r
+               _ftprintf(stderr, _T("%s '%s'.\n"), UsageMessage, CommandName);\r
                return NULL;\r
        }\r
        return & Command [i];\r
@@ -97,18 +104,26 @@ SM_CMD_DECL(boot)
 \r
        if (3 == argc)\r
        {\r
+#ifndef _UNICODE\r
                RtlInitAnsiString (& ProgramA, argv[2]);\r
                RtlAnsiStringToUnicodeString (& ProgramW, & ProgramA, TRUE);\r
                Status = SmExecuteProgram (hSmApiPort, & ProgramW);\r
                RtlFreeUnicodeString (& ProgramW);\r
+#else\r
+               ProgramW = &argv[2];      \r
+               Status = SmExecuteProgram (hSmApiPort, & ProgramW);             \r
+#endif\r
                if (STATUS_SUCCESS != Status)\r
                {\r
-                       printf ("Status 0x%08lx\n", Status);\r
+                       LoadString( GetModuleHandle(NULL), IDS_Status, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);\r
+\r
+                       _tprintf(UsageMessage, Status);\r
                }\r
+\r
        }\r
        else\r
        {\r
-               argv[2]="boot";\r
+               argv[2]=_T("boot");\r
                return SM_CMD_CALL(help,3,argv);\r
        }\r
        return rc;\r
@@ -125,7 +140,7 @@ SM_CMD_DECL(help)
        case 2:\r
                for (i=0; (i < (sizeof Command / sizeof Command[0])); i ++)\r
                {\r
-                       printf("%s\n", Command[i].Synopsis);\r
+                       _tprintf(_T("%s\n"), Command[i].Synopsis);\r
                }\r
                break;\r
        case 3:\r
@@ -135,7 +150,7 @@ SM_CMD_DECL(help)
                        rc = EXIT_FAILURE;\r
                        break;\r
                }\r
-               printf("%s\n%s\n\n%s\n",\r
+               _tprintf(_T("%s\n%s\n\n%s\n"),\r
                        cmd->Name,\r
                        cmd->Synopsis,\r
                        cmd->Description);\r
@@ -180,27 +195,29 @@ SM_CMD_DECL(info)
                                     & ReturnDataLength);\r
        if (STATUS_SUCCESS != Status)\r
        {\r
-               printf ("Status 0x%08lx\n", Status);\r
+               LoadString( GetModuleHandle(NULL), IDS_Status, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);\r
+               _tprintf(UsageMessage, Status);\r
                return EXIT_FAILURE;\r
        }\r
        switch (argc)\r
        {\r
        case 2:\r
-               printf ("SM SubSystem Directory\n\n");\r
-               printf ("SSID PID      Flags\n");\r
-               printf ("---- -------- ------------\n");\r
+        LoadString( GetModuleHandle(NULL), IDS_SM1, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);         \r
+               _tprintf(UsageMessage);\r
+        \r
+               LoadString( GetModuleHandle(NULL), IDS_SM2, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);          \r
                for (i = 0; i < Info.bi.SubSystemCount; i ++)\r
                {\r
-                       printf ("%04x %08lx %04x\n",\r
+                       _tprintf(UsageMessage,\r
                                Info.bi.SubSystem[i].Id,\r
                                Info.bi.SubSystem[i].ProcessId,\r
                                Info.bi.SubSystem[i].Flags);\r
                }\r
                break;\r
        case 3:\r
-               printf  ("SubSystem ID: %d\n",   Info.ssi.SubSystemId);\r
-               printf  ("       Flags: %04x\n", Info.ssi.Flags);\r
-               printf  ("  Process ID: %ld\n",  Info.ssi.ProcessId);\r
+        LoadString( GetModuleHandle(NULL), IDS_ID, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);          \r
+               \r
+               _tprintf  (UsageMessage, Info.ssi.SubSystemId, Info.ssi.Flags,  Info.ssi.ProcessId);\r
                wprintf(L"  NSRootNode: '%s'\n", Info.ssi.NameSpaceRootNode);\r
                break;\r
        default:\r
@@ -212,8 +229,10 @@ SM_CMD_DECL(info)
 SM_CMD_DECL(shutdown)\r
 {\r
        int rc = EXIT_SUCCESS;\r
-       \r
-       fprintf(stderr,"not implemented\n");\r
+\r
+       LoadString( GetModuleHandle(NULL), IDS_Not_Imp, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);              \r
+       \r
+       _ftprintf(stderr,UsageMessage);\r
        return rc;\r
 }\r
 \r
@@ -228,19 +247,18 @@ SM_CMD_DECL(reboot)
 }\r
 \r
 /* print command's synopsys */\r
-int print_synopsys (int argc, char *argv[])\r
+int print_synopsys (int argc, TCHAR *argv[])\r
 {\r
-       fprintf (stderr, "ReactOS/Win32 Session Manager Control Tool\n\n");\r
-       printf ("Usage:\n"\r
-               "\tsm\n"\r
-               "\tsm help [command]\n"\r
-               "\tsm command [arguments]\n\n"\r
-               "'sm help' will print the list of valid commands.\n");\r
+       LoadString( GetModuleHandle(NULL), IDS_Mangers, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);\r
+       _ftprintf (stderr, UsageMessage);\r
+\r
+       LoadString( GetModuleHandle(NULL), IDS_USING, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);        \r
+       _tprintf (UsageMessage);\r
        return EXIT_SUCCESS;\r
 }\r
 \r
 /* parse and execute */\r
-int pande (int argc, char *argv[])\r
+int pande (int argc, TCHAR *argv[])\r
 {\r
        PSM_CMD_DESCRIPTOR Command = NULL;\r
        NTSTATUS Status = STATUS_SUCCESS;\r
@@ -258,12 +276,26 @@ int pande (int argc, char *argv[])
                /* ...and execute it */\r
                return Command->EntryPoint (argc, argv);\r
        }\r
-       fprintf (stderr, "Failed to connect to the Session Manager! (Status=0x%08lx)\n", Status);\r
+    LoadString( GetModuleHandle(NULL), IDS_FAILS_MNG, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);               \r
+       _ftprintf (stderr, UsageMessage, Status);\r
+\r
        return EXIT_FAILURE;\r
 }\r
 \r
-int main (int argc, char *argv[])\r
+void loadlang(PSM_CMD_DESCRIPTOR cmd)\r
 {\r
+ int i=0;\r
+ if (cmd==NULL) return;\r
+  for (i=0;i < 5; i++)\r
+  {\r
+       LoadString( GetModuleHandle(NULL), IDS_boot+i, (LPTSTR) &cmd->Synopsis[i],RC_STRING_MAX_SIZE);\r
+  }\r
+}\r
+\r
+int _tmain (int argc, TCHAR *argv[])\r
+{ \r
+   loadlang(Command);\r
+\r
        return (1==argc)\r
                ? print_synopsys (argc, argv)\r
                : pande (argc, argv);\r
index 0de4b78..75b5e5d 100644 (file)
@@ -1,4 +1,8 @@
+#include <windows.h>\r
 #define REACTOS_STR_FILE_DESCRIPTION   "ReactOS/Win32 Session Manager Control Tool\0"\r
 #define REACTOS_STR_INTERNAL_NAME      "sm\0"\r
 #define REACTOS_STR_ORIGINAL_FILENAME  "sm.exe\0"\r
 #include <reactos/version.rc>\r
+\r
+#include "En.rc"\r
+\r