Annotation of mstools/samples/sdktools/walker/pwalkio.c, revision 1.1.1.1

1.1       root        1: #include "pwalk.h"
                      2: #include <commdlg.h>
                      3: 
                      4: 
                      5: /* global file name variables */
                      6: char   szExeFilterSpec[128] = "Executable Files (*.EXE)\0*.EXE\0";
                      7: 
                      8: 
                      9: /* call the OpenFile common dialog to get a filename */
                     10: BOOL WINAPI GetFileName (
                     11:     HWND    hWnd,
                     12:     char    *lpszFilePath,
                     13:     char    *lpszExt)
                     14: {
                     15:     OPENFILENAME    ofn;
                     16:     char           szFileOpen[25];
                     17:     char           szExt[10];
                     18:     char           szTitle[MAX_PATH];
                     19: 
                     20:     *szTitle = 0;
                     21: 
                     22:     if (lpszExt && *lpszExt)
                     23:        strcpy (szExt, lpszExt);
                     24:     else
                     25:        LoadString ((HANDLE)GetModuleHandle (NULL),
                     26:            IDS_EXEFILEEXT,
                     27:            szExt,
                     28:            sizeof (szExt));
                     29: 
                     30:     LoadString ((HANDLE)GetModuleHandle (NULL),
                     31:         IDS_FILEOPENTITLE,
                     32:        szFileOpen,
                     33:        sizeof (szFileOpen));
                     34: 
                     35:     ofn.lStructSize      = sizeof (OPENFILENAME);
                     36:     ofn.hwndOwner        = NULL;
                     37:     ofn.lpstrFilter      = szExeFilterSpec;
                     38:     ofn.lpstrCustomFilter = NULL;
                     39:     ofn.nMaxCustFilter    = 0;
                     40:     ofn.nFilterIndex      = 0;
                     41:     ofn.lpstrFile        = lpszFilePath;
                     42:     ofn.nMaxFile         = MAX_PATH;
                     43:     ofn.lpstrInitialDir   = NULL;
                     44:     ofn.lpstrFileTitle   = szTitle;
                     45:     ofn.nMaxFileTitle     = MAX_PATH;
                     46:     ofn.lpstrTitle       = szFileOpen;
                     47:     ofn.lpstrDefExt      = szExt;
                     48:     ofn.Flags            = OFN_FILEMUSTEXIST;
                     49: 
                     50:     /* call common open dialog and return result */
                     51:     return (GetOpenFileName ((LPOPENFILENAME)&ofn));
                     52: }
                     53: 
                     54: 
                     55: 
                     56: /* invokes the saveas common dialog to retrieve a file name */
                     57: /* function retrieves the filename from the path */
                     58: void WINAPI GetFileFromPath (
                     59:     char    *lpszFullPath,
                     60:     char    *lpszFile)
                     61: {
                     62:     char    *lpPtr = lpszFullPath + strlen (lpszFullPath);
                     63: 
                     64:     /* file is at end of path, so search backwards to first \ or : char */
                     65:     while (lpPtr > lpszFullPath)
                     66:     {
                     67:     if (*lpPtr == '\\' ||
                     68:         *lpPtr == ':')
                     69:         {
                     70:         lpPtr++;
                     71:         break;
                     72:         }
                     73:     lpPtr--;
                     74:     }
                     75: 
                     76:     /* return filename if found, or full path passed in */
                     77:     strcpy (lpszFile, lpPtr);
                     78: }
                     79: 
                     80: 
                     81: 
                     82: 
                     83: /* validate filename as executable image  */
                     84: BOOL WINAPI IsValidFile (
                     85:     char    *lpszFilename)
                     86: {
                     87:     OFSTRUCT   of;
                     88:     int        nLen;
                     89:     char       *pStr;
                     90: 
                     91:     /* validate filename pointer */
                     92:     if (lpszFilename == NULL ||
                     93:        !*lpszFilename)
                     94:        return FALSE;
                     95: 
                     96:     /* open the file for existance */
                     97:     if (OpenFile (lpszFilename, &of, OF_EXIST) == -1)
                     98:        /* fail validation */
                     99:        return FALSE;
                    100: 
                    101:     /* test the extension is .EXE */
                    102:     nLen = strlen (lpszFilename);
                    103:     pStr = lpszFilename + nLen - 4;
                    104:     if (!stricmp (pStr, ".EXE"))
                    105:        /* pass validation */
                    106:        return TRUE;
                    107: 
                    108:     /* fail validation */
                    109:     return FALSE;
                    110: }
                    111: 
                    112: 
                    113: 
                    114: 
                    115: /* get win32 command line parameters */
                    116: BOOL WINAPI GetCmdLine(
                    117:     char    *lpStr,
                    118:     char    *lpszCmdLine,
                    119:     BOOL    *bBkgnd)
                    120: {
                    121:     if (*lpStr)
                    122:        {
                    123:        /* skip application name which precedes parameters */
                    124:        while (*lpStr != ' ' && *lpStr != 0)
                    125:            lpStr++;
                    126: 
                    127:        /* skip spaces */
                    128:        while (*lpStr == ' ' && *lpStr != 0)
                    129:            lpStr++;
                    130: 
                    131:        /* indeed command line parameter(s) present */
                    132:        if (*lpStr != 0)
                    133:            {
                    134:            /* if background switch, set flag and remove switch from command line */
                    135:            if ((*lpStr == '/' || *lpStr == '-') &&
                    136:                (*(lpStr+1) == 'b' || *(lpStr+1) == 'B'))
                    137:                {
                    138:                *bBkgnd = TRUE;
                    139:                lpStr += 2;
                    140: 
                    141:                if (*lpStr == 0)
                    142:                    *lpszCmdLine = 0;
                    143:                else
                    144:                    strcpy (lpszCmdLine, lpStr);
                    145:                }
                    146:            /* maybe switch is embedded in parameter(s) somewhere */
                    147:            else
                    148:                {
                    149:                char    *pStr = lpStr;
                    150:                char    *pCmdLine = lpszCmdLine;
                    151:                int     i, nCnt;
                    152: 
                    153:                while (*pStr != 0)
                    154:                    {
                    155:                    /* background switch is set, so prepare parameters and set flag */
                    156:                    if ((*pStr == '/' || *pStr == '-') &&
                    157:                        (*(pStr+1) == 'b' || *(pStr+1) == 'B'))
                    158:                        {
                    159:                        *bBkgnd = TRUE;
                    160: 
                    161:                        /* copy from beg. of lpStr to *pStr to lpszCmdLine */
                    162:                        nCnt = pStr - lpStr;
                    163:                        for (i=0; i<nCnt; i++)
                    164:                            lpszCmdLine[i] = lpStr[i];
                    165:                        lpszCmdLine[i] = 0;
                    166:                        strcat (lpszCmdLine, (pStr+2));
                    167: 
                    168:                        /* break from loop */
                    169:                        break;
                    170:                        }
                    171: 
                    172:                    pStr++;
                    173:                    }
                    174: 
                    175:                /* no switch found, can only edit one file, remove extra parameters */
                    176:                if (*pStr == 0)
                    177:                    {
                    178:                    pStr = lpStr;
                    179: 
                    180:                    while (*pStr != ' ' && *pStr != 0)
                    181:                        pStr++;
                    182: 
                    183:                    if (*pStr == ' ')
                    184:                        *pStr = 0;
                    185: 
                    186:                    strcpy (lpszCmdLine, lpStr);
                    187:                    }
                    188:                }
                    189:            }
                    190:        else
                    191:            return FALSE;
                    192:        }
                    193:     else
                    194:        return FALSE;
                    195: 
                    196:     return TRUE;
                    197: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.