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