source: trunk/dll/instant.c@ 1627

Last change on this file since 1627 was 1627, checked in by Gregg Young, 14 years ago

Add a low mem version of xDosAlloc* wrappers; move error checking into all the xDosAlloc* wrappers. Ticket 471

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