source: trunk/dll/cmdline.c@ 1749

Last change on this file since 1749 was 1749, checked in by John Small, 12 years ago

Ticket #522: Ensure use of wrapper functions where needed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: cmdline.c 1749 2014-02-28 16:46:26Z jbs $
5
6 User defined commands support
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 05 Jun 05 SHL Use QWL_USER
13 22 Jul 06 SHL Check more run time errors
14 29 Jul 06 SHL Use xfgets_bstripcr
15 22 Mar 07 GKY Use QWL_USER
16 16 Jun 07 SHL Update for OpenWatcom
17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
18 29 Feb 08 GKY Use xfree where appropriate
19 20 Apr 08 GKY New variable names; Save and Load command lines of user set length
20 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
21 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
22 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
23 13 Dec 09 GKY Fixed separate paramenters. Please note that appname should be used in
24 profile calls for user settings that work and are setable in more than one
25 miniapp; FM3Str should be used for setting only relavent to FM/2 or that
26 aren't user settable; realappname should be used for setting applicable to
27 one or more miniapp but not to FM/2
28 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
29 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
30 23 Oct 10 GKY Changes to populate and utilize a HELPTABLE for context specific help
31 28 Apr 14 JBS Ticket #522: Ensure use of wrapper functions where needed
32
33***********************************************************************/
34
35#include <stdlib.h>
36#include <string.h>
37#include <share.h>
38#include <io.h> // unlink
39
40#define INCL_DOS
41#define INCL_WIN
42#define INCL_LONGLONG // dircnrs.h
43
44#include "fm3dll.h"
45#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
46#include "arccnrs.h" // Data declaration(s)
47#include "fm2cmd.h" // Data declaration(s)
48#include "notebook.h" // Data declaration(s)
49#include "init.h" // Data declaration(s)
50#include "newview.h" // Data declarations
51#include "fm3dlg.h"
52#include "fm3str.h"
53#include "mle.h"
54#include "errutil.h" // Dos_Error...
55#include "strutil.h" // GetPString
56#include "mainwnd.h" // BubbleHelp
57#include "cmdline.h" // CmdLineDlgProc, CmdLine2DlgProc
58#include "chklist.h" // PosOverOkay
59#include "pathutil.h" // MaxCmdLineStr
60#include "strips.h" // bstrip
61#include "misc.h" // CheckDriveSpaceAvail
62#include "srchpath.h" // searchpath
63#include "wrappers.h" // xfgets_bstripcr
64#include "valid.h" // IsFile
65#include "dirs.h" // save_dir2
66#include "systemf.h"
67#include "fortify.h"
68
69#define MAXNUMCMDLINES 250
70
71typedef struct LINKCMDLINES
72{
73 CHAR *cmdline;
74 struct LINKCMDLINES *next;
75}
76LINKCMDLINES;
77
78static LINKCMDLINES *DoItYourselfCmdLine = NULL, *MiniCmdLine = NULL;
79static BOOL DoItYourselfLoaded = FALSE, MiniLoaded = FALSE;
80
81// Data definitions
82static PSZ pszSrcFile = __FILE__;
83
84#pragma data_seg(GLOBAL1)
85BOOL fSaveBigCmds;
86
87
88VOID load_cmdlines(BOOL DoItYourself)
89{
90 /** load linked list of cmdlines from CMDLINES.DAT file
91 * if DoItYourself = TRUE (main command line dialog)
92 * else load from CMDMINI.DAT (mini command line at
93 * bottom of main window).
94 */
95
96 FILE *fp;
97 LINKCMDLINES *info, *last = NULL, *CmdLineHead;
98 PSZ pszCmdLine;
99 //CHAR s[1024];
100 INT x = 0;
101 CHAR *moder = "r";
102
103 pszCmdLine = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
104 if (pszCmdLine) {
105 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
106 if (DoItYourself)
107 DoItYourselfLoaded = TRUE;
108 else
109 MiniLoaded = TRUE;
110 BldFullPathName(pszCmdLine, pFM2SaveDirectory,
111 (DoItYourself) ? PCSZ_CMDLINESDAT : PCSZ_CMDMINIDAT);
112 fp = xfsopen(pszCmdLine, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
113 if (fp) {
114 while (x < MAXNUMCMDLINES && !feof(fp)) {
115 if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
116 break;
117 if (pszCmdLine && *pszCmdLine != ';') {
118 info = xmalloc(sizeof(LINKCMDLINES), pszSrcFile, __LINE__);
119 if (info) {
120 x++;
121 info->cmdline = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
122 if (!info->cmdline)
123 free(info);
124 else {
125 info->next = NULL;
126 if (!CmdLineHead)
127 CmdLineHead = info;
128 else
129 last->next = info;
130 last = info;
131 }
132 }
133 }
134 }
135 fclose(fp);
136 }
137 free(pszCmdLine);
138 }
139 if (DoItYourself)
140 DoItYourselfCmdLine = CmdLineHead;
141 else
142 MiniCmdLine = CmdLineHead;
143}
144
145VOID save_cmdlines(BOOL DoItYourself)
146{
147 /** save linked list of cmdlines from CMDLINES.DAT file
148 * if DoItYourself = TRUE (main command line dialog)
149 * else load from CMDMINI.DAT (mini command line at
150 * bottom of main window).
151 */
152
153 LINKCMDLINES *info, *CmdLineHead;
154 FILE *fp;
155 PSZ pszCmdLine;
156 //CHAR s[CCHMAXPATH + 14];
157 CHAR *modew = "w";
158
159 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
160 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded))
161 return;
162 pszCmdLine = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
163 if (!pszCmdLine)
164 return;
165 BldFullPathName(pszCmdLine, pFM2SaveDirectory,
166 (DoItYourself) ? PCSZ_CMDLINESDAT : PCSZ_CMDMINIDAT);
167 if (CheckDriveSpaceAvail(pszCmdLine, ullDATFileSpaceNeeded, 1) == 2)
168 return; //already gave error msg
169 if (CmdLineHead) {
170 fp = xfopen(pszCmdLine, modew, pszSrcFile, __LINE__, FALSE);
171 if (fp) {
172 fputs(GetPString(IDS_COMMANDFILE2TEXT), fp);
173 info = CmdLineHead;
174 while (info) {
175 fprintf(fp, "%0.*s\n", 1000, info->cmdline);
176 info = info->next;
177 }
178 fclose(fp);
179 }
180 }
181 else
182 unlink(pszCmdLine);
183 if (DoItYourself)
184 DoItYourselfCmdLine = CmdLineHead;
185 else
186 MiniCmdLine = CmdLineHead;
187}
188
189BOOL add_cmdline(CHAR *cmdline, BOOL DoItYourself)
190{
191 LINKCMDLINES *info, *last = NULL, *CmdLineHead;
192 INT x = 0;
193
194 if (!cmdline || !*cmdline)
195 return FALSE;
196 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
197 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded))
198 load_cmdlines(DoItYourself);
199 info = CmdLineHead;
200 while (info) {
201 if (!stricmp(info->cmdline, cmdline))
202 return FALSE;
203 last = info;
204 info = info->next;
205 x++;
206 }
207 info = xmalloc(sizeof(LINKCMDLINES), pszSrcFile, __LINE__);
208 if (info) {
209 info->cmdline = xstrdup(cmdline, pszSrcFile, __LINE__);
210 if (!info->cmdline)
211 xfree(info, pszSrcFile, __LINE__);
212 else {
213 info->next = NULL;
214 if (!CmdLineHead)
215 CmdLineHead = info;
216 else
217 last->next = info;
218 if (x > MAXNUMCMDLINES) {
219 info = CmdLineHead;
220 CmdLineHead = CmdLineHead->next;
221 free(info);
222 }
223 if (DoItYourself)
224 DoItYourselfCmdLine = CmdLineHead;
225 else
226 MiniCmdLine = CmdLineHead;
227 return TRUE;
228 }
229 }
230 return FALSE;
231}
232
233BOOL remove_cmdline(CHAR *cmdline, BOOL DoItYourself)
234{
235 LINKCMDLINES *info, *last = NULL, *CmdLineHead;
236
237 if (!cmdline || !*cmdline)
238 return FALSE;
239 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded))
240 load_cmdlines(DoItYourself);
241 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
242 info = CmdLineHead;
243 while (info) {
244 if (!stricmp(info->cmdline, cmdline)) {
245 if (last)
246 last->next = info->next;
247 else
248 CmdLineHead = info->next;
249 xfree(info->cmdline, pszSrcFile, __LINE__);
250 free(info);
251 if (DoItYourself)
252 DoItYourselfCmdLine = CmdLineHead;
253 else
254 MiniCmdLine = CmdLineHead;
255 return TRUE;
256 }
257 last = info;
258 info = info->next;
259 }
260 return FALSE;
261}
262
263VOID free_cmdlines(BOOL DoItYourself)
264{
265 LINKCMDLINES *info, *next, *CmdLineHead;
266
267 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
268 info = CmdLineHead;
269 while (info) {
270 next = info->next;
271 xfree(info->cmdline, pszSrcFile, __LINE__);
272 free(info);
273 info = next;
274 }
275 CmdLineHead = NULL;
276 if (DoItYourself)
277 DoItYourselfCmdLine = CmdLineHead;
278 else
279 MiniCmdLine = CmdLineHead;
280 DosPostEventSem(CompactSem);
281}
282
283MRESULT EXPENTRY CmdBtnSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
284{
285 switch (msg) {
286 case WM_MOUSEMOVE:
287 {
288 ULONG strid = 0;
289
290 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
291 case EXEC2_CLR:
292 strid = IDS_CMDWIPEALLHELPTEXT;
293 break;
294 case EXEC2_DEL:
295 strid = IDS_CMDDELHILITEHELPTEXT;
296 break;
297 case IDM_HELP:
298 strid = IDS_CMDHELPHELPTEXT;
299 break;
300 case DID_CANCEL:
301 strid = IDS_CMDCLOSEBOXHELPTEXT;
302 break;
303 case EXEC2_OPEN:
304 strid = IDS_CMDOPENHELPTEXT;
305 break;
306 case EXEC2_CLOSE:
307 strid = IDS_CMDCLOSEHELPTEXT;
308 break;
309 case EXEC2_FILTER:
310 strid = IDS_CMDFILTERHELPTEXT;
311 break;
312 case EXEC2_KEEP:
313 strid = IDS_CMDKEEPHELPTEXT;
314 break;
315 case EXEC2_SAVE:
316 strid = IDS_CMDSAVEHELPTEXT;
317 break;
318 }
319 if (strid)
320 BubbleHelp(hwnd, TRUE, FALSE, FALSE, GetPString(strid));
321 }
322 break;
323 }
324 return PFNWPButton(hwnd, msg, mp1, mp2);
325}
326
327MRESULT EXPENTRY CmdListSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
328{
329 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
330
331 switch (msg) {
332 case WM_MOUSEMOVE:
333 if (hwndBubble)
334 WinDestroyWindow(hwndBubble);
335 break;
336
337 case WM_CHAR:
338 if (SHORT1FROMMP(mp1) & KC_KEYUP) {
339 if ((SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
340 (SHORT2FROMMP(mp2)) == VK_DELETE) {
341 if ((SHORT1FROMMP(mp1) & KC_CTRL) != KC_CTRL)
342 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
343 MPFROM2SHORT(EXEC2_DEL, 0), MPVOID);
344 else
345 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
346 MPFROM2SHORT(EXEC2_CLR, 0), MPVOID);
347 }
348 }
349 break;
350 }
351 return oldproc(hwnd, msg, mp1, mp2);
352}
353
354MRESULT EXPENTRY CmdLineDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
355{
356 EXECARGS *ex;
357
358 switch (msg) {
359 case WM_INITDLG:
360 ex = (EXECARGS *) mp2;
361 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) ex);
362 if (!ex || !ex->commandline) {
363 WinDismissDlg(hwnd, 0);
364 break;
365 }
366 if (*ex->title)
367 WinSetWindowText(hwnd, ex->title);
368 WinShowWindow(WinWindowFromID(hwnd, EXEC2_DEL), FALSE);
369 WinCheckButton(hwnd, EXEC_SAVECMD, fSaveBigCmds);
370 WinSendDlgItemMsg(hwnd, EXEC_CL, EM_SETTEXTLIMIT,
371 MPFROM2SHORT(1000, 0), MPVOID);
372 WinSetDlgItemText(hwnd, EXEC_CL, ex->commandline);
373 WinSetWindowPtr(WinWindowFromID(hwnd, EXEC_LISTBOX),
374 QWL_USER,
375 (PVOID) WinSubclassWindow(WinWindowFromID(hwnd,
376 EXEC_LISTBOX),
377 (PFNWP) CmdListSubProc));
378 if (*ex->commandline == ' ')
379 WinSendDlgItemMsg(hwnd, EXEC_CL, EM_SETSEL, MPFROM2SHORT(0, 0), MPVOID);
380 WinSendDlgItemMsg(hwnd, EXEC_CL, EM_SETINSERTMODE,
381 MPFROMSHORT(TRUE), MPVOID);
382 if (ex->flags & MINIMIZED)
383 WinCheckButton(hwnd, EXEC_MINIMIZED, TRUE);
384 else if (ex->flags & MAXIMIZED)
385 WinCheckButton(hwnd, EXEC_MAXIMIZED, TRUE);
386 else if (ex->flags & FULLSCREEN)
387 WinCheckButton(hwnd, EXEC_FULLSCREEN, TRUE);
388 else if (ex->flags & INVISIBLE)
389 WinCheckButton(hwnd, EXEC_INVISIBLE, TRUE);
390 else
391 WinCheckButton(hwnd, EXEC_DEFAULT, TRUE);
392 if ((ex->flags & SEPARATEKEEP) == SEPARATEKEEP)
393 WinCheckButton(hwnd, EXEC_KEEP, TRUE);
394 else
395 WinCheckButton(hwnd, EXEC_KEEP, FALSE);
396 MLEsetformat(WinWindowFromID(hwnd, EXEC_ENVIRON), MLFIE_NOTRANS);
397 MLEsetlimit(WinWindowFromID(hwnd, EXEC_ENVIRON), 1000);
398 WinSetDlgItemText(hwnd, EXEC_ENVIRON, ex->environment);
399// WinEnableWindow(WinWindowFromID(hwnd,EXEC_ENVIRON),FALSE);
400 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
401 PosOverOkay(hwnd);
402 break;
403
404 case UM_SETUP:
405 {
406 ULONG apptype = 0L;
407 // Change DosQueryAppType to xDosQueryAppType if "executable"is no longer local
408 CHAR executable[CCHMAXPATH], commandline[1001], *p;
409
410 ex = INSTDATA(hwnd);
411 if (!ex)
412 return 0;
413 WinSetDlgItemText(hwnd, EXEC_WARNING, NullStr);
414 WinSetDlgItemText(hwnd, EXEC_WARNING2, NullStr);
415 *commandline = 0;
416 WinQueryDlgItemText(hwnd, EXEC_CL, 1000, commandline);
417 if (!*commandline)
418 return 0;
419 if (*ex->path) {
420 strcpy(executable, ex->path);
421 AddBackslashToPath(executable);
422 //if (executable[strlen(executable) - 1] != '\\')
423 // strcat(executable, "\\");
424 }
425 else
426 *executable = 0;
427 strncat(executable, commandline, CCHMAXPATH - strlen(executable));
428 executable[CCHMAXPATH - 1] = 0;
429 p = strchr(executable, ' ');
430 if (p)
431 *p = 0;
432 if (IsFile(executable) == -1) {
433 strncpy(executable, commandline, CCHMAXPATH);
434 executable[CCHMAXPATH - 1] = 0;
435 p = strchr(executable, ' ');
436 if (p)
437 *p = 0;
438 if (IsFile(executable) == -1) {
439 p = searchpath(executable);
440 if (*p)
441 strcpy(executable, p);
442 else {
443 WinSetDlgItemText(hwnd,
444 EXEC_WARNING2,
445 (CHAR *) GetPString(IDS_CANTFINDFILETEXT));
446 break;
447 }
448 }
449 }
450 if (DosQueryAppType(executable, &apptype) ||
451 (apptype && !(apptype &
452 (FAPPTYP_NOTWINDOWCOMPAT |
453 FAPPTYP_WINDOWCOMPAT |
454 FAPPTYP_WINDOWAPI |
455 FAPPTYP_BOUND |
456 FAPPTYP_DOS |
457 FAPPTYP_WINDOWSREAL |
458 FAPPTYP_WINDOWSPROT | FAPPTYP_32BIT | 0x1000)))) {
459 p = strchr(executable, '.');
460 if (p) {
461 if (!stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTCMD) ||
462 !stricmp(p, PCSZ_DOTBTM)) {
463 WinSetDlgItemText(hwnd,
464 EXEC_WARNING2,
465 (CHAR *) GetPString(IDS_RUNTHRUCMDEXETEXT));
466 break;
467 }
468 }
469 WinSetDlgItemText(hwnd, EXEC_WARNING2, (CHAR *) GetPString(IDS_NOTDIRECTEXETEXT));
470 }
471 else if (apptype) { // acceptable
472
473 CHAR s[257];
474
475 *s = 0;
476 WinSetDlgItemText(hwnd, EXEC_WARNING, (CHAR *) GetPString(IDS_ACCEPTABLEAPPTEXT));
477 if (apptype & FAPPTYP_DOS)
478 strcat(s, GetPString(IDS_DOSTEXT));
479 if (apptype & FAPPTYP_WINDOWSREAL) {
480 if (*s)
481 strcat(s, " ");
482 strcat(s, GetPString(IDS_WINDOWSREALTEXT));
483 }
484 if (apptype & FAPPTYP_WINDOWSPROT) {
485 if (*s)
486 strcat(s, " ");
487 strcat(s, GetPString(IDS_WINDOWSPROTTEXT));
488 }
489 if (apptype & 0x1000) {
490 if (*s)
491 strcat(s, " ");
492 strcat(s, GetPString(IDS_WINDOWSENHTEXT));
493 }
494 if ((apptype & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) {
495 if (*s)
496 strcat(s, " ");
497 strcat(s, GetPString(IDS_PMTEXT));
498 WinCheckButton(hwnd, EXEC_FULLSCREEN, FALSE);
499 WinEnableWindow(WinWindowFromID(hwnd, EXEC_FULLSCREEN), FALSE);
500 }
501 if (apptype & FAPPTYP_BOUND) {
502 if (*s)
503 strcat(s, " ");
504 strcat(s, GetPString(IDS_BOUNDTEXT));
505 }
506 if ((apptype & FAPPTYP_WINDOWCOMPAT) &&
507 !(apptype & FAPPTYP_NOTWINDOWCOMPAT)) {
508 if (*s)
509 strcat(s, " ");
510 strcat(s, GetPString(IDS_VIOTEXT));
511 }
512 if ((apptype & FAPPTYP_NOTWINDOWCOMPAT) &&
513 !(apptype & FAPPTYP_WINDOWCOMPAT)) {
514 if (*s)
515 strcat(s, " ");
516 strcat(s, GetPString(IDS_FULLSCREENTEXT));
517 }
518 if (apptype & FAPPTYP_32BIT) {
519 if (*s)
520 strcat(s, " ");
521 strcat(s, GetPString(IDS_32BITTEXT));
522 }
523 WinSetDlgItemText(hwnd, EXEC_WARNING2, s);
524 if ((apptype & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL |
525 FAPPTYP_WINDOWSPROT | 0x1000)) ||
526 ((apptype & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI)) {
527 WinCheckButton(hwnd, EXEC_KEEP, FALSE);
528 WinEnableWindow(WinWindowFromID(hwnd, EXEC_KEEP), FALSE);
529 }
530 if (apptype & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | 0x1000))
531 WinCheckButton(hwnd, EXEC_FULLSCREEN, TRUE);
532 }
533 else
534 WinSetDlgItemText(hwnd, EXEC_WARNING2, (CHAR *) GetPString(IDS_UNKNOWNDEFAULTTEXT));
535 }
536 return 0;
537
538 case WM_ADJUSTWINDOWPOS:
539 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
540 break;
541
542 case UM_SETDIR:
543 PaintRecessedWindow(WinWindowFromID(hwnd,
544 EXEC_WARNING2),
545 (HPS) 0, FALSE, FALSE);
546 return 0;
547
548 case UM_RESCAN:
549 WinSendDlgItemMsg(hwnd, EXEC_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
550 if (!DoItYourselfLoaded)
551 load_cmdlines(TRUE);
552 {
553 LINKCMDLINES *info;
554
555 info = DoItYourselfCmdLine;
556 while (info) {
557 WinSendDlgItemMsg(hwnd,
558 EXEC_LISTBOX,
559 LM_INSERTITEM,
560 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->cmdline));
561 info = info->next;
562 }
563 }
564 return 0;
565
566 case WM_CONTROL:
567 switch (SHORT1FROMMP(mp1)) {
568 case EXEC_SAVECMD:
569 {
570 fSaveBigCmds = (fSaveBigCmds) ? FALSE : TRUE;
571 WinCheckButton(hwnd, EXEC_SAVECMD, fSaveBigCmds);
572 PrfWriteProfileData(fmprof, appname, "SaveBigCmds", &fSaveBigCmds, sizeof(BOOL));
573 }
574 break;
575 case EXEC_CL:
576 switch (SHORT2FROMMP(mp1)) {
577 case EN_KILLFOCUS:
578 ex = INSTDATA(hwnd);
579 if (!ex || !ex->dropped)
580 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
581 break;
582 }
583 break;
584 case EXEC_LISTBOX:
585 switch (SHORT2FROMMP(mp1)) {
586 case LN_KILLFOCUS:
587 ex = INSTDATA(hwnd);
588 if (ex) {
589 if (ex->dropped)
590 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(EXEC_DROP, 0), MPVOID);
591 }
592 break;
593 case LN_ENTER:
594 {
595 SHORT x;
596 CHAR cmdline[1001];
597
598 x = (SHORT) WinSendDlgItemMsg(hwnd,
599 EXEC_LISTBOX,
600 LM_QUERYSELECTION,
601 MPFROMSHORT(LIT_FIRST), MPVOID);
602 if (x >= 0) {
603 *cmdline = 0;
604 WinSendDlgItemMsg(hwnd,
605 EXEC_LISTBOX,
606 LM_QUERYITEMTEXT,
607 MPFROM2SHORT(x,
608 sizeof(cmdline)),
609 MPFROMP(cmdline));
610 bstrip(cmdline);
611 if (*cmdline) {
612 WinSetDlgItemText(hwnd, EXEC_CL, cmdline);
613 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(EXEC_DROP, 0), MPVOID);
614 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
615 }
616 }
617 }
618 break;
619 }
620 break;
621 }
622 return 0;
623
624 case WM_HELP:
625 if (hwndHelp)
626 WinSendMsg(hwndHelp,
627 HM_DISPLAY_HELP,
628 MPFROM2SHORT(HELP_CMDLINE, 0), MPFROMSHORT(HM_RESOURCEID));
629 break;
630
631 case WM_COMMAND:
632 switch (SHORT1FROMMP(mp1)) {
633 case EXEC2_CLR:
634 free_cmdlines(TRUE);
635 save_cmdlines(TRUE);
636 WinSendDlgItemMsg(hwnd, EXEC_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
637 break;
638 case EXEC2_DEL:
639 {
640 SHORT x;
641 CHAR cmdline[1001];
642
643 x = (SHORT) WinSendDlgItemMsg(hwnd,
644 EXEC_LISTBOX,
645 LM_QUERYSELECTION,
646 MPFROMSHORT(LIT_FIRST), MPVOID);
647 if (x >= 0) {
648 *cmdline = 0;
649 WinSendDlgItemMsg(hwnd,
650 EXEC_LISTBOX,
651 LM_QUERYITEMTEXT,
652 MPFROM2SHORT(x, sizeof(cmdline)),
653 MPFROMP(cmdline));
654 bstrip(cmdline);
655 if (*cmdline) {
656 if (remove_cmdline(cmdline, TRUE) && fSaveBigCmds) {
657 save_cmdlines(TRUE);
658 WinSendDlgItemMsg(hwnd,
659 EXEC_LISTBOX,
660 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
661 if (x)
662 x--;
663 WinSendDlgItemMsg(hwnd,
664 EXEC_LISTBOX,
665 LM_SELECTITEM,
666 MPFROMSHORT(x), MPFROMSHORT(TRUE));
667 }
668 }
669 }
670 }
671 break;
672 case EXEC_DROP:
673 ex = INSTDATA(hwnd);
674 if (ex) {
675 if (!ex->dropped) {
676 *ex->tempprompt = 0;
677 WinQueryDlgItemText(hwnd,
678 EXEC_WARNING2,
679 sizeof(ex->tempprompt), ex->tempprompt);
680 WinSetDlgItemText(hwnd, EXEC_WARNING2, (CHAR *) GetPString(IDS_CMDSELCMDHELPTEXT));
681 ex->dropped = TRUE;
682 if ((SHORT) WinSendDlgItemMsg(hwnd,
683 EXEC_LISTBOX,
684 LM_QUERYITEMCOUNT,
685 MPVOID, MPVOID) == 0)
686 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
687 WinShowWindow(WinWindowFromID(hwnd, EXEC_CL), FALSE);
688 WinShowWindow(WinWindowFromID(hwnd, EXEC_WARNING), FALSE);
689 WinShowWindow(WinWindowFromID(hwnd, EXEC_DEFAULT), FALSE);
690 WinShowWindow(WinWindowFromID(hwnd, EXEC_MINIMIZED), FALSE);
691 WinShowWindow(WinWindowFromID(hwnd, EXEC_MAXIMIZED), FALSE);
692 WinShowWindow(WinWindowFromID(hwnd, EXEC_FULLSCREEN), FALSE);
693 WinShowWindow(WinWindowFromID(hwnd, EXEC_INVISIBLE), FALSE);
694 WinShowWindow(WinWindowFromID(hwnd, EXEC_KEEP), FALSE);
695 WinShowWindow(WinWindowFromID(hwnd, EXEC_ENVIRON), FALSE);
696 WinShowWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
697 WinShowWindow(WinWindowFromID(hwnd, IDM_HELP), FALSE);
698 WinShowWindow(WinWindowFromID(hwnd, EXEC_ABORT), FALSE);
699 WinShowWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
700 WinShowWindow(WinWindowFromID(hwnd, EXEC_LISTBOX), TRUE);
701 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, EXEC_LISTBOX));
702 WinSetDlgItemText(hwnd, EXEC_DROP, "^");
703 WinShowWindow(WinWindowFromID(hwnd, EXEC2_DEL), TRUE);
704 }
705 else {
706 ex->dropped = FALSE;
707 WinSetDlgItemText(hwnd, EXEC_WARNING2, ex->tempprompt);
708 WinShowWindow(WinWindowFromID(hwnd, EXEC_LISTBOX), FALSE);
709 WinShowWindow(WinWindowFromID(hwnd, EXEC_CL), TRUE);
710 WinShowWindow(WinWindowFromID(hwnd, EXEC_WARNING), TRUE);
711 WinShowWindow(WinWindowFromID(hwnd, EXEC_DEFAULT), TRUE);
712 WinShowWindow(WinWindowFromID(hwnd, EXEC_MINIMIZED), TRUE);
713 WinShowWindow(WinWindowFromID(hwnd, EXEC_MAXIMIZED), TRUE);
714 WinShowWindow(WinWindowFromID(hwnd, EXEC_FULLSCREEN), TRUE);
715 WinShowWindow(WinWindowFromID(hwnd, EXEC_INVISIBLE), TRUE);
716 WinShowWindow(WinWindowFromID(hwnd, EXEC_KEEP), TRUE);
717 WinShowWindow(WinWindowFromID(hwnd, EXEC_ENVIRON), TRUE);
718 WinShowWindow(WinWindowFromID(hwnd, DID_OK), TRUE);
719 WinShowWindow(WinWindowFromID(hwnd, IDM_HELP), TRUE);
720 WinShowWindow(WinWindowFromID(hwnd, EXEC_ABORT), TRUE);
721 WinShowWindow(WinWindowFromID(hwnd, DID_CANCEL), TRUE);
722 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, EXEC_CL));
723 WinSetDlgItemText(hwnd, EXEC_DROP, "v");
724 WinShowWindow(WinWindowFromID(hwnd, EXEC2_DEL), FALSE);
725 }
726 }
727 break;
728
729 case DID_OK:
730 ex = INSTDATA(hwnd);
731 WinQueryDlgItemText(hwnd, EXEC_CL, 1000, ex->commandline);
732 ex->flags = CheckExecutibleFlags(hwnd, 2);
733 strset(ex->environment, 0);
734 WinQueryDlgItemText(hwnd, EXEC_ENVIRON, 1000, ex->environment);
735 if (add_cmdline(ex->commandline, TRUE) && fSaveBigCmds)
736 save_cmdlines(TRUE);
737 WinDismissDlg(hwnd, 1);
738 break;
739
740 case DID_CANCEL:
741 WinDismissDlg(hwnd, 0);
742 break;
743
744 case EXEC_ABORT:
745 WinDismissDlg(hwnd, 2);
746 break;
747
748 case IDM_HELP:
749 if (hwndHelp)
750 WinSendMsg(hwndHelp,
751 HM_DISPLAY_HELP,
752 MPFROM2SHORT(HELP_CMDLINE, 0), MPFROMSHORT(HM_RESOURCEID));
753 break;
754 }
755 return 0;
756
757 case WM_DESTROY:
758 break;
759 }
760 return WinDefDlgProc(hwnd, msg, mp1, mp2);
761}
762
763MRESULT EXPENTRY CmdLine2DlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
764{
765 switch (msg) {
766 case WM_INITDLG:
767 if (!mp2) {
768 WinDismissDlg(hwnd, 0);
769 break;
770 }
771 WinSetWindowPtr(hwnd, QWL_USER, mp2);
772 {
773 int x;
774 USHORT ids[] = { IDM_HELP, EXEC2_CLR, EXEC2_DEL, EXEC2_KEEP, EXEC2_SAVE,
775 EXEC2_OPEN, EXEC2_CLOSE, EXEC2_FILTER, DID_CANCEL, 0
776 };
777
778 WinSetWindowPtr(WinWindowFromID(hwnd, EXEC2_LISTBOX),
779 QWL_USER,
780 (PVOID) WinSubclassWindow(WinWindowFromID(hwnd,
781 EXEC2_LISTBOX),
782 (PFNWP) CmdListSubProc));
783 for (x = 0; ids[x]; x++)
784 WinSetWindowPtr(WinWindowFromID(hwnd, ids[x]),
785 QWL_USER,
786 (PVOID) WinSubclassWindow(WinWindowFromID(hwnd,
787 ids[x]),
788 (PFNWP) CmdBtnSubProc));
789 }
790 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
791 break;
792
793 case UM_RESCAN:
794 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
795 if (!MiniLoaded)
796 load_cmdlines(FALSE);
797 {
798 LINKCMDLINES *info;
799
800 info = MiniCmdLine;
801 while (info) {
802 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_INSERTITEM,
803 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->cmdline));
804 info = info->next;
805 }
806 }
807 return 0;
808
809 case WM_CONTROL:
810 switch (SHORT1FROMMP(mp1)) {
811 case EXEC2_LISTBOX:
812 switch (SHORT2FROMMP(mp1)) {
813 case LN_ENTER:
814 {
815 SHORT x;
816 CHAR *cmdline = WinQueryWindowPtr(hwnd, QWL_USER);
817
818 x = (SHORT) WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX,
819 LM_QUERYSELECTION,
820 MPFROMSHORT(LIT_FIRST), MPVOID);
821 if (x >= 0) {
822 *cmdline = 0;
823 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_QUERYITEMTEXT,
824 MPFROM2SHORT(x, 1000), MPFROMP(cmdline));
825 bstrip(cmdline);
826 if (*cmdline)
827 WinDismissDlg(hwnd, 1);
828 }
829 }
830 break;
831 }
832 break;
833 }
834 return 0;
835
836 case WM_COMMAND:
837 switch (SHORT1FROMMP(mp1)) {
838 case EXEC2_KEEP:
839 case EXEC2_SAVE:
840 case EXEC2_FILTER:
841 case EXEC2_CLOSE:
842 case EXEC2_OPEN:
843 case IDM_HELP:
844 {
845 char *cmdline = WinQueryWindowPtr(hwnd, QWL_USER);
846 ULONG strid = 0;
847
848 if (cmdline) {
849 switch (SHORT1FROMMP(mp1)) {
850 case EXEC2_OPEN:
851 strid = IDS_OPENCMDTEXT;
852 break;
853 case EXEC2_CLOSE:
854 strid = IDS_CLOSECMDTEXT;
855 break;
856 case EXEC2_FILTER:
857 strid = IDS_FILTERCMDTEXT;
858 break;
859 case EXEC2_SAVE:
860 strid = (fSaveMiniCmds) ? IDS_NOSAVECMDTEXT : IDS_SAVECMDTEXT;
861 break;
862 case EXEC2_KEEP:
863 strid = (fKeepCmdLine) ? IDS_NOKEEPCMDTEXT : IDS_KEEPCMDTEXT;
864 break;
865 case IDM_HELP:
866 strid = IDS_HELPCMDTEXT;
867 break;
868 }
869 if (strid) {
870 strcpy(cmdline, GetPString(strid));
871 WinDismissDlg(hwnd, 1);
872 }
873 }
874 break;
875 }
876 case EXEC2_CLR:
877 free_cmdlines(FALSE);
878 save_cmdlines(FALSE);
879 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
880 break;
881 case EXEC2_DEL:
882 {
883 SHORT x;
884 CHAR cmdline[1001];
885
886 x = (SHORT) WinSendDlgItemMsg(hwnd,
887 EXEC2_LISTBOX,
888 LM_QUERYSELECTION,
889 MPFROMSHORT(LIT_FIRST), MPVOID);
890 if (x >= 0) {
891 *cmdline = 0;
892 WinSendDlgItemMsg(hwnd,
893 EXEC2_LISTBOX,
894 LM_QUERYITEMTEXT,
895 MPFROM2SHORT(x, sizeof(cmdline)),
896 MPFROMP(cmdline));
897 bstrip(cmdline);
898 if (*cmdline) {
899 if (remove_cmdline(cmdline, FALSE) && fSaveMiniCmds) {
900 save_cmdlines(FALSE);
901 WinSendDlgItemMsg(hwnd,
902 EXEC2_LISTBOX,
903 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
904 if (x)
905 x--;
906 WinSendDlgItemMsg(hwnd,
907 EXEC2_LISTBOX,
908 LM_SELECTITEM,
909 MPFROMSHORT(x), MPFROMSHORT(TRUE));
910 }
911 }
912 }
913 }
914 break;
915 case DID_CANCEL:
916 WinDismissDlg(hwnd, 0);
917 break;
918 }
919 return 0;
920
921 case WM_DESTROY:
922 break;
923 }
924 return WinDefDlgProc(hwnd, msg, mp1, mp2);
925}
926
927#pragma alloc_text(CMDLINE1,CmdLineDlgProc,CmdListSubProc,CmdLine2DlgProc,CmdBtnSubProc)
928#pragma alloc_text(CMDLINE2,save_cmdlines,load_cmdlines,add_cmdline,remove_cmdline,free_cmdlines)
Note: See TracBrowser for help on using the repository browser.