[SC] print.c: Minor code improvements. (#324)
authorSerge Gautherie <32623169+SergeGautherie@users.noreply.github.com>
Sat, 27 Jan 2018 19:54:26 +0000 (20:54 +0100)
committerGed Murphy <gedmurphy@reactos.org>
Sat, 27 Jan 2018 19:54:26 +0000 (19:54 +0000)
- Plus: Update license header.
- Re-use PrintServiceStatus(), as SERVICE_STATUS_PROCESS is in fact an extension of SERVICE_STATUS.
- Use the "SERVICE_*" defines, not magic numbers.

base/applications/sc/print.c

index 7c3a26a..caf82a4 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * PROJECT:     ReactOS Services
 /*
  * PROJECT:     ReactOS Services
- * LICENSE:     GPL - See COPYING in the top level directory
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
  * FILE:        base/applications/sc/print.c
  * PURPOSE:     print service info
  * COPYRIGHT:   Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
  * FILE:        base/applications/sc/print.c
  * PURPOSE:     print service info
  * COPYRIGHT:   Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
- *
+ *              Copyright 2016 Eric Kohl <eric.kohl@reactos.org>
  */
 
 #include "sc.h"
  */
 
 #include "sc.h"
@@ -16,81 +16,8 @@ PrintService(LPCTSTR lpServiceName,
 {
     _tprintf(_T("SERVICE_NAME: %s\n"), lpServiceName);
 
 {
     _tprintf(_T("SERVICE_NAME: %s\n"), lpServiceName);
 
-    _tprintf(_T("\tTYPE               : %x  "),
-        (unsigned int)pStatus->dwServiceType);
-    switch (pStatus->dwServiceType)
-    {
-        case SERVICE_KERNEL_DRIVER:
-            _tprintf(_T("KERNEL_DRIVER\n"));
-            break;
-
-        case SERVICE_FILE_SYSTEM_DRIVER:
-            _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
-            break;
-
-        case SERVICE_WIN32_OWN_PROCESS:
-            _tprintf(_T("WIN32_OWN_PROCESS\n"));
-            break;
-
-        case SERVICE_WIN32_SHARE_PROCESS:
-            _tprintf(_T("WIN32_SHARE_PROCESS\n"));
-            break;
-
-        case SERVICE_WIN32_OWN_PROCESS + SERVICE_INTERACTIVE_PROCESS:
-            _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
-            break;
-
-        case SERVICE_WIN32_SHARE_PROCESS + SERVICE_INTERACTIVE_PROCESS:
-            _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
-            break;
-
-        default : _tprintf(_T("\n")); break;
-    }
-
-    _tprintf(_T("\tSTATE              : %x  "),
-        (unsigned int)pStatus->dwCurrentState);
-
-    switch (pStatus->dwCurrentState)
-    {
-        case 1 : _tprintf(_T("STOPPED\n")); break;
-        case 2 : _tprintf(_T("START_PENDING\n")); break;
-        case 3 : _tprintf(_T("STOP_PENDING\n")); break;
-        case 4 : _tprintf(_T("RUNNING\n")); break;
-        case 5 : _tprintf(_T("CONTINUE_PENDING\n")); break;
-        case 6 : _tprintf(_T("PAUSE_PENDING\n")); break;
-        case 7 : _tprintf(_T("PAUSED\n")); break;
-        default : _tprintf(_T("\n")); break;
-    }
-
-    _tprintf(_T("\t\t\t\t("));
-
-    if (pStatus->dwControlsAccepted & SERVICE_ACCEPT_STOP)
-        _tprintf(_T("STOPPABLE,"));
-    else
-        _tprintf(_T("NOT_STOPPABLE,"));
-
-    if (pStatus->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE)
-        _tprintf(_T("PAUSABLE,"));
-    else
-        _tprintf(_T("NOT_PAUSABLE,"));
-
-    if (pStatus->dwControlsAccepted & SERVICE_ACCEPT_SHUTDOWN)
-        _tprintf(_T("ACCEPTS_SHUTDOWN"));
-    else
-        _tprintf(_T("IGNORES_SHUTDOWN"));
-
-    _tprintf(_T(")\n"));
-
-    _tprintf(_T("\tWIN32_EXIT_CODE    : %u  (0x%x)\n"),
-        (unsigned int)pStatus->dwWin32ExitCode,
-        (unsigned int)pStatus->dwWin32ExitCode);
-    _tprintf(_T("\tSERVICE_EXIT_CODE  : %u  (0x%x)\n"),
-        (unsigned int)pStatus->dwServiceSpecificExitCode,
-        (unsigned int)pStatus->dwServiceSpecificExitCode);
-    _tprintf(_T("\tCHECKPOINT         : 0x%x\n"),
-        (unsigned int)pStatus->dwCheckPoint);
-    _tprintf(_T("\tWAIT_HINT          : 0x%x\n"),
-        (unsigned int)pStatus->dwWaitHint);
+    // Re-use PrintServiceStatus(), as SERVICE_STATUS_PROCESS is in fact an extension of SERVICE_STATUS.
+    PrintServiceStatus((LPSERVICE_STATUS)pStatus);
 
     if (bExtended)
     {
 
     if (bExtended)
     {
@@ -110,33 +37,29 @@ PrintServiceStatus(
 {
     _tprintf(_T("\tTYPE               : %x  "),
         (unsigned int)pStatus->dwServiceType);
 {
     _tprintf(_T("\tTYPE               : %x  "),
         (unsigned int)pStatus->dwServiceType);
+
     switch (pStatus->dwServiceType)
     {
         case SERVICE_KERNEL_DRIVER:
             _tprintf(_T("KERNEL_DRIVER\n"));
             break;
     switch (pStatus->dwServiceType)
     {
         case SERVICE_KERNEL_DRIVER:
             _tprintf(_T("KERNEL_DRIVER\n"));
             break;
-
         case SERVICE_FILE_SYSTEM_DRIVER:
             _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
             break;
         case SERVICE_FILE_SYSTEM_DRIVER:
             _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
             break;
-
         case SERVICE_WIN32_OWN_PROCESS:
             _tprintf(_T("WIN32_OWN_PROCESS\n"));
             break;
         case SERVICE_WIN32_OWN_PROCESS:
             _tprintf(_T("WIN32_OWN_PROCESS\n"));
             break;
-
         case SERVICE_WIN32_SHARE_PROCESS:
             _tprintf(_T("WIN32_SHARE_PROCESS\n"));
             break;
         case SERVICE_WIN32_SHARE_PROCESS:
             _tprintf(_T("WIN32_SHARE_PROCESS\n"));
             break;
-
         case SERVICE_WIN32_OWN_PROCESS + SERVICE_INTERACTIVE_PROCESS:
             _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
             break;
         case SERVICE_WIN32_OWN_PROCESS + SERVICE_INTERACTIVE_PROCESS:
             _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
             break;
-
         case SERVICE_WIN32_SHARE_PROCESS + SERVICE_INTERACTIVE_PROCESS:
             _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
             break;
         case SERVICE_WIN32_SHARE_PROCESS + SERVICE_INTERACTIVE_PROCESS:
             _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
             break;
-
-        default : _tprintf(_T("\n")); break;
+        default:
+            _tprintf(_T("\n"));
     }
 
     _tprintf(_T("\tSTATE              : %x  "),
     }
 
     _tprintf(_T("\tSTATE              : %x  "),
@@ -144,14 +67,29 @@ PrintServiceStatus(
 
     switch (pStatus->dwCurrentState)
     {
 
     switch (pStatus->dwCurrentState)
     {
-        case 1 : _tprintf(_T("STOPPED\n")); break;
-        case 2 : _tprintf(_T("START_PENDING\n")); break;
-        case 3 : _tprintf(_T("STOP_PENDING\n")); break;
-        case 4 : _tprintf(_T("RUNNING\n")); break;
-        case 5 : _tprintf(_T("CONTINUE_PENDING\n")); break;
-        case 6 : _tprintf(_T("PAUSE_PENDING\n")); break;
-        case 7 : _tprintf(_T("PAUSED\n")); break;
-        default : _tprintf(_T("\n")); break;
+        case SERVICE_STOPPED:
+            _tprintf(_T("STOPPED\n"));
+            break;
+        case SERVICE_START_PENDING:
+            _tprintf(_T("START_PENDING\n"));
+            break;
+        case SERVICE_STOP_PENDING:
+            _tprintf(_T("STOP_PENDING\n"));
+            break;
+        case SERVICE_RUNNING:
+            _tprintf(_T("RUNNING\n"));
+            break;
+        case SERVICE_CONTINUE_PENDING:
+            _tprintf(_T("CONTINUE_PENDING\n"));
+            break;
+        case SERVICE_PAUSE_PENDING:
+            _tprintf(_T("PAUSE_PENDING\n"));
+            break;
+        case SERVICE_PAUSED:
+            _tprintf(_T("PAUSED\n"));
+            break;
+        default:
+            _tprintf(_T("\n"));
     }
 
     _tprintf(_T("\t\t\t\t("));
     }
 
     _tprintf(_T("\t\t\t\t("));
@@ -183,4 +121,4 @@ PrintServiceStatus(
         (unsigned int)pStatus->dwCheckPoint);
     _tprintf(_T("\tWAIT_HINT          : 0x%x\n"),
         (unsigned int)pStatus->dwWaitHint);
         (unsigned int)pStatus->dwCheckPoint);
     _tprintf(_T("\tWAIT_HINT          : 0x%x\n"),
         (unsigned int)pStatus->dwWaitHint);
-}
\ No newline at end of file
+}