Changeset 1247 for trunk/dll/pathutil.c


Ignore:
Timestamp:
Oct 15, 2008, 3:44:29 PM (17 years ago)
Author:
Gregg Young
Message:

Fix issues with NormalizeCmdLine; it now uses searchapath to check for nonexe files in the path, it tries all 5 defined executible extensions when no exetension is provided, it closes dosfind, eliminates extra error message on failure to find extensionless file in commands, improved error message for extensionless file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/pathutil.c

    r1211 r1247  
    1212  06 Jan 08 GKY Add NormalizeCmdLine to check program strings on entry
    1313  29 Feb 08 GKY Changes to enable user settable command line length
     14  15 Oct 08 GKY Fix NormalizeCmdLine to check all 5 executible extensions when no extension provided;
     15                use searchapath to check for existance of file types not checked by DosQAppType;
     16                close DosFind.
    1417
    1518***********************************************************************/
     
    2629#include "init.h"                       // Data declaration(s)
    2730#include "fm3str.h"
     31#include "srchpath.h"                   // searchapath
    2832#include "pathutil.h"
    2933#include "strips.h"                     // remove_first_occurence_of_character
     
    126130  ULONG ulAppType;
    127131  char *pszChar;
     132  char *FullPath;
    128133  FILEFINDBUF3 FindBuffer;
    129134  ULONG ulResultBufLen = sizeof(FILEFINDBUF3);
     
    181186               GetPString(IDS_QUOTESINARGSTEXT),
    182187               pszCmdLine_);
    183       if (!offsetexe) {
     188      if (!offsetexe && !offsetcom) {
    184189        ret = DosFindFirst(szCmdLine, &hdirFindHandle, FILE_NORMAL, &FindBuffer,
    185190                           ulResultBufLen, &ulFindCount, FIL_STANDARD);
    186         if (ret) {
    187           pszChar = szCmdLine;
    188           while (pszChar) {
    189             if (*pszChar == ' ') {
    190               *pszChar = '\0';
    191               strcat(szCmdLine, ".exe");
    192               ret = DosQueryAppType(szCmdLine, &ulAppType);
    193               //printf("%d %s\n", ret, szCmdLine); fflush(stdout);
    194               if (!ret) {
    195                 strcpy(szArgs, pszCmdLine_ + strlen(szCmdLine) - 3);
    196                 break;
    197               }
    198             }
    199             strcpy(szCmdLine, pszCmdLine_);
    200             pszChar++;
    201           }
    202         }
     191        if (ret) {
     192          FullPath = searchapath("PATH", szCmdLine);
     193          if (*FullPath != 0)
     194            ret = 0;
     195        }
     196        DosFindClose(hdirFindHandle);
    203197      }
    204198      else
     
    229223
    230224    }
     225    // if it doesn't have an extension try it with all the standard ones and add if found
    231226    else if (szCmdLine && (!strchr(szCmdLine, '.') ||
    232                          strrchr(szCmdLine, '.' ) < strrchr(szCmdLine, '\\'))) {
     227                           strrchr(szCmdLine, '.' ) < strrchr(szCmdLine, '\\'))) {
    233228      if (!strchr(szCmdLine, ' ')) {
     229        // strip quotes readded by BuildQuotedFileName
    234230        while (strchr(szCmdLine, '\"'))
    235231          remove_first_occurence_of_character("\"", szCmdLine);
    236         strcat(szCmdLine, ".exe");
    237         ret = DosFindFirst(szCmdLine, &hdirFindHandle, FILE_NORMAL, &FindBuffer,
    238                            ulResultBufLen, &ulFindCount, FIL_STANDARD);
     232        ret = DosQueryAppType(szCmdLine, &ulAppType);
     233        if (!ret)
     234          strcat(szCmdLine, ".exe");
     235        else {
     236          strcat(szCmdLine, ".com");
     237          ret = DosQueryAppType(szCmdLine, &ulAppType);
     238          if (ret) {
     239            offset = strrchr(szCmdLine, '.' );
     240            *offset = 0;
     241            strcat(szCmdLine, ".cmd");
     242            FullPath = searchapath("PATH", szCmdLine);
     243            if (*FullPath != 0)
     244              ret = 0;
     245            else {
     246              offset = strrchr(szCmdLine, '.' );
     247              *offset = 0;
     248              strcat(szCmdLine, ".bat");
     249              FullPath = searchapath("PATH", szCmdLine);
     250              if (*FullPath != 0)
     251                ret = 0;
     252              else {
     253                offset = strrchr(szCmdLine, '.' );
     254                *offset = 0;
     255                strcat(szCmdLine, ".bmt");
     256                FullPath = searchapath("PATH", szCmdLine);
     257                if (*FullPath != 0)
     258                  ret = 0;
     259              }
     260            }
     261          }
     262        }
    239263        //printf("%d", ret); fflush(stdout);
    240264      }
     
    244268          while (strchr(szCmdLine, '\"'))
    245269            remove_first_occurence_of_character("\"", szCmdLine);
    246           if (*pszChar == ' ') {
     270          if (*pszChar == ' ') { //test at every space for the end of the filename
    247271            *pszChar = '\0';
    248             strcat(szCmdLine, ".exe");
    249             ret = DosQueryAppType(szCmdLine, &ulAppType);
     272            ret = DosQueryAppType(szCmdLine, &ulAppType);
     273            if (!ret) {
     274              strcat(szCmdLine, ".exe");
     275              break;
     276            }
     277            else {
     278              strcat(szCmdLine, ".com");
     279              ret = DosQueryAppType(szCmdLine, &ulAppType);
     280              if (ret) {
     281                offset = strrchr(szCmdLine, '.' );
     282                *offset = 0;
     283                strcat(szCmdLine, ".cmd");
     284                FullPath = searchapath("PATH", szCmdLine);
     285                if (*FullPath != 0) {
     286                  ret = 0;
     287                  break;
     288                }
     289                else {
     290                  offset = strrchr(szCmdLine, '.' );
     291                  *offset = 0;
     292                  strcat(szCmdLine, ".bat");
     293                  FullPath = searchapath("PATH", szCmdLine);
     294                  if (*FullPath != 0) {
     295                    ret = 0;
     296                    break;
     297                  }
     298                  else {
     299                    offset = strrchr(szCmdLine, '.' );
     300                    *offset = 0;
     301                    strcat(szCmdLine, ".bmt");
     302                    FullPath = searchapath("PATH", szCmdLine);
     303                    if (*FullPath != 0) {
     304                      ret = 0;
     305                      break;
     306                    }
     307                  }
     308                }
     309              }
     310              else
     311                break;
     312            }
    250313            //printf("%d %s\n", ret, szCmdLine); fflush(stdout);
    251             if (!ret) {
    252               break;
    253             }
    254314          }
    255315          strcpy(szCmdLine, pszCmdLine_);
     
    273333        strcat(pszNewCmdLine, szArgs);
    274334      }
    275       else {
     335      else { // fail if no extension can be found we require one
    276336        ret = saymsg(MB_OK,
    277337                     HWND_DESKTOP,
     
    283343      }
    284344    }
    285     else {
     345    else { // file has a nonstandard extension for executible
    286346      pszChar = strrchr(szCmdLine, '.');
    287347      while (pszChar && *pszChar !=' ') {
     
    302362             pszCmdLine_);
    303363    ret = DosFindFirst(szCmdLine, &hdirFindHandle, FILE_NORMAL, &FindBuffer,
    304                         ulResultBufLen, &ulFindCount, FIL_STANDARD);
    305 
     364                      ulResultBufLen, &ulFindCount, FIL_STANDARD);
     365    DosFindClose(hdirFindHandle);
    306366    BldQuotedFileName(pszNewCmdLine, szCmdLine);
    307367    //printf("%d %s ", ret, szCmdLine); fflush(stdout);
Note: See TracChangeset for help on using the changeset viewer.