]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/win32/popup.c
c556fa8a68544f5e76f425bb2bd343b35cfa3e46
[bacula/bacula] / bacula / src / filed / win32 / popup.c
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
11
12 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
13                    PSTR szCmdLine, int iCmdShow)
14 {
15    int len = strlen(szCmdLine);
16    char *msg, *wordPtr;
17
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);
38    }
39
40    msg = szCmdLine;
41    if (*szCmdLine == '"' && len > 0 && szCmdLine[len-1] == '"') {
42       msg = szCmdLine + 1;
43       szCmdLine[len-1] = 0;
44    }
45    MessageBox(NULL, msg, "Apcupsd message", MB_OK);
46    return 0;
47 }