Changeset 888 for trunk/dll/systemf.c


Ignore:
Timestamp:
Dec 22, 2007, 11:02:11 PM (18 years ago)
Author:
Gregg Young
Message:

runemf2 now quotes executable strings if needed (Ticket 180); it also reports where it was called from on errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/systemf.c

    r793 r888  
    7171
    7272int ExecOnList(HWND hwnd, char *command, int flags, char *tpath,
    73                char **list, char *prompt)
     73               char **list, char *prompt, PCSZ pszCallingFile, UINT uiLineNumber)
    7474{
    7575  /* executes the command once for all files in list */
     
    591591      ex.flags = flags;
    592592    ex.flags &= (~PROMPT);
    593     return runemf2(ex.flags, hwnd, path,
     593    return runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path,
    594594                   (*ex.environment) ? ex.environment : NULL,
    595595                   "%s", commandline);
     
    599599//== runemf2() run requested app, return -1 if problem starting else return app rc ==
    600600
    601 int runemf2(int type, HWND hwnd, char *pszDirectory, char *pszEnvironment,
     601int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber,
     602            char *pszDirectory, char *pszEnvironment,
    602603            char *formatstring,...)
    603604{
     
    605606
    606607   * status = runemf2(SEPARATE | WINDOWED,
    607    *                  hwnd,
     608   *                  hwnd, pszCallingFile, __LINE__,
    608609   *                  NullStr,
    609610   *                  NULL,
     
    613614   *
    614615   * use (HWND)0 for hwnd if window handle not handy.
     616   * pszCallingFile and __LINE__ are used to determine caller for easier error tracking
    615617   */
    616618
     
    634636  BOOL useTermQ = FALSE;
    635637  char szTempdir[CCHMAXPATH];
     638  char szTempPgm[CCHMAXPATH], tempcom[1024], temparg[1024], buf[10] = " &|<>";
     639  char *offset, *offsetexe, *offsetcom, *offsetcmd, *offsetbtm, *offsetbat;
     640  UINT offsetquote;
    636641
    637642  typedef struct {
     
    675680  *pszPgm = 0;
    676681  va_start(parguments,
    677            formatstring);
     682           formatstring);
    678683  vsprintf(pszPgm,
    679684           formatstring,
    680            parguments);
     685           parguments);
    681686  va_end(parguments);
    682 
     687  offsetexe = strstr(pszPgm, ".exe");
     688  offsetcmd = strstr(pszPgm, ".cmd");
     689  offsetcom = strstr(pszPgm, ".com");
     690  offsetbtm = strstr(pszPgm, ".btm");
     691  offsetbat = strstr(pszPgm, ".bat");
     692  if (offsetexe)
     693    offset = offsetexe;
     694  else if (offsetcom)
     695    offset = offsetcom;
     696  else if (offsetcmd)
     697    offset = offsetcmd;
     698  else if (offsetbtm)
     699    offset = offsetbtm;
     700  else if (offsetbat)
     701    offset = offsetbat;
     702  else
     703    offset = NULL;
     704  offsetquote = strcspn(pszPgm, buf);
     705  if (pszPgm[0] != '\"' && offsetquote < offset - pszPgm && offsetquote != NULL){
     706    strcpy(tempcom, pszPgm);
     707    tempcom[offset + 4 - pszPgm] = '\0';
     708    strcpy (temparg, &pszPgm[offset + 4 - pszPgm]);
     709    pszDirectory = szTempdir;
     710    strcpy(pszDirectory, tempcom);
     711    offset = strrchr(pszDirectory, '\\');
     712    pszDirectory[offset +1 - pszDirectory] = '\0';
     713    BldQuotedFileName(szTempPgm, tempcom);
     714    strcat(szTempPgm, temparg);
     715    memcpy(pszPgm, szTempPgm, 1024);
     716    //printf("%s\n %s\n%s %s\n %d %d",
     717    //       pszPgm, szTempPgm, tempcom, temparg, offset, offsetquote); fflush(stdout);
     718  }
    683719  if (pszEnvironment) {
    684720    p = &pszEnvironment[strlen(pszEnvironment)] + 1;
     
    789825          Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
    790826                    GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
    791                     pszPgm);
     827                    pszPgm, pszCallingFile, __LINE__);
    792828          DosFreeMem(pszPgm);
    793829          if (pszArgs)
     
    801837            Runtime_Error(pszSrcFile, __LINE__,
    802838                          GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
    803                           ulAppType, pszPgm);
     839                          ulAppType, pszPgm, pszCallingFile, __LINE__);
    804840            if (pszPgm)
    805841              DosFreeMem(pszPgm);
     
    813849            Runtime_Error(pszSrcFile, __LINE__,
    814850                          GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
    815                           ulAppType, pszPgm);
     851                          ulAppType, pszPgm, pszCallingFile, __LINE__);
    816852            if (pszPgm)
    817853              DosFreeMem(pszPgm);
     
    834870        if (ret) {
    835871          Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
    836                     GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm);
     872                    GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm,
     873                    pszCallingFile, __LINE__);
    837874        }
    838875      }
     
    903940      }
    904941
    905       /* goddamned OS/2 limit */
     942      // goddamned OS/2 limit
    906943
    907944      if (strlen(pszPgm) + strlen(pszArgs) > 1024)
     
    922959          *pszDirectory)
    923960        switch_to(szSavedir);
    924       if (rc) {
     961      if (rc){
    925962        Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
    926963                  GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
    927                   pszPgm);
     964                  pszPgm, pszCallingFile, __LINE__);
    928965        DosFreeMem(pszPgm);
    929966        if (pszArgs)
     
    937974          Runtime_Error(pszSrcFile, __LINE__,
    938975                        GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
    939                         pszPgm);
     976                        pszPgm, pszCallingFile, __LINE__);
    940977          DosFreeMem(pszPgm);
    941978          if (pszArgs)
     
    11061143      if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
    11071144        Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
    1108                   GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs);
     1145                  GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs,
     1146                  pszCallingFile, __LINE__);
    11091147      }
    11101148      else if (type & WAIT) {
Note: See TracChangeset for help on using the changeset viewer.