aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c1276
1 files changed, 638 insertions, 638 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c
index 0955047..60b45c6 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jmemdos.c
@@ -1,638 +1,638 @@
1/* 1/*
2 * jmemdos.c 2 * jmemdos.c
3 * 3 *
4 * Copyright (C) 1992-1997, Thomas G. Lane. 4 * Copyright (C) 1992-1997, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software. 5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file. 6 * For conditions of distribution and use, see the accompanying README file.
7 * 7 *
8 * This file provides an MS-DOS-compatible implementation of the system- 8 * This file provides an MS-DOS-compatible implementation of the system-
9 * dependent portion of the JPEG memory manager. Temporary data can be 9 * dependent portion of the JPEG memory manager. Temporary data can be
10 * stored in extended or expanded memory as well as in regular DOS files. 10 * stored in extended or expanded memory as well as in regular DOS files.
11 * 11 *
12 * If you use this file, you must be sure that NEED_FAR_POINTERS is defined 12 * If you use this file, you must be sure that NEED_FAR_POINTERS is defined
13 * if you compile in a small-data memory model; it should NOT be defined if 13 * if you compile in a small-data memory model; it should NOT be defined if
14 * you use a large-data memory model. This file is not recommended if you 14 * you use a large-data memory model. This file is not recommended if you
15 * are using a flat-memory-space 386 environment such as DJGCC or Watcom C. 15 * are using a flat-memory-space 386 environment such as DJGCC or Watcom C.
16 * Also, this code will NOT work if struct fields are aligned on greater than 16 * Also, this code will NOT work if struct fields are aligned on greater than
17 * 2-byte boundaries. 17 * 2-byte boundaries.
18 * 18 *
19 * Based on code contributed by Ge' Weijers. 19 * Based on code contributed by Ge' Weijers.
20 */ 20 */
21 21
22/* 22/*
23 * If you have both extended and expanded memory, you may want to change the 23 * If you have both extended and expanded memory, you may want to change the
24 * order in which they are tried in jopen_backing_store. On a 286 machine 24 * order in which they are tried in jopen_backing_store. On a 286 machine
25 * expanded memory is usually faster, since extended memory access involves 25 * expanded memory is usually faster, since extended memory access involves
26 * an expensive protected-mode-and-back switch. On 386 and better, extended 26 * an expensive protected-mode-and-back switch. On 386 and better, extended
27 * memory is usually faster. As distributed, the code tries extended memory 27 * memory is usually faster. As distributed, the code tries extended memory
28 * first (what? not everyone has a 386? :-). 28 * first (what? not everyone has a 386? :-).
29 * 29 *
30 * You can disable use of extended/expanded memory entirely by altering these 30 * You can disable use of extended/expanded memory entirely by altering these
31 * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0). 31 * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).
32 */ 32 */
33 33
34#ifndef XMS_SUPPORTED 34#ifndef XMS_SUPPORTED
35#define XMS_SUPPORTED 1 35#define XMS_SUPPORTED 1
36#endif 36#endif
37#ifndef EMS_SUPPORTED 37#ifndef EMS_SUPPORTED
38#define EMS_SUPPORTED 1 38#define EMS_SUPPORTED 1
39#endif 39#endif
40 40
41 41
42#define JPEG_INTERNALS 42#define JPEG_INTERNALS
43#include "jinclude.h" 43#include "jinclude.h"
44#include "jpeglib.h" 44#include "jpeglib.h"
45#include "jmemsys.h" /* import the system-dependent declarations */ 45#include "jmemsys.h" /* import the system-dependent declarations */
46 46
47#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare these */ 47#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare these */
48extern void * malloc JPP((size_t size)); 48extern void * malloc JPP((size_t size));
49extern void free JPP((void *ptr)); 49extern void free JPP((void *ptr));
50extern char * getenv JPP((const char * name)); 50extern char * getenv JPP((const char * name));
51#endif 51#endif
52 52
53#ifdef NEED_FAR_POINTERS 53#ifdef NEED_FAR_POINTERS
54 54
55#ifdef __TURBOC__ 55#ifdef __TURBOC__
56/* These definitions work for Borland C (Turbo C) */ 56/* These definitions work for Borland C (Turbo C) */
57#include <alloc.h> /* need farmalloc(), farfree() */ 57#include <alloc.h> /* need farmalloc(), farfree() */
58#define far_malloc(x) farmalloc(x) 58#define far_malloc(x) farmalloc(x)
59#define far_free(x) farfree(x) 59#define far_free(x) farfree(x)
60#else 60#else
61/* These definitions work for Microsoft C and compatible compilers */ 61/* These definitions work for Microsoft C and compatible compilers */
62#include <malloc.h> /* need _fmalloc(), _ffree() */ 62#include <malloc.h> /* need _fmalloc(), _ffree() */
63#define far_malloc(x) _fmalloc(x) 63#define far_malloc(x) _fmalloc(x)
64#define far_free(x) _ffree(x) 64#define far_free(x) _ffree(x)
65#endif 65#endif
66 66
67#else /* not NEED_FAR_POINTERS */ 67#else /* not NEED_FAR_POINTERS */
68 68
69#define far_malloc(x) malloc(x) 69#define far_malloc(x) malloc(x)
70#define far_free(x) free(x) 70#define far_free(x) free(x)
71 71
72#endif /* NEED_FAR_POINTERS */ 72#endif /* NEED_FAR_POINTERS */
73 73
74#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ 74#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
75#define READ_BINARY "r" 75#define READ_BINARY "r"
76#else 76#else
77#define READ_BINARY "rb" 77#define READ_BINARY "rb"
78#endif 78#endif
79 79
80#ifndef USE_MSDOS_MEMMGR /* make sure user got configuration right */ 80#ifndef USE_MSDOS_MEMMGR /* make sure user got configuration right */
81 You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */ 81 You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */
82#endif 82#endif
83 83
84#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */ 84#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */
85 MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */ 85 MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */
86#endif 86#endif
87 87
88 88
89/* 89/*
90 * Declarations for assembly-language support routines (see jmemdosa.asm). 90 * Declarations for assembly-language support routines (see jmemdosa.asm).
91 * 91 *
92 * The functions are declared "far" as are all their pointer arguments; 92 * The functions are declared "far" as are all their pointer arguments;
93 * this ensures the assembly source code will work regardless of the 93 * this ensures the assembly source code will work regardless of the
94 * compiler memory model. We assume "short" is 16 bits, "long" is 32. 94 * compiler memory model. We assume "short" is 16 bits, "long" is 32.
95 */ 95 */
96 96
97typedef void far * XMSDRIVER; /* actually a pointer to code */ 97typedef void far * XMSDRIVER; /* actually a pointer to code */
98typedef struct { /* registers for calling XMS driver */ 98typedef struct { /* registers for calling XMS driver */
99 unsigned short ax, dx, bx; 99 unsigned short ax, dx, bx;
100 void far * ds_si; 100 void far * ds_si;
101 } XMScontext; 101 } XMScontext;
102typedef struct { /* registers for calling EMS driver */ 102typedef struct { /* registers for calling EMS driver */
103 unsigned short ax, dx, bx; 103 unsigned short ax, dx, bx;
104 void far * ds_si; 104 void far * ds_si;
105 } EMScontext; 105 } EMScontext;
106 106
107extern short far jdos_open JPP((short far * handle, char far * filename)); 107extern short far jdos_open JPP((short far * handle, char far * filename));
108extern short far jdos_close JPP((short handle)); 108extern short far jdos_close JPP((short handle));
109extern short far jdos_seek JPP((short handle, long offset)); 109extern short far jdos_seek JPP((short handle, long offset));
110extern short far jdos_read JPP((short handle, void far * buffer, 110extern short far jdos_read JPP((short handle, void far * buffer,
111 unsigned short count)); 111 unsigned short count));
112extern short far jdos_write JPP((short handle, void far * buffer, 112extern short far jdos_write JPP((short handle, void far * buffer,
113 unsigned short count)); 113 unsigned short count));
114extern void far jxms_getdriver JPP((XMSDRIVER far *)); 114extern void far jxms_getdriver JPP((XMSDRIVER far *));
115extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *)); 115extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
116extern short far jems_available JPP((void)); 116extern short far jems_available JPP((void));
117extern void far jems_calldriver JPP((EMScontext far *)); 117extern void far jems_calldriver JPP((EMScontext far *));
118 118
119 119
120/* 120/*
121 * Selection of a file name for a temporary file. 121 * Selection of a file name for a temporary file.
122 * This is highly system-dependent, and you may want to customize it. 122 * This is highly system-dependent, and you may want to customize it.
123 */ 123 */
124 124
125static int next_file_num; /* to distinguish among several temp files */ 125static int next_file_num; /* to distinguish among several temp files */
126 126
127LOCAL(void) 127LOCAL(void)
128select_file_name (char * fname) 128select_file_name (char * fname)
129{ 129{
130 const char * env; 130 const char * env;
131 char * ptr; 131 char * ptr;
132 FILE * tfile; 132 FILE * tfile;
133 133
134 /* Keep generating file names till we find one that's not in use */ 134 /* Keep generating file names till we find one that's not in use */
135 for (;;) { 135 for (;;) {
136 /* Get temp directory name from environment TMP or TEMP variable; 136 /* Get temp directory name from environment TMP or TEMP variable;
137 * if none, use "." 137 * if none, use "."
138 */ 138 */
139 if ((env = (const char *) getenv("TMP")) == NULL) 139 if ((env = (const char *) getenv("TMP")) == NULL)
140 if ((env = (const char *) getenv("TEMP")) == NULL) 140 if ((env = (const char *) getenv("TEMP")) == NULL)
141 env = "."; 141 env = ".";
142 if (*env == '\0') /* null string means "." */ 142 if (*env == '\0') /* null string means "." */
143 env = "."; 143 env = ".";
144 ptr = fname; /* copy name to fname */ 144 ptr = fname; /* copy name to fname */
145 while (*env != '\0') 145 while (*env != '\0')
146 *ptr++ = *env++; 146 *ptr++ = *env++;
147 if (ptr[-1] != '\\' && ptr[-1] != '/') 147 if (ptr[-1] != '\\' && ptr[-1] != '/')
148 *ptr++ = '\\'; /* append backslash if not in env variable */ 148 *ptr++ = '\\'; /* append backslash if not in env variable */
149 /* Append a suitable file name */ 149 /* Append a suitable file name */
150 next_file_num++; /* advance counter */ 150 next_file_num++; /* advance counter */
151 sprintf(ptr, "JPG%03d.TMP", next_file_num); 151 sprintf(ptr, "JPG%03d.TMP", next_file_num);
152 /* Probe to see if file name is already in use */ 152 /* Probe to see if file name is already in use */
153 if ((tfile = fopen(fname, READ_BINARY)) == NULL) 153 if ((tfile = fopen(fname, READ_BINARY)) == NULL)
154 break; 154 break;
155 fclose(tfile); /* oops, it's there; close tfile & try again */ 155 fclose(tfile); /* oops, it's there; close tfile & try again */
156 } 156 }
157} 157}
158 158
159 159
160/* 160/*
161 * Near-memory allocation and freeing are controlled by the regular library 161 * Near-memory allocation and freeing are controlled by the regular library
162 * routines malloc() and free(). 162 * routines malloc() and free().
163 */ 163 */
164 164
165GLOBAL(void *) 165GLOBAL(void *)
166jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 166jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
167{ 167{
168 return (void *) malloc(sizeofobject); 168 return (void *) malloc(sizeofobject);
169} 169}
170 170
171GLOBAL(void) 171GLOBAL(void)
172jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 172jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
173{ 173{
174 free(object); 174 free(object);
175} 175}
176 176
177 177
178/* 178/*
179 * "Large" objects are allocated in far memory, if possible 179 * "Large" objects are allocated in far memory, if possible
180 */ 180 */
181 181
182GLOBAL(void FAR *) 182GLOBAL(void FAR *)
183jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 183jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
184{ 184{
185 return (void FAR *) far_malloc(sizeofobject); 185 return (void FAR *) far_malloc(sizeofobject);
186} 186}
187 187
188GLOBAL(void) 188GLOBAL(void)
189jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 189jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
190{ 190{
191 far_free(object); 191 far_free(object);
192} 192}
193 193
194 194
195/* 195/*
196 * This routine computes the total memory space available for allocation. 196 * This routine computes the total memory space available for allocation.
197 * It's impossible to do this in a portable way; our current solution is 197 * It's impossible to do this in a portable way; our current solution is
198 * to make the user tell us (with a default value set at compile time). 198 * to make the user tell us (with a default value set at compile time).
199 * If you can actually get the available space, it's a good idea to subtract 199 * If you can actually get the available space, it's a good idea to subtract
200 * a slop factor of 5% or so. 200 * a slop factor of 5% or so.
201 */ 201 */
202 202
203#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ 203#ifndef DEFAULT_MAX_MEM /* so can override from makefile */
204#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */ 204#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */
205#endif 205#endif
206 206
207GLOBAL(long) 207GLOBAL(long)
208jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 208jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
209 long max_bytes_needed, long already_allocated) 209 long max_bytes_needed, long already_allocated)
210{ 210{
211 return cinfo->mem->max_memory_to_use - already_allocated; 211 return cinfo->mem->max_memory_to_use - already_allocated;
212} 212}
213 213
214 214
215/* 215/*
216 * Backing store (temporary file) management. 216 * Backing store (temporary file) management.
217 * Backing store objects are only used when the value returned by 217 * Backing store objects are only used when the value returned by
218 * jpeg_mem_available is less than the total space needed. You can dispense 218 * jpeg_mem_available is less than the total space needed. You can dispense
219 * with these routines if you have plenty of virtual memory; see jmemnobs.c. 219 * with these routines if you have plenty of virtual memory; see jmemnobs.c.
220 */ 220 */
221 221
222/* 222/*
223 * For MS-DOS we support three types of backing storage: 223 * For MS-DOS we support three types of backing storage:
224 * 1. Conventional DOS files. We access these by direct DOS calls rather 224 * 1. Conventional DOS files. We access these by direct DOS calls rather
225 * than via the stdio package. This provides a bit better performance, 225 * than via the stdio package. This provides a bit better performance,
226 * but the real reason is that the buffers to be read or written are FAR. 226 * but the real reason is that the buffers to be read or written are FAR.
227 * The stdio library for small-data memory models can't cope with that. 227 * The stdio library for small-data memory models can't cope with that.
228 * 2. Extended memory, accessed per the XMS V2.0 specification. 228 * 2. Extended memory, accessed per the XMS V2.0 specification.
229 * 3. Expanded memory, accessed per the LIM/EMS 4.0 specification. 229 * 3. Expanded memory, accessed per the LIM/EMS 4.0 specification.
230 * You'll need copies of those specs to make sense of the related code. 230 * You'll need copies of those specs to make sense of the related code.
231 * The specs are available by Internet FTP from the SIMTEL archives 231 * The specs are available by Internet FTP from the SIMTEL archives
232 * (oak.oakland.edu and its various mirror sites). See files 232 * (oak.oakland.edu and its various mirror sites). See files
233 * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip. 233 * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip.
234 */ 234 */
235 235
236 236
237/* 237/*
238 * Access methods for a DOS file. 238 * Access methods for a DOS file.
239 */ 239 */
240 240
241 241
242METHODDEF(void) 242METHODDEF(void)
243read_file_store (j_common_ptr cinfo, backing_store_ptr info, 243read_file_store (j_common_ptr cinfo, backing_store_ptr info,
244 void FAR * buffer_address, 244 void FAR * buffer_address,
245 long file_offset, long byte_count) 245 long file_offset, long byte_count)
246{ 246{
247 if (jdos_seek(info->handle.file_handle, file_offset)) 247 if (jdos_seek(info->handle.file_handle, file_offset))
248 ERREXIT(cinfo, JERR_TFILE_SEEK); 248 ERREXIT(cinfo, JERR_TFILE_SEEK);
249 /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */ 249 /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
250 if (byte_count > 65535L) /* safety check */ 250 if (byte_count > 65535L) /* safety check */
251 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); 251 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
252 if (jdos_read(info->handle.file_handle, buffer_address, 252 if (jdos_read(info->handle.file_handle, buffer_address,
253 (unsigned short) byte_count)) 253 (unsigned short) byte_count))
254 ERREXIT(cinfo, JERR_TFILE_READ); 254 ERREXIT(cinfo, JERR_TFILE_READ);
255} 255}
256 256
257 257
258METHODDEF(void) 258METHODDEF(void)
259write_file_store (j_common_ptr cinfo, backing_store_ptr info, 259write_file_store (j_common_ptr cinfo, backing_store_ptr info,
260 void FAR * buffer_address, 260 void FAR * buffer_address,
261 long file_offset, long byte_count) 261 long file_offset, long byte_count)
262{ 262{
263 if (jdos_seek(info->handle.file_handle, file_offset)) 263 if (jdos_seek(info->handle.file_handle, file_offset))
264 ERREXIT(cinfo, JERR_TFILE_SEEK); 264 ERREXIT(cinfo, JERR_TFILE_SEEK);
265 /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */ 265 /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
266 if (byte_count > 65535L) /* safety check */ 266 if (byte_count > 65535L) /* safety check */
267 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); 267 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
268 if (jdos_write(info->handle.file_handle, buffer_address, 268 if (jdos_write(info->handle.file_handle, buffer_address,
269 (unsigned short) byte_count)) 269 (unsigned short) byte_count))
270 ERREXIT(cinfo, JERR_TFILE_WRITE); 270 ERREXIT(cinfo, JERR_TFILE_WRITE);
271} 271}
272 272
273 273
274METHODDEF(void) 274METHODDEF(void)
275close_file_store (j_common_ptr cinfo, backing_store_ptr info) 275close_file_store (j_common_ptr cinfo, backing_store_ptr info)
276{ 276{
277 jdos_close(info->handle.file_handle); /* close the file */ 277 jdos_close(info->handle.file_handle); /* close the file */
278 remove(info->temp_name); /* delete the file */ 278 remove(info->temp_name); /* delete the file */
279/* If your system doesn't have remove(), try unlink() instead. 279/* If your system doesn't have remove(), try unlink() instead.
280 * remove() is the ANSI-standard name for this function, but 280 * remove() is the ANSI-standard name for this function, but
281 * unlink() was more common in pre-ANSI systems. 281 * unlink() was more common in pre-ANSI systems.
282 */ 282 */
283 TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); 283 TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
284} 284}
285 285
286 286
287LOCAL(boolean) 287LOCAL(boolean)
288open_file_store (j_common_ptr cinfo, backing_store_ptr info, 288open_file_store (j_common_ptr cinfo, backing_store_ptr info,
289 long total_bytes_needed) 289 long total_bytes_needed)
290{ 290{
291 short handle; 291 short handle;
292 292
293 select_file_name(info->temp_name); 293 select_file_name(info->temp_name);
294 if (jdos_open((short far *) & handle, (char far *) info->temp_name)) { 294 if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
295 /* might as well exit since jpeg_open_backing_store will fail anyway */ 295 /* might as well exit since jpeg_open_backing_store will fail anyway */
296 ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); 296 ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
297 return FALSE; 297 return FALSE;
298 } 298 }
299 info->handle.file_handle = handle; 299 info->handle.file_handle = handle;
300 info->read_backing_store = read_file_store; 300 info->read_backing_store = read_file_store;
301 info->write_backing_store = write_file_store; 301 info->write_backing_store = write_file_store;
302 info->close_backing_store = close_file_store; 302 info->close_backing_store = close_file_store;
303 TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); 303 TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
304 return TRUE; /* succeeded */ 304 return TRUE; /* succeeded */
305} 305}
306 306
307 307
308/* 308/*
309 * Access methods for extended memory. 309 * Access methods for extended memory.
310 */ 310 */
311 311
312#if XMS_SUPPORTED 312#if XMS_SUPPORTED
313 313
314static XMSDRIVER xms_driver; /* saved address of XMS driver */ 314static XMSDRIVER xms_driver; /* saved address of XMS driver */
315 315
316typedef union { /* either long offset or real-mode pointer */ 316typedef union { /* either long offset or real-mode pointer */
317 long offset; 317 long offset;
318 void far * ptr; 318 void far * ptr;
319 } XMSPTR; 319 } XMSPTR;
320 320
321typedef struct { /* XMS move specification structure */ 321typedef struct { /* XMS move specification structure */
322 long length; 322 long length;
323 XMSH src_handle; 323 XMSH src_handle;
324 XMSPTR src; 324 XMSPTR src;
325 XMSH dst_handle; 325 XMSH dst_handle;
326 XMSPTR dst; 326 XMSPTR dst;
327 } XMSspec; 327 } XMSspec;
328 328
329#define ODD(X) (((X) & 1L) != 0) 329#define ODD(X) (((X) & 1L) != 0)
330 330
331 331
332METHODDEF(void) 332METHODDEF(void)
333read_xms_store (j_common_ptr cinfo, backing_store_ptr info, 333read_xms_store (j_common_ptr cinfo, backing_store_ptr info,
334 void FAR * buffer_address, 334 void FAR * buffer_address,
335 long file_offset, long byte_count) 335 long file_offset, long byte_count)
336{ 336{
337 XMScontext ctx; 337 XMScontext ctx;
338 XMSspec spec; 338 XMSspec spec;
339 char endbuffer[2]; 339 char endbuffer[2];
340 340
341 /* The XMS driver can't cope with an odd length, so handle the last byte 341 /* The XMS driver can't cope with an odd length, so handle the last byte
342 * specially if byte_count is odd. We don't expect this to be common. 342 * specially if byte_count is odd. We don't expect this to be common.
343 */ 343 */
344 344
345 spec.length = byte_count & (~ 1L); 345 spec.length = byte_count & (~ 1L);
346 spec.src_handle = info->handle.xms_handle; 346 spec.src_handle = info->handle.xms_handle;
347 spec.src.offset = file_offset; 347 spec.src.offset = file_offset;
348 spec.dst_handle = 0; 348 spec.dst_handle = 0;
349 spec.dst.ptr = buffer_address; 349 spec.dst.ptr = buffer_address;
350 350
351 ctx.ds_si = (void far *) & spec; 351 ctx.ds_si = (void far *) & spec;
352 ctx.ax = 0x0b00; /* EMB move */ 352 ctx.ax = 0x0b00; /* EMB move */
353 jxms_calldriver(xms_driver, (XMScontext far *) & ctx); 353 jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
354 if (ctx.ax != 1) 354 if (ctx.ax != 1)
355 ERREXIT(cinfo, JERR_XMS_READ); 355 ERREXIT(cinfo, JERR_XMS_READ);
356 356
357 if (ODD(byte_count)) { 357 if (ODD(byte_count)) {
358 read_xms_store(cinfo, info, (void FAR *) endbuffer, 358 read_xms_store(cinfo, info, (void FAR *) endbuffer,
359 file_offset + byte_count - 1L, 2L); 359 file_offset + byte_count - 1L, 2L);
360 ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0]; 360 ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
361 } 361 }
362} 362}
363 363
364 364
365METHODDEF(void) 365METHODDEF(void)
366write_xms_store (j_common_ptr cinfo, backing_store_ptr info, 366write_xms_store (j_common_ptr cinfo, backing_store_ptr info,
367 void FAR * buffer_address, 367 void FAR * buffer_address,
368 long file_offset, long byte_count) 368 long file_offset, long byte_count)
369{ 369{
370 XMScontext ctx; 370 XMScontext ctx;
371 XMSspec spec; 371 XMSspec spec;
372 char endbuffer[2]; 372 char endbuffer[2];
373 373
374 /* The XMS driver can't cope with an odd length, so handle the last byte 374 /* The XMS driver can't cope with an odd length, so handle the last byte
375 * specially if byte_count is odd. We don't expect this to be common. 375 * specially if byte_count is odd. We don't expect this to be common.
376 */ 376 */
377 377
378 spec.length = byte_count & (~ 1L); 378 spec.length = byte_count & (~ 1L);
379 spec.src_handle = 0; 379 spec.src_handle = 0;
380 spec.src.ptr = buffer_address; 380 spec.src.ptr = buffer_address;
381 spec.dst_handle = info->handle.xms_handle; 381 spec.dst_handle = info->handle.xms_handle;
382 spec.dst.offset = file_offset; 382 spec.dst.offset = file_offset;
383 383
384 ctx.ds_si = (void far *) & spec; 384 ctx.ds_si = (void far *) & spec;
385 ctx.ax = 0x0b00; /* EMB move */ 385 ctx.ax = 0x0b00; /* EMB move */
386 jxms_calldriver(xms_driver, (XMScontext far *) & ctx); 386 jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
387 if (ctx.ax != 1) 387 if (ctx.ax != 1)
388 ERREXIT(cinfo, JERR_XMS_WRITE); 388 ERREXIT(cinfo, JERR_XMS_WRITE);
389 389
390 if (ODD(byte_count)) { 390 if (ODD(byte_count)) {
391 read_xms_store(cinfo, info, (void FAR *) endbuffer, 391 read_xms_store(cinfo, info, (void FAR *) endbuffer,
392 file_offset + byte_count - 1L, 2L); 392 file_offset + byte_count - 1L, 2L);
393 endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L]; 393 endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
394 write_xms_store(cinfo, info, (void FAR *) endbuffer, 394 write_xms_store(cinfo, info, (void FAR *) endbuffer,
395 file_offset + byte_count - 1L, 2L); 395 file_offset + byte_count - 1L, 2L);
396 } 396 }
397} 397}
398 398
399 399
400METHODDEF(void) 400METHODDEF(void)
401close_xms_store (j_common_ptr cinfo, backing_store_ptr info) 401close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
402{ 402{
403 XMScontext ctx; 403 XMScontext ctx;
404 404
405 ctx.dx = info->handle.xms_handle; 405 ctx.dx = info->handle.xms_handle;
406 ctx.ax = 0x0a00; 406 ctx.ax = 0x0a00;
407 jxms_calldriver(xms_driver, (XMScontext far *) & ctx); 407 jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
408 TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle); 408 TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
409 /* we ignore any error return from the driver */ 409 /* we ignore any error return from the driver */
410} 410}
411 411
412 412
413LOCAL(boolean) 413LOCAL(boolean)
414open_xms_store (j_common_ptr cinfo, backing_store_ptr info, 414open_xms_store (j_common_ptr cinfo, backing_store_ptr info,
415 long total_bytes_needed) 415 long total_bytes_needed)
416{ 416{
417 XMScontext ctx; 417 XMScontext ctx;
418 418
419 /* Get address of XMS driver */ 419 /* Get address of XMS driver */
420 jxms_getdriver((XMSDRIVER far *) & xms_driver); 420 jxms_getdriver((XMSDRIVER far *) & xms_driver);
421 if (xms_driver == NULL) 421 if (xms_driver == NULL)
422 return FALSE; /* no driver to be had */ 422 return FALSE; /* no driver to be had */
423 423
424 /* Get version number, must be >= 2.00 */ 424 /* Get version number, must be >= 2.00 */
425 ctx.ax = 0x0000; 425 ctx.ax = 0x0000;
426 jxms_calldriver(xms_driver, (XMScontext far *) & ctx); 426 jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
427 if (ctx.ax < (unsigned short) 0x0200) 427 if (ctx.ax < (unsigned short) 0x0200)
428 return FALSE; 428 return FALSE;
429 429
430 /* Try to get space (expressed in kilobytes) */ 430 /* Try to get space (expressed in kilobytes) */
431 ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10); 431 ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
432 ctx.ax = 0x0900; 432 ctx.ax = 0x0900;
433 jxms_calldriver(xms_driver, (XMScontext far *) & ctx); 433 jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
434 if (ctx.ax != 1) 434 if (ctx.ax != 1)
435 return FALSE; 435 return FALSE;
436 436
437 /* Succeeded, save the handle and away we go */ 437 /* Succeeded, save the handle and away we go */
438 info->handle.xms_handle = ctx.dx; 438 info->handle.xms_handle = ctx.dx;
439 info->read_backing_store = read_xms_store; 439 info->read_backing_store = read_xms_store;
440 info->write_backing_store = write_xms_store; 440 info->write_backing_store = write_xms_store;
441 info->close_backing_store = close_xms_store; 441 info->close_backing_store = close_xms_store;
442 TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx); 442 TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
443 return TRUE; /* succeeded */ 443 return TRUE; /* succeeded */
444} 444}
445 445
446#endif /* XMS_SUPPORTED */ 446#endif /* XMS_SUPPORTED */
447 447
448 448
449/* 449/*
450 * Access methods for expanded memory. 450 * Access methods for expanded memory.
451 */ 451 */
452 452
453#if EMS_SUPPORTED 453#if EMS_SUPPORTED
454 454
455/* The EMS move specification structure requires word and long fields aligned 455/* The EMS move specification structure requires word and long fields aligned
456 * at odd byte boundaries. Some compilers will align struct fields at even 456 * at odd byte boundaries. Some compilers will align struct fields at even
457 * byte boundaries. While it's usually possible to force byte alignment, 457 * byte boundaries. While it's usually possible to force byte alignment,
458 * that causes an overall performance penalty and may pose problems in merging 458 * that causes an overall performance penalty and may pose problems in merging
459 * JPEG into a larger application. Instead we accept some rather dirty code 459 * JPEG into a larger application. Instead we accept some rather dirty code
460 * here. Note this code would fail if the hardware did not allow odd-byte 460 * here. Note this code would fail if the hardware did not allow odd-byte
461 * word & long accesses, but all 80x86 CPUs do. 461 * word & long accesses, but all 80x86 CPUs do.
462 */ 462 */
463 463
464typedef void far * EMSPTR; 464typedef void far * EMSPTR;
465 465
466typedef union { /* EMS move specification structure */ 466typedef union { /* EMS move specification structure */
467 long length; /* It's easy to access first 4 bytes */ 467 long length; /* It's easy to access first 4 bytes */
468 char bytes[18]; /* Misaligned fields in here! */ 468 char bytes[18]; /* Misaligned fields in here! */
469 } EMSspec; 469 } EMSspec;
470 470
471/* Macros for accessing misaligned fields */ 471/* Macros for accessing misaligned fields */
472#define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset]))) 472#define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset])))
473#define SRC_TYPE(spec) FIELD_AT(spec,4,char) 473#define SRC_TYPE(spec) FIELD_AT(spec,4,char)
474#define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH) 474#define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH)
475#define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short) 475#define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short)
476#define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short) 476#define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short)
477#define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR) 477#define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR)
478#define DST_TYPE(spec) FIELD_AT(spec,11,char) 478#define DST_TYPE(spec) FIELD_AT(spec,11,char)
479#define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH) 479#define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH)
480#define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short) 480#define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short)
481#define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short) 481#define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short)
482#define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR) 482#define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR)
483 483
484#define EMSPAGESIZE 16384L /* gospel, see the EMS specs */ 484#define EMSPAGESIZE 16384L /* gospel, see the EMS specs */
485 485
486#define HIBYTE(W) (((W) >> 8) & 0xFF) 486#define HIBYTE(W) (((W) >> 8) & 0xFF)
487#define LOBYTE(W) ((W) & 0xFF) 487#define LOBYTE(W) ((W) & 0xFF)
488 488
489 489
490METHODDEF(void) 490METHODDEF(void)
491read_ems_store (j_common_ptr cinfo, backing_store_ptr info, 491read_ems_store (j_common_ptr cinfo, backing_store_ptr info,
492 void FAR * buffer_address, 492 void FAR * buffer_address,
493 long file_offset, long byte_count) 493 long file_offset, long byte_count)
494{ 494{
495 EMScontext ctx; 495 EMScontext ctx;
496 EMSspec spec; 496 EMSspec spec;
497 497
498 spec.length = byte_count; 498 spec.length = byte_count;
499 SRC_TYPE(spec) = 1; 499 SRC_TYPE(spec) = 1;
500 SRC_HANDLE(spec) = info->handle.ems_handle; 500 SRC_HANDLE(spec) = info->handle.ems_handle;
501 SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); 501 SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
502 SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); 502 SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
503 DST_TYPE(spec) = 0; 503 DST_TYPE(spec) = 0;
504 DST_HANDLE(spec) = 0; 504 DST_HANDLE(spec) = 0;
505 DST_PTR(spec) = buffer_address; 505 DST_PTR(spec) = buffer_address;
506 506
507 ctx.ds_si = (void far *) & spec; 507 ctx.ds_si = (void far *) & spec;
508 ctx.ax = 0x5700; /* move memory region */ 508 ctx.ax = 0x5700; /* move memory region */
509 jems_calldriver((EMScontext far *) & ctx); 509 jems_calldriver((EMScontext far *) & ctx);
510 if (HIBYTE(ctx.ax) != 0) 510 if (HIBYTE(ctx.ax) != 0)
511 ERREXIT(cinfo, JERR_EMS_READ); 511 ERREXIT(cinfo, JERR_EMS_READ);
512} 512}
513 513
514 514
515METHODDEF(void) 515METHODDEF(void)
516write_ems_store (j_common_ptr cinfo, backing_store_ptr info, 516write_ems_store (j_common_ptr cinfo, backing_store_ptr info,
517 void FAR * buffer_address, 517 void FAR * buffer_address,
518 long file_offset, long byte_count) 518 long file_offset, long byte_count)
519{ 519{
520 EMScontext ctx; 520 EMScontext ctx;
521 EMSspec spec; 521 EMSspec spec;
522 522
523 spec.length = byte_count; 523 spec.length = byte_count;
524 SRC_TYPE(spec) = 0; 524 SRC_TYPE(spec) = 0;
525 SRC_HANDLE(spec) = 0; 525 SRC_HANDLE(spec) = 0;
526 SRC_PTR(spec) = buffer_address; 526 SRC_PTR(spec) = buffer_address;
527 DST_TYPE(spec) = 1; 527 DST_TYPE(spec) = 1;
528 DST_HANDLE(spec) = info->handle.ems_handle; 528 DST_HANDLE(spec) = info->handle.ems_handle;
529 DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); 529 DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
530 DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); 530 DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
531 531
532 ctx.ds_si = (void far *) & spec; 532 ctx.ds_si = (void far *) & spec;
533 ctx.ax = 0x5700; /* move memory region */ 533 ctx.ax = 0x5700; /* move memory region */
534 jems_calldriver((EMScontext far *) & ctx); 534 jems_calldriver((EMScontext far *) & ctx);
535 if (HIBYTE(ctx.ax) != 0) 535 if (HIBYTE(ctx.ax) != 0)
536 ERREXIT(cinfo, JERR_EMS_WRITE); 536 ERREXIT(cinfo, JERR_EMS_WRITE);
537} 537}
538 538
539 539
540METHODDEF(void) 540METHODDEF(void)
541close_ems_store (j_common_ptr cinfo, backing_store_ptr info) 541close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
542{ 542{
543 EMScontext ctx; 543 EMScontext ctx;
544 544
545 ctx.ax = 0x4500; 545 ctx.ax = 0x4500;
546 ctx.dx = info->handle.ems_handle; 546 ctx.dx = info->handle.ems_handle;
547 jems_calldriver((EMScontext far *) & ctx); 547 jems_calldriver((EMScontext far *) & ctx);
548 TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle); 548 TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
549 /* we ignore any error return from the driver */ 549 /* we ignore any error return from the driver */
550} 550}
551 551
552 552
553LOCAL(boolean) 553LOCAL(boolean)
554open_ems_store (j_common_ptr cinfo, backing_store_ptr info, 554open_ems_store (j_common_ptr cinfo, backing_store_ptr info,
555 long total_bytes_needed) 555 long total_bytes_needed)
556{ 556{
557 EMScontext ctx; 557 EMScontext ctx;
558 558
559 /* Is EMS driver there? */ 559 /* Is EMS driver there? */
560 if (! jems_available()) 560 if (! jems_available())
561 return FALSE; 561 return FALSE;
562 562
563 /* Get status, make sure EMS is OK */ 563 /* Get status, make sure EMS is OK */
564 ctx.ax = 0x4000; 564 ctx.ax = 0x4000;
565 jems_calldriver((EMScontext far *) & ctx); 565 jems_calldriver((EMScontext far *) & ctx);
566 if (HIBYTE(ctx.ax) != 0) 566 if (HIBYTE(ctx.ax) != 0)
567 return FALSE; 567 return FALSE;
568 568
569 /* Get version, must be >= 4.0 */ 569 /* Get version, must be >= 4.0 */
570 ctx.ax = 0x4600; 570 ctx.ax = 0x4600;
571 jems_calldriver((EMScontext far *) & ctx); 571 jems_calldriver((EMScontext far *) & ctx);
572 if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40) 572 if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
573 return FALSE; 573 return FALSE;
574 574
575 /* Try to allocate requested space */ 575 /* Try to allocate requested space */
576 ctx.ax = 0x4300; 576 ctx.ax = 0x4300;
577 ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE); 577 ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
578 jems_calldriver((EMScontext far *) & ctx); 578 jems_calldriver((EMScontext far *) & ctx);
579 if (HIBYTE(ctx.ax) != 0) 579 if (HIBYTE(ctx.ax) != 0)
580 return FALSE; 580 return FALSE;
581 581
582 /* Succeeded, save the handle and away we go */ 582 /* Succeeded, save the handle and away we go */
583 info->handle.ems_handle = ctx.dx; 583 info->handle.ems_handle = ctx.dx;
584 info->read_backing_store = read_ems_store; 584 info->read_backing_store = read_ems_store;
585 info->write_backing_store = write_ems_store; 585 info->write_backing_store = write_ems_store;
586 info->close_backing_store = close_ems_store; 586 info->close_backing_store = close_ems_store;
587 TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx); 587 TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
588 return TRUE; /* succeeded */ 588 return TRUE; /* succeeded */
589} 589}
590 590
591#endif /* EMS_SUPPORTED */ 591#endif /* EMS_SUPPORTED */
592 592
593 593
594/* 594/*
595 * Initial opening of a backing-store object. 595 * Initial opening of a backing-store object.
596 */ 596 */
597 597
598GLOBAL(void) 598GLOBAL(void)
599jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 599jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
600 long total_bytes_needed) 600 long total_bytes_needed)
601{ 601{
602 /* Try extended memory, then expanded memory, then regular file. */ 602 /* Try extended memory, then expanded memory, then regular file. */
603#if XMS_SUPPORTED 603#if XMS_SUPPORTED
604 if (open_xms_store(cinfo, info, total_bytes_needed)) 604 if (open_xms_store(cinfo, info, total_bytes_needed))
605 return; 605 return;
606#endif 606#endif
607#if EMS_SUPPORTED 607#if EMS_SUPPORTED
608 if (open_ems_store(cinfo, info, total_bytes_needed)) 608 if (open_ems_store(cinfo, info, total_bytes_needed))
609 return; 609 return;
610#endif 610#endif
611 if (open_file_store(cinfo, info, total_bytes_needed)) 611 if (open_file_store(cinfo, info, total_bytes_needed))
612 return; 612 return;
613 ERREXITS(cinfo, JERR_TFILE_CREATE, ""); 613 ERREXITS(cinfo, JERR_TFILE_CREATE, "");
614} 614}
615 615
616 616
617/* 617/*
618 * These routines take care of any system-dependent initialization and 618 * These routines take care of any system-dependent initialization and
619 * cleanup required. 619 * cleanup required.
620 */ 620 */
621 621
622GLOBAL(long) 622GLOBAL(long)
623jpeg_mem_init (j_common_ptr cinfo) 623jpeg_mem_init (j_common_ptr cinfo)
624{ 624{
625 next_file_num = 0; /* initialize temp file name generator */ 625 next_file_num = 0; /* initialize temp file name generator */
626 return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ 626 return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
627} 627}
628 628
629GLOBAL(void) 629GLOBAL(void)
630jpeg_mem_term (j_common_ptr cinfo) 630jpeg_mem_term (j_common_ptr cinfo)
631{ 631{
632 /* Microsoft C, at least in v6.00A, will not successfully reclaim freed 632 /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
633 * blocks of size > 32Kbytes unless we give it a kick in the rear, like so: 633 * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
634 */ 634 */
635#ifdef NEED_FHEAPMIN 635#ifdef NEED_FHEAPMIN
636 _fheapmin(); 636 _fheapmin();
637#endif 637#endif
638} 638}