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