Author: ekohl
Date: Sat Oct 25 21:27:05 2014
New Revision: 64998

URL: http://svn.reactos.org/svn/reactos?rev=64998&view=rev
Log:
[NET]
Implement and use console-aware print functions to print strings and resources.

Modified:
    trunk/reactos/base/applications/network/net/cmdAccounts.c
    trunk/reactos/base/applications/network/net/cmdHelpMsg.c
    trunk/reactos/base/applications/network/net/cmdLocalGroup.c
    trunk/reactos/base/applications/network/net/cmdStart.c
    trunk/reactos/base/applications/network/net/cmdUser.c
    trunk/reactos/base/applications/network/net/main.c
    trunk/reactos/base/applications/network/net/net.h

Modified: trunk/reactos/base/applications/network/net/cmdAccounts.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/cmdAccounts.c?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdAccounts.c   [iso-8859-1] 
(original)
+++ trunk/reactos/base/applications/network/net/cmdAccounts.c   [iso-8859-1] 
Sat Oct 25 21:27:05 2014
@@ -48,7 +48,7 @@
 
         if (_wcsicmp(argv[i], L"/domain") == 0)
         {
-            printf("The /DOMAIN option is not supported yet!\n");
+            PrintToConsole(L"The /DOMAIN option is not supported yet!\n");
 #if 0
             Domain = TRUE;
 #endif
@@ -74,7 +74,7 @@
                 value = wcstoul(p, &endptr, 10);
                 if (*endptr != 0)
                 {
-                    printf("You entered an invalid value for the /FORCELOGOFF 
option.\n");
+                    PrintToConsole(L"You entered an invalid value for the 
/FORCELOGOFF option.\n");
                     result = 1;
                     goto done;
                 }
@@ -89,7 +89,7 @@
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                    printf("You entered an invalid value for the /MINPWLEN 
option.\n");
+                    PrintToConsole(L"You entered an invalid value for the 
/MINPWLEN option.\n");
                     result = 1;
                     goto done;
             }
@@ -111,7 +111,7 @@
                 value = wcstoul(p, &endptr, 10);
                 if (*endptr != 0)
                 {
-                    printf("You entered an invalid value for the /MAXPWAGE 
option.\n");
+                    PrintToConsole(L"You entered an invalid value for the 
/MAXPWAGE option.\n");
                     result = 1;
                     goto done;
                 }
@@ -126,7 +126,7 @@
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                printf("You entered an invalid value for the /MINPWAGE 
option.\n");
+                PrintToConsole(L"You entered an invalid value for the 
/MINPWAGE option.\n");
                 result = 1;
                 goto done;
             }
@@ -140,7 +140,7 @@
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                printf("You entered an invalid value for the /UNIQUEPW 
option.\n");
+                PrintToConsole(L"You entered an invalid value for the 
/UNIQUEPW option.\n");
                 result = 1;
                 goto done;
             }
@@ -168,51 +168,51 @@
 
         RtlGetNtProductType(&ProductType);
 
-        printf("Force logoff after: ");
+        PrintToConsole(L"Force logoff after: ");
         if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
-            printf("Never\n");
-        else
-            printf("%lu seconds\n", Info0->usrmod0_force_logoff);
-
-        printf("Minimum password age (in days): %lu\n", 
Info0->usrmod0_min_passwd_age / 86400);
-        printf("Maximum password age (in days): %lu\n", 
Info0->usrmod0_max_passwd_age / 86400);
-        printf("Minimum password length: %lu\n", 
Info0->usrmod0_min_passwd_len);
-
-        printf("Password history length: ");
+            PrintToConsole(L"Never\n");
+        else
+            PrintToConsole(L"%lu seconds\n", Info0->usrmod0_force_logoff);
+
+        PrintToConsole(L"Minimum password age (in days): %lu\n", 
Info0->usrmod0_min_passwd_age / 86400);
+        PrintToConsole(L"Maximum password age (in days): %lu\n", 
Info0->usrmod0_max_passwd_age / 86400);
+        PrintToConsole(L"Minimum password length: %lu\n", 
Info0->usrmod0_min_passwd_len);
+
+        PrintToConsole(L"Password history length: ");
         if (Info0->usrmod0_password_hist_len == 0)
-            printf("None\n");
-        else
-            printf("%lu\n", Info0->usrmod0_password_hist_len);
-
-        printf("Lockout threshold: ");
+            PrintToConsole(L"None\n");
+        else
+            PrintToConsole(L"%lu\n", Info0->usrmod0_password_hist_len);
+
+        PrintToConsole(L"Lockout threshold: ");
         if (Info3->usrmod3_lockout_threshold == 0)
-            printf("Never\n");
-        else
-            printf("%lu\n", Info3->usrmod3_lockout_threshold);
-
-        printf("Lockout duration (in minutes): %lu\n", 
Info3->usrmod3_lockout_duration / 60);
-        printf("Lockout observation window (in minutes): %lu\n", 
Info3->usrmod3_lockout_observation_window / 60);
-
-        printf("Computer role: ");
+            PrintToConsole(L"Never\n");
+        else
+            PrintToConsole(L"%lu\n", Info3->usrmod3_lockout_threshold);
+
+        PrintToConsole(L"Lockout duration (in minutes): %lu\n", 
Info3->usrmod3_lockout_duration / 60);
+        PrintToConsole(L"Lockout observation window (in minutes): %lu\n", 
Info3->usrmod3_lockout_observation_window / 60);
+
+        PrintToConsole(L"Computer role: ");
 
         if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
         {
             if (ProductType == NtProductLanManNt)
             {
-                printf("Primary server\n");
+                PrintToConsole(L"Primary server\n");
             }
             else if (ProductType == NtProductServer)
             {
-                printf("Standalone server\n");
+                PrintToConsole(L"Standalone server\n");
             }
             else
             {
-                printf("Workstation\n");
-            }
-        }
-        else
-        {
-            printf("Backup server\n");
+                PrintToConsole(L"Workstation\n");
+            }
+        }
+        else
+        {
+            PrintToConsole(L"Backup server\n");
         }
     }
 

Modified: trunk/reactos/base/applications/network/net/cmdHelpMsg.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/cmdHelpMsg.c?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdHelpMsg.c    [iso-8859-1] 
(original)
+++ trunk/reactos/base/applications/network/net/cmdHelpMsg.c    [iso-8859-1] 
Sat Oct 25 21:27:05 2014
@@ -49,12 +49,12 @@
                        0,
                        NULL))
     {
-        printf("\n%S\n", lpBuffer);
+        PrintToConsole(L"\n%s\n", lpBuffer);
         LocalFree(lpBuffer);
     }
     else
     {
-        printf("Unrecognized error code: %ld\n", errNum);
+        PrintToConsole(L"Unrecognized error code: %ld\n", errNum);
     }
 
     return 0;

Modified: trunk/reactos/base/applications/network/net/cmdLocalGroup.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/cmdLocalGroup.c?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdLocalGroup.c [iso-8859-1] 
(original)
+++ trunk/reactos/base/applications/network/net/cmdLocalGroup.c [iso-8859-1] 
Sat Oct 25 21:27:05 2014
@@ -38,8 +38,8 @@
     if (Status != NERR_Success)
         return Status;
 
-    printf("\nAliases for \\\\%S\n\n", pServer->sv100_name);
-    printf("------------------------------------------\n");
+    PrintToConsole(L"\nAliases for \\\\%s\n\n", pServer->sv100_name);
+    PrintToConsole(L"------------------------------------------\n");
 
     NetApiBufferFree(pServer);
 
@@ -58,12 +58,10 @@
           sizeof(PLOCALGROUP_INFO_0),
           CompareInfo);
 
-//    printf("dwRead: %lu  dwTotal: %lu\n", dwRead, dwTotal);
     for (i = 0; i < dwRead; i++)
     {
-//        printf("%p\n", pBuffer[i].lgrpi0_name);
          if (pBuffer[i].lgrpi0_name)
-            printf("*%S\n", pBuffer[i].lgrpi0_name);
+            PrintToConsole(L"*%s\n", pBuffer[i].lgrpi0_name);
     }
 
     NetApiBufferFree(pBuffer);
@@ -129,17 +127,17 @@
              pNames[i] = pMembers[i].lgrmi3_domainandname;
     }
 
-    printf("Alias name        %S\n", pGroupInfo->lgrpi1_name);
-    printf("Comment           %S\n", pGroupInfo->lgrpi1_comment);
-    printf("\n");
-    printf("Members\n");
-    printf("\n");
-    printf("------------------------------------------\n");
+    PrintToConsole(L"Alias name        %s\n", pGroupInfo->lgrpi1_name);
+    PrintToConsole(L"Comment           %s\n", pGroupInfo->lgrpi1_comment);
+    PrintToConsole(L"\n");
+    PrintToConsole(L"Members\n");
+    PrintToConsole(L"\n");
+    PrintToConsole(L"------------------------------------------\n");
 
     for (i = 0; i < dwRead; i++)
     {
-         if (pNames[i])
-            printf("%S\n", pNames[i]);
+        if (pNames[i])
+            PrintToConsole(L"%s\n", pNames[i]);
     }
 
 done:

Modified: trunk/reactos/base/applications/network/net/cmdStart.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/cmdStart.c?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdStart.c      [iso-8859-1] 
(original)
+++ trunk/reactos/base/applications/network/net/cmdStart.c      [iso-8859-1] 
Sat Oct 25 21:27:05 2014
@@ -57,11 +57,11 @@
                                     &dwServiceCount,
                                     &dwResumeHandle))
             {
-                printf("The following services hav been started:\n\n");
+                PrintToConsole(L"The following services hav been 
started:\n\n");
 
                 for (i = 0; i < dwServiceCount; i++)
                 {
-                    printf("  %S\n", lpServiceBuffer[i].lpDisplayName);
+                    PrintToConsole(L"  %s\n", 
lpServiceBuffer[i].lpDisplayName);
                 }
             }
 

Modified: trunk/reactos/base/applications/network/net/cmdUser.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/cmdUser.c?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdUser.c       [iso-8859-1] 
(original)
+++ trunk/reactos/base/applications/network/net/cmdUser.c       [iso-8859-1] 
Sat Oct 25 21:27:05 2014
@@ -37,11 +37,11 @@
     if (Status != NERR_Success)
         return Status;
 
-    printf("\nUser accounts for \\\\%S\n\n", pServer->sv100_name);
+    PrintToConsole(L"\nUser accounts for \\\\%s\n\n", pServer->sv100_name);
 
     NetApiBufferFree(pServer);
 
-    printf("------------------------------------------\n");
+    PrintToConsole(L"------------------------------------------\n");
 
     Status = NetUserEnum(NULL,
                          0,
@@ -64,7 +64,7 @@
     {
 //        printf("%p\n", pBuffer[i].lgrpi0_name);
          if (pBuffer[i].usri0_name)
-            printf("%S\n", pBuffer[i].usri0_name);
+            PrintToConsole(L"%s\n", pBuffer[i].usri0_name);
     }
 
     NetApiBufferFree(pBuffer);
@@ -102,7 +102,7 @@
                    TimeBuffer,
                    80);
 
-    printf("%S %S\n", DateBuffer, TimeBuffer);
+    PrintToConsole(L"%s %s\n", DateBuffer, TimeBuffer);
 }
 
 
@@ -110,6 +110,7 @@
 NET_API_STATUS
 DisplayUser(LPWSTR lpUserName)
 {
+    PUSER_MODALS_INFO_0 pUserModals = NULL;
     PUSER_INFO_4 pUserInfo = NULL;
     NET_API_STATUS Status;
 
@@ -121,39 +122,56 @@
     if (Status != NERR_Success)
         return Status;
 
-    printf("User name                    %S\n", pUserInfo->usri4_name);
-    printf("Full name                    %S\n", pUserInfo->usri4_full_name);
-    printf("Comment                      %S\n", pUserInfo->usri4_comment);
-    printf("User comment                 %S\n", pUserInfo->usri4_usr_comment);
-    printf("Country code                 %03ld ()\n", 
pUserInfo->usri4_country_code);
-    printf("Account active               %S\n", (pUserInfo->usri4_flags & 
UF_ACCOUNTDISABLE)? L"No" : ((pUserInfo->usri4_flags & UF_LOCKOUT) ? L"Locked" 
: L"Yes"));
-    printf("Account expires              ");
+    Status = NetUserModalsGet(NULL,
+                              0,
+                              (LPBYTE*)&pUserModals);
+    if (Status != NERR_Success)
+        goto done;
+
+    PrintToConsole(L"User name                    %s\n", 
pUserInfo->usri4_name);
+    PrintToConsole(L"Full name                    %s\n", 
pUserInfo->usri4_full_name);
+    PrintToConsole(L"Comment                      %s\n", 
pUserInfo->usri4_comment);
+    PrintToConsole(L"User comment                 %s\n", 
pUserInfo->usri4_usr_comment);
+    PrintToConsole(L"Country code                 %03ld ()\n", 
pUserInfo->usri4_country_code);
+    PrintToConsole(L"Account active               %s\n", 
(pUserInfo->usri4_flags & UF_ACCOUNTDISABLE)? L"No" : ((pUserInfo->usri4_flags 
& UF_LOCKOUT) ? L"Locked" : L"Yes"));
+    PrintToConsole(L"Account expires              ");
     if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER)
-        printf("Never\n");
+        PrintToConsole(L"Never\n");
     else
         PrintDateTime(pUserInfo->usri4_acct_expires);
 
-    printf("\n");
-    printf("Password last set            \n");
-    printf("Password expires             \n");
-    printf("Password changeable          \n");
-    printf("Password required            \n");
-    printf("User may change password     \n");
-    printf("\n");
-    printf("Workstation allowed          %S\n", pUserInfo->usri4_workstations);
-    printf("Logon script                 %S\n", pUserInfo->usri4_script_path);
-    printf("User profile                 %S\n", pUserInfo->usri4_profile);
-    printf("Home directory               %S\n", pUserInfo->usri4_home_dir);
-    printf("Last logon                   ");
+    PrintToConsole(L"\n");
+    PrintToConsole(L"Password last set            \n");
+
+    PrintToConsole(L"Password expires             ");
+    if (pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER)
+        PrintToConsole(L"Never\n");
+    else
+        PrintDateTime(pUserInfo->usri4_acct_expires);
+
+    PrintToConsole(L"Password changeable          \n");
+    PrintToConsole(L"Password required            \n");
+    PrintToConsole(L"User may change password     \n");
+
+    PrintToConsole(L"\n");
+    PrintToConsole(L"Workstation allowed          %s\n", 
pUserInfo->usri4_workstations);
+    PrintToConsole(L"Logon script                 %s\n", 
pUserInfo->usri4_script_path);
+    PrintToConsole(L"User profile                 %s\n", 
pUserInfo->usri4_profile);
+    PrintToConsole(L"Home directory               %s\n", 
pUserInfo->usri4_home_dir);
+    PrintToConsole(L"Last logon                   ");
     if (pUserInfo->usri4_last_logon == 0)
-        printf("Never\n");
+        PrintToConsole(L"Never\n");
     else
         PrintDateTime(pUserInfo->usri4_last_logon);
-    printf("\n");
-    printf("Logon hours allowed          \n");
-    printf("\n");
-    printf("Local group memberships      \n");
-    printf("Global group memberships     \n");
+    PrintToConsole(L"\n");
+    PrintToConsole(L"Logon hours allowed          \n");
+    PrintToConsole(L"\n");
+    PrintToConsole(L"Local group memberships      \n");
+    PrintToConsole(L"Global group memberships     \n");
+
+done:
+    if (pUserModals != NULL)
+        NetApiBufferFree(pUserModals);
 
     if (pUserInfo != NULL)
         NetApiBufferFree(pUserInfo);

Modified: trunk/reactos/base/applications/network/net/main.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/main.c?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/main.c  [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/main.c  [iso-8859-1] Sat Oct 25 
21:27:05 2014
@@ -51,13 +51,70 @@
     INT resID,
     ...)
 {
-    WCHAR szMsgBuf[MAX_BUFFER_SIZE];
+    WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
+    WCHAR szOutBuffer[MAX_BUFFER_SIZE];
     va_list arg_ptr;
 
     va_start(arg_ptr, resID);
-    LoadStringW(GetModuleHandle(NULL), resID, szMsgBuf, MAX_BUFFER_SIZE);
-    vwprintf(szMsgBuf, arg_ptr);
+    LoadStringW(GetModuleHandle(NULL), resID, szMsgBuffer, MAX_BUFFER_SIZE);
+    _vsnwprintf(szOutBuffer, MAX_BUFFER_SIZE, szMsgBuffer, arg_ptr);
     va_end(arg_ptr);
+
+    WriteToConsole(szOutBuffer);
+}
+
+
+VOID
+PrintToConsole(
+    LPWSTR lpFormat,
+    ...)
+{
+    WCHAR szBuffer[MAX_BUFFER_SIZE];
+    va_list arg_ptr;
+
+    va_start(arg_ptr, lpFormat);
+    _vsnwprintf(szBuffer, MAX_BUFFER_SIZE, lpFormat, arg_ptr);
+    va_end(arg_ptr);
+
+    WriteToConsole(szBuffer);
+}
+
+
+VOID
+WriteToConsole(
+    LPWSTR lpString)
+{
+    CHAR szOemBuffer[MAX_BUFFER_SIZE * 2];
+    HANDLE hOutput;
+    DWORD dwLength;
+
+    dwLength = wcslen(lpString);
+
+    hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+    if ((GetFileType(hOutput) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR)
+    {
+        WriteConsoleW(hOutput,
+                      lpString,
+                      dwLength,
+                      &dwLength,
+                      NULL);
+    }
+    else
+    {
+        dwLength = WideCharToMultiByte(CP_OEMCP,
+                                       0,
+                                       lpString,
+                                       dwLength,
+                                       szOemBuffer,
+                                       MAX_BUFFER_SIZE * 2,
+                                       NULL,
+                                       NULL);
+        WriteFile(hOutput,
+                  szOemBuffer,
+                  dwLength,
+                  &dwLength,
+                  NULL);
+    }
 }
 
 

Modified: trunk/reactos/base/applications/network/net/net.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/net/net.h?rev=64998&r1=64997&r2=64998&view=diff
==============================================================================
--- trunk/reactos/base/applications/network/net/net.h   [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/net.h   [iso-8859-1] Sat Oct 25 
21:27:05 2014
@@ -14,6 +14,7 @@
 #include <windef.h>
 #include <winbase.h>
 #include <winnls.h>
+#include <wincon.h>
 #include <winuser.h>
 #include <winsvc.h>
 #include <stdio.h>
@@ -29,6 +30,15 @@
     INT resID,
     ...);
 
+VOID
+PrintToConsole(
+    LPWSTR lpFormat,
+    ...);
+
+VOID
+WriteToConsole(
+    LPWSTR lpString);
+
 VOID help(VOID);
 INT unimplemented(INT argc, WCHAR **argv);
 


Reply via email to