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