source: trunk/dll/instant.c@ 1156

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

Ticket 187: Draft 1: Functions only

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