source: branches/v2.9/JPGPROC/source/jpgfunc.c@ 20

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

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

File size: 9.8 KB
Line 
1/*
2 * Copyright (c) Chris Wohlgemuth 2002
3 * All rights reserved.
4 *
5 * http://www.geocities.com/SiliconValley/Sector/5785/
6 * http://www.os2world.com/cdwriting
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The authors name may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33/************************************************************************/
34/* Put all #defines here */
35/************************************************************************/
36
37#define INCL_32 * force 32 bit compile
38#define INCL_GPIBITMAPS
39#define INCL_DOSFILEMGR
40#define INCL_DOSRESOURCES
41#define INCL_DOSMODULEMGR
42#define INCL_WIN
43#define INCL_GPI
44#define INCL_PM /* force 32 bit compile */
45
46/************************************************************************/
47/* Put all #includes here */
48/************************************************************************/
49
50#include <limits.h>
51#include <os2.h>
52#include <string.h>
53#include <stdlib.h>
54#include <os2medef.h>
55#include <mmioos2.h>
56#include "jpgproc.h"
57
58
59
60/*************************************************************************************
61 * Routine is called on each DLL instantiation and termination.
62 * Caller assures that no two instances execute this code
63 * at the same time.
64 * 00) Change name to _DLL_InitTerm and use the linkage pragma.
65 *************************************************************************************/
66/*************************************************************************************
67 * Variable holds DLL module handle. Gets set at initialization.
68 * Data area is separate for each using process, so this value
69 * could be different (or same) per process.
70 *************************************************************************************/
71HMODULE hModuleHandle;
72
73#pragma linkage (_DLL_InitTerm, system)
74//#pragma checkout (suspend) /* Prevent unreferenced parameter messages */
75ULONG _DLL_InitTerm (ULONG hModHandle, ULONG fTerm/*, BOOL FirstInstance*/)
76{
77 hModuleHandle = hModHandle; /* Remember for NLS lookup */
78 if (!fTerm) {
79 if (_CRT_init())
80 return (0L);
81 } /* endif */
82
83 return (1L); /* Success */
84} /* DLL_InitTerm */
85//#pragma checkout (resume)
86
87
88/**************************************************************************
89 * GetFormatString **
90 **************************************************************************
91 *
92 * ARGUMENTS:
93 *
94 * lSearchId - Table search key
95 * pszFormatString - Address where to return string.
96 * If null, then string is not returned.
97 * lBytes - Number of bytes to copy.
98 *
99 * RETURN:
100 *
101 * Returns 0 if string not found, or the number of characters (bytes)
102 * copied to the callers buffer.
103 * Note, returned string is not ASCII nul terminated
104 *
105 * DESCRIPTION:
106 *
107 * This function will retrieve the format string for the specified
108 * IOProc from the resource file that contains the strings.
109 *
110 ***************************************************************************/
111LONG GetFormatString (LONG lSearchId,
112 PSZ pszFormatString, /* Null, or dest address */
113 LONG lBytes) /* Caller provided maximum */
114{
115 PVOID pResourceData;
116 CHAR *pTemp;
117 LONG lStringLen; /* Length of format string */
118 LONG lRetVal = 0; /* Function return value */
119 LONG lSearchTemp;
120
121 if (DosGetResource(hModuleHandle,
122 RT_RCDATA,
123 MMOTION_IOPROC_NAME_TABLE,
124 &pResourceData))
125 {
126 return (MMIO_ERROR);
127 }
128
129 /*
130 * The resource table is of the form : FOURCC String\0
131 * Loop until a match is found, then return the string.
132 * Copy up to the number of bytes specified.
133 */
134
135 lStringLen = 0;
136 pTemp = (CHAR *)pResourceData;
137
138 while (pTemp)
139 {
140 memmove(&lSearchTemp, pTemp, sizeof(LONG));
141
142 if (lSearchTemp == 0L)
143 {
144 break; /* End of table, search item not found */
145 }
146
147 if (lSearchTemp == lSearchId) /* Search item found? */
148 {
149 pTemp += sizeof(LONG); /* Bypass numeric search id */
150 lStringLen = strlen(pTemp); /* Determine length of found string */
151 if (lStringLen >= lBytes) /* Truncate, if necessary */
152 {
153 if (lBytes > 0)
154 lStringLen = lBytes; /* Number of characters to return */
155 else
156 {
157 /* Callers buffer has zero size. Cannot return any data */
158 lRetVal = 0; /* Size of returned data */
159 break; /* Done searching */
160 }
161 }
162 if (pszFormatString != NULL)
163 {
164 memcpy(pszFormatString, pTemp, lStringLen); /* Copy string to caller */
165 }
166 lRetVal = lStringLen; /* Function return value */
167 break; /* We're done searching */
168 }
169
170 pTemp += sizeof(FOURCC);
171 pTemp += (strlen(pTemp) + 1); /* Advance to next search key */
172 }
173
174 DosFreeResource( pResourceData );
175
176 return (lRetVal); /* Zero or strlen */
177}
178
179
180/**************************************************************************
181 * GetFormatStringLength **
182 **************************************************************************
183 *
184 * ARGUMENTS:
185 *
186 * lSearchId - Table search key
187 * plNameLength - Address where to return string length.
188 *
189 * RETURN:
190 *
191 * Length of the format string not including the terminating '\0'.
192 * That is, the same value as would be returned from strlen().
193 *
194 * DESCRIPTION:
195 *
196 * This function will retrieve the length of the format string
197 * for the specified IOProc from the resource file that contains
198 * the strings.
199 *
200 ***************************************************************************/
201LONG GetFormatStringLength (LONG lSearchId,
202 PLONG plNameLength)
203{
204 LONG lStringSize;
205 LONG lRetVal;
206
207 lStringSize = GetFormatString (lSearchId, NULL, LONG_MAX);
208 if (lStringSize > 0) /* String found? */
209 {
210 *plNameLength = lStringSize; /* yes, return strlen */
211 lRetVal = 0; /* and indicate success to caller */
212 }
213 else
214 {
215 *plNameLength = 0; /* no, error. Return zero for length */
216 lRetVal = lStringSize; /* and error code from called routine */
217 }
218 return (lRetVal);
219}
220
221
222/**************************************************************************
223 * GetNLSData **
224 **************************************************************************
225 *
226 * ARGUMENTS:
227 *
228 * pulCodePage - Address where to return the code page/country.
229 * pulLanguage - Address where to return the language/dialect.
230 *
231 * RETURN:
232 *
233 * Error code or 0.
234 *
235 * DESCRIPTION:
236 *
237 * This function will retrieve the NLS information for the IOProc
238 * strings contained in the resource file.
239 *
240 ***************************************************************************/
241
242ULONG APIENTRY GetNLSData( PULONG pulCodePage,
243 PULONG pulLanguage )
244{
245 PVOID pResourceData;
246 CHAR *pTemp;
247
248 if (DosGetResource( hModuleHandle,
249 RT_RCDATA,
250 MMOTION_NLS_CHARSET_INFO,
251 &pResourceData ))
252 {
253 return (MMIO_ERROR);
254 }
255
256 /*
257 * The resource table is of the form :
258 * usCodePage Low
259 * usCountryCode High
260 * usLanguage Low
261 * usDialect High
262 */
263
264 pTemp = (CHAR *)pResourceData;
265
266 while (pTemp)
267 {
268 memmove( pulCodePage, pTemp, sizeof(ULONG) );
269 pTemp += sizeof(ULONG);
270
271 if (pTemp == NULL)
272 {
273 break;
274 }
275
276 memmove( pulLanguage, pTemp, sizeof(ULONG) );
277
278 break;
279 }
280
281 DosFreeResource( pResourceData );
282
283 return (MMIO_SUCCESS);
284}
Note: See TracBrowser for help on using the repository browser.