| [123] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: instant.c 888 2007-12-22 22:02:11Z gyoung $ | 
|---|
|  | 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 |  | 
|---|
| [2] | 18 | #define INCL_DOS | 
|---|
|  | 19 | #define INCL_WIN | 
|---|
| [342] | 20 | #include <os2.h> | 
|---|
| [2] | 21 |  | 
|---|
|  | 22 | #include <stdlib.h> | 
|---|
|  | 23 | #include <stdio.h> | 
|---|
|  | 24 | #include <string.h> | 
|---|
|  | 25 | #include <ctype.h> | 
|---|
| [342] | 26 |  | 
|---|
| [2] | 27 | #include "fm3dll.h" | 
|---|
|  | 28 | #include "fm3dlg.h" | 
|---|
|  | 29 | #include "fm3str.h" | 
|---|
|  | 30 | #include "mle.h" | 
|---|
|  | 31 |  | 
|---|
|  | 32 | #pragma data_seg(DATA1) | 
|---|
| [342] | 33 |  | 
|---|
|  | 34 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 35 |  | 
|---|
| [2] | 36 | #define hwndMLE            WinWindowFromID(hwnd,BAT_MLE) | 
|---|
|  | 37 |  | 
|---|
|  | 38 | static INT batches = 0; | 
|---|
|  | 39 |  | 
|---|
| [551] | 40 | MRESULT 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 | } | 
|---|
| [574] | 61 | WinSetWindowPtr(hwnd, QWL_USER, mp2); | 
|---|
| [551] | 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: | 
|---|
| [574] | 88 | path = (CHAR *) WinQueryWindowPtr(hwnd, QWL_USER); | 
|---|
| [551] | 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, | 
|---|
| [888] | 146 | hwnd, pszSrcFile, __LINE__, | 
|---|
| [551] | 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: | 
|---|
| [574] | 161 | path = WinQueryWindowPtr(hwnd, QWL_USER); | 
|---|
| [551] | 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, | 
|---|
| [888] | 170 | hwnd, pszSrcFile, __LINE__, NULL, NULL, | 
|---|
|  | 171 | "%s /C HELP BATCH", GetCmdSpec(FALSE)); | 
|---|
| [551] | 172 | else if (rc == MBID_CANCEL) | 
|---|
|  | 173 | WinDismissDlg(hwnd, 0); | 
|---|
|  | 174 | break; | 
|---|
|  | 175 | } | 
|---|
|  | 176 | return 0; | 
|---|
| [2] | 177 |  | 
|---|
| [551] | 178 | case WM_CLOSE: | 
|---|
|  | 179 | case WM_DESTROY: | 
|---|
|  | 180 | myhwnd = (HWND) 0; | 
|---|
|  | 181 | break; | 
|---|
| [2] | 182 | } | 
|---|
| [551] | 183 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| [2] | 184 | } | 
|---|
| [793] | 185 |  | 
|---|
|  | 186 | #pragma alloc_text(INSTANT,InstantDlgProc) | 
|---|