source: trunk/dll/instant.c@ 888

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

runemf2 now quotes executable strings if needed (Ticket 180); it also reports where it was called from on errors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1
2/***********************************************************************
3
4 $Id: instant.c 888 2007-12-22 22:02:11Z 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 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
15
16***********************************************************************/
17
18#define INCL_DOS
19#define INCL_WIN
20#include <os2.h>
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25#include <ctype.h>
26
27#include "fm3dll.h"
28#include "fm3dlg.h"
29#include "fm3str.h"
30#include "mle.h"
31
32#pragma data_seg(DATA1)
33
34static PSZ pszSrcFile = __FILE__;
35
36#define hwndMLE WinWindowFromID(hwnd,BAT_MLE)
37
38static INT batches = 0;
39
40MRESULT 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, QWL_USER, mp2);
62 path = (CHAR *) mp2;
63 {
64 CHAR s[CCHMAXPATH + 81];
65
66 sprintf(s, GetPString(IDS_INSTANTTITLETEXT), path);
67 WinSetWindowText(hwnd, s);
68 }
69 WinSendMsg(hwndMLE,
70 MLM_SETTEXTLIMIT, MPFROMLONG((LONG) (10240L)), MPVOID);
71 WinSendMsg(hwndMLE, MLM_FORMAT, MPFROM2SHORT(MLFIE_NOTRANS, 0), MPVOID);
72 if (bat) {
73
74 ULONG tlen = strlen(bat);
75 IPT iptOffset = 0L;
76
77 WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT,
78 MPFROMP(bat), MPFROMLONG(12287L));
79 WinSendMsg(hwndMLE, MLM_IMPORT, MPFROMP(&iptOffset), MPFROMP(tlen));
80 DosFreeMem(bat);
81 bat = NULL;
82 }
83 break;
84
85 case WM_COMMAND:
86 switch (SHORT1FROMMP(mp1)) {
87 case DID_OK:
88 path = (CHAR *) WinQueryWindowPtr(hwnd, QWL_USER);
89 {
90 CHAR s[CCHMAXPATH + 1];
91 FILE *fp;
92 IPT iptOffset = 0L;
93 LONG len, tlen, mem;
94 CHAR *rexx = "";
95
96 mem = MLEgetlen(hwndMLE);
97 if (mem) {
98 rc = DosAllocMem((PVOID) & bat, mem,
99 PAG_COMMIT | PAG_READ | PAG_WRITE);
100 if (rc || !bat) {
101 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
102 GetPString(IDS_OUTOFMEMORY));
103 WinDismissDlg(hwnd, 0);
104 break;
105 }
106 tlen =
107 (LONG) WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, MPVOID, MPVOID);
108 if (!tlen)
109 Runtime_Error(pszSrcFile, __LINE__, "no data");
110 else {
111 WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT,
112 MPFROMP(bat), MPFROMLONG(mem));
113 len = (LONG) WinSendMsg(hwndMLE, MLM_EXPORT,
114 MPFROMP(&iptOffset), MPFROMP(&tlen));
115 bat[len] = 0;
116 lstrip(bat);
117 while (strlen(bat) && bat[strlen(bat) - 1] == '\n' ||
118 bat[strlen(bat) - 1] == ' ') {
119 // fixme to understand
120 stripcr(bat);
121 rstrip(bat);
122 stripcr(bat);
123 rstrip(bat);
124 }
125 if (!*bat)
126 Runtime_Error(pszSrcFile, __LINE__, "no data");
127 else {
128 sprintf(s, "%s%sFMTMP%d.CMD", path,
129 (path[strlen(path) - 1] == '\\') ? "" : "\\",
130 batches++);
131 fp = fopen(s, "w");
132 if (!fp)
133 Runtime_Error(pszSrcFile, __LINE__, "fopen");
134 else {
135 if (!strncmp(bat, "/*", 2)) {
136 rexx = "'";
137 fprintf(fp, "%s\n", GetPString(IDS_REXXCOMMENT));
138 }
139 fprintf(fp, "%s%c:%s\n", rexx, toupper(*path), rexx);
140 fprintf(fp, "%sCD \"%s%s\"%s\n", rexx, path,
141 (strlen(path) < 3) ? "\\" : "", rexx);
142 fprintf(fp, "%s", bat);
143 fprintf(fp, "\n%sDEL \"%s\"%s\n", rexx, s, rexx);
144 fclose(fp);
145 runemf2(WINDOWED | SEPARATE,
146 hwnd, pszSrcFile, __LINE__,
147 path, NULL, "%s /C \"%s\"", GetCmdSpec(FALSE), s);
148 }
149 }
150 }
151 }
152 }
153 WinDismissDlg(hwnd, 0);
154 break;
155
156 case DID_CANCEL:
157 WinDismissDlg(hwnd, 0);
158 break;
159
160 case IDM_HELP:
161 path = WinQueryWindowPtr(hwnd, QWL_USER);
162 rc = saymsg(MB_YESNOCANCEL,
163 hwnd,
164 GetPString(IDS_INSTANTHELPTITLETEXT),
165 GetPString(IDS_INSTANTHELPTEXT),
166 path, (strlen(path) < 3) ? "\\" : "", path,
167 (path[strlen(path) - 1] == '\\') ? "" : "\\", batches);
168 if (rc == MBID_YES)
169 runemf2(WINDOWED | INVISIBLE | BACKGROUND,
170 hwnd, pszSrcFile, __LINE__, NULL, NULL,
171 "%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}
185
186#pragma alloc_text(INSTANT,InstantDlgProc)
Note: See TracBrowser for help on using the repository browser.