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
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: instant.c 1156 2008-09-05 21:39:19Z jbs $
5
[342]6 Instant command
7
[123]8 Copyright (c) 1993-98 M. Kimes
[574]9 Copyright (c) 2004, 2007 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
25#include "fm3dlg.h"
26#include "fm3str.h"
27#include "mle.h"
[907]28#include "errutil.h" // Dos_Error...
29#include "strutil.h" // GetPString
[1156]30#include "instant.h"
[907]31#include "fm3dll.h"
[2]32
33#pragma data_seg(DATA1)
[342]34
35static PSZ pszSrcFile = __FILE__;
36
[2]37#define hwndMLE WinWindowFromID(hwnd,BAT_MLE)
38
39static INT batches = 0;
40
[551]41MRESULT EXPENTRY InstantDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[342]42{
[551]43 CHAR *path;
[342]44 APIRET rc;
[2]45 static CHAR *bat = NULL;
[551]46 static HWND myhwnd = (HWND) 0;
[2]47
[551]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 }
[574]62 WinSetWindowPtr(hwnd, QWL_USER, mp2);
[551]63 path = (CHAR *) mp2;
64 {
65 CHAR s[CCHMAXPATH + 81];
[2]66
[551]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) {
[2]74
[551]75 ULONG tlen = strlen(bat);
76 IPT iptOffset = 0L;
[2]77
[551]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;
[2]85
[551]86 case WM_COMMAND:
87 switch (SHORT1FROMMP(mp1)) {
88 case DID_OK:
[574]89 path = (CHAR *) WinQueryWindowPtr(hwnd, QWL_USER);
[551]90 {
91 CHAR s[CCHMAXPATH + 1];
92 FILE *fp;
93 IPT iptOffset = 0L;
94 LONG len, tlen, mem;
95 CHAR *rexx = "";
[2]96
[551]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");
[342]135 else {
[551]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,
[888]147 hwnd, pszSrcFile, __LINE__,
[551]148 path, NULL, "%s /C \"%s\"", GetCmdSpec(FALSE), s);
149 }
150 }
151 }
152 }
153 }
154 WinDismissDlg(hwnd, 0);
155 break;
[2]156
[551]157 case DID_CANCEL:
158 WinDismissDlg(hwnd, 0);
159 break;
[2]160
[551]161 case IDM_HELP:
[574]162 path = WinQueryWindowPtr(hwnd, QWL_USER);
[551]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,
[888]171 hwnd, pszSrcFile, __LINE__, NULL, NULL,
172 "%s /C HELP BATCH", GetCmdSpec(FALSE));
[551]173 else if (rc == MBID_CANCEL)
174 WinDismissDlg(hwnd, 0);
175 break;
176 }
177 return 0;
[2]178
[551]179 case WM_CLOSE:
180 case WM_DESTROY:
181 myhwnd = (HWND) 0;
182 break;
[2]183 }
[551]184 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]185}
[793]186
187#pragma alloc_text(INSTANT,InstantDlgProc)
Note: See TracBrowser for help on using the repository browser.