source: trunk/dll/instant.c@ 1438

Last change on this file since 1438 was 1438, checked in by Gregg Young, 16 years ago

Improved drivebar changes; Added AddBackslashToPath() to remove repeatative code. replaced "
" with PCSZ variable; ANY_OBJ added the DosAlloc... (experimental)

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