source: trunk/dll/instant.c@ 574

Last change on this file since 574 was 574, checked in by Gregg Young, 18 years ago

Use QWL_USER; Replace doesn't move the command and Okay on cmd dialog removed error on unchanged command

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: instant.c 574 2007-03-23 22:37:07Z gyoung $
5
6 Instant command
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2007 Steven H.Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 14 Jul 06 SHL Use Runtime_Error
13 22 Mar 07 GKY Use QWL_USER
14
15***********************************************************************/
16
17#define INCL_DOS
18#define INCL_WIN
19#include <os2.h>
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <ctype.h>
25
26#include "fm3dll.h"
27#include "fm3dlg.h"
28#include "fm3str.h"
29#include "mle.h"
30
31#pragma data_seg(DATA1)
32
33static PSZ pszSrcFile = __FILE__;
34
35#pragma alloc_text(INSTANT,InstantDlgProc)
36
37#define hwndMLE WinWindowFromID(hwnd,BAT_MLE)
38
39static INT batches = 0;
40
41MRESULT EXPENTRY InstantDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
42{
43 CHAR *path;
44 APIRET rc;
45 static CHAR *bat = NULL;
46 static HWND myhwnd = (HWND) 0;
47
48 switch (msg) {
49 case WM_INITDLG:
50 if (myhwnd) {
51 Runtime_Error(pszSrcFile, __LINE__, "busy");
52 WinSendMsg(myhwnd, WM_SYSCOMMAND, MPFROM2SHORT(SC_RESTORE, 0), MPVOID);
53 WinSetActiveWindow(HWND_DESKTOP, myhwnd);
54 WinDismissDlg(hwnd, 0);
55 break;
56 }
57 if (!mp2) {
58 Runtime_Error(pszSrcFile, __LINE__, "no data");
59 WinDismissDlg(hwnd, 0);
60 break;
61 }
62 WinSetWindowPtr(hwnd, QWL_USER, mp2);
63 path = (CHAR *) mp2;
64 {
65 CHAR s[CCHMAXPATH + 81];
66
67 sprintf(s, GetPString(IDS_INSTANTTITLETEXT), path);
68 WinSetWindowText(hwnd, s);
69 }
70 WinSendMsg(hwndMLE,
71 MLM_SETTEXTLIMIT, MPFROMLONG((LONG) (10240L)), MPVOID);
72 WinSendMsg(hwndMLE, MLM_FORMAT, MPFROM2SHORT(MLFIE_NOTRANS, 0), MPVOID);
73 if (bat) {
74
75 ULONG tlen = strlen(bat);
76 IPT iptOffset = 0L;
77
78 WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT,
79 MPFROMP(bat), MPFROMLONG(12287L));
80 WinSendMsg(hwndMLE, MLM_IMPORT, MPFROMP(&iptOffset), MPFROMP(tlen));
81 DosFreeMem(bat);
82 bat = NULL;
83 }
84 break;
85
86 case WM_COMMAND:
87 switch (SHORT1FROMMP(mp1)) {
88 case DID_OK:
89 path = (CHAR *) WinQueryWindowPtr(hwnd, QWL_USER);
90 {
91 CHAR s[CCHMAXPATH + 1];
92 FILE *fp;
93 IPT iptOffset = 0L;
94 LONG len, tlen, mem;
95 CHAR *rexx = "";
96
97 mem = MLEgetlen(hwndMLE);
98 if (mem) {
99 rc = DosAllocMem((PVOID) & bat, mem,
100 PAG_COMMIT | PAG_READ | PAG_WRITE);
101 if (rc || !bat) {
102 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
103 GetPString(IDS_OUTOFMEMORY));
104 WinDismissDlg(hwnd, 0);
105 break;
106 }
107 tlen =
108 (LONG) WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, MPVOID, MPVOID);
109 if (!tlen)
110 Runtime_Error(pszSrcFile, __LINE__, "no data");
111 else {
112 WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT,
113 MPFROMP(bat), MPFROMLONG(mem));
114 len = (LONG) WinSendMsg(hwndMLE, MLM_EXPORT,
115 MPFROMP(&iptOffset), MPFROMP(&tlen));
116 bat[len] = 0;
117 lstrip(bat);
118 while (strlen(bat) && bat[strlen(bat) - 1] == '\n' ||
119 bat[strlen(bat) - 1] == ' ') {
120 // fixme to understand
121 stripcr(bat);
122 rstrip(bat);
123 stripcr(bat);
124 rstrip(bat);
125 }
126 if (!*bat)
127 Runtime_Error(pszSrcFile, __LINE__, "no data");
128 else {
129 sprintf(s, "%s%sFMTMP%d.CMD", path,
130 (path[strlen(path) - 1] == '\\') ? "" : "\\",
131 batches++);
132 fp = fopen(s, "w");
133 if (!fp)
134 Runtime_Error(pszSrcFile, __LINE__, "fopen");
135 else {
136 if (!strncmp(bat, "/*", 2)) {
137 rexx = "'";
138 fprintf(fp, "%s\n", GetPString(IDS_REXXCOMMENT));
139 }
140 fprintf(fp, "%s%c:%s\n", rexx, toupper(*path), rexx);
141 fprintf(fp, "%sCD \"%s%s\"%s\n", rexx, path,
142 (strlen(path) < 3) ? "\\" : "", rexx);
143 fprintf(fp, "%s", bat);
144 fprintf(fp, "\n%sDEL \"%s\"%s\n", rexx, s, rexx);
145 fclose(fp);
146 runemf2(WINDOWED | SEPARATE,
147 hwnd,
148 path, NULL, "%s /C \"%s\"", GetCmdSpec(FALSE), s);
149 }
150 }
151 }
152 }
153 }
154 WinDismissDlg(hwnd, 0);
155 break;
156
157 case DID_CANCEL:
158 WinDismissDlg(hwnd, 0);
159 break;
160
161 case IDM_HELP:
162 path = WinQueryWindowPtr(hwnd, QWL_USER);
163 rc = saymsg(MB_YESNOCANCEL,
164 hwnd,
165 GetPString(IDS_INSTANTHELPTITLETEXT),
166 GetPString(IDS_INSTANTHELPTEXT),
167 path, (strlen(path) < 3) ? "\\" : "", path,
168 (path[strlen(path) - 1] == '\\') ? "" : "\\", batches);
169 if (rc == MBID_YES)
170 runemf2(WINDOWED | INVISIBLE | BACKGROUND,
171 hwnd, NULL, NULL, "%s /C HELP BATCH", GetCmdSpec(FALSE));
172 else if (rc == MBID_CANCEL)
173 WinDismissDlg(hwnd, 0);
174 break;
175 }
176 return 0;
177
178 case WM_CLOSE:
179 case WM_DESTROY:
180 myhwnd = (HWND) 0;
181 break;
182 }
183 return WinDefDlgProc(hwnd, msg, mp1, mp2);
184}
Note: See TracBrowser for help on using the repository browser.