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