UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / win32 / popup.c
blobdb0511df1157142d2280bd72d8d8cf45cfaeec2c
1 /*
2 * Dumb Windows program to put up a message box
3 * containing the command line. Any leading and
4 * trailing quotes are stripped.
5 *
6 * Kern E. Sibbald
7 * July MM
8 */
9 #include "windows.h"
10 #include <stdio.h>
12 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
13 PSTR szCmdLine, int iCmdShow)
15 int len = strlen(szCmdLine);
16 char *msg, *wordPtr;
18 // Funny things happen with the command line if the
19 // execution comes from c:/Program Files/apcupsd/apcupsd.exe
20 // We get a command line like: Files/apcupsd/apcupsd.exe" options
21 // I.e. someone stops scanning command line on a space, not
22 // realizing that the filename is quoted!!!!!!!!!!
23 // So if first character is not a double quote and
24 // the last character before first space is a double
25 // quote, we throw away the junk.
26 wordPtr = szCmdLine;
27 while (*wordPtr && *wordPtr != ' ')
28 wordPtr++;
29 if (wordPtr > szCmdLine) // backup to char before space
30 wordPtr--;
31 // if first character is not a quote and last is, junk it
32 if (*szCmdLine != '"' && *wordPtr == '"') {
33 wordPtr++;
34 while (*wordPtr && *wordPtr == ' ')
35 wordPtr++; /* strip leading spaces */
36 szCmdLine = wordPtr;
37 len = strlen(szCmdLine);
40 msg = szCmdLine;
41 if (*szCmdLine == '"' && len > 0 && szCmdLine[len-1] == '"') {
42 msg = szCmdLine + 1;
43 szCmdLine[len-1] = 0;
46 // Now display the popup
47 MessageBox(NULL, msg, "Apcupsd message", MB_OK);
49 return 0;