source: trunk/dll/command.c@ 1498

Last change on this file since 1498 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

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