source: trunk/dll/command.c@ 1877

Last change on this file since 1877 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: command.c 1877 2015-10-11 21:43:27Z gyoung $
5
6 Custom commands
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2010 Steven H. Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 06 Jun 05 SHL Drop unused code
13 14 Jul 06 SHL Use Runtime_Error
14 29 Jul 06 SHL Use xfgets_bstripcr
15 15 Aug 06 SHL Better can't add message
16 18 Sep 06 GKY Add replace command and update okay to add if changed
17 17 Feb 07 GKY Move error messages etc to string file
18 22 Mar 07 GKY Use QWL_USER
19 23 Mar 07 GKY Replace doesn't change item position
20 23 Mar 07 GKY Okay fails silently when item not changed
21 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
22 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
23 06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry
24 29 Feb 08 GKY Changes to enable user settable command line length
25 29 Feb 08 GKY Use xfree where appropriate
26 18 Jul 08 SHL Add Fortify support
27 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
28 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
29 15 Oct 08 GKY Prevent asking to add %a on NormalizeCmdLine abort
30 21 Dec 09 GKY Fix the environment so it can be saved, deleted and used consistently.
31 21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
32 Added load_inicommand to load the IDs from the ini file.
33 21 Dec 09 GKY Added 20 new hot keys for commands.
34 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
35 27 Dec 09 GKY Moved Commands to the INI file this makes commands.dat obsolete
36 27 Dec 09 GKY Added QueryCommandSettings to streamline code
37 27 Dec 09 GKY Made command hotkeys user selectable.
38 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10).
39 Mostly cast CHAR CONSTANT * as CHAR *.
40 01 May 10 GKY Add ENVIRONMENT_SIZE variable to standardize this size everywhere.
41 01 May 10 GKY Changes to move environment storage to INI file
42 03 Jul 11 GKY Fixed problem with creation of duplicate command IDs.
43 24 Sep 11 GKY Fixed trap caused by selecting cancel from duplicate hotkey dialog if adding or replacing a command
44 28 Jun 14 GKY Fix errors identified with CPPCheck
45
46***********************************************************************/
47
48#include <stdlib.h>
49#include <string.h>
50#include <share.h>
51
52#define INCL_DOS
53#define INCL_WIN
54#define INCL_LONGLONG // dircnrs.h
55
56#include "fm3dll.h"
57#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
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
62#include "fm3dlg.h"
63#include "fm3str.h"
64#include "tools.h"
65#include "arccnrs.h" // BldQuotedFileName
66#include "errutil.h" // Dos_Error...
67#include "strutil.h" // GetPString
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
73#include "pathutil.h" // NormalizeCmdLine
74#include "command.h"
75#include "strips.h" // bstrip
76#include "dirs.h" // save_dir2
77#include "fortify.h"
78
79VOID load_inicommands(VOID);
80
81typedef struct
82{
83 PSZ pszCmdLine;
84 CHAR title[100];
85 CHAR env[ENVIRONMENT_SIZE];
86 ULONG flags;
87 ULONG ID;
88 ULONG HotKeyID;
89}
90COMMAND;
91
92BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp);
93VOID save_commands(VOID);
94
95// Data defintions
96#pragma data_seg(DATA1)
97
98static PSZ pszSrcFile = __FILE__;
99static LINKCMDS *cmdtail;
100static BOOL UsedCommandIDs[300] = {FALSE};
101static BOOL UsedHotKeyIDs[40] = {FALSE};
102static PSZ pszCommandsList;
103static ULONG ulSizeCommandsList = 10000;
104static BOOL fLoadCommandsFromINI = FALSE;
105
106#pragma data_seg(GLOBAL2)
107LINKCMDS *cmdhead;
108BOOL cmdloaded;
109
110MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
111{
112 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
113 static BOOL emphasized = FALSE;
114
115 switch (msg) {
116 case DM_DRAGOVER:
117 if (!emphasized) {
118 emphasized = TRUE;
119 DrawTargetEmphasis(hwnd, emphasized);
120 }
121 if (AcceptOneDrop(hwnd, mp1, mp2))
122 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
123 return MRFROM2SHORT(DOR_NEVERDROP, 0);
124
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) {
141 emphasized = FALSE;
142 DrawTargetEmphasis(hwnd, emphasized);
143 }
144 if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
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
155MRESULT 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);
161 break;
162 }
163 {
164 LINKCMDS *info;
165 SHORT x;
166
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);
175 }
176 else {
177 WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SETITEMHANDLE,
178 MPFROMSHORT(x), MPFROMP(info));
179 }
180 info = info->next;
181 }
182 }
183 break;
184
185 case WM_CONTROL:
186 return 0;
187
188 case WM_COMMAND:
189 switch (SHORT1FROMMP(mp1)) {
190 case DID_CANCEL:
191 WinDismissDlg(hwnd, 0);
192 break;
193
194 case DID_OK:
195 {
196 LINKCMDS *temphead = NULL, *info, *last = NULL, *temptail = NULL;
197 SHORT sSelect, numitems;
198
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;
220 }
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;
244 }
245 numitems--;
246 }
247 cmdhead = temphead;
248 cmdtail = temptail;
249 }
250 WinDismissDlg(hwnd, 1);
251 break;
252
253 case IDM_HELP:
254 if (hwndHelp)
255 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
256 MPFROM2SHORT(HELP_REORDERCOMMANDS, 0),
257 MPFROMSHORT(HM_RESOURCEID));
258 break;
259
260 case RE_ADD:
261 {
262 SHORT sSelect, x;
263 LINKCMDS *info;
264
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);
283 }
284 }
285 else
286 WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SELECTITEM,
287 MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
288 sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
289 LM_QUERYSELECTION,
290 MPFROMSHORT(LIT_FIRST),
291 MPVOID);
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);
319 }
320 }
321 else
322 WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_SELECTITEM,
323 MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
324 sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
325 LM_QUERYSELECTION,
326 MPFROMSHORT(LIT_FIRST),
327 MPVOID);
328 }
329 }
330 break;
331 }
332 return 0;
333 }
334 return WinDefDlgProc(hwnd, msg, mp1, mp2);
335}
336
337CHAR *command_title(INT cx)
338{
339 static CHAR duh[] = "???";
340 LINKCMDS *info;
341 INT x = 0;
342
343 if (!cmdloaded)
344 load_commands();
345 info = cmdhead;
346 while (info) {
347 if (x == cx)
348 return info->title;
349 info = info->next;
350 }
351 return duh;
352}
353
354VOID free_commands(VOID)
355{
356 LINKCMDS *info, *next;
357
358 info = cmdhead;
359 while (info) {
360 next = info->next;
361 xfree(info->title, pszSrcFile, __LINE__);
362 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
363 xfree(info->env, pszSrcFile, __LINE__);
364 free(info);
365 info = next;
366 }
367 free(pszCommandsList);
368 cmdhead = cmdtail = NULL;
369}
370
371VOID load_commands(VOID)
372{
373 FILE *fp;
374 LINKCMDS *info;
375 PSZ pszCmdLine;
376 CHAR title[100];
377 CHAR flags[34];
378 CHAR *moder = "r";
379 ULONG size;
380
381 size = sizeof(BOOL);
382 PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
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);
392 fp = xfsopen(pszCmdLine, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
393 if (fp) {
394 while (!feof(fp)) {
395 if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
396 break;
397 if (!*title || *title == ';')
398 continue;
399 if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
400 break; // error!
401 if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
402 break;
403 flags[33] = 0;
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;
439 }
440 }
441 free(pszCmdLine);
442 fclose(fp);
443 if (pszCommandsList) {
444 ulSizeCommandsList = strlen(pszCommandsList) + 1;
445 }
446 }
447 }
448 }
449 load_inicommands();
450}
451
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
458VOID load_inicommands(VOID)
459{
460 LINKCMDS *info;;
461 INT x = 0;
462 INT y = 0;
463 ULONG ID = 0;
464 ULONG HotKeyID = 0;
465 CHAR env[ENVIRONMENT_SIZE];
466 CHAR key[120];
467 CHAR szTitle[100];
468 ULONG size;
469 CHAR *p, *pp;
470 PSZ pszCmdLine;
471 ULONG flags;
472
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);
483 PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
484 &ulSizeCommandsList, &size);
485 pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
486 if (pszCommandsList) {
487 PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
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);
504 PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
505 UsedCommandIDs[ID - IDM_COMMANDSTART] = TRUE; // No need to use profile just count them GKY 02 JUL 11
506 sprintf(key, "COMMAND.%sHotKeyID", szTitle);
507 size = sizeof(ULONG);
508 PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
509 UsedHotKeyIDs[HotKeyID - IDM_COMMANDNUM0] = TRUE; // No need to use profile just count them GKY 02 JUL 11
510 sprintf(key, "COMMAND.%sflags", szTitle);
511 size = sizeof(ULONG);
512 PrfQueryProfileData(fmprof, FM3Str, key, &flags, &size);
513 sprintf(key, "COMMAND.%senv", szTitle);
514 PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
515 sprintf(key, "COMMAND.%sCmdLine", szTitle);
516 PrfQueryProfileString(fmprof, FM3Str, key, NullStr, pszCmdLine, MaxComLineStrg);
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 }
548 }
549 else {
550 info = cmdhead;
551 while (info) {
552 bstripcr(info->title);
553 sprintf(key, "COMMAND.%sID", info->title);
554 size = sizeof(ULONG);
555 PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
556 sprintf(key, "COMMAND.%sHotKeyID", info->title);
557 size = sizeof(ULONG);
558 PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
559 sprintf(key, "COMMAND.%senv", info->title);
560 PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
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
568 //assigning the IDs based on file order or on next available ID
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 }
581 break;
582 }
583 if (x == 299)
584 saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
585 GetPString(IDS_COMMANDSLIMITTITLETEXT),
586 GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
587 }
588 PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
589 info->env = xstrdup(env, pszSrcFile, __LINE__);
590 }
591 ID = 0;
592 HotKeyID = 0;
593 info = info->next;
594 }
595 fLoadCommandsFromINI = TRUE;
596 save_commands();
597 }
598 free(pszCmdLine);
599 }
600}
601
602VOID save_commands(VOID)
603{
604 LINKCMDS *info;
605 CHAR key[120];
606
607 if (!cmdloaded || !cmdhead)
608 return;
609
610 info = cmdhead;
611 pszCommandsList[0] = 0;
612 while (info) {
613 sprintf(key, "COMMAND.%sflags", info->title);
614 PrfWriteProfileData(fmprof, FM3Str, key, &info->flags, sizeof(ULONG));
615 sprintf(key, "COMMAND.%sCmdLine", info->title);
616 PrfWriteProfileString(fmprof, FM3Str, key, info->pszCmdLine);
617 bstripcr(info->title);
618 sprintf(key, "COMMAND.%sID", info->title);
619 PrfWriteProfileData(fmprof, FM3Str, key, &info->ID, sizeof(INT));
620 UsedCommandIDs[info->ID - IDM_COMMANDSTART] = TRUE;
621 sprintf(key, "COMMAND.%sHotKeyID", info->title);
622 PrfWriteProfileData(fmprof, FM3Str, key, &info->HotKeyID, sizeof(INT));
623 UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
624 if (info->env != NullStr) {
625 sprintf(key, "COMMAND.%senv", info->title);
626 PrfWriteProfileString(fmprof, FM3Str, key, info->env);
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), ";");
634 info = info->next;
635 } // while info
636 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
637 sizeof(BOOL) * 300); // left for backward compatability GKY 02 Jul 11
638 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
639 sizeof(BOOL) * 40);// left for backward compatability GKY 02 Jul 11
640 ulSizeCommandsList = strlen(pszCommandsList) + 1;
641 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
642 &ulSizeCommandsList, sizeof(ULONG));
643 PrfWriteProfileString(fmprof, FM3Str, "COMMANDS.SortOrder", pszCommandsList);
644 PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
645 &fLoadCommandsFromINI, sizeof(BOOL));
646}
647
648//== add_command() Add command to list ==
649
650LINKCMDS *add_command(COMMAND *addme, BOOL fDontCheckHotKey)
651{
652 LINKCMDS *info;
653 INT x;
654 INT y;
655 APIRET ret;
656
657 if (!addme || !*addme->pszCmdLine || !*addme->title)
658 return NULL; // No data
659# ifdef FORTIFY
660 Fortify_EnterScope();
661# endif
662 info = cmdhead;
663 while (info) {
664 if (!stricmp(info->title, addme->title))
665 return NULL; // Got a dup
666 info = info->next;
667 }
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
684 return (LINKCMDS *) -1;
685 }
686 info = info->next;
687 }
688 }
689 info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
690 if (!info)
691 return NULL;
692 info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
693 info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
694 info->HotKeyID = addme->HotKeyID;
695 info->ID = addme->ID;
696 if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM39) {
697 UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
698 }
699 else
700 info->HotKeyID = 0;
701 if (!info->ID) {
702 //profile updated by save_commands
703 for (x = 0; x < 300; x++) {
704 if (!UsedCommandIDs[x]) {
705 info->ID = IDM_COMMANDSTART + x;
706 UsedCommandIDs[x] = TRUE;
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;
713 }
714 }
715 }
716 break;
717 }
718 if (x == 299)
719 saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
720 GetPString(IDS_COMMANDSLIMITTITLETEXT),
721 GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
722 }
723 }
724 if (addme->flags)
725 info->flags = addme->flags;
726 if (addme->env)
727 info->env = xstrdup(addme->env, pszSrcFile, __LINE__);
728 if (!info->pszCmdLine || !info->title || !info->ID) {
729 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
730 xfree(info->title, pszSrcFile, __LINE__);
731 xfree(info->env, pszSrcFile, __LINE__);
732 free(info);
733 return NULL;
734 }
735 if (!cmdhead) // only item in list
736 cmdhead = cmdtail = info;
737 else {
738 // place at tail
739 cmdtail->next = info;
740 info->prev = cmdtail;
741 cmdtail = info;
742 }
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)
753 PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
754 NullStr, pszCommandsList, ulSizeCommandsList);
755 return 0;
756 }
757 return info;
758}
759
760BOOL kill_command(CHAR * killme)
761{
762 LINKCMDS *info;
763
764 if (killme && *killme) {
765 info = cmdhead;
766 while (info) {
767 if (!stricmp(info->title, killme)) {
768 UsedCommandIDs[info->ID - IDM_COMMANDSTART] = FALSE;
769 if (info->HotKeyID)
770 UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = FALSE;
771 if (info == cmdhead) {
772 cmdhead = info->next;
773 if (info == cmdtail)
774 cmdtail = info->prev;
775 }
776 else {
777 if (info->next)
778 (info->next)->prev = info->prev;
779 if (info->prev)
780 (info->prev)->next = info->next;
781 if (info == cmdtail)
782 cmdtail = info->prev;
783 }
784 xfree(info->pszCmdLine, pszSrcFile, __LINE__);
785 xfree(info->title, pszSrcFile, __LINE__);
786 xfree(info->env, pszSrcFile, __LINE__);
787 free(info);
788 return TRUE;
789 }
790 info = info->next;
791 }
792 }
793# ifdef FORTIFY
794 Fortify_LeaveScope();
795# endif
796 return FALSE;
797}
798
799BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp)
800{
801 PSZ pszWorkBuf;
802 APIRET ret;
803 CHAR env[ENVIRONMENT_SIZE];
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;
830 WinQueryDlgItemText(hwnd, CMD_ENVIRON, ENVIRONMENT_SIZE - 1, env);
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;
841 return TRUE;
842}
843
844MRESULT EXPENTRY CommandDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
845{
846 SHORT x, y;
847 LINKCMDS *info;
848
849# ifdef FORTIFY
850 Fortify_EnterScope();
851# endif
852 switch (msg) {
853 case WM_INITDLG:
854 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
855 WinSendDlgItemMsg(hwnd, CMD_CL, EM_SETTEXTLIMIT,
856 MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
857 WinSendDlgItemMsg(hwnd, CMD_TITLE, EM_SETTEXTLIMIT,
858 MPFROM2SHORT(99, 0), MPVOID);
859 WinSetDlgItemText(hwnd, CMD_CL, NullStr);
860 WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
861 WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
862 WinCheckButton(hwnd, CMD_PROMPT, FALSE);
863 WinCheckButton(hwnd, CMD_ONCE, FALSE);
864 info = cmdhead;
865 while (info) {
866 x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_INSERTITEM,
867 MPFROM2SHORT(LIT_END, 0),
868 MPFROMP(info->title));
869 if (x >= 0)
870 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SETITEMHANDLE,
871 MPFROMSHORT(x), MPFROMP(info));
872 info = info->next;
873 }
874 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SELECTITEM,
875 MPFROMSHORT(0), MPFROMSHORT(TRUE));
876 {
877 PFNWP oldproc;
878
879 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, CMD_CL),
880 (PFNWP) CommandTextProc);
881 if (oldproc)
882 WinSetWindowPtr(WinWindowFromID(hwnd, CMD_CL), QWL_USER, (PVOID) oldproc);
883 }
884 break;
885
886 case WM_CONTROL:
887 if (SHORT1FROMMP(mp1) == CMD_LISTBOX) {
888 switch (SHORT2FROMMP(mp1)) {
889 case LN_ENTER:
890 case LN_SELECT:
891 x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
892 LM_QUERYSELECTION,
893 MPFROMSHORT(LIT_FIRST), MPVOID);
894 if (x >= 0) {
895 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
896 LM_QUERYITEMHANDLE,
897 MPFROMSHORT(x), MPVOID);
898 if (!info) {
899 Runtime_Error(pszSrcFile, __LINE__, "LM_QUERYITEMHANDLE");
900 break;
901 }
902 WinSetDlgItemText(hwnd, CMD_CL, info->pszCmdLine);
903 if (!(info->flags & 1023))
904 WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
905 else {
906 if (info->flags & FULLSCREEN)
907 WinCheckButton(hwnd, CMD_FULLSCREEN, TRUE);
908 else if (info->flags & MINIMIZED)
909 WinCheckButton(hwnd, CMD_MINIMIZED, TRUE);
910 else if (info->flags & MAXIMIZED)
911 WinCheckButton(hwnd, CMD_MAXIMIZED, TRUE);
912 else if (info->flags & INVISIBLE)
913 WinCheckButton(hwnd, CMD_INVISIBLE, TRUE);
914 }
915 WinCheckButton(hwnd, CMD_PROMPT, ((info->flags & PROMPT) != 0));
916 WinCheckButton(hwnd, CMD_KEEP, ((info->flags & KEEP) != 0));
917 WinCheckButton(hwnd, CMD_ONCE, ((info->flags & ONCE) != 0));
918 WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
919 if (info->env)
920 WinSetDlgItemText(hwnd, CMD_ENVIRON, info->env);
921 else
922 WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
923 for (x = 0; x < 40; x++) {
924 CHAR s[CCHMAXPATH + 24];
925
926 sprintf(s, "%s%s%s",
927 x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0 ? "Ctrl+" : NullStr,
928 x > IDM_COMMANDNUM19 - IDM_COMMANDNUM0 ? "Alt+" : NullStr,
929 (x > IDM_COMMANDNUM9 - IDM_COMMANDNUM0 &&
930 x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0) ||
931 x > IDM_COMMANDNUM29 - IDM_COMMANDNUM0 ? "Shift+" : NullStr);
932 sprintf(&s[strlen(s)], "%d", (x % 10) + 1 == 10 ? 0 : (x % 10) + 1);
933 sprintf(&s[strlen(s)], " %s", UsedHotKeyIDs[x] ? "(in use)" : NullStr);
934 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
935 MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
936 if (x == 39)
937 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
938 MPFROM2SHORT(LIT_END, 0), MPFROMP("none"));
939 if (info->HotKeyID == x + IDM_COMMANDNUM0)
940 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
941 MPFROM2SHORT(x, 0), MPFROMLONG(TRUE));
942 if (x == 39 && info->HotKeyID == 0)
943 WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
944 MPFROM2SHORT(x + 1, 0), MPFROMLONG(TRUE));
945 } // for
946 }
947 break;
948 }
949 }
950 return 0;
951
952 case WM_COMMAND:
953 switch (SHORT1FROMMP(mp1)) {
954 case CMD_FIND:
955 {
956 CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
957
958 *filename = 0;
959 if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
960 BldQuotedFileName(szfilename, filename);
961 WinSetDlgItemText(hwnd, CMD_CL, szfilename);
962 }
963 }
964 break;
965
966 case CMD_REORDER:
967 if (!cmdhead || !cmdhead->next) {
968 Runtime_Error(pszSrcFile, __LINE__, "no cmd");
969 break;
970 }
971 if (WinDlgBox(HWND_DESKTOP, hwnd, ReOrderProc, FM3ModHandle,
972 RE_FRAME, MPVOID)) {
973 WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
974 WinSetDlgItemText(hwnd, CMD_CL, NullStr);
975 WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
976 info = cmdhead;
977 while (info) {
978 x = (SHORT) WinSendDlgItemMsg(hwnd,
979 CMD_LISTBOX,
980 LM_INSERTITEM,
981 MPFROM2SHORT(LIT_END, 0),
982 MPFROMP(info->title));
983 if (x >= 0)
984 WinSendDlgItemMsg(hwnd,
985 CMD_LISTBOX,
986 LM_SETITEMHANDLE,
987 MPFROMSHORT(x), MPFROMP(info));
988 info = info->next;
989 }
990 WinSendDlgItemMsg(hwnd,
991 CMD_LISTBOX,
992 LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
993 WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
994 WinCheckButton(hwnd, CMD_PROMPT, FALSE);
995 WinCheckButton(hwnd, CMD_ONCE, FALSE);
996 save_commands();
997 }
998 break;
999
1000 case DID_OK:
1001 {
1002 COMMAND *temp;
1003 BOOL fDontCheckHotKey = FALSE;
1004
1005 temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
1006 if (!temp)
1007 break; //already complained
1008 temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1009 if (!temp->pszCmdLine) {
1010 free (temp);
1011 break; //already complained
1012 }
1013 if (QueryCommandSettings(hwnd, temp)){
1014 if (temp->HotKeyID == 0)
1015 fDontCheckHotKey = TRUE;
1016 info = add_command(temp, fDontCheckHotKey);
1017 if (info == (LINKCMDS *) -1) {
1018 free(temp->pszCmdLine);
1019 free(temp);
1020 break;
1021 }
1022 }
1023 else {
1024 free(temp->pszCmdLine);
1025 free(temp);
1026 break;
1027 }
1028 free(temp->pszCmdLine);
1029 free(temp);
1030 save_commands();
1031 WinDismissDlg(hwnd, 0);
1032 break;
1033 }
1034
1035 case DID_CANCEL:
1036 WinDismissDlg(hwnd, 0);
1037 break;
1038
1039 case IDM_HELP:
1040 if (hwndHelp)
1041 WinSendMsg(hwndHelp,
1042 HM_DISPLAY_HELP,
1043 MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
1044 break;
1045
1046 case CMD_ADD:
1047 {
1048 COMMAND *temp;
1049 BOOL fDontCheckHotKey = FALSE;
1050
1051 temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
1052 if (!temp)
1053 break; //already complained
1054 temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1055 if (!temp->pszCmdLine) {
1056 free (temp);
1057 break; //already complained
1058 }
1059 if (!QueryCommandSettings(hwnd, temp)) {
1060 free(temp->pszCmdLine);
1061 free(temp);
1062 break;
1063 }
1064 else {
1065 if (temp->HotKeyID == 0)
1066 fDontCheckHotKey = TRUE;
1067 info = add_command(temp, fDontCheckHotKey);
1068 if (!info) {
1069 saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
1070 GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp->title);
1071 free(temp->pszCmdLine);
1072 free(temp);
1073 break;
1074 }
1075 if (info == (LINKCMDS *) -1) {
1076 free(temp->pszCmdLine);
1077 free(temp);
1078 break;
1079 }
1080 x = (SHORT) WinSendDlgItemMsg(hwnd,
1081 CMD_LISTBOX,
1082 LM_INSERTITEM,
1083 MPFROM2SHORT(LIT_END, 0),
1084 MPFROMP(temp->title));
1085 if (x >= 0) {
1086 WinSendDlgItemMsg(hwnd,
1087 CMD_LISTBOX,
1088 LM_SETITEMHANDLE,
1089 MPFROMSHORT(x), MPFROMP(info));
1090 WinSendDlgItemMsg(hwnd,
1091 CMD_LISTBOX,
1092 LM_SELECTITEM,
1093 MPFROMSHORT(x), MPFROMSHORT(TRUE));
1094 }
1095 save_commands();
1096 }
1097 free(temp->pszCmdLine);
1098 free(temp);
1099 break;
1100 }
1101
1102 case CMD_DELETE:
1103 {
1104 CHAR temp[100];
1105 CHAR key[120];
1106
1107 WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
1108 bstripcr(temp);
1109 if (!kill_command(temp))
1110 Runtime_Error(pszSrcFile, __LINE__, "kill_command");
1111 else {
1112 sprintf(key, "COMMAND.%sID", temp);
1113 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1114 sprintf(key, "COMMAND.%sHotKeyID", temp);
1115 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1116 sprintf(key, "COMMAND.%senv", temp);
1117 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1118 sprintf(key, "COMMAND.%sflags", temp);
1119 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1120 sprintf(key, "COMMAND.%sCmdLine", temp);
1121 PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
1122 x = (SHORT) WinSendDlgItemMsg(hwnd,
1123 CMD_LISTBOX,
1124 LM_QUERYSELECTION,
1125 MPFROMSHORT(LIT_FIRST), MPVOID);
1126 if (x >= 0) {
1127 WinSendDlgItemMsg(hwnd,
1128 CMD_LISTBOX,
1129 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
1130 WinSendDlgItemMsg(hwnd,
1131 CMD_LISTBOX,
1132 LM_SELECTITEM,
1133 MPFROMSHORT(0), MPFROMSHORT(TRUE));
1134 }
1135 save_commands();
1136 }
1137 }
1138 break;
1139
1140 case CMD_REPLACE:
1141 {
1142 COMMAND *temp;
1143 CHAR keyID[120];
1144 CHAR keyHotKeyID[120];
1145 CHAR keyenv[120];
1146 INT ID = 0;
1147 INT HotKeyID = 0;
1148 ULONG size;
1149 BOOL fDontCheckHotKey = FALSE;
1150
1151 // Query the dialog
1152 temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
1153 if (!temp)
1154 break; //already complained
1155 temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1156 if (!temp->pszCmdLine) {
1157 free (temp);
1158 break; //already complained
1159 }
1160 if (!QueryCommandSettings(hwnd, temp)) {
1161 free(temp->pszCmdLine);
1162 free(temp);
1163 break;
1164 }
1165 //remember item location in the list
1166 y = (SHORT) WinSendDlgItemMsg(hwnd,
1167 CMD_LISTBOX,
1168 LM_QUERYSELECTION,
1169 MPFROMSHORT(LIT_CURSOR), MPVOID);
1170 //Delete
1171 sprintf(keyID, "COMMAND.%sID", temp->title);
1172 sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp->title);
1173 sprintf(keyenv, "COMMAND.%senv", temp->title);
1174 PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
1175 PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
1176 temp->ID = ID;
1177 if (temp->HotKeyID == HotKeyID || temp->HotKeyID == 0)
1178 fDontCheckHotKey = TRUE;
1179 if (kill_command(temp->title)) {
1180 PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
1181 PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
1182 PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
1183 x = (SHORT) WinSendDlgItemMsg(hwnd,
1184 CMD_LISTBOX,
1185 LM_QUERYSELECTION,
1186 MPFROMSHORT(LIT_FIRST), MPVOID);
1187 if (x >= 0) {
1188 WinSendDlgItemMsg(hwnd,
1189 CMD_LISTBOX,
1190 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
1191 WinSendDlgItemMsg(hwnd,
1192 CMD_LISTBOX,
1193 LM_SELECTITEM,
1194 MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
1195 }
1196 } // then do an add
1197 info = add_command(temp, fDontCheckHotKey);
1198 if (!info || info == (LINKCMDS *) -1) {
1199 if (!info)
1200 saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
1201 GetPString(IDS_CANTADDCOMMANDTEXT),
1202 temp->title);
1203 }
1204 else {
1205 //put item back in original place
1206 x = (SHORT) WinSendDlgItemMsg(hwnd,
1207 CMD_LISTBOX,
1208 LM_INSERTITEM,
1209 MPFROM2SHORT(y, 0),
1210 MPFROMP(temp->title));
1211 if (x >= 0) {
1212 LINKCMDS *temphead = NULL,*last = NULL, *temptail = NULL;
1213 SHORT numitems, sSelect = 0;
1214
1215 WinSendDlgItemMsg(hwnd,
1216 CMD_LISTBOX,
1217 LM_SETITEMHANDLE,
1218 MPFROMSHORT(x), MPFROMP(info));
1219 WinSendDlgItemMsg(hwnd,
1220 CMD_LISTBOX,
1221 LM_SELECTITEM,
1222 MPFROMSHORT(x), MPFROMSHORT(TRUE));
1223 //then reorder
1224 numitems = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
1225 LM_QUERYITEMCOUNT,
1226 MPVOID, MPVOID);
1227
1228 while (numitems) {
1229
1230
1231 info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
1232 LM_QUERYITEMHANDLE,
1233 MPFROMSHORT(sSelect++),
1234 MPVOID);
1235 if (info) {
1236 if (!temphead) {
1237 temphead = info;
1238 info->prev = NULL;
1239 }
1240 else {
1241 last->next = info;
1242 info->prev = last;
1243 }
1244 temptail = info;
1245 last = info;
1246 info->next = NULL;
1247 }
1248 numitems--;
1249 }
1250 cmdhead = temphead;
1251 cmdtail = temptail;
1252 save_commands();
1253 }
1254 }
1255 xfree(temp->pszCmdLine, pszSrcFile, __LINE__);
1256 xfree(temp, pszSrcFile, __LINE__);
1257 }
1258 break;
1259 }
1260 return 0;
1261 }
1262# ifdef FORTIFY
1263 Fortify_LeaveScope();
1264# endif
1265 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1266}
1267
1268VOID RunCommand(HWND hwnd, INT cx)
1269{
1270 INT x;
1271 CHAR **list;
1272 LINKCMDS *info;
1273
1274 list = BuildList(hwnd);
1275 x = 0;
1276 info = cmdhead;
1277 while (info) {
1278 if (cx < 4300) {
1279 if (info->ID == cx)
1280 break;
1281 }
1282 else {
1283 if (info->HotKeyID == cx)
1284 break;
1285 }
1286 info = info->next;
1287 }
1288 if (info) {
1289
1290 INT flags;
1291
1292 x--;
1293 flags = info->flags;
1294 if (!(flags & FULLSCREEN))
1295 flags |= WINDOWED;
1296 if (flags & KEEP)
1297 flags |= SEPARATEKEEP;
1298 else
1299 flags |= SEPARATE;
1300 flags &= ~(KEEP | DIEAFTER);
1301 if (!strchr(info->pszCmdLine, '%')) {
1302 CHAR *fakelist[2];
1303
1304 *fakelist = "C";
1305 fakelist[1] = NULL;
1306 ExecOnList(hwnd,
1307 info->pszCmdLine,
1308 flags, NULL, info->env != NullStr ? info->env : NULL,
1309 fakelist, GetPString(IDS_EXECCMDTITLETEXT),
1310 pszSrcFile, __LINE__);
1311 }
1312 else if ((flags & ONCE) && list && list[0]) {
1313
1314 CHAR *fakelist[2];
1315 INT cntr;
1316
1317 flags &= (~ONCE);
1318 for (cntr = 0; list[cntr]; cntr++) {
1319 *fakelist = list[cntr];
1320 fakelist[1] = NULL;
1321 ExecOnList(hwnd,
1322 info->pszCmdLine,
1323 flags, NULL, info->env != NullStr ? info->env : NULL,
1324 fakelist, GetPString(IDS_EXECCMDTITLETEXT),
1325 pszSrcFile, __LINE__);
1326 }
1327 }
1328 else if (list && list[0])
1329 ExecOnList(hwnd,
1330 info->pszCmdLine,
1331 flags, NULL, info->env != NullStr ? info->env : NULL,
1332 list, GetPString(IDS_EXECCMDTITLETEXT),
1333 pszSrcFile, __LINE__);
1334 else
1335 return;
1336 }
1337 FreeList(list);
1338 DosPostEventSem(CompactSem);
1339}
1340
1341VOID EditCommands(HWND hwnd)
1342{
1343 static CHAR stop = 0;
1344
1345 if (stop)
1346 return;
1347 stop++;
1348 if (!cmdloaded)
1349 load_commands();
1350 WinDlgBox(HWND_DESKTOP,
1351 hwnd, CommandDlgProc, FM3ModHandle, CMD_FRAME, MPFROMP(&hwnd));
1352 stop = 0;
1353}
1354
1355#pragma alloc_text(COMMAND,command_title,free_commands,add_command,kill_command)
1356#pragma alloc_text(COMMAND,CommandDlgProc,EditCommands,ReOrderProc,CommandTextProc)
Note: See TracBrowser for help on using the repository browser.