| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: command.c 1593 2011-07-04 02:32:25Z gyoung $
 | 
|---|
| 5 | 
 | 
|---|
| 6 |   Custom commands
 | 
|---|
| 7 | 
 | 
|---|
| 8 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| 9 |   Copyright (c) 2004, 2010 Steven H. Levine
 | 
|---|
| 10 | 
 | 
|---|
| 11 |   01 Aug 04 SHL Rework lstrip/rstrip usage
 | 
|---|
| 12 |   06 Jun 05 SHL Drop unused code
 | 
|---|
| 13 |   14 Jul 06 SHL Use Runtime_Error
 | 
|---|
| 14 |   29 Jul 06 SHL Use xfgets_bstripcr
 | 
|---|
| 15 |   15 Aug 06 SHL Better can't add message
 | 
|---|
| 16 |   18 Sep 06 GKY Add replace command and update okay to add if changed
 | 
|---|
| 17 |   17 Feb 07 GKY Move error messages etc to string file
 | 
|---|
| 18 |   22 Mar 07 GKY Use QWL_USER
 | 
|---|
| 19 |   23 Mar 07 GKY Replace doesn't change item position
 | 
|---|
| 20 |   23 Mar 07 GKY Okay fails silently when item not changed
 | 
|---|
| 21 |   19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
 | 
|---|
| 22 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
| 23 |   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
 | 
|---|
| 26 |   18 Jul 08 SHL Add Fortify support
 | 
|---|
| 27 |   19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
 | 
|---|
| 28 |   24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
 | 
|---|
| 29 |   15 Oct 08 GKY Prevent asking to add %a on NormalizeCmdLine abort
 | 
|---|
| 30 |   21 Dec 09 GKY Fix the environment so it can be saved, deleted and used consistently.
 | 
|---|
| 31 |   21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
 | 
|---|
| 32 |                 Added load_inicommand to load the IDs from the ini file.
 | 
|---|
| 33 |   21 Dec 09 GKY Added 20 new hot keys for commands.
 | 
|---|
| 34 |   21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
 | 
|---|
| 35 |   27 Dec 09 GKY Moved Commands to the INI file this makes commands.dat obsolete
 | 
|---|
| 36 |   27 Dec 09 GKY Added QueryCommandSettings to streamline code
 | 
|---|
| 37 |   27 Dec 09 GKY Made command hotkeys user selectable.
 | 
|---|
| 38 |   17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10).
 | 
|---|
| 39 |                 Mostly cast CHAR CONSTANT * as CHAR *.
 | 
|---|
| 40 |   01 May 10 GKY Add ENVIRONMENT_SIZE variable to standardize this size everywhere.
 | 
|---|
| 41 |   01 May 10 GKY Changes to move environment storage to INI file
 | 
|---|
| 42 |   03 Jul 11 GKY Fixed problem with creation of duplicate command IDs.
 | 
|---|
| 43 | 
 | 
|---|
| 44 | ***********************************************************************/
 | 
|---|
| 45 | 
 | 
|---|
| 46 | #include <stdlib.h>
 | 
|---|
| 47 | #include <string.h>
 | 
|---|
| 48 | #include <share.h>
 | 
|---|
| 49 | 
 | 
|---|
| 50 | #define INCL_DOS
 | 
|---|
| 51 | #define INCL_WIN
 | 
|---|
| 52 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| 53 | 
 | 
|---|
| 54 | #include "fm3dll.h"
 | 
|---|
| 55 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc.
 | 
|---|
| 56 | #include "notebook.h"                   // Data declaration(s)
 | 
|---|
| 57 | #include "init.h"                       // Data declaration(s)
 | 
|---|
| 58 | #include "mainwnd.h"                    // Data declaration(s)
 | 
|---|
| 59 | #include "newview.h"                    // Data declarations
 | 
|---|
| 60 | #include "fm3dlg.h"
 | 
|---|
| 61 | #include "fm3str.h"
 | 
|---|
| 62 | #include "tools.h"
 | 
|---|
| 63 | #include "arccnrs.h"                    // BldQuotedFileName
 | 
|---|
| 64 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 65 | #include "strutil.h"                    // GetPString
 | 
|---|
| 66 | #include "droplist.h"                   // AcceptOneDrop, DropHelp, GetOneDrop
 | 
|---|
| 67 | #include "misc.h"                       // DrawTargetEmphasis
 | 
|---|
| 68 | #include "systemf.h"                    // ExecOnList
 | 
|---|
| 69 | #include "getnames.h"                   // insert_filename
 | 
|---|
| 70 | #include "wrappers.h"                   // xfgets
 | 
|---|
| 71 | #include "pathutil.h"                   // NormalizeCmdLine
 | 
|---|
| 72 | #include "command.h"
 | 
|---|
| 73 | #include "strips.h"                     // bstrip
 | 
|---|
| 74 | #include "dirs.h"                       // save_dir2
 | 
|---|
| 75 | #include "fortify.h"
 | 
|---|
| 76 | 
 | 
|---|
| 77 | VOID load_inicommands(VOID);
 | 
|---|
| 78 | 
 | 
|---|
| 79 | typedef struct
 | 
|---|
| 80 | {
 | 
|---|
| 81 |   PSZ pszCmdLine;
 | 
|---|
| 82 |   CHAR title[100];
 | 
|---|
| 83 |   CHAR env[ENVIRONMENT_SIZE];
 | 
|---|
| 84 |   ULONG flags;
 | 
|---|
| 85 |   ULONG ID;
 | 
|---|
| 86 |   ULONG HotKeyID;
 | 
|---|
| 87 | }
 | 
|---|
| 88 | COMMAND;
 | 
|---|
| 89 | 
 | 
|---|
| 90 | BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp);
 | 
|---|
| 91 | VOID save_commands(VOID);
 | 
|---|
| 92 | 
 | 
|---|
| 93 | // Data defintions
 | 
|---|
| 94 | #pragma data_seg(DATA1)
 | 
|---|
| 95 | 
 | 
|---|
| 96 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
| 97 | static LINKCMDS *cmdtail;
 | 
|---|
| 98 | static BOOL UsedCommandIDs[300] = {FALSE};
 | 
|---|
| 99 | static BOOL UsedHotKeyIDs[40] = {FALSE};
 | 
|---|
| 100 | static PSZ pszCommandsList;
 | 
|---|
| 101 | static ULONG ulSizeCommandsList = 10000;
 | 
|---|
| 102 | static BOOL fLoadCommandsFromINI = FALSE;
 | 
|---|
| 103 | 
 | 
|---|
| 104 | #pragma data_seg(GLOBAL2)
 | 
|---|
| 105 | LINKCMDS *cmdhead;
 | 
|---|
| 106 | BOOL cmdloaded;
 | 
|---|
| 107 | 
 | 
|---|
| 108 | MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 | 
|---|
| 109 | {
 | 
|---|
| 110 |   PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
 | 
|---|
| 111 |   static BOOL emphasized = FALSE;
 | 
|---|
| 112 | 
 | 
|---|
| 113 |   switch (msg) {
 | 
|---|
| 114 |   case DM_DRAGOVER:
 | 
|---|
| 115 |     if (!emphasized) {
 | 
|---|
| 116 |       emphasized = TRUE;
 | 
|---|
| 117 |       DrawTargetEmphasis(hwnd, emphasized);
 | 
|---|
| 118 |     }
 | 
|---|
| 119 |     if (AcceptOneDrop(hwnd, mp1, mp2))
 | 
|---|
| 120 |       return MRFROM2SHORT(DOR_DROP, DO_MOVE);
 | 
|---|
| 121 |     return MRFROM2SHORT(DOR_NEVERDROP, 0);
 | 
|---|
| 122 | 
 | 
|---|
| 123 |   case DM_DRAGLEAVE:
 | 
|---|
| 124 |     if (emphasized) {
 | 
|---|
| 125 |       emphasized = FALSE;
 | 
|---|
| 126 |       DrawTargetEmphasis(hwnd, emphasized);
 | 
|---|
| 127 |     }
 | 
|---|
| 128 |     break;
 | 
|---|
| 129 | 
 | 
|---|
| 130 |   case DM_DROPHELP:
 | 
|---|
| 131 |     DropHelp(mp1, mp2, hwnd, GetPString(IDS_DROPCMDHELPTEXT));
 | 
|---|
| 132 |     return 0;
 | 
|---|
| 133 | 
 | 
|---|
| 134 |   case DM_DROP:
 | 
|---|
| 135 |     {
 | 
|---|
| 136 |       char szFrom[CCHMAXPATH + 5];
 | 
|---|
| 137 | 
 | 
|---|
| 138 |       if (emphasized) {
 | 
|---|
| 139 |         emphasized = FALSE;
 | 
|---|
| 140 |         DrawTargetEmphasis(hwnd, emphasized);
 | 
|---|
| 141 |       }
 | 
|---|
| 142 |       if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
 | 
|---|
| 143 |         strcat(szFrom, " %a");
 | 
|---|
| 144 |         WinSetWindowText(hwnd, szFrom);
 | 
|---|
| 145 |       }
 | 
|---|
| 146 |     }
 | 
|---|
| 147 |     return 0;
 | 
|---|
| 148 |   }
 | 
|---|
| 149 |   return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
 | 
|---|
| 150 |     WinDefWindowProc(hwnd, msg, mp1, mp2);
 | 
|---|
| 151 | }
 | 
|---|
| 152 | 
 | 
|---|
| 153 | MRESULT EXPENTRY ReOrderProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 | 
|---|
| 154 | {
 | 
|---|
| 155 |   switch (msg) {
 | 
|---|
| 156 |   case WM_INITDLG:
 | 
|---|
| 157 |     if (!cmdhead) {
 | 
|---|
| 158 |       WinDismissDlg(hwnd, 0);
 | 
|---|
| 159 |       break;
 | 
|---|
| 160 |     }
 | 
|---|
| 161 |     {
 | 
|---|
| 162 |       LINKCMDS *info;
 | 
|---|
| 163 |       SHORT x;
 | 
|---|
| 164 | 
 | 
|---|
| 165 |       info = cmdhead;
 | 
|---|
| 166 |       while (info) {
 | 
|---|
| 167 |         x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_INSERTITEM,
 | 
|---|
| 168 |                                       MPFROMSHORT(LIT_END),
 | 
|---|
| 169 |                                       MPFROMP(info->title));
 | 
|---|
| 170 |         if (x < 0) {
 | 
|---|
| 171 |           Runtime_Error(pszSrcFile, __LINE__, "no cmd");
 | 
|---|
| 172 |           WinDismissDlg(hwnd, 0);
 | 
|---|
| 173 |         }
 | 
|---|
| 174 |         else {
 | 
|---|
| 175 |           WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SETITEMHANDLE,
 | 
|---|
| 176 |                             MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 177 |         }
 | 
|---|
| 178 |         info = info->next;
 | 
|---|
| 179 |       }
 | 
|---|
| 180 |     }
 | 
|---|
| 181 |     break;
 | 
|---|
| 182 | 
 | 
|---|
| 183 |   case WM_CONTROL:
 | 
|---|
| 184 |     return 0;
 | 
|---|
| 185 | 
 | 
|---|
| 186 |   case WM_COMMAND:
 | 
|---|
| 187 |     switch (SHORT1FROMMP(mp1)) {
 | 
|---|
| 188 |     case DID_CANCEL:
 | 
|---|
| 189 |       WinDismissDlg(hwnd, 0);
 | 
|---|
| 190 |       break;
 | 
|---|
| 191 | 
 | 
|---|
| 192 |     case DID_OK:
 | 
|---|
| 193 |       {
 | 
|---|
| 194 |         LINKCMDS *temphead = NULL, *info, *last = NULL, *temptail = NULL;
 | 
|---|
| 195 |         SHORT sSelect, numitems;
 | 
|---|
| 196 | 
 | 
|---|
| 197 |         sSelect = 0;
 | 
|---|
| 198 |         numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 199 |                                              LM_QUERYITEMCOUNT,
 | 
|---|
| 200 |                                              MPVOID, MPVOID);
 | 
|---|
| 201 |         while (numitems) {
 | 
|---|
| 202 |           info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 203 |                                                 LM_QUERYITEMHANDLE,
 | 
|---|
| 204 |                                                 MPFROMSHORT(sSelect++),
 | 
|---|
| 205 |                                                 MPVOID);
 | 
|---|
| 206 |           if (info) {
 | 
|---|
| 207 |             if (!temphead) {
 | 
|---|
| 208 |               temphead = info;
 | 
|---|
| 209 |               info->prev = NULL;
 | 
|---|
| 210 |             }
 | 
|---|
| 211 |             else {
 | 
|---|
| 212 |               last->next = info;
 | 
|---|
| 213 |               info->prev = last;
 | 
|---|
| 214 |             }
 | 
|---|
| 215 |             temptail = info;
 | 
|---|
| 216 |             last = info;
 | 
|---|
| 217 |             info->next = NULL;
 | 
|---|
| 218 |           }
 | 
|---|
| 219 |           numitems--;
 | 
|---|
| 220 |         }
 | 
|---|
| 221 |         sSelect = 0;
 | 
|---|
| 222 |         numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 223 |                                              LM_QUERYITEMCOUNT,
 | 
|---|
| 224 |                                              MPVOID, MPVOID);
 | 
|---|
| 225 |         while (numitems) {
 | 
|---|
| 226 |           info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 227 |                                                 LM_QUERYITEMHANDLE,
 | 
|---|
| 228 |                                                 MPFROMSHORT(sSelect++),
 | 
|---|
| 229 |                                                 MPVOID);
 | 
|---|
| 230 |           if (info) {
 | 
|---|
| 231 |             if (!temphead) {
 | 
|---|
| 232 |               temphead = info;
 | 
|---|
| 233 |               info->prev = NULL;
 | 
|---|
| 234 |             }
 | 
|---|
| 235 |             else {
 | 
|---|
| 236 |               last->next = info;
 | 
|---|
| 237 |               info->prev = last;
 | 
|---|
| 238 |             }
 | 
|---|
| 239 |             temptail = info;
 | 
|---|
| 240 |             last = info;
 | 
|---|
| 241 |             info->next = NULL;
 | 
|---|
| 242 |           }
 | 
|---|
| 243 |           numitems--;
 | 
|---|
| 244 |         }
 | 
|---|
| 245 |         cmdhead = temphead;
 | 
|---|
| 246 |         cmdtail = temptail;
 | 
|---|
| 247 |       }
 | 
|---|
| 248 |       WinDismissDlg(hwnd, 1);
 | 
|---|
| 249 |       break;
 | 
|---|
| 250 | 
 | 
|---|
| 251 |     case IDM_HELP:
 | 
|---|
| 252 |       if (hwndHelp)
 | 
|---|
| 253 |         WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
 | 
|---|
| 254 |                    MPFROM2SHORT(HELP_REORDERCOMMANDS, 0),
 | 
|---|
| 255 |                    MPFROMSHORT(HM_RESOURCEID));
 | 
|---|
| 256 |       break;
 | 
|---|
| 257 | 
 | 
|---|
| 258 |     case RE_ADD:
 | 
|---|
| 259 |       {
 | 
|---|
| 260 |         SHORT sSelect, x;
 | 
|---|
| 261 |         LINKCMDS *info;
 | 
|---|
| 262 | 
 | 
|---|
| 263 |         sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 264 |                                             LM_QUERYSELECTION,
 | 
|---|
| 265 |                                             MPFROMSHORT(LIT_FIRST), MPVOID);
 | 
|---|
| 266 |         while (sSelect >= 0) {
 | 
|---|
| 267 |           info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 268 |                                                 LM_QUERYITEMHANDLE,
 | 
|---|
| 269 |                                                 MPFROMSHORT(sSelect), MPVOID);
 | 
|---|
| 270 |           if (info) {
 | 
|---|
| 271 |             x = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 272 |                                           LM_INSERTITEM,
 | 
|---|
| 273 |                                           MPFROM2SHORT(LIT_END, 0),
 | 
|---|
| 274 |                                           MPFROMP(info->title));
 | 
|---|
| 275 |             if (x >= 0) {
 | 
|---|
| 276 |               WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 277 |                                 LM_SETITEMHANDLE,
 | 
|---|
| 278 |                                 MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 279 |               WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_DELETEITEM,
 | 
|---|
| 280 |                                 MPFROMSHORT(sSelect), MPVOID);
 | 
|---|
| 281 |             }
 | 
|---|
| 282 |           }
 | 
|---|
| 283 |           else
 | 
|---|
| 284 |             WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SELECTITEM,
 | 
|---|
| 285 |                               MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
 | 
|---|
| 286 |           sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 287 |                                                LM_QUERYSELECTION,
 | 
|---|
| 288 |                                                MPFROMSHORT(LIT_FIRST),
 | 
|---|
| 289 |                                                MPVOID);
 | 
|---|
| 290 |         }
 | 
|---|
| 291 |       }
 | 
|---|
| 292 |       break;
 | 
|---|
| 293 | 
 | 
|---|
| 294 |     case RE_REMOVE:
 | 
|---|
| 295 |       {
 | 
|---|
| 296 |         SHORT sSelect, x;
 | 
|---|
| 297 |         LINKCMDS *info;
 | 
|---|
| 298 | 
 | 
|---|
| 299 |         sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 300 |                                             LM_QUERYSELECTION,
 | 
|---|
| 301 |                                             MPFROMSHORT(LIT_FIRST), MPVOID);
 | 
|---|
| 302 |         while (sSelect >= 0) {
 | 
|---|
| 303 |           info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 304 |                                                 LM_QUERYITEMHANDLE,
 | 
|---|
| 305 |                                                 MPFROMSHORT(sSelect), MPVOID);
 | 
|---|
| 306 |           if (info) {
 | 
|---|
| 307 |             x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 308 |                                           LM_INSERTITEM,
 | 
|---|
| 309 |                                           MPFROM2SHORT(LIT_END, 0),
 | 
|---|
| 310 |                                           MPFROMP(info->title));
 | 
|---|
| 311 |             if (x >= 0) {
 | 
|---|
| 312 |               WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
 | 
|---|
| 313 |                                 LM_SETITEMHANDLE,
 | 
|---|
| 314 |                                 MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 315 |               WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_DELETEITEM,
 | 
|---|
| 316 |                                 MPFROMSHORT(sSelect), MPVOID);
 | 
|---|
| 317 |             }
 | 
|---|
| 318 |           }
 | 
|---|
| 319 |           else
 | 
|---|
| 320 |             WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_SELECTITEM,
 | 
|---|
| 321 |                               MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
 | 
|---|
| 322 |           sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
 | 
|---|
| 323 |                                                LM_QUERYSELECTION,
 | 
|---|
| 324 |                                                MPFROMSHORT(LIT_FIRST),
 | 
|---|
| 325 |                                                MPVOID);
 | 
|---|
| 326 |         }
 | 
|---|
| 327 |       }
 | 
|---|
| 328 |       break;
 | 
|---|
| 329 |     }
 | 
|---|
| 330 |     return 0;
 | 
|---|
| 331 |   }
 | 
|---|
| 332 |   return WinDefDlgProc(hwnd, msg, mp1, mp2);
 | 
|---|
| 333 | }
 | 
|---|
| 334 | 
 | 
|---|
| 335 | CHAR *command_title(INT cx)
 | 
|---|
| 336 | {
 | 
|---|
| 337 |   static CHAR duh[] = "???";
 | 
|---|
| 338 |   LINKCMDS *info;
 | 
|---|
| 339 |   INT x = 0;
 | 
|---|
| 340 | 
 | 
|---|
| 341 |   if (!cmdloaded)
 | 
|---|
| 342 |     load_commands();
 | 
|---|
| 343 |   info = cmdhead;
 | 
|---|
| 344 |   while (info) {
 | 
|---|
| 345 |     if (x == cx)
 | 
|---|
| 346 |       return info->title;
 | 
|---|
| 347 |     info = info->next;
 | 
|---|
| 348 |   }
 | 
|---|
| 349 |   return duh;
 | 
|---|
| 350 | }
 | 
|---|
| 351 | 
 | 
|---|
| 352 | VOID free_commands(VOID)
 | 
|---|
| 353 | {
 | 
|---|
| 354 |   LINKCMDS *info, *next;
 | 
|---|
| 355 | 
 | 
|---|
| 356 |   info = cmdhead;
 | 
|---|
| 357 |   while (info) {
 | 
|---|
| 358 |     next = info->next;
 | 
|---|
| 359 |     xfree(info->title, pszSrcFile, __LINE__);
 | 
|---|
| 360 |     xfree(info->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 361 |     xfree(info->env, pszSrcFile, __LINE__);
 | 
|---|
| 362 |     free(info);
 | 
|---|
| 363 |     info = next;
 | 
|---|
| 364 |   }
 | 
|---|
| 365 |   free(pszCommandsList);
 | 
|---|
| 366 |   cmdhead = cmdtail = NULL;
 | 
|---|
| 367 | }
 | 
|---|
| 368 | 
 | 
|---|
| 369 | VOID load_commands(VOID)
 | 
|---|
| 370 | {
 | 
|---|
| 371 |   FILE *fp;
 | 
|---|
| 372 |   LINKCMDS *info;
 | 
|---|
| 373 |   PSZ pszCmdLine;
 | 
|---|
| 374 |   CHAR title[100];
 | 
|---|
| 375 |   CHAR flags[34];
 | 
|---|
| 376 |   CHAR *moder = "r";
 | 
|---|
| 377 |   ULONG size;
 | 
|---|
| 378 | 
 | 
|---|
| 379 | 
 | 
|---|
| 380 |   /*size = sizeof(BOOL) * 300;
 | 
|---|
| 381 |   PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
 | 
|---|
| 382 |                       &size);
 | 
|---|
| 383 |   size = sizeof(BOOL) * 40;
 | 
|---|
| 384 |   PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
 | 
|---|
| 385 |                       &size);*/    // No need to use profile just count them GKY 02 JUL 11
 | 
|---|
| 386 |   size = sizeof(BOOL);
 | 
|---|
| 387 |   PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
 | 
|---|
| 388 |                       &fLoadCommandsFromINI, &size);
 | 
|---|
| 389 |   if (!fLoadCommandsFromINI) {
 | 
|---|
| 390 |     if (cmdhead)
 | 
|---|
| 391 |       free_commands();
 | 
|---|
| 392 |     cmdloaded = TRUE;
 | 
|---|
| 393 |     pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
 | 
|---|
| 394 |     pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
 | 
|---|
| 395 |     if (pszCmdLine) {
 | 
|---|
| 396 |       BldFullPathName(pszCmdLine, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
 | 
|---|
| 397 |       fp = xfsopen(pszCmdLine, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
 | 
|---|
| 398 |       if (fp) {
 | 
|---|
| 399 |         while (!feof(fp)) {
 | 
|---|
| 400 |           if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
 | 
|---|
| 401 |             break;
 | 
|---|
| 402 |           if (!*title || *title == ';')
 | 
|---|
| 403 |             continue;
 | 
|---|
| 404 |           if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
 | 
|---|
| 405 |             break;                              /* error! */
 | 
|---|
| 406 |           if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
 | 
|---|
| 407 |             break;
 | 
|---|
| 408 |           flags[34] = 0;
 | 
|---|
| 409 |           if (!pszCmdLine)
 | 
|---|
| 410 |             continue;
 | 
|---|
| 411 |           info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
 | 
|---|
| 412 |           if (info) {
 | 
|---|
| 413 |   #       ifdef FORTIFY
 | 
|---|
| 414 |             Fortify_SetOwner(info, 1);
 | 
|---|
| 415 |             Fortify_SetScope(info, 1);
 | 
|---|
| 416 |   #       endif
 | 
|---|
| 417 |             info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 418 | 
 | 
|---|
| 419 |             if (pszCommandsList) {
 | 
|---|
| 420 |               strcpy(pszCommandsList + strlen(pszCommandsList), title);
 | 
|---|
| 421 |               strcpy(pszCommandsList + strlen(pszCommandsList), ";");
 | 
|---|
| 422 |             }
 | 
|---|
| 423 |             info->title = xstrdup(title, pszSrcFile, __LINE__);
 | 
|---|
| 424 |             info->flags = atol(flags);
 | 
|---|
| 425 |             if (!info->pszCmdLine || !info->title) {
 | 
|---|
| 426 |               xfree(info->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 427 |               xfree(info->title, pszSrcFile, __LINE__);
 | 
|---|
| 428 |               free(info);
 | 
|---|
| 429 |               break;
 | 
|---|
| 430 |             }
 | 
|---|
| 431 |   #       ifdef FORTIFY
 | 
|---|
| 432 |             Fortify_SetOwner(info->pszCmdLine, 1);
 | 
|---|
| 433 |             Fortify_SetScope(info->pszCmdLine, 1);
 | 
|---|
| 434 |             Fortify_SetOwner(info->title, 1);
 | 
|---|
| 435 |             Fortify_SetScope(info->title, 1);
 | 
|---|
| 436 |   #       endif
 | 
|---|
| 437 |             if (!cmdhead)
 | 
|---|
| 438 |               cmdhead = info;
 | 
|---|
| 439 |             else {
 | 
|---|
| 440 |               cmdtail->next = info;
 | 
|---|
| 441 |               info->prev = cmdtail;
 | 
|---|
| 442 |             }
 | 
|---|
| 443 |             cmdtail = info;
 | 
|---|
| 444 |           }
 | 
|---|
| 445 |         }
 | 
|---|
| 446 |         free(pszCmdLine);
 | 
|---|
| 447 |         fclose(fp);
 | 
|---|
| 448 |         if (pszCommandsList) {
 | 
|---|
| 449 |           ulSizeCommandsList = strlen(pszCommandsList) + 1;
 | 
|---|
| 450 |         }
 | 
|---|
| 451 |       }
 | 
|---|
| 452 |     }
 | 
|---|
| 453 |   }
 | 
|---|
| 454 |   load_inicommands();
 | 
|---|
| 455 | }
 | 
|---|
| 456 | 
 | 
|---|
| 457 | /**
 | 
|---|
| 458 |  * load_inicommand loads the data from the ini file into an info struct
 | 
|---|
| 459 |  * after COMMANDS.DAT has been loaded; It generates new IDs where necessary
 | 
|---|
| 460 |  * it saves the environment from the old ini key and deletes it as needed
 | 
|---|
| 461 |  **/
 | 
|---|
| 462 | 
 | 
|---|
| 463 | VOID load_inicommands(VOID)
 | 
|---|
| 464 | {
 | 
|---|
| 465 |   LINKCMDS *info;;
 | 
|---|
| 466 |   INT x = 0;
 | 
|---|
| 467 |   INT y = 0;
 | 
|---|
| 468 |   ULONG ID = 0;
 | 
|---|
| 469 |   ULONG HotKeyID = 0;
 | 
|---|
| 470 |   CHAR env[ENVIRONMENT_SIZE];
 | 
|---|
| 471 |   CHAR key[120];
 | 
|---|
| 472 |   CHAR szTitle[100];
 | 
|---|
| 473 |   ULONG size;
 | 
|---|
| 474 |   CHAR *p, *pp;
 | 
|---|
| 475 |   PSZ pszCmdLine;
 | 
|---|
| 476 |   ULONG flags;
 | 
|---|
| 477 | 
 | 
|---|
| 478 | #   ifdef FORTIFY
 | 
|---|
| 479 |   Fortify_EnterScope();
 | 
|---|
| 480 | #    endif
 | 
|---|
| 481 |   pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
 | 
|---|
| 482 |   if (pszCmdLine) {
 | 
|---|
| 483 |     if (fLoadCommandsFromINI) {
 | 
|---|
| 484 |       if (cmdhead)
 | 
|---|
| 485 |         free_commands();
 | 
|---|
| 486 |       cmdloaded = TRUE;
 | 
|---|
| 487 |       size = sizeof(ULONG);
 | 
|---|
| 488 |       PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
 | 
|---|
| 489 |                           &ulSizeCommandsList, &size);
 | 
|---|
| 490 |       pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
 | 
|---|
| 491 |       if (pszCommandsList) {
 | 
|---|
| 492 |         PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
 | 
|---|
| 493 |                               NullStr, pszCommandsList, ulSizeCommandsList);
 | 
|---|
| 494 |         p = pszCommandsList;
 | 
|---|
| 495 |         while (*p == ';')
 | 
|---|
| 496 |           p++;
 | 
|---|
| 497 |         while (*p) {
 | 
|---|
| 498 |           *szTitle = 0;
 | 
|---|
| 499 |           pp = szTitle;
 | 
|---|
| 500 |           while (*p && *p != ';')
 | 
|---|
| 501 |             *pp++ = *p++;
 | 
|---|
| 502 |           *pp = 0;
 | 
|---|
| 503 |           while (*p == ';')
 | 
|---|
| 504 |             p++;
 | 
|---|
| 505 |           if (*szTitle) {
 | 
|---|
| 506 |             bstripcr(szTitle);
 | 
|---|
| 507 |             sprintf(key, "COMMAND.%sID", szTitle);
 | 
|---|
| 508 |             size = sizeof(ULONG);
 | 
|---|
| 509 |             PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
 | 
|---|
| 510 |             UsedCommandIDs[ID - IDM_COMMANDSTART] = TRUE; // No need to use profile just count them GKY 02 JUL 11
 | 
|---|
| 511 |             sprintf(key, "COMMAND.%sHotKeyID", szTitle);
 | 
|---|
| 512 |             size = sizeof(ULONG);
 | 
|---|
| 513 |             PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
 | 
|---|
| 514 |             UsedHotKeyIDs[HotKeyID - IDM_COMMANDNUM0] = TRUE;  // No need to use profile just count them GKY 02 JUL 11
 | 
|---|
| 515 |             sprintf(key, "COMMAND.%sflags", szTitle);
 | 
|---|
| 516 |             size = sizeof(ULONG);
 | 
|---|
| 517 |             PrfQueryProfileData(fmprof, FM3Str, key, &flags, &size);
 | 
|---|
| 518 |             sprintf(key, "COMMAND.%senv", szTitle);
 | 
|---|
| 519 |             PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
 | 
|---|
| 520 |             sprintf(key, "COMMAND.%sCmdLine", szTitle);
 | 
|---|
| 521 |             PrfQueryProfileString(fmprof, FM3Str, key, NullStr, pszCmdLine, MaxComLineStrg);
 | 
|---|
| 522 |           }
 | 
|---|
| 523 |           info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
 | 
|---|
| 524 |           if (info) {
 | 
|---|
| 525 |   #       ifdef FORTIFY
 | 
|---|
| 526 |             Fortify_SetOwner(info, 1);
 | 
|---|
| 527 |             Fortify_SetScope(info, 1);
 | 
|---|
| 528 |   #       endif
 | 
|---|
| 529 |             info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 530 |             info->title = xstrdup(szTitle, pszSrcFile, __LINE__);
 | 
|---|
| 531 |             info->flags = flags;
 | 
|---|
| 532 |             if (env != NullStr)
 | 
|---|
| 533 |               info->env = xstrdup(env, pszSrcFile, __LINE__);
 | 
|---|
| 534 |             info->ID = ID;
 | 
|---|
| 535 |             info->HotKeyID = HotKeyID;
 | 
|---|
| 536 |             if (!info->pszCmdLine || !info->title) {
 | 
|---|
| 537 |               xfree(info->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 538 |               xfree(info->title, pszSrcFile, __LINE__);
 | 
|---|
| 539 |               xfree(info->env, pszSrcFile, __LINE__);
 | 
|---|
| 540 |               free(info);
 | 
|---|
| 541 |               break;
 | 
|---|
| 542 |             }
 | 
|---|
| 543 |             if (!cmdhead)
 | 
|---|
| 544 |               cmdhead = info;
 | 
|---|
| 545 |             else {
 | 
|---|
| 546 |               cmdtail->next = info;
 | 
|---|
| 547 |               info->prev = cmdtail;
 | 
|---|
| 548 |             }
 | 
|---|
| 549 |             cmdtail = info;
 | 
|---|
| 550 |           }
 | 
|---|
| 551 |         }
 | 
|---|
| 552 |       }
 | 
|---|
| 553 |     }
 | 
|---|
| 554 |     else {
 | 
|---|
| 555 |       info = cmdhead;
 | 
|---|
| 556 |       while (info) {
 | 
|---|
| 557 |         bstripcr(info->title);
 | 
|---|
| 558 |         sprintf(key, "COMMAND.%sID", info->title);
 | 
|---|
| 559 |         size = sizeof(ULONG);
 | 
|---|
| 560 |         PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
 | 
|---|
| 561 |         sprintf(key, "COMMAND.%sHotKeyID", info->title);
 | 
|---|
| 562 |         size = sizeof(ULONG);
 | 
|---|
| 563 |         PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
 | 
|---|
| 564 |         sprintf(key, "COMMAND.%senv", info->title);
 | 
|---|
| 565 |         PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
 | 
|---|
| 566 |         if (ID != 0) {
 | 
|---|
| 567 |           if (env != NullStr)
 | 
|---|
| 568 |             info->env = xstrdup(env, pszSrcFile, __LINE__);
 | 
|---|
| 569 |           info->ID = ID;
 | 
|---|
| 570 |           info->HotKeyID = HotKeyID;
 | 
|---|
| 571 |         }
 | 
|---|
| 572 |         //This updates the old commands.dat file to the new format
 | 
|---|
| 573 |         //assigning the IDs based on file order or on next available ID 
 | 
|---|
| 574 |         else {
 | 
|---|
| 575 |           for (x = 0; x < 300; x++) {
 | 
|---|
| 576 |             if (!UsedCommandIDs[x]) {
 | 
|---|
| 577 |               ID = info->ID = IDM_COMMANDSTART + x;
 | 
|---|
| 578 |               UsedCommandIDs[x] = TRUE;
 | 
|---|
| 579 |               for (y = 0; y < 40; y++) {
 | 
|---|
| 580 |                 if (!UsedHotKeyIDs[y]) {
 | 
|---|
| 581 |                   HotKeyID = info->HotKeyID = IDM_COMMANDNUM0 + y;
 | 
|---|
| 582 |                   UsedHotKeyIDs[y] = TRUE;
 | 
|---|
| 583 |                   break;
 | 
|---|
| 584 |                 }
 | 
|---|
| 585 |               }
 | 
|---|
| 586 |               break;
 | 
|---|
| 587 |             }
 | 
|---|
| 588 |             if (x == 299)
 | 
|---|
| 589 |               saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
 | 
|---|
| 590 |                      GetPString(IDS_COMMANDSLIMITTITLETEXT),
 | 
|---|
| 591 |                      GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
 | 
|---|
| 592 |           }
 | 
|---|
| 593 |           PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
 | 
|---|
| 594 |           info->env = xstrdup(env, pszSrcFile, __LINE__);
 | 
|---|
| 595 |         }
 | 
|---|
| 596 |         ID = 0;
 | 
|---|
| 597 |         HotKeyID = 0;
 | 
|---|
| 598 |         info = info->next;
 | 
|---|
| 599 |       }
 | 
|---|
| 600 |       fLoadCommandsFromINI = TRUE;
 | 
|---|
| 601 |       save_commands();
 | 
|---|
| 602 |     }
 | 
|---|
| 603 |     free(pszCmdLine);
 | 
|---|
| 604 |   }
 | 
|---|
| 605 | }
 | 
|---|
| 606 | 
 | 
|---|
| 607 | VOID save_commands(VOID)
 | 
|---|
| 608 | {
 | 
|---|
| 609 |   LINKCMDS *info;
 | 
|---|
| 610 |   CHAR key[120];
 | 
|---|
| 611 |   
 | 
|---|
| 612 |   if (!cmdloaded || !cmdhead)
 | 
|---|
| 613 |     return;
 | 
|---|
| 614 |   
 | 
|---|
| 615 |   info = cmdhead;
 | 
|---|
| 616 |   pszCommandsList[0] = 0;
 | 
|---|
| 617 |     while (info) {
 | 
|---|
| 618 |       sprintf(key, "COMMAND.%sflags", info->title);
 | 
|---|
| 619 |       PrfWriteProfileData(fmprof, FM3Str, key, &info->flags, sizeof(ULONG));
 | 
|---|
| 620 |       sprintf(key, "COMMAND.%sCmdLine", info->title);
 | 
|---|
| 621 |       PrfWriteProfileString(fmprof, FM3Str, key, info->pszCmdLine);
 | 
|---|
| 622 |       bstripcr(info->title);
 | 
|---|
| 623 |       sprintf(key, "COMMAND.%sID", info->title);
 | 
|---|
| 624 |       PrfWriteProfileData(fmprof, FM3Str, key, &info->ID, sizeof(INT));
 | 
|---|
| 625 |       UsedCommandIDs[info->ID - IDM_COMMANDSTART] = TRUE;
 | 
|---|
| 626 |       sprintf(key, "COMMAND.%sHotKeyID", info->title);
 | 
|---|
| 627 |       PrfWriteProfileData(fmprof, FM3Str, key, &info->HotKeyID, sizeof(INT));
 | 
|---|
| 628 |       UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
 | 
|---|
| 629 |       if (info->env != NullStr) {
 | 
|---|
| 630 |         sprintf(key, "COMMAND.%senv", info->title);
 | 
|---|
| 631 |         PrfWriteProfileString(fmprof, FM3Str, key, info->env);
 | 
|---|
| 632 |       }
 | 
|---|
| 633 |       if ((strlen(pszCommandsList) + strlen(info->title) + 1) > ulSizeCommandsList)
 | 
|---|
| 634 |         pszCommandsList = xrealloc(pszCommandsList,
 | 
|---|
| 635 |                                    ulSizeCommandsList + strlen(info->title) + 1,
 | 
|---|
| 636 |                                    pszSrcFile, __LINE__);
 | 
|---|
| 637 |       strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
 | 
|---|
| 638 |       strcpy(pszCommandsList + strlen(pszCommandsList), ";");
 | 
|---|
| 639 |       info = info->next;
 | 
|---|
| 640 |     } // while info
 | 
|---|
| 641 |     PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
 | 
|---|
| 642 |                         sizeof(BOOL) * 300); // left for backward compatability GKY 02 Jul 11
 | 
|---|
| 643 |     PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
 | 
|---|
| 644 |                         sizeof(BOOL) * 40);// left for backward compatability GKY 02 Jul 11
 | 
|---|
| 645 |     ulSizeCommandsList = strlen(pszCommandsList) + 1;
 | 
|---|
| 646 |     PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
 | 
|---|
| 647 |                         &ulSizeCommandsList, sizeof(ULONG));
 | 
|---|
| 648 |     PrfWriteProfileString(fmprof, FM3Str, "COMMANDS.SortOrder", pszCommandsList);
 | 
|---|
| 649 |     PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
 | 
|---|
| 650 |                         &fLoadCommandsFromINI, sizeof(BOOL));
 | 
|---|
| 651 | }
 | 
|---|
| 652 | 
 | 
|---|
| 653 | //== add_command() Add command to list ==
 | 
|---|
| 654 | 
 | 
|---|
| 655 | LINKCMDS *add_command(COMMAND *addme, BOOL fDontCheckHotKey)
 | 
|---|
| 656 | {
 | 
|---|
| 657 |   LINKCMDS *info;
 | 
|---|
| 658 |   INT x;
 | 
|---|
| 659 |   INT y;
 | 
|---|
| 660 |   APIRET ret;
 | 
|---|
| 661 | 
 | 
|---|
| 662 |   if (!addme || !*addme->pszCmdLine || !*addme->title)
 | 
|---|
| 663 |     return NULL;                        // No data
 | 
|---|
| 664 | #   ifdef FORTIFY
 | 
|---|
| 665 |     Fortify_EnterScope();
 | 
|---|
| 666 | #    endif
 | 
|---|
| 667 |   info = cmdhead;
 | 
|---|
| 668 |   while (info) {
 | 
|---|
| 669 |     if (!stricmp(info->title, addme->title))
 | 
|---|
| 670 |       return NULL;                      // Got a dup
 | 
|---|
| 671 |     info = info->next;
 | 
|---|
| 672 |   }
 | 
|---|
| 673 |   if (!fDontCheckHotKey && UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0]) {
 | 
|---|
| 674 |     info = cmdhead;
 | 
|---|
| 675 |     while (info) {
 | 
|---|
| 676 |       if (info->HotKeyID == addme->HotKeyID) { //avoid assigning hot key to multiple commands
 | 
|---|
| 677 |         ret = saymsg(MB_YESNOCANCEL, HWND_DESKTOP, NullStr,
 | 
|---|
| 678 |                      GetPString(IDS_DUPLICATEHOTKEYTEXT));
 | 
|---|
| 679 |         if (ret == MBID_YES) {
 | 
|---|
| 680 |           info->HotKeyID = 0;  
 | 
|---|
| 681 |           UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0] = FALSE;
 | 
|---|
| 682 |           break;
 | 
|---|
| 683 |         }
 | 
|---|
| 684 |         else if (ret == MBID_NO) {
 | 
|---|
| 685 |           addme->HotKeyID = 0;
 | 
|---|
| 686 |           break;
 | 
|---|
| 687 |         }
 | 
|---|
| 688 |         else
 | 
|---|
| 689 |           return (LINKCMDS *) -1;
 | 
|---|
| 690 |       }
 | 
|---|
| 691 |       info = info->next;
 | 
|---|
| 692 |     }
 | 
|---|
| 693 |   }
 | 
|---|
| 694 |   info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
 | 
|---|
| 695 |   if (!info)
 | 
|---|
| 696 |     return NULL;
 | 
|---|
| 697 |   info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 698 |   info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
 | 
|---|
| 699 |   info->HotKeyID = addme->HotKeyID;
 | 
|---|
| 700 |   info->ID = addme->ID;
 | 
|---|
| 701 |   if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM39) {
 | 
|---|
| 702 |     UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
 | 
|---|
| 703 |   }
 | 
|---|
| 704 |   else
 | 
|---|
| 705 |     info->HotKeyID = 0;
 | 
|---|
| 706 |   if (!info->ID) {
 | 
|---|
| 707 |     //profile updated by save_commands
 | 
|---|
| 708 |     for (x = 0; x < 300; x++) {
 | 
|---|
| 709 |       if (!UsedCommandIDs[x]) {
 | 
|---|
| 710 |         info->ID = IDM_COMMANDSTART + x;
 | 
|---|
| 711 |         UsedCommandIDs[x] = TRUE;
 | 
|---|
| 712 |         if (!info->HotKeyID && !fDontCheckHotKey) {
 | 
|---|
| 713 |           for (y = 0; y < 40; y++) {
 | 
|---|
| 714 |             if (!UsedHotKeyIDs[y]) {
 | 
|---|
| 715 |               info->HotKeyID = IDM_COMMANDNUM0 + y;
 | 
|---|
| 716 |               UsedHotKeyIDs[y] = TRUE;
 | 
|---|
| 717 |               break;
 | 
|---|
| 718 |             }
 | 
|---|
| 719 |           }
 | 
|---|
| 720 |         }
 | 
|---|
| 721 |         break;
 | 
|---|
| 722 |       }
 | 
|---|
| 723 |       if (x == 299)
 | 
|---|
| 724 |         saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
 | 
|---|
| 725 |                GetPString(IDS_COMMANDSLIMITTITLETEXT),
 | 
|---|
| 726 |                GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
 | 
|---|
| 727 |     }
 | 
|---|
| 728 |   }
 | 
|---|
| 729 |   if (addme->flags)
 | 
|---|
| 730 |     info->flags = addme->flags;
 | 
|---|
| 731 |   if (addme->env)
 | 
|---|
| 732 |     info->env = xstrdup(addme->env, pszSrcFile, __LINE__);
 | 
|---|
| 733 |   if (!info->pszCmdLine || !info->title || !info->ID) {
 | 
|---|
| 734 |     xfree(info->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 735 |     xfree(info->title, pszSrcFile, __LINE__);
 | 
|---|
| 736 |     xfree(info->env, pszSrcFile, __LINE__);
 | 
|---|
| 737 |     free(info);
 | 
|---|
| 738 |     return NULL;
 | 
|---|
| 739 |   }
 | 
|---|
| 740 |   if (!cmdhead)                         /* only item in list */
 | 
|---|
| 741 |     cmdhead = cmdtail = info;
 | 
|---|
| 742 |   else {
 | 
|---|
| 743 |     /* place at tail */
 | 
|---|
| 744 |     cmdtail->next = info;
 | 
|---|
| 745 |     info->prev = cmdtail;
 | 
|---|
| 746 |     cmdtail = info;
 | 
|---|
| 747 |   }
 | 
|---|
| 748 |   pszCommandsList = xrealloc(pszCommandsList, ulSizeCommandsList + strlen(info->title) + 1,
 | 
|---|
| 749 |                              pszSrcFile, __LINE__);
 | 
|---|
| 750 |   if (pszCommandsList) {
 | 
|---|
| 751 |     strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
 | 
|---|
| 752 |     strcpy(pszCommandsList + strlen(pszCommandsList), ";");
 | 
|---|
| 753 |     ulSizeCommandsList = ulSizeCommandsList + strlen(info->title) + 1;
 | 
|---|
| 754 |   }
 | 
|---|
| 755 |   else {
 | 
|---|
| 756 |     pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
 | 
|---|
| 757 |     if (pszCommandsList)
 | 
|---|
| 758 |       PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
 | 
|---|
| 759 |                             NullStr, pszCommandsList, ulSizeCommandsList);
 | 
|---|
| 760 |     return 0;
 | 
|---|
| 761 |   }
 | 
|---|
| 762 |   return info;
 | 
|---|
| 763 | }
 | 
|---|
| 764 | 
 | 
|---|
| 765 | BOOL kill_command(CHAR * killme)
 | 
|---|
| 766 | {
 | 
|---|
| 767 |   LINKCMDS *info;
 | 
|---|
| 768 | 
 | 
|---|
| 769 |   if (killme && *killme) {
 | 
|---|
| 770 |     info = cmdhead;
 | 
|---|
| 771 |     while (info) {
 | 
|---|
| 772 |       if (!stricmp(info->title, killme)) {
 | 
|---|
| 773 |         UsedCommandIDs[info->ID - IDM_COMMANDSTART] = FALSE;
 | 
|---|
| 774 |         if (info->HotKeyID)
 | 
|---|
| 775 |           UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = FALSE;
 | 
|---|
| 776 |         if (info == cmdhead) {
 | 
|---|
| 777 |           cmdhead = info->next;
 | 
|---|
| 778 |           if (info == cmdtail)
 | 
|---|
| 779 |             cmdtail = info->prev;
 | 
|---|
| 780 |         }
 | 
|---|
| 781 |         else {
 | 
|---|
| 782 |           if (info->next)
 | 
|---|
| 783 |             (info->next)->prev = info->prev;
 | 
|---|
| 784 |           if (info->prev)
 | 
|---|
| 785 |             (info->prev)->next = info->next;
 | 
|---|
| 786 |           if (info == cmdtail)
 | 
|---|
| 787 |             cmdtail = info->prev;
 | 
|---|
| 788 |         }
 | 
|---|
| 789 |         xfree(info->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 790 |         xfree(info->title, pszSrcFile, __LINE__);
 | 
|---|
| 791 |         xfree(info->env, pszSrcFile, __LINE__);
 | 
|---|
| 792 |         free(info);
 | 
|---|
| 793 |         return TRUE;
 | 
|---|
| 794 |       }
 | 
|---|
| 795 |       info = info->next;
 | 
|---|
| 796 |     }
 | 
|---|
| 797 |   }
 | 
|---|
| 798 | #   ifdef FORTIFY
 | 
|---|
| 799 |     Fortify_LeaveScope();
 | 
|---|
| 800 | #    endif
 | 
|---|
| 801 |   return FALSE;
 | 
|---|
| 802 | }
 | 
|---|
| 803 | 
 | 
|---|
| 804 | BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp)
 | 
|---|
| 805 | {
 | 
|---|
| 806 |    PSZ pszWorkBuf;
 | 
|---|
| 807 |    APIRET ret;
 | 
|---|
| 808 |    CHAR env[ENVIRONMENT_SIZE];
 | 
|---|
| 809 |    INT x;
 | 
|---|
| 810 | 
 | 
|---|
| 811 |    pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
 | 
|---|
| 812 |    if (!pszWorkBuf) {
 | 
|---|
| 813 |      return FALSE; //already complained
 | 
|---|
| 814 |    }
 | 
|---|
| 815 |    WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp->pszCmdLine);
 | 
|---|
| 816 |    NormalizeCmdLine(pszWorkBuf, temp->pszCmdLine);
 | 
|---|
| 817 |    memcpy(temp->pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
 | 
|---|
| 818 |    free(pszWorkBuf);
 | 
|---|
| 819 |    if (fCancelAction) {
 | 
|---|
| 820 |      fCancelAction = FALSE;
 | 
|---|
| 821 |      return FALSE;
 | 
|---|
| 822 |    }
 | 
|---|
| 823 |    if (!strchr(temp->pszCmdLine, '%')) {
 | 
|---|
| 824 |      ret = saymsg(MB_YESNO,
 | 
|---|
| 825 |                   HWND_DESKTOP,
 | 
|---|
| 826 |                   NullStr,
 | 
|---|
| 827 |                   GetPString(IDS_TOACTONSELECTEDTEXT));
 | 
|---|
| 828 |      if (ret == MBID_YES)
 | 
|---|
| 829 |        strcat(temp->pszCmdLine, " %a");
 | 
|---|
| 830 |    }
 | 
|---|
| 831 |    WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp->title), temp->title);
 | 
|---|
| 832 |    bstripcr(temp->title);
 | 
|---|
| 833 |    temp->flags = CheckExecutibleFlags(hwnd, 3);
 | 
|---|
| 834 |    *env = 0;
 | 
|---|
| 835 |    WinQueryDlgItemText(hwnd, CMD_ENVIRON, ENVIRONMENT_SIZE - 1, env);
 | 
|---|
| 836 |    bstripcr(env);
 | 
|---|
| 837 |    if (*env)
 | 
|---|
| 838 |      strcpy(temp->env, env);
 | 
|---|
| 839 |    x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_HOTKEY,
 | 
|---|
| 840 |                                  LM_QUERYSELECTION,
 | 
|---|
| 841 |                                  MPFROMSHORT(LIT_FIRST), MPVOID);
 | 
|---|
| 842 |    if (x < 40)
 | 
|---|
| 843 |      temp->HotKeyID = x + IDM_COMMANDNUM0;
 | 
|---|
| 844 |    else
 | 
|---|
| 845 |      temp->HotKeyID = 0;
 | 
|---|
| 846 |    //DbgMsg(pszSrcFile, __LINE__, "info %i", temp->HotKeyID);
 | 
|---|
| 847 |    return TRUE;
 | 
|---|
| 848 | }
 | 
|---|
| 849 | 
 | 
|---|
| 850 | MRESULT EXPENTRY CommandDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 | 
|---|
| 851 | {
 | 
|---|
| 852 |   SHORT x, y;
 | 
|---|
| 853 |   LINKCMDS *info;
 | 
|---|
| 854 | 
 | 
|---|
| 855 | #   ifdef FORTIFY
 | 
|---|
| 856 |     Fortify_EnterScope();
 | 
|---|
| 857 | #    endif
 | 
|---|
| 858 |   switch (msg) {
 | 
|---|
| 859 |   case WM_INITDLG:
 | 
|---|
| 860 |     WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
 | 
|---|
| 861 |     WinSendDlgItemMsg(hwnd, CMD_CL, EM_SETTEXTLIMIT,
 | 
|---|
| 862 |                       MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
 | 
|---|
| 863 |     WinSendDlgItemMsg(hwnd, CMD_TITLE, EM_SETTEXTLIMIT,
 | 
|---|
| 864 |                       MPFROM2SHORT(99, 0), MPVOID);
 | 
|---|
| 865 |     WinSetDlgItemText(hwnd, CMD_CL, NullStr);
 | 
|---|
| 866 |     WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
 | 
|---|
| 867 |     WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
 | 
|---|
| 868 |     WinCheckButton(hwnd, CMD_PROMPT, FALSE);
 | 
|---|
| 869 |     WinCheckButton(hwnd, CMD_ONCE, FALSE);
 | 
|---|
| 870 |     info = cmdhead;
 | 
|---|
| 871 |     while (info) {
 | 
|---|
| 872 |       x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_INSERTITEM,
 | 
|---|
| 873 |                                     MPFROM2SHORT(LIT_END, 0),
 | 
|---|
| 874 |                                     MPFROMP(info->title));
 | 
|---|
| 875 |       if (x >= 0)
 | 
|---|
| 876 |         WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SETITEMHANDLE,
 | 
|---|
| 877 |                           MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 878 |       info = info->next;
 | 
|---|
| 879 |     }
 | 
|---|
| 880 |     WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SELECTITEM,
 | 
|---|
| 881 |                       MPFROMSHORT(0), MPFROMSHORT(TRUE));
 | 
|---|
| 882 |     {
 | 
|---|
| 883 |       PFNWP oldproc;
 | 
|---|
| 884 | 
 | 
|---|
| 885 |       oldproc = WinSubclassWindow(WinWindowFromID(hwnd, CMD_CL),
 | 
|---|
| 886 |                                   (PFNWP) CommandTextProc);
 | 
|---|
| 887 |       if (oldproc)
 | 
|---|
| 888 |         WinSetWindowPtr(WinWindowFromID(hwnd, CMD_CL), QWL_USER, (PVOID) oldproc);
 | 
|---|
| 889 |     }
 | 
|---|
| 890 |     break;
 | 
|---|
| 891 | 
 | 
|---|
| 892 |   case WM_CONTROL:
 | 
|---|
| 893 |     if (SHORT1FROMMP(mp1) == CMD_LISTBOX) {
 | 
|---|
| 894 |       switch (SHORT2FROMMP(mp1)) {
 | 
|---|
| 895 |       case LN_ENTER:
 | 
|---|
| 896 |       case LN_SELECT:
 | 
|---|
| 897 |         x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
 | 
|---|
| 898 |                                       LM_QUERYSELECTION,
 | 
|---|
| 899 |                                       MPFROMSHORT(LIT_FIRST), MPVOID);
 | 
|---|
| 900 |         if (x >= 0) {
 | 
|---|
| 901 |           info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
 | 
|---|
| 902 |                                                 LM_QUERYITEMHANDLE,
 | 
|---|
| 903 |                                                 MPFROMSHORT(x), MPVOID);
 | 
|---|
| 904 |           if (!info) {
 | 
|---|
| 905 |             Runtime_Error(pszSrcFile, __LINE__, "LM_QUERYITEMHANDLE");
 | 
|---|
| 906 |             break;
 | 
|---|
| 907 |           }
 | 
|---|
| 908 |           WinSetDlgItemText(hwnd, CMD_CL, info->pszCmdLine);
 | 
|---|
| 909 |           if (!(info->flags & 1023))
 | 
|---|
| 910 |             WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
 | 
|---|
| 911 |           else {
 | 
|---|
| 912 |             if (info->flags & FULLSCREEN)
 | 
|---|
| 913 |               WinCheckButton(hwnd, CMD_FULLSCREEN, TRUE);
 | 
|---|
| 914 |             else if (info->flags & MINIMIZED)
 | 
|---|
| 915 |               WinCheckButton(hwnd, CMD_MINIMIZED, TRUE);
 | 
|---|
| 916 |             else if (info->flags & MAXIMIZED)
 | 
|---|
| 917 |               WinCheckButton(hwnd, CMD_MAXIMIZED, TRUE);
 | 
|---|
| 918 |             else if (info->flags & INVISIBLE)
 | 
|---|
| 919 |               WinCheckButton(hwnd, CMD_INVISIBLE, TRUE);
 | 
|---|
| 920 |           }
 | 
|---|
| 921 |           WinCheckButton(hwnd, CMD_PROMPT, ((info->flags & PROMPT) != 0));
 | 
|---|
| 922 |           WinCheckButton(hwnd, CMD_KEEP, ((info->flags & KEEP) != 0));
 | 
|---|
| 923 |           WinCheckButton(hwnd, CMD_ONCE, ((info->flags & ONCE) != 0));
 | 
|---|
| 924 |           WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
 | 
|---|
| 925 |           if (info->env)
 | 
|---|
| 926 |             WinSetDlgItemText(hwnd, CMD_ENVIRON, info->env);
 | 
|---|
| 927 |           else
 | 
|---|
| 928 |             WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
 | 
|---|
| 929 |           for (x = 0; x < 40; x++) {
 | 
|---|
| 930 |             CHAR s[CCHMAXPATH + 24];
 | 
|---|
| 931 | 
 | 
|---|
| 932 |             sprintf(s, "%s%s%s",
 | 
|---|
| 933 |                     x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0 ? "Ctrl+" : NullStr,
 | 
|---|
| 934 |                     x > IDM_COMMANDNUM19 - IDM_COMMANDNUM0 ? "Alt+" : NullStr,
 | 
|---|
| 935 |                     (x > IDM_COMMANDNUM9 - IDM_COMMANDNUM0 &&
 | 
|---|
| 936 |                     x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0) ||
 | 
|---|
| 937 |                     x > IDM_COMMANDNUM29 - IDM_COMMANDNUM0 ? "Shift+" : NullStr);
 | 
|---|
| 938 |             sprintf(&s[strlen(s)], "%d", (x % 10) + 1 == 10 ? 0 : (x % 10) + 1);
 | 
|---|
| 939 |             sprintf(&s[strlen(s)], " %s", UsedHotKeyIDs[x] ? "(in use)" : NullStr);
 | 
|---|
| 940 |             WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
 | 
|---|
| 941 |                        MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
 | 
|---|
| 942 |             if (x == 39)
 | 
|---|
| 943 |               WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
 | 
|---|
| 944 |                          MPFROM2SHORT(LIT_END, 0), MPFROMP("none"));
 | 
|---|
| 945 |             if (info->HotKeyID == x + IDM_COMMANDNUM0)
 | 
|---|
| 946 |               WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
 | 
|---|
| 947 |                          MPFROM2SHORT(x, 0), MPFROMLONG(TRUE));
 | 
|---|
| 948 |             if (x == 39 && info->HotKeyID == 0)
 | 
|---|
| 949 |               WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
 | 
|---|
| 950 |                          MPFROM2SHORT(x + 1, 0), MPFROMLONG(TRUE));
 | 
|---|
| 951 |           } // for
 | 
|---|
| 952 |         }
 | 
|---|
| 953 |         break;
 | 
|---|
| 954 |       }
 | 
|---|
| 955 |     }
 | 
|---|
| 956 |     return 0;
 | 
|---|
| 957 | 
 | 
|---|
| 958 |   case WM_COMMAND:
 | 
|---|
| 959 |     switch (SHORT1FROMMP(mp1)) {
 | 
|---|
| 960 |     case CMD_FIND:
 | 
|---|
| 961 |       {
 | 
|---|
| 962 |         CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
 | 
|---|
| 963 | 
 | 
|---|
| 964 |         *filename = 0;
 | 
|---|
| 965 |         if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
 | 
|---|
| 966 |           BldQuotedFileName(szfilename, filename);
 | 
|---|
| 967 |           WinSetDlgItemText(hwnd, CMD_CL, szfilename);
 | 
|---|
| 968 |         }
 | 
|---|
| 969 |       }
 | 
|---|
| 970 |       break;
 | 
|---|
| 971 | 
 | 
|---|
| 972 |     case CMD_REORDER:
 | 
|---|
| 973 |       if (!cmdhead || !cmdhead->next) {
 | 
|---|
| 974 |         Runtime_Error(pszSrcFile, __LINE__, "no cmd");
 | 
|---|
| 975 |         break;
 | 
|---|
| 976 |       }
 | 
|---|
| 977 |       if (WinDlgBox(HWND_DESKTOP, hwnd, ReOrderProc, FM3ModHandle,
 | 
|---|
| 978 |                     RE_FRAME, MPVOID)) {
 | 
|---|
| 979 |         WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
 | 
|---|
| 980 |         WinSetDlgItemText(hwnd, CMD_CL, NullStr);
 | 
|---|
| 981 |         WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
 | 
|---|
| 982 |         info = cmdhead;
 | 
|---|
| 983 |         while (info) {
 | 
|---|
| 984 |           x = (SHORT) WinSendDlgItemMsg(hwnd,
 | 
|---|
| 985 |                                         CMD_LISTBOX,
 | 
|---|
| 986 |                                         LM_INSERTITEM,
 | 
|---|
| 987 |                                         MPFROM2SHORT(LIT_END, 0),
 | 
|---|
| 988 |                                         MPFROMP(info->title));
 | 
|---|
| 989 |           if (x >= 0)
 | 
|---|
| 990 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 991 |                               CMD_LISTBOX,
 | 
|---|
| 992 |                               LM_SETITEMHANDLE,
 | 
|---|
| 993 |                               MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 994 |           info = info->next;
 | 
|---|
| 995 |         }
 | 
|---|
| 996 |         WinSendDlgItemMsg(hwnd,
 | 
|---|
| 997 |                           CMD_LISTBOX,
 | 
|---|
| 998 |                           LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
 | 
|---|
| 999 |         WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
 | 
|---|
| 1000 |         WinCheckButton(hwnd, CMD_PROMPT, FALSE);
 | 
|---|
| 1001 |         WinCheckButton(hwnd, CMD_ONCE, FALSE);
 | 
|---|
| 1002 |         save_commands();
 | 
|---|
| 1003 |       }
 | 
|---|
| 1004 |       break;
 | 
|---|
| 1005 | 
 | 
|---|
| 1006 |     case DID_OK:
 | 
|---|
| 1007 |       {
 | 
|---|
| 1008 |         COMMAND *temp;
 | 
|---|
| 1009 |         BOOL fDontCheckHotKey = FALSE;
 | 
|---|
| 1010 | 
 | 
|---|
| 1011 |         temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
 | 
|---|
| 1012 |         if (!temp)
 | 
|---|
| 1013 |           break;  //already complained
 | 
|---|
| 1014 |         temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
 | 
|---|
| 1015 |         if (!temp->pszCmdLine) {
 | 
|---|
| 1016 |           free (temp);
 | 
|---|
| 1017 |           break; //already complained
 | 
|---|
| 1018 |         }
 | 
|---|
| 1019 |         if (QueryCommandSettings(hwnd, temp)){
 | 
|---|
| 1020 |           if (temp->HotKeyID == 0)
 | 
|---|
| 1021 |             fDontCheckHotKey = TRUE;
 | 
|---|
| 1022 |           info = add_command(temp, fDontCheckHotKey);
 | 
|---|
| 1023 |           if (info == (LINKCMDS *) -1)
 | 
|---|
| 1024 |             break;
 | 
|---|
| 1025 |         }
 | 
|---|
| 1026 |         else {
 | 
|---|
| 1027 |           free(temp->pszCmdLine);
 | 
|---|
| 1028 |           free(temp);
 | 
|---|
| 1029 |           break;
 | 
|---|
| 1030 |         }
 | 
|---|
| 1031 |         free(temp->pszCmdLine);
 | 
|---|
| 1032 |         free(temp);
 | 
|---|
| 1033 |         save_commands();
 | 
|---|
| 1034 |         WinDismissDlg(hwnd, 0);
 | 
|---|
| 1035 |         break;
 | 
|---|
| 1036 |       }
 | 
|---|
| 1037 | 
 | 
|---|
| 1038 |     case DID_CANCEL:
 | 
|---|
| 1039 |       WinDismissDlg(hwnd, 0);
 | 
|---|
| 1040 |       break;
 | 
|---|
| 1041 | 
 | 
|---|
| 1042 |     case IDM_HELP:
 | 
|---|
| 1043 |       if (hwndHelp)
 | 
|---|
| 1044 |         WinSendMsg(hwndHelp,
 | 
|---|
| 1045 |                    HM_DISPLAY_HELP,
 | 
|---|
| 1046 |                    MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
 | 
|---|
| 1047 |       break;
 | 
|---|
| 1048 | 
 | 
|---|
| 1049 |     case CMD_ADD:
 | 
|---|
| 1050 |       {
 | 
|---|
| 1051 |         COMMAND *temp;
 | 
|---|
| 1052 |         BOOL fDontCheckHotKey = FALSE;
 | 
|---|
| 1053 | 
 | 
|---|
| 1054 |         temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
 | 
|---|
| 1055 |         if (!temp)
 | 
|---|
| 1056 |           break;  //already complained
 | 
|---|
| 1057 |         temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
 | 
|---|
| 1058 |         if (!temp->pszCmdLine) {
 | 
|---|
| 1059 |           free (temp);
 | 
|---|
| 1060 |           break; //already complained
 | 
|---|
| 1061 |         }
 | 
|---|
| 1062 |         if (!QueryCommandSettings(hwnd, temp)) {
 | 
|---|
| 1063 |           free(temp->pszCmdLine);
 | 
|---|
| 1064 |           free(temp);
 | 
|---|
| 1065 |           break;
 | 
|---|
| 1066 |         }
 | 
|---|
| 1067 |         else {
 | 
|---|
| 1068 |           if (temp->HotKeyID == 0)
 | 
|---|
| 1069 |             fDontCheckHotKey = TRUE;
 | 
|---|
| 1070 |           info = add_command(temp, fDontCheckHotKey);
 | 
|---|
| 1071 |           if (!info) {
 | 
|---|
| 1072 |             saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
 | 
|---|
| 1073 |                    GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp->title);
 | 
|---|
| 1074 |             free(temp->pszCmdLine);
 | 
|---|
| 1075 |             free(temp);
 | 
|---|
| 1076 |             break;
 | 
|---|
| 1077 |           }
 | 
|---|
| 1078 |         x = (SHORT) WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1079 |                                       CMD_LISTBOX,
 | 
|---|
| 1080 |                                       LM_INSERTITEM,
 | 
|---|
| 1081 |                                       MPFROM2SHORT(LIT_END, 0),
 | 
|---|
| 1082 |                                       MPFROMP(temp->title));
 | 
|---|
| 1083 |         if (x >= 0) {
 | 
|---|
| 1084 |           WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1085 |                             CMD_LISTBOX,
 | 
|---|
| 1086 |                             LM_SETITEMHANDLE,
 | 
|---|
| 1087 |                             MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 1088 |           WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1089 |                             CMD_LISTBOX,
 | 
|---|
| 1090 |                             LM_SELECTITEM,
 | 
|---|
| 1091 |                             MPFROMSHORT(x), MPFROMSHORT(TRUE));
 | 
|---|
| 1092 |           }
 | 
|---|
| 1093 |           save_commands();
 | 
|---|
| 1094 |         }
 | 
|---|
| 1095 |         free(temp->pszCmdLine);
 | 
|---|
| 1096 |         free(temp);
 | 
|---|
| 1097 |         break;
 | 
|---|
| 1098 |       }
 | 
|---|
| 1099 | 
 | 
|---|
| 1100 |     case CMD_DELETE:
 | 
|---|
| 1101 |       {
 | 
|---|
| 1102 |         CHAR temp[100];
 | 
|---|
| 1103 |         CHAR keyID[120];
 | 
|---|
| 1104 |         CHAR keyHotKeyID[120];
 | 
|---|
| 1105 |         CHAR keyenv[120];
 | 
|---|
| 1106 | 
 | 
|---|
| 1107 |         WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
 | 
|---|
| 1108 |         bstripcr(temp);
 | 
|---|
| 1109 |         if (!kill_command(temp))
 | 
|---|
| 1110 |           Runtime_Error(pszSrcFile, __LINE__, "kill_command");
 | 
|---|
| 1111 |         else {
 | 
|---|
| 1112 |           sprintf(keyID, "COMMAND.%sID", temp);
 | 
|---|
| 1113 |           sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp);
 | 
|---|
| 1114 |           sprintf(keyenv, "COMMAND.%senv", temp);
 | 
|---|
| 1115 |           PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
 | 
|---|
| 1116 |           PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
 | 
|---|
| 1117 |           PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
 | 
|---|
| 1118 |           x = (SHORT) WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1119 |                                         CMD_LISTBOX,
 | 
|---|
| 1120 |                                         LM_QUERYSELECTION,
 | 
|---|
| 1121 |                                         MPFROMSHORT(LIT_FIRST), MPVOID);
 | 
|---|
| 1122 |           if (x >= 0) {
 | 
|---|
| 1123 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1124 |                               CMD_LISTBOX,
 | 
|---|
| 1125 |                               LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
 | 
|---|
| 1126 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1127 |                               CMD_LISTBOX,
 | 
|---|
| 1128 |                               LM_SELECTITEM,
 | 
|---|
| 1129 |                               MPFROMSHORT(0), MPFROMSHORT(TRUE));
 | 
|---|
| 1130 |           }
 | 
|---|
| 1131 |           save_commands();
 | 
|---|
| 1132 |         }
 | 
|---|
| 1133 |       }
 | 
|---|
| 1134 |       break;
 | 
|---|
| 1135 | 
 | 
|---|
| 1136 |     case CMD_REPLACE:
 | 
|---|
| 1137 |       { 
 | 
|---|
| 1138 |         COMMAND *temp;
 | 
|---|
| 1139 |         CHAR keyID[120];
 | 
|---|
| 1140 |         CHAR keyHotKeyID[120];
 | 
|---|
| 1141 |         CHAR keyenv[120];
 | 
|---|
| 1142 |         INT ID = 0;
 | 
|---|
| 1143 |         INT HotKeyID = 0;
 | 
|---|
| 1144 |         ULONG size;
 | 
|---|
| 1145 |         BOOL fDontCheckHotKey = FALSE;
 | 
|---|
| 1146 | 
 | 
|---|
| 1147 |         // Query the dialog
 | 
|---|
| 1148 |         temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
 | 
|---|
| 1149 |         if (!temp)
 | 
|---|
| 1150 |           break;  //already complained
 | 
|---|
| 1151 |         temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
 | 
|---|
| 1152 |         if (!temp->pszCmdLine) {
 | 
|---|
| 1153 |           free (temp);
 | 
|---|
| 1154 |           break; //already complained
 | 
|---|
| 1155 |         }
 | 
|---|
| 1156 |         if (!QueryCommandSettings(hwnd, temp)) {
 | 
|---|
| 1157 |           free(temp->pszCmdLine);
 | 
|---|
| 1158 |           free(temp);
 | 
|---|
| 1159 |           break;
 | 
|---|
| 1160 |         }
 | 
|---|
| 1161 |         //remember item location in the list
 | 
|---|
| 1162 |         y = (SHORT) WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1163 |                                       CMD_LISTBOX,
 | 
|---|
| 1164 |                                       LM_QUERYSELECTION,
 | 
|---|
| 1165 |                                       MPFROMSHORT(LIT_CURSOR), MPVOID);
 | 
|---|
| 1166 |         //Delete
 | 
|---|
| 1167 |         sprintf(keyID, "COMMAND.%sID", temp->title);
 | 
|---|
| 1168 |         sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp->title);
 | 
|---|
| 1169 |         sprintf(keyenv, "COMMAND.%senv", temp->title);
 | 
|---|
| 1170 |         PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
 | 
|---|
| 1171 |         PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
 | 
|---|
| 1172 |         temp->ID = ID;
 | 
|---|
| 1173 |         if (temp->HotKeyID == HotKeyID || temp->HotKeyID == 0)
 | 
|---|
| 1174 |           fDontCheckHotKey = TRUE;
 | 
|---|
| 1175 |         if (kill_command(temp->title)) {
 | 
|---|
| 1176 |           PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
 | 
|---|
| 1177 |           PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
 | 
|---|
| 1178 |           PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
 | 
|---|
| 1179 |           x = (SHORT) WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1180 |                                         CMD_LISTBOX,
 | 
|---|
| 1181 |                                         LM_QUERYSELECTION,
 | 
|---|
| 1182 |                                         MPFROMSHORT(LIT_FIRST), MPVOID);
 | 
|---|
| 1183 |           if (x >= 0) {
 | 
|---|
| 1184 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1185 |                               CMD_LISTBOX,
 | 
|---|
| 1186 |                               LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
 | 
|---|
| 1187 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1188 |                               CMD_LISTBOX,
 | 
|---|
| 1189 |                               LM_SELECTITEM,
 | 
|---|
| 1190 |                               MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
 | 
|---|
| 1191 |           }
 | 
|---|
| 1192 |         } // then do an add
 | 
|---|
| 1193 |         info = add_command(temp, fDontCheckHotKey);
 | 
|---|
| 1194 |         if (!info) {
 | 
|---|
| 1195 |           saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
 | 
|---|
| 1196 |                  GetPString(IDS_CANTADDCOMMANDTEXT),
 | 
|---|
| 1197 |                  temp->title);
 | 
|---|
| 1198 |         }
 | 
|---|
| 1199 |         else {
 | 
|---|
| 1200 |           //put item back in original place
 | 
|---|
| 1201 |           x = (SHORT) WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1202 |                                         CMD_LISTBOX,
 | 
|---|
| 1203 |                                         LM_INSERTITEM,
 | 
|---|
| 1204 |                                         MPFROM2SHORT(y, 0),
 | 
|---|
| 1205 |                                         MPFROMP(temp->title));
 | 
|---|
| 1206 |           if (x >= 0) {
 | 
|---|
| 1207 |             LINKCMDS *temphead = NULL,*last = NULL, *temptail = NULL;
 | 
|---|
| 1208 |             SHORT numitems, sSelect = 0;
 | 
|---|
| 1209 | 
 | 
|---|
| 1210 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1211 |                               CMD_LISTBOX,
 | 
|---|
| 1212 |                               LM_SETITEMHANDLE,
 | 
|---|
| 1213 |                               MPFROMSHORT(x), MPFROMP(info));
 | 
|---|
| 1214 |             WinSendDlgItemMsg(hwnd,
 | 
|---|
| 1215 |                               CMD_LISTBOX,
 | 
|---|
| 1216 |                               LM_SELECTITEM,
 | 
|---|
| 1217 |                               MPFROMSHORT(x), MPFROMSHORT(TRUE));
 | 
|---|
| 1218 |             //then reorder
 | 
|---|
| 1219 |             numitems = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
 | 
|---|
| 1220 |                                                  LM_QUERYITEMCOUNT,
 | 
|---|
| 1221 |                                                  MPVOID, MPVOID);
 | 
|---|
| 1222 | 
 | 
|---|
| 1223 |             while (numitems) {
 | 
|---|
| 1224 | 
 | 
|---|
| 1225 | 
 | 
|---|
| 1226 |               info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
 | 
|---|
| 1227 |                                                     LM_QUERYITEMHANDLE,
 | 
|---|
| 1228 |                                                     MPFROMSHORT(sSelect++),
 | 
|---|
| 1229 |                                                     MPVOID);
 | 
|---|
| 1230 |               if (info) {
 | 
|---|
| 1231 |                 if (!temphead) {
 | 
|---|
| 1232 |                   temphead = info;
 | 
|---|
| 1233 |                   info->prev = NULL;
 | 
|---|
| 1234 |                 }
 | 
|---|
| 1235 |                 else {
 | 
|---|
| 1236 |                   last->next = info;
 | 
|---|
| 1237 |                   info->prev = last;
 | 
|---|
| 1238 |                 }
 | 
|---|
| 1239 |                 temptail = info;
 | 
|---|
| 1240 |                 last = info;
 | 
|---|
| 1241 |                 info->next = NULL;
 | 
|---|
| 1242 |               }
 | 
|---|
| 1243 |               numitems--;
 | 
|---|
| 1244 |             }
 | 
|---|
| 1245 |             cmdhead = temphead;
 | 
|---|
| 1246 |             cmdtail = temptail;
 | 
|---|
| 1247 |             save_commands();
 | 
|---|
| 1248 |           }
 | 
|---|
| 1249 |         }
 | 
|---|
| 1250 |         xfree(temp->pszCmdLine, pszSrcFile, __LINE__);
 | 
|---|
| 1251 |         xfree(temp, pszSrcFile, __LINE__);
 | 
|---|
| 1252 |       }
 | 
|---|
| 1253 |       break;
 | 
|---|
| 1254 |     }
 | 
|---|
| 1255 |     return 0;
 | 
|---|
| 1256 |   }
 | 
|---|
| 1257 | #   ifdef FORTIFY
 | 
|---|
| 1258 |     Fortify_LeaveScope();
 | 
|---|
| 1259 | #    endif
 | 
|---|
| 1260 |   return WinDefDlgProc(hwnd, msg, mp1, mp2);
 | 
|---|
| 1261 | }
 | 
|---|
| 1262 | 
 | 
|---|
| 1263 | VOID RunCommand(HWND hwnd, INT cx)
 | 
|---|
| 1264 | {
 | 
|---|
| 1265 |   INT x;
 | 
|---|
| 1266 |   CHAR **list;
 | 
|---|
| 1267 |   LINKCMDS *info;
 | 
|---|
| 1268 | 
 | 
|---|
| 1269 |   list = BuildList(hwnd);
 | 
|---|
| 1270 |   x = 0;
 | 
|---|
| 1271 |   info = cmdhead;
 | 
|---|
| 1272 |   while (info) {
 | 
|---|
| 1273 |     if (cx < 4300) {
 | 
|---|
| 1274 |       if (info->ID == cx)
 | 
|---|
| 1275 |         break;
 | 
|---|
| 1276 |     }
 | 
|---|
| 1277 |     else {
 | 
|---|
| 1278 |       if (info->HotKeyID == cx)
 | 
|---|
| 1279 |         break;
 | 
|---|
| 1280 |     }
 | 
|---|
| 1281 |     info = info->next;
 | 
|---|
| 1282 |   }
 | 
|---|
| 1283 |   if (info) {
 | 
|---|
| 1284 | 
 | 
|---|
| 1285 |     INT flags;
 | 
|---|
| 1286 | 
 | 
|---|
| 1287 |     x--;
 | 
|---|
| 1288 |     flags = info->flags;
 | 
|---|
| 1289 |     if (!(flags & FULLSCREEN))
 | 
|---|
| 1290 |       flags |= WINDOWED;
 | 
|---|
| 1291 |     if (flags & KEEP)
 | 
|---|
| 1292 |       flags |= SEPARATEKEEP;
 | 
|---|
| 1293 |     else
 | 
|---|
| 1294 |       flags |= SEPARATE;
 | 
|---|
| 1295 |     flags &= ~(KEEP | DIEAFTER);
 | 
|---|
| 1296 |     if (!strchr(info->pszCmdLine, '%')) {
 | 
|---|
| 1297 |       CHAR *fakelist[2];
 | 
|---|
| 1298 | 
 | 
|---|
| 1299 |       *fakelist = "C";
 | 
|---|
| 1300 |       fakelist[1] = NULL;
 | 
|---|
| 1301 |       ExecOnList(hwnd,
 | 
|---|
| 1302 |                  info->pszCmdLine,
 | 
|---|
| 1303 |                  flags, NULL, info->env != NullStr ? info->env : NULL,
 | 
|---|
| 1304 |                  fakelist, GetPString(IDS_EXECCMDTITLETEXT),
 | 
|---|
| 1305 |                  pszSrcFile, __LINE__);
 | 
|---|
| 1306 |     }
 | 
|---|
| 1307 |     else if ((flags & ONCE) && list && list[0]) {
 | 
|---|
| 1308 | 
 | 
|---|
| 1309 |       CHAR *fakelist[2];
 | 
|---|
| 1310 |       INT cntr;
 | 
|---|
| 1311 | 
 | 
|---|
| 1312 |       flags &= (~ONCE);
 | 
|---|
| 1313 |       for (cntr = 0; list[cntr]; cntr++) {
 | 
|---|
| 1314 |         *fakelist = list[cntr];
 | 
|---|
| 1315 |         fakelist[1] = NULL;
 | 
|---|
| 1316 |         ExecOnList(hwnd,
 | 
|---|
| 1317 |                    info->pszCmdLine,
 | 
|---|
| 1318 |                    flags, NULL, info->env != NullStr ? info->env : NULL,
 | 
|---|
| 1319 |                    fakelist, GetPString(IDS_EXECCMDTITLETEXT),
 | 
|---|
| 1320 |                    pszSrcFile, __LINE__);
 | 
|---|
| 1321 |       }
 | 
|---|
| 1322 |     }
 | 
|---|
| 1323 |     else if (list && list[0])
 | 
|---|
| 1324 |       ExecOnList(hwnd,
 | 
|---|
| 1325 |                  info->pszCmdLine,
 | 
|---|
| 1326 |                  flags, NULL, info->env != NullStr ? info->env : NULL,
 | 
|---|
| 1327 |                  list, GetPString(IDS_EXECCMDTITLETEXT),
 | 
|---|
| 1328 |                  pszSrcFile, __LINE__);
 | 
|---|
| 1329 |     else
 | 
|---|
| 1330 |       return;
 | 
|---|
| 1331 |   }
 | 
|---|
| 1332 |   FreeList(list);
 | 
|---|
| 1333 |   DosPostEventSem(CompactSem);
 | 
|---|
| 1334 | }
 | 
|---|
| 1335 | 
 | 
|---|
| 1336 | VOID EditCommands(HWND hwnd)
 | 
|---|
| 1337 | {
 | 
|---|
| 1338 |   static CHAR stop = 0;
 | 
|---|
| 1339 | 
 | 
|---|
| 1340 |   if (stop)
 | 
|---|
| 1341 |     return;
 | 
|---|
| 1342 |   stop++;
 | 
|---|
| 1343 |   if (!cmdloaded)
 | 
|---|
| 1344 |     load_commands();
 | 
|---|
| 1345 |   WinDlgBox(HWND_DESKTOP,
 | 
|---|
| 1346 |             hwnd, CommandDlgProc, FM3ModHandle, CMD_FRAME, MPFROMP(&hwnd));
 | 
|---|
| 1347 |   stop = 0;
 | 
|---|
| 1348 | }
 | 
|---|
| 1349 | 
 | 
|---|
| 1350 | #pragma alloc_text(COMMAND,command_title,free_commands,add_command,kill_command)
 | 
|---|
| 1351 | #pragma alloc_text(COMMAND,CommandDlgProc,EditCommands,ReOrderProc,CommandTextProc)
 | 
|---|