home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: WPS_PM
/
WPS_PM.zip
/
xf083czs.zip
/
XSHUT421
/
xshutdwn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-12-20
|
6KB
|
165 lines
/*
* xshutdwn.c:
* this is the XShutdown command-line interface. It does NOT
* contain any real shutdown code, but only posts a message
* to the XFolder Object window in XFLDR.DLL which will then
* do the rest.
*
* Copyright (C) 1997-98 Ulrich Möller.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 2 as it comes in the COPYING
* file of the XFolder main distribution.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define INCL_WIN
#define INCL_DOS
#define INCL_GPI
#include <os2.h>
#include <stdio.h>
#include <string.h>
#pragma linkage (main,optlink)
#include "..\main\common.h"
void Explain(void) {
DosBeep(100, 500);
}
int main(int argc, char *argv[])
{
HAB hab;
HMQ hmq;
HWND hwndXFolderObject;
CHAR szBlah[1000];
MRESULT mrVersion = 0;
PSHUTDOWNPARAMS psdp;
BOOL fProceed = TRUE;
if (DosAllocSharedMem((PVOID*)&psdp,
NULL,
sizeof(SHUTDOWNPARAMS),
PAG_COMMIT | OBJ_GETTABLE | PAG_READ | PAG_WRITE
) == 0)
{
// defaults
psdp->optReboot = FALSE;
psdp->optDebug = FALSE;
psdp->optRestartWPS = FALSE;
psdp->optWPSCloseWindows = FALSE;
psdp->optAutoCloseVIO = FALSE;
psdp->optLog = FALSE;
psdp->optAnimate = FALSE;
psdp->optConfirm = TRUE;
strcpy(psdp->szRebootCommand, "");
// evaluate command line
if (argc > 1) {
SHORT i = 0;
while (i++ < argc-1) {
if (argv[i][0] == '-') {
SHORT i2;
for (i2 = 1; i2 < strlen(argv[i]); i2++) {
switch (argv[i][i2]) {
case 'r':
psdp->optReboot = TRUE;
break;
case 'R':
psdp->optReboot = TRUE;
if (i < argc-1) {
strcpy(psdp->szRebootCommand, argv[i+1]);
i++;
i2 = 1000;
} else {
Explain();
fProceed = FALSE;
}
break;
case 'D':
psdp->optDebug = TRUE;
break;
case 'l':
psdp->optLog = TRUE;
break;
case 'v':
psdp->optAutoCloseVIO = TRUE;
break;
case 'a':
psdp->optAnimate = TRUE;
break;
case 'f':
psdp->optConfirm = FALSE;
break;
default: // unknown parameter
Explain();
fProceed = FALSE;
break;
}
}
}
else {
// no option ("-"): explain
Explain();
}
}
}
if (fProceed) {
if (!(hab = WinInitialize(0)))
return FALSE;
if (!(hmq = WinCreateMsgQueue(hab, 0)))
return FALSE;
// find the XFolder object window
hwndXFolderObject = WinWindowFromID(HWND_OBJECT, ID_XFOLDEROBJECT);
// check if this window understands the
// "query version" message
if (hwndXFolderObject)
mrVersion = WinSendMsg(hwndXFolderObject, XOM_QUERYXFOLDERVERSION,
(MPARAM)NULL, (MPARAM)NULL);
// error:
if ( (ULONG)mrVersion < (ULONG)(MRFROM2SHORT(0, 80)) )
DebugBox("XShutdown: Chyba", "Nelze komunikovat s externím rozhraním XShutdown. "
"Bu╘ nebyl korektn╪ instalován produkt XFolder "
"nebo momentáln╪ neb╪ºí prost²edí WPS "
"nebo instalovaná verze produktu XFolder je p²íliτ stará a neumoºσuje "
"volání XShutdown z p²íkazové ²ádky.");
else {
// XFolder version supports command line: go on
if (!WinSendMsg(hwndXFolderObject, XOM_EXTERNALSHUTDOWN, (MPARAM)psdp, (MPARAM)NULL))
DebugBox("XShutdown: Chyba",
"Produkt XFolder hlásí chybu p²i zpracování "
"externího poºadavku na ukonƒení práce systému. "
"XShutdown nebyl spuτt╪n. Prosím, ukonƒete práci systému pomocí "
"objektové nabídky pracovní plochy.");
}
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
}
} else
DebugBox("XShutdown: Chyba",
"Nástroji XShutdown se nepoda²ilo alokovat sdílenou pam╪£.");
return TRUE;
}