Changeset 985 for trunk/dll/command.c


Ignore:
Timestamp:
Mar 1, 2008, 2:37:14 AM (17 years ago)
Author:
Gregg Young
Message:

Update sizes dialog (ticket 44); Make max command line length user settable (ticket 199); use xfree for free in most cases (ticket 212); initial code to check for valid ini file (ticket 102); Some additional refactoring and structure rework; Some documentation updates;

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/command.c

    r959 r985  
    2222  20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
    2323  06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry
     24  29 Feb 08 GKY Changes to enable user settable command line length
     25  29 Feb 08 GKY Use xfree where appropriate
    2426
    2527***********************************************************************/
     
    4446typedef struct
    4547{
    46   CHAR cl[MAXCOMLINESTRG];
     48  PSZ pszCmdLine;
    4749  INT flags;
    4850  CHAR title[34];
     
    307309    xfree(info->title);
    308310    xfree(info->cl);
    309     free(info);
     311    xfree(info);
    310312    info = next;
    311313  }
     
    355357          xfree(info->cl);
    356358          xfree(info->title);
    357           free(info);
     359          xfree(info);
    358360          break;
    359361        }
     
    404406  LINKCMDS *info;
    405407
    406   if (!addme || !*addme->cl || !*addme->title)
     408  if (!addme || !*addme->pszCmdLine || !*addme->title)
    407409    return NULL;                        // No data
    408410  info = cmdhead;
     
    415417  if (!info)
    416418    return NULL;
    417   info->cl = xstrdup(addme->cl, pszSrcFile, __LINE__);
     419  info->cl = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
    418420  info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
    419421  if (addme->flags)
     
    422424    xfree(info->cl);
    423425    xfree(info->title);
    424     free(info);
     426    xfree(info);
    425427    return NULL;
    426428  }
     
    459461        xfree(info->cl);
    460462        xfree(info->title);
    461         free(info);
     463        xfree(info);
    462464        return TRUE;
    463465      }
     
    622624        APIRET ret;
    623625
    624         pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
    625         if (!pszWorkBuf)
     626        memset(&temp, 0, sizeof(COMMAND));
     627        temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     628        if (!temp.pszCmdLine)
    626629          break; //already complained
    627         memset(&temp, 0, sizeof(COMMAND));
    628         WinQueryDlgItemText(hwnd, CMD_CL, sizeof(temp.cl), temp.cl);
    629         NormalizeCmdLine(pszWorkBuf, temp.cl);
    630         memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
     630        pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
     631        if (!pszWorkBuf) {
     632          xfree(temp.pszCmdLine);
     633          break; //already complained
     634        }
     635        WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
     636        NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
     637        memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    631638        xfree(pszWorkBuf);
    632         if (!strchr(temp.cl, '%')){
     639        if (!strchr(temp.pszCmdLine, '%')){
    633640          ret = saymsg(MB_YESNO,
    634641                       HWND_DESKTOP,
     
    636643                       GetPString(IDS_TOACTONSELECTEDTEXT));
    637644          if (ret == MBID_YES)
    638             strcat(temp.cl, " %a");
     645            strcat(temp.pszCmdLine, " %a");
    639646        }
    640647        WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
     
    657664        if (fCancelAction){
    658665          fCancelAction = FALSE;
     666          xfree(temp.pszCmdLine);
    659667          break;
    660668        }
     
    676684          bstripcr(env);
    677685          if (*env) {
    678             PrfWriteProfileString(fmprof, FM3Str, temp.cl, env);
     686            PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
    679687          }
    680688          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    694702            save_commands();
    695703          }
    696         }
     704        }
     705        xfree(temp.pszCmdLine);
    697706      }
    698707      x = (SHORT) WinSendDlgItemMsg(hwnd,
    699708                                    CMD_LISTBOX,
    700709                                    LM_QUERYSELECTION,
    701                                     MPFROMSHORT(LIT_FIRST), MPVOID);
     710                                    MPFROMSHORT(LIT_FIRST), MPVOID);
    702711      WinDismissDlg(hwnd, 0);
    703712      break;
     
    720729        APIRET ret;
    721730
    722         pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
    723         if (!pszWorkBuf)
     731        memset(&temp, 0, sizeof(COMMAND));
     732        temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     733        if (!temp.pszCmdLine)
    724734          break; //already complained
    725         memset(&temp, 0, sizeof(COMMAND));
    726         WinQueryDlgItemText(hwnd, CMD_CL, sizeof(temp.cl), temp.cl);
    727         NormalizeCmdLine(pszWorkBuf, temp.cl);
    728         memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
     735        pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
     736        if (!pszWorkBuf) {
     737          xfree(temp.pszCmdLine);
     738          break; //already complained
     739        }
     740        WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
     741        NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
     742        memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    729743        xfree(pszWorkBuf);
    730         if (!strchr(temp.cl, '%')){
     744        if (!strchr(temp.pszCmdLine, '%')){
    731745          ret = saymsg(MB_YESNO,
    732746                       HWND_DESKTOP,
     
    734748                       GetPString(IDS_TOACTONSELECTEDTEXT));
    735749          if (ret == MBID_YES)
    736             strcat(temp.cl, " %a");
     750            strcat(temp.pszCmdLine, " %a");
    737751        }
    738752        WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
     
    755769        if (fCancelAction){
    756770          fCancelAction = FALSE;
     771          xfree(temp.pszCmdLine);
    757772          break;
    758773        }
     
    770785          bstripcr(env);
    771786          if (*env) {
    772             PrfWriteProfileString(fmprof, FM3Str, temp.cl, env);
     787            PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
    773788          }
    774789          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    788803            save_commands();
    789804          }
    790         }
     805        }
     806        xfree(temp.pszCmdLine);
    791807      }
    792808      break;
     
    818834      }
    819835      break;
     836
    820837    case CMD_REPLACE:
    821838      { //Delete first
     
    824841        APIRET ret;
    825842
    826         pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__);
    827         if (!pszWorkBuf)
     843        pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
     844        if (!pszWorkBuf) {
    828845          break; //already complained
    829         memset(&temp, 0, sizeof(COMMAND));
    830         WinQueryDlgItemText(hwnd, CMD_CL, sizeof(temp.cl), temp.cl);
    831         NormalizeCmdLine(pszWorkBuf, temp.cl);
    832         memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1);
     846        }
     847        memset(&temp, 0, sizeof(COMMAND));
     848        temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     849        if (!temp.pszCmdLine) {
     850          xfree(pszWorkBuf);
     851          break; //already complained
     852        }
     853        WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
     854        NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
     855        memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    833856        xfree(pszWorkBuf);
    834857        if (fCancelAction){
    835858          fCancelAction = FALSE;
     859          xfree(temp.pszCmdLine);
    836860          break;
    837861        }
    838         if (!strchr(temp.cl, '%')){
     862        if (!strchr(temp.pszCmdLine, '%')){
    839863          ret = saymsg(MB_YESNO,
    840864                       HWND_DESKTOP,
     
    842866                       GetPString(IDS_TOACTONSELECTEDTEXT));
    843867          if (ret == MBID_YES)
    844             strcat(temp.cl, " %a");
     868            strcat(temp.pszCmdLine, " %a");
    845869        }
    846870        //remember item location in the list
     
    896920          bstripcr(env);
    897921          if (*env) {
    898             PrfWriteProfileString(fmprof, FM3Str, temp.cl, env);
     922            PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
    899923          } //put item back in original place
    900924          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    947971          }
    948972        }
     973        xfree(temp.pszCmdLine);
    949974      }
    950975      break;
Note: See TracChangeset for help on using the changeset viewer.