home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / xf083czs.zip / XSHUT421 / xshutdwn.c < prev    next >
C/C++ Source or Header  |  1998-12-20  |  6KB  |  165 lines

  1.  
  2. /*
  3.  * xshutdwn.c:
  4.  *      this is the XShutdown command-line interface. It does NOT
  5.  *      contain any real shutdown code, but only posts a message
  6.  *      to the XFolder Object window in XFLDR.DLL which will then
  7.  *      do the rest.
  8.  *
  9.  *      Copyright (C) 1997-98 Ulrich Möller.
  10.  *      This program is free software; you can redistribute it and/or modify
  11.  *      it under the terms of the GNU General Public License as published by
  12.  *      the Free Software Foundation, in version 2 as it comes in the COPYING
  13.  *      file of the XFolder main distribution.
  14.  *      This program is distributed in the hope that it will be useful,
  15.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *      GNU General Public License for more details.
  18.  */
  19.  
  20. #define  INCL_WIN
  21. #define  INCL_DOS
  22. #define  INCL_GPI
  23.  
  24. #include <os2.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27.  
  28. #pragma  linkage (main,optlink)
  29.  
  30. #include "..\main\common.h"
  31.  
  32. void Explain(void) {
  33.     DosBeep(100, 500);
  34. }
  35.  
  36. int main(int argc, char *argv[])
  37. {
  38.     HAB         hab;
  39.     HMQ         hmq;
  40.     HWND        hwndXFolderObject;
  41.     CHAR        szBlah[1000];
  42.     MRESULT     mrVersion = 0;
  43.     PSHUTDOWNPARAMS psdp;
  44.     BOOL        fProceed = TRUE;
  45.  
  46.     if (DosAllocSharedMem((PVOID*)&psdp,
  47.                     NULL,
  48.                     sizeof(SHUTDOWNPARAMS),
  49.                     PAG_COMMIT | OBJ_GETTABLE | PAG_READ | PAG_WRITE
  50.         ) == 0)
  51.     {
  52.         // defaults
  53.         psdp->optReboot = FALSE;
  54.         psdp->optDebug = FALSE;
  55.         psdp->optRestartWPS = FALSE;
  56.         psdp->optWPSCloseWindows = FALSE;
  57.         psdp->optAutoCloseVIO = FALSE;
  58.         psdp->optLog = FALSE;
  59.         psdp->optAnimate = FALSE;
  60.         psdp->optConfirm = TRUE;
  61.         strcpy(psdp->szRebootCommand, "");
  62.  
  63.         // evaluate command line
  64.         if (argc > 1) {
  65.             SHORT i = 0;
  66.             while (i++ < argc-1) {
  67.                 if (argv[i][0] == '-') {
  68.                     SHORT i2;
  69.                     for (i2 = 1; i2 < strlen(argv[i]); i2++) {
  70.                         switch (argv[i][i2]) {
  71.                             case 'r':
  72.                                 psdp->optReboot = TRUE;
  73.                             break;
  74.  
  75.                             case 'R':
  76.                                 psdp->optReboot = TRUE;
  77.                                 if (i < argc-1) {
  78.                                     strcpy(psdp->szRebootCommand, argv[i+1]);
  79.                                     i++;
  80.                                     i2 = 1000;
  81.                                 } else {
  82.                                     Explain();
  83.                                     fProceed = FALSE;
  84.                                 }
  85.                             break;
  86.  
  87.                             case 'D':
  88.                                 psdp->optDebug = TRUE;
  89.                             break;
  90.  
  91.                             case 'l':
  92.                                 psdp->optLog = TRUE;
  93.                             break;
  94.  
  95.                             case 'v':
  96.                                 psdp->optAutoCloseVIO = TRUE;
  97.                             break;
  98.  
  99.                             case 'a':
  100.                                 psdp->optAnimate = TRUE;
  101.                             break;
  102.  
  103.                             case 'f':
  104.                                 psdp->optConfirm = FALSE;
  105.                             break;
  106.  
  107.                             default:  // unknown parameter
  108.                                 Explain();
  109.                                 fProceed = FALSE;
  110.                             break;
  111.                         }
  112.                     }
  113.                 }
  114.                 else {
  115.                     // no option ("-"): explain
  116.                     Explain();
  117.                 }
  118.             }
  119.         }
  120.  
  121.         if (fProceed) {
  122.             if (!(hab = WinInitialize(0)))
  123.                 return FALSE;
  124.  
  125.             if (!(hmq = WinCreateMsgQueue(hab, 0)))
  126.                 return FALSE;
  127.  
  128.             // find the XFolder object window
  129.             hwndXFolderObject = WinWindowFromID(HWND_OBJECT, ID_XFOLDEROBJECT);
  130.  
  131.             // check if this window understands the
  132.             // "query version" message
  133.             if (hwndXFolderObject)
  134.                 mrVersion = WinSendMsg(hwndXFolderObject, XOM_QUERYXFOLDERVERSION,
  135.                                 (MPARAM)NULL, (MPARAM)NULL);
  136.  
  137.             // error:
  138.             if ( (ULONG)mrVersion < (ULONG)(MRFROM2SHORT(0, 80)) )
  139.                 DebugBox("XShutdown: Chyba", "Nelze komunikovat s externím rozhraním XShutdown. "
  140.                             "Bu╘ nebyl korektn╪ instalován produkt XFolder "
  141.                             "nebo momentáln╪ neb╪ºí prost²edí WPS "
  142.                             "nebo instalovaná verze produktu XFolder je p²íliτ stará a neumoºσuje "
  143.                             "volání XShutdown z p²íkazové ²ádky.");
  144.             else {
  145.                 // XFolder version supports command line: go on
  146.                 if (!WinSendMsg(hwndXFolderObject, XOM_EXTERNALSHUTDOWN, (MPARAM)psdp, (MPARAM)NULL))
  147.                     DebugBox("XShutdown: Chyba",
  148.                             "Produkt XFolder hlásí chybu p²i zpracování "
  149.                             "externího poºadavku na ukonƒení práce systému. "
  150.                             "XShutdown nebyl spuτt╪n. Prosím, ukonƒete práci systému pomocí "
  151.                             "objektové nabídky pracovní plochy.");
  152.             }
  153.  
  154.             WinDestroyMsgQueue(hmq);
  155.             WinTerminate(hab);
  156.         }
  157.     } else
  158.             DebugBox("XShutdown: Chyba",
  159.                     "Nástroji XShutdown se nepoda²ilo alokovat sdílenou pam╪£.");
  160.  
  161.     return TRUE;
  162. }
  163.  
  164.  
  165.