source: trunk/dll/instant.c@ 1178

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

Ticket 187: Draft 2: Move remaining function declarations

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