| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: instant.c 1628 2011-08-27 19:35:39Z gyoung $ | 
|---|
| 5 |  | 
|---|
| 6 | Instant command | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2004, 2008 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 | 12 Jul 09 GKY Add xDosQueryAppType and xDosAlloc... to allow FM/2 to load in high memory | 
|---|
| 16 | 26 Aug 11 GKY Add a low mem version of xDosAlloc* wrappers; move error checking into all the | 
|---|
| 17 | xDosAlloc* wrappers. | 
|---|
| 18 |  | 
|---|
| 19 | ***********************************************************************/ | 
|---|
| 20 |  | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 | #include <ctype.h> | 
|---|
| 23 |  | 
|---|
| 24 | #define INCL_DOS | 
|---|
| 25 | #define INCL_WIN | 
|---|
| 26 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| 27 |  | 
|---|
| 28 | #include "fm3dll.h" | 
|---|
| 29 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
| 30 | #include "fm3dlg.h" | 
|---|
| 31 | #include "fm3str.h" | 
|---|
| 32 | #include "mle.h" | 
|---|
| 33 | #include "errutil.h"                    // Dos_Error... | 
|---|
| 34 | #include "strutil.h"                    // GetPString | 
|---|
| 35 | #include "instant.h" | 
|---|
| 36 | #include "misc.h"                       // GetCmdSpec | 
|---|
| 37 | #include "systemf.h"                    // runemf2 | 
|---|
| 38 | #include "strips.h"                     // bstrip | 
|---|
| 39 | #include "wrappers.h"                   // xDosAllocMem | 
|---|
| 40 | #include "init.h"                       // Strings | 
|---|
| 41 |  | 
|---|
| 42 | #pragma data_seg(DATA1) | 
|---|
| 43 |  | 
|---|
| 44 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 45 |  | 
|---|
| 46 | #define hwndMLE            WinWindowFromID(hwnd,BAT_MLE) | 
|---|
| 47 |  | 
|---|
| 48 | static INT batches = 0; | 
|---|
| 49 |  | 
|---|
| 50 | MRESULT EXPENTRY InstantDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 51 | { | 
|---|
| 52 | CHAR *path; | 
|---|
| 53 | APIRET rc; | 
|---|
| 54 | static CHAR *bat = NULL; | 
|---|
| 55 | static HWND myhwnd = (HWND) 0; | 
|---|
| 56 |  | 
|---|
| 57 | switch (msg) { | 
|---|
| 58 | case WM_INITDLG: | 
|---|
| 59 | if (myhwnd) { | 
|---|
| 60 | Runtime_Error(pszSrcFile, __LINE__, "busy"); | 
|---|
| 61 | WinSendMsg(myhwnd, WM_SYSCOMMAND, MPFROM2SHORT(SC_RESTORE, 0), MPVOID); | 
|---|
| 62 | WinSetActiveWindow(HWND_DESKTOP, myhwnd); | 
|---|
| 63 | WinDismissDlg(hwnd, 0); | 
|---|
| 64 | break; | 
|---|
| 65 | } | 
|---|
| 66 | if (!mp2) { | 
|---|
| 67 | Runtime_Error(pszSrcFile, __LINE__, NULL); | 
|---|
| 68 | WinDismissDlg(hwnd, 0); | 
|---|
| 69 | break; | 
|---|
| 70 | } | 
|---|
| 71 | WinSetWindowPtr(hwnd, QWL_USER, mp2); | 
|---|
| 72 | path = (CHAR *) mp2; | 
|---|
| 73 | { | 
|---|
| 74 | CHAR s[CCHMAXPATH + 81]; | 
|---|
| 75 |  | 
|---|
| 76 | sprintf(s, GetPString(IDS_INSTANTTITLETEXT), path); | 
|---|
| 77 | WinSetWindowText(hwnd, s); | 
|---|
| 78 | } | 
|---|
| 79 | WinSendMsg(hwndMLE, | 
|---|
| 80 | MLM_SETTEXTLIMIT, MPFROMLONG((LONG) (10240L)), MPVOID); | 
|---|
| 81 | WinSendMsg(hwndMLE, MLM_FORMAT, MPFROM2SHORT(MLFIE_NOTRANS, 0), MPVOID); | 
|---|
| 82 | if (bat) { | 
|---|
| 83 |  | 
|---|
| 84 | ULONG tlen = strlen(bat); | 
|---|
| 85 | IPT iptOffset = 0L; | 
|---|
| 86 |  | 
|---|
| 87 | WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT, | 
|---|
| 88 | MPFROMP(bat), MPFROMLONG(12287L)); | 
|---|
| 89 | WinSendMsg(hwndMLE, MLM_IMPORT, MPFROMP(&iptOffset), MPFROMP(tlen)); | 
|---|
| 90 | DosFreeMem(bat); | 
|---|
| 91 | bat = NULL; | 
|---|
| 92 | } | 
|---|
| 93 | break; | 
|---|
| 94 |  | 
|---|
| 95 | case WM_COMMAND: | 
|---|
| 96 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 97 | case DID_OK: | 
|---|
| 98 | path = (CHAR *) WinQueryWindowPtr(hwnd, QWL_USER); | 
|---|
| 99 | { | 
|---|
| 100 | CHAR s[CCHMAXPATH + 1]; | 
|---|
| 101 | FILE *fp; | 
|---|
| 102 | IPT iptOffset = 0L; | 
|---|
| 103 | LONG len, tlen, mem; | 
|---|
| 104 | CHAR *rexx = ""; | 
|---|
| 105 | CHAR *modew = "w"; | 
|---|
| 106 |  | 
|---|
| 107 | mem = MLEgetlen(hwndMLE); | 
|---|
| 108 | if (mem) { | 
|---|
| 109 | if (xDosAllocMem((PVOID) & bat, mem, pszSrcFile, __LINE__)) { | 
|---|
| 110 | WinDismissDlg(hwnd, 0); | 
|---|
| 111 | break; | 
|---|
| 112 | } | 
|---|
| 113 | tlen = | 
|---|
| 114 | (LONG) WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, MPVOID, MPVOID); | 
|---|
| 115 | if (!tlen) | 
|---|
| 116 | Runtime_Error(pszSrcFile, __LINE__, NULL); | 
|---|
| 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) | 
|---|
| 133 | Runtime_Error(pszSrcFile, __LINE__, NULL); | 
|---|
| 134 | else { | 
|---|
| 135 | sprintf(s, "%s%sFMTMP%d.CMD", path, | 
|---|
| 136 | (path[strlen(path) - 1] == '\\') ? NullStr : PCSZ_BACKSLASH, | 
|---|
| 137 | batches++); | 
|---|
| 138 | fp = xfopen(s, modew, pszSrcFile, __LINE__, FALSE); | 
|---|
| 139 | //if (!fp) | 
|---|
| 140 | //  Runtime_Error(pszSrcFile, __LINE__, "fopen"); | 
|---|
| 141 | if (fp) { | 
|---|
| 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, | 
|---|
| 148 | (strlen(path) < 3) ? PCSZ_BACKSLASH : NullStr, rexx); | 
|---|
| 149 | fprintf(fp, "%s", bat); | 
|---|
| 150 | fprintf(fp, "\n%sDEL \"%s\"%s\n", rexx, s, rexx); | 
|---|
| 151 | fclose(fp); | 
|---|
| 152 | runemf2(WINDOWED | SEPARATE, | 
|---|
| 153 | hwnd, pszSrcFile, __LINE__, | 
|---|
| 154 | path, NULL, "%s /C \"%s\"", GetCmdSpec(FALSE), s); | 
|---|
| 155 | } | 
|---|
| 156 | } | 
|---|
| 157 | } | 
|---|
| 158 | } | 
|---|
| 159 | } | 
|---|
| 160 | WinDismissDlg(hwnd, 0); | 
|---|
| 161 | break; | 
|---|
| 162 |  | 
|---|
| 163 | case DID_CANCEL: | 
|---|
| 164 | WinDismissDlg(hwnd, 0); | 
|---|
| 165 | break; | 
|---|
| 166 |  | 
|---|
| 167 | case IDM_HELP: | 
|---|
| 168 | path = WinQueryWindowPtr(hwnd, QWL_USER); | 
|---|
| 169 | rc = saymsg(MB_YESNOCANCEL, | 
|---|
| 170 | hwnd, | 
|---|
| 171 | GetPString(IDS_INSTANTHELPTITLETEXT), | 
|---|
| 172 | GetPString(IDS_INSTANTHELPTEXT), | 
|---|
| 173 | path, (strlen(path) < 3) ? PCSZ_BACKSLASH : NullStr, path, | 
|---|
| 174 | (path[strlen(path) - 1] == '\\') ? NullStr : PCSZ_BACKSLASH, batches); | 
|---|
| 175 | if (rc == MBID_YES) | 
|---|
| 176 | runemf2(WINDOWED | INVISIBLE | BACKGROUND, | 
|---|
| 177 | hwnd, pszSrcFile, __LINE__, NULL, NULL, | 
|---|
| 178 | "%s /C HELP BATCH", GetCmdSpec(FALSE)); | 
|---|
| 179 | else if (rc == MBID_CANCEL) | 
|---|
| 180 | WinDismissDlg(hwnd, 0); | 
|---|
| 181 | break; | 
|---|
| 182 | } | 
|---|
| 183 | return 0; | 
|---|
| 184 |  | 
|---|
| 185 | case WM_CLOSE: | 
|---|
| 186 | case WM_DESTROY: | 
|---|
| 187 | myhwnd = (HWND) 0; | 
|---|
| 188 | break; | 
|---|
| 189 | } | 
|---|
| 190 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | #pragma alloc_text(INSTANT,InstantDlgProc) | 
|---|