source: trunk/dll/instant.c@ 1224

Last change on this file since 1224 was 1224, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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