Changeset 989 for trunk/dll/command.c


Ignore:
Timestamp:
Mar 2, 2008, 12:34:12 AM (17 years ago)
Author:
Gregg Young
Message:

Refactor fm3dll.h to create command.h; broken ini is now replaced with backup or new ini as available; more variable command line ledth changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/command.c

    r985 r989  
    4343#include "fm3dll.h"
    4444#include "pathutil.h"                   // NormalizeCmdLine
     45#include "command.h"
    4546
    4647typedef struct
     
    308309    next = info->next;
    309310    xfree(info->title);
    310     xfree(info->cl);
     311    xfree(info->pszCmdLine);
    311312    xfree(info);
    312313    info = next;
     
    319320  FILE *fp;
    320321  LINKCMDS *info;
    321   CHAR cl[1024];
     322  PSZ pszCmdLine;
    322323  CHAR title[100];
    323324  CHAR flags[72];
     
    326327    free_commands();
    327328  cmdloaded = TRUE;
    328   save_dir2(cl);
    329   if (cl[strlen(cl) - 1] != '\\')
    330     strcat(cl, "\\");
    331   strcat(cl, "COMMANDS.DAT");
    332   fp = _fsopen(cl, "r", SH_DENYWR);
    333   if (fp) {
    334     while (!feof(fp)) {
    335       if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
    336         break;
    337       title[34] = 0;                    // fixme to know why chopped this way?
    338       bstripcr(title);
    339       if (!*title || *title == ';')
    340         continue;
    341       if (!xfgets(cl, sizeof(cl), fp, pszSrcFile, __LINE__))
    342         break;                          /* error! */
    343       if (!xfgets(flags, 72, fp, pszSrcFile, __LINE__))
    344         break;                          /* error! */
    345       cl[1000] = 0;                     // fixme to know why chopped this way?
    346       bstripcr(cl);
    347       flags[34] = 0;
    348       bstripcr(flags);
    349       if (!*cl)
    350         continue;
    351       info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
    352       if (info) {
    353         info->cl = xstrdup(cl, pszSrcFile, __LINE__);
    354         info->title = xstrdup(title, pszSrcFile, __LINE__);
    355         info->flags = atol(flags);
    356         if (!info->cl || !info->title) {
    357           xfree(info->cl);
    358           xfree(info->title);
    359           xfree(info);
    360           break;
    361         }
    362         if (!cmdhead)
    363           cmdhead = info;
    364         else {
    365           cmdtail->next = info;
    366           info->prev = cmdtail;
    367         }
    368         cmdtail = info;
    369       }
    370     }
    371     fclose(fp);
     329  pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     330  if (pszCmdLine) {
     331    save_dir2(pszCmdLine);
     332    if (pszCmdLine[strlen(pszCmdLine) - 1] != '\\')
     333      strcat(pszCmdLine, "\\");
     334    strcat(pszCmdLine, "COMMANDS.DAT");
     335    fp = _fsopen(pszCmdLine, "r", SH_DENYWR);
     336    if (fp) {
     337      while (!feof(fp)) {
     338        if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
     339          break;
     340        title[34] = 0;                  // fixme to know why chopped this way?
     341        bstripcr(title);
     342        if (!*title || *title == ';')
     343          continue;
     344        if (!xfgets(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
     345          break;                                /* error! */
     346        if (!xfgets(flags, 72, fp, pszSrcFile, __LINE__))
     347          break;                                /* error! */
     348        pszCmdLine[MaxComLineStrg - 1] = 0;                     // fixme to know why chopped this way?
     349        bstripcr(pszCmdLine);
     350        flags[34] = 0;
     351        bstripcr(flags);
     352        if (!pszCmdLine)
     353          continue;
     354        info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
     355        if (info) {
     356          info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
     357          info->title = xstrdup(title, pszSrcFile, __LINE__);
     358          info->flags = atol(flags);
     359          if (!info->pszCmdLine || !info->title) {
     360            xfree(info->pszCmdLine);
     361            xfree(info->title);
     362            xfree(info);
     363            break;
     364          }
     365          if (!cmdhead)
     366            cmdhead = info;
     367          else {
     368            cmdtail->next = info;
     369            info->prev = cmdtail;
     370          }
     371          cmdtail = info;
     372        }
     373      }
     374      xfree(pszCmdLine);
     375      fclose(fp);
     376    }
    372377  }
    373378}
     
    392397    while (info) {
    393398      fprintf(fp,
    394               ";\n%0.34s\n%0.1000s\n%lu\n",
    395               info->title, info->cl, info->flags);
     399              ";\n%0.34s\n%0.*s\n%lu\n",
     400              info->title, MaxComLineStrg, info->pszCmdLine, info->flags);
    396401      info = info->next;
    397402    }
     
    417422  if (!info)
    418423    return NULL;
    419   info->cl = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
     424  info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
    420425  info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
    421426  if (addme->flags)
    422427    info->flags = addme->flags;
    423   if (!info->cl || !info->title) {
    424     xfree(info->cl);
     428  if (!info->pszCmdLine || !info->title) {
     429    xfree(info->pszCmdLine);
    425430    xfree(info->title);
    426431    xfree(info);
     
    459464            cmdtail = info->prev;
    460465        }
    461         xfree(info->cl);
     466        xfree(info->pszCmdLine);
    462467        xfree(info->title);
    463468        xfree(info);
     
    525530            break;
    526531          }
    527           WinSetDlgItemText(hwnd, CMD_CL, info->cl);
     532          WinSetDlgItemText(hwnd, CMD_CL, info->pszCmdLine);
    528533          if (!(info->flags & 1023))
    529534            WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
     
    548553            *env = 0;
    549554            size = sizeof(env) - 1;
    550             if (PrfQueryProfileData(fmprof, FM3Str, info->cl, env, &size) &&
     555            if (PrfQueryProfileData(fmprof, FM3Str, info->pszCmdLine, env, &size) &&
    551556                *env)
    552557              WinSetDlgItemText(hwnd, CMD_ENVIRON, env);
     
    10201025        fakelist[1] = NULL;
    10211026        ExecOnList(hwnd,
    1022                    info->cl,
     1027                   info->pszCmdLine,
    10231028                   flags, NULL, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
    10241029                   pszSrcFile, __LINE__);
     
    10271032    else
    10281033      ExecOnList(hwnd,
    1029                  info->cl,
     1034                 info->pszCmdLine,
    10301035                 flags, NULL, list, GetPString(IDS_EXECCMDTITLETEXT),
    10311036                 pszSrcFile, __LINE__);
Note: See TracChangeset for help on using the changeset viewer.