source: branches/v2.9/classes/c/c_common/mmrexx.c

Last change on this file was 2, checked in by stevenhl, 8 years ago

Import sources from cwmm-full.zip dated 2005-03-21

File size: 8.9 KB
Line 
1/*
2 * (C) Chris Wohlgemuth 2002-2003
3 *
4 */
5/*
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20/*
21 * If you need another license for your project/product contact me at
22 *
23 * http://www.os2world.com/cdwriting
24 * http://www.geocities.com/SiliconValley/Sector/5785/
25 */
26
27#define INCL_REXXSAA
28#define INCL_PM
29#define INCL_DOS
30
31#include <os2.h>
32#include <stdio.h>
33#include "except.h"
34#include <rexxsaa.h> /* needed for Rexx */
35#include "cwmmdataf.h"
36#include "cwaudioinc.h"
37#include "sys_funcs.h"
38
39PSZ queryInstallDir(void);
40
41typedef ULONG (APIENTRY FNWPSFUNC)(WPObject* ,...);
42typedef FNWPSFUNC *PFNWPSFUNC;
43
44
45BOOL getStringFromRexxScript(PSZ rexxFile, char* chrResult, ULONG ulSize)
46{
47
48 RXSTRING arg[1]; /* argument string for REXX */
49 RXSTRING rexxretval; /* return value from REXX */
50 APIRET rc; /* return code from REXX */
51 SHORT rexxrc = 0; /* return code from function */
52 char theScript[CCHMAXPATH];
53 /* By setting the strlength of the output RXSTRING to zero, we */
54 /* force the interpreter to allocate memory and return it to us. */
55 /* We could provide a buffer for the interpreter to use instead. */
56 rexxretval.strlength = 0L; /* initialize return to empty*/
57
58
59 sprintf(theScript, "%s\\bin\\%s", queryInstallDir(), rexxFile);
60
61 TRY_LOUD(RX_START) {
62 /* Here we call the interpreter. We don't really need to use */
63 /* all the casts in this call; they just help illustrate */
64 /* the data types used. */
65 rc=RexxStart((LONG) 0, /* number of arguments */
66 (PRXSTRING) &arg, /* array of arguments */
67 (PSZ) theScript,/* name of REXX file */
68 (PRXSTRING) 0, /* No INSTORE used */
69 (PSZ) "CWRXX", /* Command env. name */
70 (LONG) RXSUBROUTINE, /* Code for how invoked */
71 (PRXSYSEXIT) 0, /* No EXITs on this call */
72 (PSHORT) &rexxrc, /* Rexx program output */
73 (PRXSTRING) &rexxretval ); /* Rexx program output */
74
75
76#if 0
77 if(rc) {
78 sprintf(text,"Error in the Rexx skript %s\n\n Get more information with 'help REX%04d'.\n",
79 tPt->rexxSkript, rc*-1);
80 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE|MB_ERROR);
81 }
82#endif
83 if(!rc) {
84 if(ulSize>rexxretval.strlength) {
85 strncpy(chrResult, rexxretval.strptr, rexxretval.strlength);
86 chrResult[rexxretval.strlength]=0;
87 }
88 else
89 strncpy(chrResult, rexxretval.strptr, ulSize);
90 chrResult[ulSize-1]=0;
91 }
92 if(rexxretval.strptr)
93 DosFreeMem(rexxretval.strptr); /* Release storage given to us by REXX. */
94 }
95 CATCH(RX_START)
96 {}END_CATCH;
97 return TRUE;
98}
99
100void parameterError(char *chrMethod, ULONG ulReq, ULONG ulActual)
101{
102 char text[200];
103 sprintf(text, "%s(): wrong count of parameters. Required: %d, actual: %d",
104 chrMethod, ulReq, ulActual);
105
106 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "Method error",
107 1234, MB_OK|MB_MOVEABLE);
108
109}
110
111void wpObjectError(char *chrMethod)
112{
113 char text[200];
114 sprintf(text, "%s(): object pointer is not valid.", chrMethod);
115
116 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "Object error",
117 1234, MB_OK|MB_MOVEABLE);
118
119}
120
121
122#define HASHSIZE 101
123ULONG calculateHash(char * theString)
124{
125 ULONG ulHash=0;
126
127 if(theString)
128 for(ulHash=0;*theString!='\0'; theString++)
129 ulHash=*theString+31*ulHash;
130
131 return ulHash%HASHSIZE;
132}
133
134#define HASHSIZE2 123
135ULONG calculateHash2(char * theString)
136{
137 ULONG ulHash=0;
138
139 if(theString)
140 for(ulHash=0;*theString!='\0'; theString++)
141 ulHash=*theString+37*ulHash;
142
143 return ulHash%HASHSIZE;
144}
145
146/*
147 This function will be registered in the wpclsInitData() of MMDataFile
148 */
149
150/* This function handles new WPS functions introduced by private classes */
151ULONG EXPENTRY rxCallCWMMFunc(PSZ name, LONG argc, RXSTRING argv[], PSZ queuename,PRXSTRING retstring)
152{
153 ULONG ulHash;
154 ULONG ulReturn;
155 WPObject* wpObject;
156
157 /* At least WPObject* and name of method */
158 if(argc<2)
159 return 40;
160
161 /* TRY_LOUD(RX) {*/
162 /* Get a hash for the methodname for the switch() statement */
163 ulHash=calculateHash(argv[0].strptr)<<8;
164 ulHash+=calculateHash2(argv[0].strptr);
165 ulReturn=0;
166
167 wpObject=(WPObject*)atol(argv[1].strptr);
168 /* Check if it's a valid object */
169 if(somIsObj(wpObject)) {
170 PFNWPSFUNC procAddr;
171
172 /* Try to find the requested method */
173 if((procAddr=(PFNWPSFUNC) somResolveByName(wpObject, argv[0].strptr))==NULL) {
174 /* method not found */
175 sprintf(retstring->strptr, "ERROR_METHOD:");
176 retstring->strlength=strlen(retstring->strptr);
177 }
178 else {
179 switch(ulHash)
180 {
181 // case 0x2e0e: /* mmQueryTrackInfo */ /* New generic name with V0.2.5 */
182 case 0x2a1b: /* cwmmQueryTrackInfo */
183 {
184 ULONG ulParam1;
185
186 if(argc<3) {
187 parameterError(argv[0].strptr, 3 , argc);
188 ulReturn=40;
189 break;
190 }
191
192 ulParam1=atol(argv[2].strptr);/* ulWhich */
193
194 switch(ulParam1)
195 {
196 case IDINFO_PLAYTIME:
197 case IDINFO_BPS:
198 case IDINFO_CHANNELS:
199 case IDINFO_SAMPLERATE:
200 case IDINFO_BITRATE:
201 sprintf(retstring->strptr,"%d",procAddr(wpObject, NULLHANDLE, 0, ulParam1));
202 break;
203 case IDINFO_NAME:
204 case IDINFO_ARTIST:
205 case IDINFO_GENRE:
206 case IDINFO_YEAR:
207 /* Maximum length of the returned value is 256 bytes (default retstring length) */
208 if(!procAddr(wpObject, retstring->strptr, retstring->strlength, ulParam1))
209 sprintf(retstring->strptr,"ERROR:");
210 break;
211 default:
212 {
213 if(!procAddr(wpObject, retstring->strptr, retstring->strlength, ulParam1))
214 //if(!procAddr(wpObject, text, 100, ))
215 sprintf(retstring->strptr,"ERROR:");
216 }
217 }
218 retstring->strlength=strlen(retstring->strptr);
219 break;
220 }
221 case 0x220f: /* cwmmQueryImageInfo New with V0.2.5 */
222 // case 0x0502: /* mmQueryImageInfo */ /* New with V0.2.5 */
223 {
224 ULONG ulParam1;
225
226 if(argc<3) {
227 parameterError(argv[0].strptr, 3 , argc);
228 ulReturn=40;
229 break;
230 }
231
232 ulParam1=atol(argv[2].strptr);/* ulWhich */
233
234 switch(ulParam1)
235 {
236 case IDINFO_WIDTH:
237 case IDINFO_HEIGHT:
238 case IDINFO_BPP:
239 sprintf(retstring->strptr,"%d",procAddr(wpObject, NULLHANDLE, 0, ulParam1));
240 break;
241 default:
242 if(!procAddr(wpObject, &retstring->strptr, retstring->strlength, ulParam1))
243 sprintf(retstring->strptr,"ERROR:");
244 }
245 retstring->strlength=strlen(retstring->strptr);
246 break;
247 }
248 default:
249 ulReturn=40;
250 }/* switch */
251 }/* else if((procAddr=(PFNWPSFUNC) somResolveByName(wpObject, argv[1].strptr))==NULL) */
252 }/* if(somIsObj(wpObject)) */
253 else {
254 /* wpObject is not valid */
255 wpObjectError(argv[0].strptr);
256
257 ulReturn=40;
258 }
259
260 /* }
261 CATCH(RX)
262 {}END_CATCH;*/
263 return ulReturn;
264}
265
266
267/*
268
2690x2e0e: mmQueryTrackInfo New generic name with V0.2.5
2700x2a1b: cwmmQueryTrackInfo
271
2720x0502: mmQueryImageInfo New with V0.2.5
2730x220f: cwmmQueryImageInfo New with V0.2.5
274 */
Note: See TracBrowser for help on using the repository browser.