source: trunk/dll/instant.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 18 years ago

Indentation cleanup

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