source: trunk/dll/instant.c@ 1570

Last change on this file since 1570 was 1544, checked in by Gregg Young, 15 years ago

Changes to fopen and _fsopen to allow FM2 to be loaded in high memory

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