Back to index

plt-scheme  4.2.1
Classes | Defines | Typedefs | Functions | Variables
jmemdos.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jmemsys.h"

Go to the source code of this file.

Classes

struct  XMScontext
struct  EMScontext
union  XMSPTR
struct  XMSspec
union  EMSspec

Defines

#define XMS_SUPPORTED   1
#define EMS_SUPPORTED   1
#define JPEG_INTERNALS
#define far_malloc(x)   malloc(x)
#define far_free(x)   free(x)
#define READ_BINARY   "rb"
#define DEFAULT_MAX_MEM   300000L /* for total usage about 450K */
#define ODD(X)   (((X) & 1L) != 0)
#define FIELD_AT(spec, offset, type)   (*((type *) &(spec.bytes[offset])))
#define SRC_TYPE(spec)   FIELD_AT(spec,4,char)
#define SRC_HANDLE(spec)   FIELD_AT(spec,5,EMSH)
#define SRC_OFFSET(spec)   FIELD_AT(spec,7,unsigned short)
#define SRC_PAGE(spec)   FIELD_AT(spec,9,unsigned short)
#define SRC_PTR(spec)   FIELD_AT(spec,7,EMSPTR)
#define DST_TYPE(spec)   FIELD_AT(spec,11,char)
#define DST_HANDLE(spec)   FIELD_AT(spec,12,EMSH)
#define DST_OFFSET(spec)   FIELD_AT(spec,14,unsigned short)
#define DST_PAGE(spec)   FIELD_AT(spec,16,unsigned short)
#define DST_PTR(spec)   FIELD_AT(spec,14,EMSPTR)
#define EMSPAGESIZE   16384L /* gospel, see the EMS specs */
#define HIBYTE(W)   (((W) >> 8) & 0xFF)
#define LOBYTE(W)   ((W) & 0xFF)

Typedefs

typedef void far * EMSPTR

Functions

void *malloc JPP ((size_t size))
void free JPP ((void *ptr))
char *getenv JPP ((const char *name))
short far jdos_open JPP ((short far *handle, char far *filename))
short far jdos_close JPP ((short handle))
short far jdos_seek JPP ((short handle, long offset))
short far jdos_read JPP ((short handle, void far *buffer, unsigned short count))
void far jxms_getdriver JPP ((XMSDRIVER far *))
void far jxms_calldriver JPP ((XMSDRIVER, XMScontext far *))
short far jems_available JPP ((void))
void far jems_calldriver JPP ((EMScontext far *))
 select_file_name (char *fname)
 jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
 jpeg_free_small (j_common_ptr cinfo, void *object, size_t sizeofobject)
 jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
 jpeg_free_large (j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
 jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
 read_file_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 write_file_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 close_file_store (j_common_ptr cinfo, backing_store_ptr info)
 open_file_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 read_xms_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 write_xms_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
 open_xms_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 read_ems_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 write_ems_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
 open_ems_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 jpeg_mem_init (j_common_ptr cinfo)
 jpeg_mem_term (j_common_ptr cinfo)

Variables

You forgot to define
USE_MSDOS_MEMMGR in jconfig h
MAX_ALLOC_CHUNK should be less
than typedef void far * 
XMSDRIVER
static int next_file_num
static XMSDRIVER xms_driver

Class Documentation

struct XMScontext

Definition at line 98 of file jmemdos.c.

Class Members
unsigned short ax
unsigned short bx
void far * ds_si
unsigned short dx
struct EMScontext

Definition at line 102 of file jmemdos.c.

Class Members
unsigned short ax
unsigned short bx
void far * ds_si
unsigned short dx
union XMSPTR

Definition at line 316 of file jmemdos.c.

Class Members
long offset
void far * ptr
struct XMSspec

Definition at line 321 of file jmemdos.c.

Collaboration diagram for XMSspec:
Class Members
XMSPTR dst
XMSH dst_handle
long length
XMSPTR src
XMSH src_handle
union EMSspec

Definition at line 466 of file jmemdos.c.

Class Members
char bytes
long length

Define Documentation

#define DEFAULT_MAX_MEM   300000L /* for total usage about 450K */

Definition at line 204 of file jmemdos.c.

#define DST_HANDLE (   spec)    FIELD_AT(spec,12,EMSH)

Definition at line 479 of file jmemdos.c.

#define DST_OFFSET (   spec)    FIELD_AT(spec,14,unsigned short)

Definition at line 480 of file jmemdos.c.

#define DST_PAGE (   spec)    FIELD_AT(spec,16,unsigned short)

Definition at line 481 of file jmemdos.c.

#define DST_PTR (   spec)    FIELD_AT(spec,14,EMSPTR)

Definition at line 482 of file jmemdos.c.

#define DST_TYPE (   spec)    FIELD_AT(spec,11,char)

Definition at line 478 of file jmemdos.c.

#define EMS_SUPPORTED   1

Definition at line 38 of file jmemdos.c.

#define EMSPAGESIZE   16384L /* gospel, see the EMS specs */

Definition at line 484 of file jmemdos.c.

#define far_free (   x)    free(x)

Definition at line 70 of file jmemdos.c.

#define far_malloc (   x)    malloc(x)

Definition at line 69 of file jmemdos.c.

#define FIELD_AT (   spec,
  offset,
  type 
)    (*((type *) &(spec.bytes[offset])))

Definition at line 472 of file jmemdos.c.

#define HIBYTE (   W)    (((W) >> 8) & 0xFF)

Definition at line 486 of file jmemdos.c.

#define JPEG_INTERNALS

Definition at line 42 of file jmemdos.c.

#define LOBYTE (   W)    ((W) & 0xFF)

Definition at line 487 of file jmemdos.c.

#define ODD (   X)    (((X) & 1L) != 0)

Definition at line 329 of file jmemdos.c.

#define READ_BINARY   "rb"

Definition at line 77 of file jmemdos.c.

#define SRC_HANDLE (   spec)    FIELD_AT(spec,5,EMSH)

Definition at line 474 of file jmemdos.c.

#define SRC_OFFSET (   spec)    FIELD_AT(spec,7,unsigned short)

Definition at line 475 of file jmemdos.c.

#define SRC_PAGE (   spec)    FIELD_AT(spec,9,unsigned short)

Definition at line 476 of file jmemdos.c.

#define SRC_PTR (   spec)    FIELD_AT(spec,7,EMSPTR)

Definition at line 477 of file jmemdos.c.

#define SRC_TYPE (   spec)    FIELD_AT(spec,4,char)

Definition at line 473 of file jmemdos.c.

#define XMS_SUPPORTED   1

Definition at line 35 of file jmemdos.c.


Typedef Documentation

typedef void far* EMSPTR

Definition at line 464 of file jmemdos.c.


Function Documentation

Definition at line 541 of file jmemdos.c.

{
  EMScontext ctx;

  ctx.ax = 0x4500;
  ctx.dx = info->handle.ems_handle;
  jems_calldriver((EMScontext far *) & ctx);
  TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
  /* we ignore any error return from the driver */
}

Here is the caller graph for this function:

Definition at line 275 of file jmemdos.c.

{
  jdos_close(info->handle.file_handle);   /* close the file */
  remove(info->temp_name);  /* delete the file */
/* If your system doesn't have remove(), try unlink() instead.
 * remove() is the ANSI-standard name for this function, but
 * unlink() was more common in pre-ANSI systems.
 */
  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
}

Here is the caller graph for this function:

Definition at line 401 of file jmemdos.c.

{
  XMScontext ctx;

  ctx.dx = info->handle.xms_handle;
  ctx.ax = 0x0a00;
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
  TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
  /* we ignore any error return from the driver */
}

Here is the caller graph for this function:

jpeg_free_large ( j_common_ptr  cinfo,
void FAR object,
size_t  sizeofobject 
)

Definition at line 189 of file jmemdos.c.

{
  far_free(object);
}
jpeg_free_small ( j_common_ptr  cinfo,
void object,
size_t  sizeofobject 
)

Definition at line 172 of file jmemdos.c.

{
  free(object);
}
jpeg_get_large ( j_common_ptr  cinfo,
size_t  sizeofobject 
)

Definition at line 183 of file jmemdos.c.

{
  return (void FAR *) far_malloc(sizeofobject);
}
jpeg_get_small ( j_common_ptr  cinfo,
size_t  sizeofobject 
)

Definition at line 166 of file jmemdos.c.

{
  return (void *) malloc(sizeofobject);
}
jpeg_mem_available ( j_common_ptr  cinfo,
long  min_bytes_needed,
long  max_bytes_needed,
long  already_allocated 
)

Definition at line 208 of file jmemdos.c.

{
  return cinfo->mem->max_memory_to_use - already_allocated;
}

Definition at line 623 of file jmemdos.c.

{
  next_file_num = 0;        /* initialize temp file name generator */
  return DEFAULT_MAX_MEM;   /* default for max_memory_to_use */
}

Definition at line 630 of file jmemdos.c.

{
  /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
   * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
   */
#ifdef NEED_FHEAPMIN
  _fheapmin();
#endif
}
jpeg_open_backing_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 599 of file jmemdos.c.

{
  /* Try extended memory, then expanded memory, then regular file. */
#if XMS_SUPPORTED
  if (open_xms_store(cinfo, info, total_bytes_needed))
    return;
#endif
#if EMS_SUPPORTED
  if (open_ems_store(cinfo, info, total_bytes_needed))
    return;
#endif
  if (open_file_store(cinfo, info, total_bytes_needed))
    return;
  ERREXITS(cinfo, JERR_TFILE_CREATE, "");
}

Here is the call graph for this function:

void* malloc JPP ( (size_t size )
void free JPP ( (void *ptr )
char* getenv JPP ( (const char *name )
short far jdos_open JPP ( (short far *handle, char far *filename )
short far jdos_close JPP ( (short handle)  )
short far jdos_seek JPP ( (short handle, long offset )
short far jdos_write JPP ( (short handle, void far *buffer, unsigned short count )
void far jxms_getdriver JPP ( (XMSDRIVER far *)  )
void far jxms_calldriver JPP ( (XMSDRIVER, XMScontext far *)  )
short far jems_available JPP ( (void )
void far jems_calldriver JPP ( (EMScontext far *)  )
open_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 554 of file jmemdos.c.

{
  EMScontext ctx;

  /* Is EMS driver there? */
  if (! jems_available())
    return FALSE;

  /* Get status, make sure EMS is OK */
  ctx.ax = 0x4000;
  jems_calldriver((EMScontext far *) & ctx);
  if (HIBYTE(ctx.ax) != 0)
    return FALSE;

  /* Get version, must be >= 4.0 */
  ctx.ax = 0x4600;
  jems_calldriver((EMScontext far *) & ctx);
  if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
    return FALSE;

  /* Try to allocate requested space */
  ctx.ax = 0x4300;
  ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
  jems_calldriver((EMScontext far *) & ctx);
  if (HIBYTE(ctx.ax) != 0)
    return FALSE;

  /* Succeeded, save the handle and away we go */
  info->handle.ems_handle = ctx.dx;
  info->read_backing_store = read_ems_store;
  info->write_backing_store = write_ems_store;
  info->close_backing_store = close_ems_store;
  TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
  return TRUE;                     /* succeeded */
}

Here is the call graph for this function:

Here is the caller graph for this function:

open_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 288 of file jmemdos.c.

{
  short handle;

  select_file_name(info->temp_name);
  if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
    /* might as well exit since jpeg_open_backing_store will fail anyway */
    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
    return FALSE;
  }
  info->handle.file_handle = handle;
  info->read_backing_store = read_file_store;
  info->write_backing_store = write_file_store;
  info->close_backing_store = close_file_store;
  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
  return TRUE;                     /* succeeded */
}

Here is the call graph for this function:

Here is the caller graph for this function:

open_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 414 of file jmemdos.c.

{
  XMScontext ctx;

  /* Get address of XMS driver */
  jxms_getdriver((XMSDRIVER far *) & xms_driver);
  if (xms_driver == NULL)
    return FALSE;           /* no driver to be had */

  /* Get version number, must be >= 2.00 */
  ctx.ax = 0x0000;
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
  if (ctx.ax < (unsigned short) 0x0200)
    return FALSE;

  /* Try to get space (expressed in kilobytes) */
  ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
  ctx.ax = 0x0900;
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
  if (ctx.ax != 1)
    return FALSE;

  /* Succeeded, save the handle and away we go */
  info->handle.xms_handle = ctx.dx;
  info->read_backing_store = read_xms_store;
  info->write_backing_store = write_xms_store;
  info->close_backing_store = close_xms_store;
  TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
  return TRUE;                     /* succeeded */
}

Here is the call graph for this function:

Here is the caller graph for this function:

read_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 491 of file jmemdos.c.

{
  EMScontext ctx;
  EMSspec spec;

  spec.length = byte_count;
  SRC_TYPE(spec) = 1;
  SRC_HANDLE(spec) = info->handle.ems_handle;
  SRC_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);
  SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
  DST_TYPE(spec) = 0;
  DST_HANDLE(spec) = 0;
  DST_PTR(spec)    = buffer_address;
  
  ctx.ds_si = (void far *) & spec;
  ctx.ax = 0x5700;          /* move memory region */
  jems_calldriver((EMScontext far *) & ctx);
  if (HIBYTE(ctx.ax) != 0)
    ERREXIT(cinfo, JERR_EMS_READ);
}

Here is the caller graph for this function:

read_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 243 of file jmemdos.c.

{
  if (jdos_seek(info->handle.file_handle, file_offset))
    ERREXIT(cinfo, JERR_TFILE_SEEK);
  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
  if (byte_count > 65535L)  /* safety check */
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  if (jdos_read(info->handle.file_handle, buffer_address,
              (unsigned short) byte_count))
    ERREXIT(cinfo, JERR_TFILE_READ);
}

Here is the caller graph for this function:

read_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 333 of file jmemdos.c.

{
  XMScontext ctx;
  XMSspec spec;
  char endbuffer[2];

  /* The XMS driver can't cope with an odd length, so handle the last byte
   * specially if byte_count is odd.  We don't expect this to be common.
   */

  spec.length = byte_count & (~ 1L);
  spec.src_handle = info->handle.xms_handle;
  spec.src.offset = file_offset;
  spec.dst_handle = 0;
  spec.dst.ptr = buffer_address;
  
  ctx.ds_si = (void far *) & spec;
  ctx.ax = 0x0b00;          /* EMB move */
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
  if (ctx.ax != 1)
    ERREXIT(cinfo, JERR_XMS_READ);

  if (ODD(byte_count)) {
    read_xms_store(cinfo, info, (void FAR *) endbuffer,
                 file_offset + byte_count - 1L, 2L);
    ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
  }
}

Here is the caller graph for this function:

select_file_name ( char *  fname)

Definition at line 128 of file jmemdos.c.

{
  const char * env;
  char * ptr;
  FILE * tfile;

  /* Keep generating file names till we find one that's not in use */
  for (;;) {
    /* Get temp directory name from environment TMP or TEMP variable;
     * if none, use "."
     */
    if ((env = (const char *) getenv("TMP")) == NULL)
      if ((env = (const char *) getenv("TEMP")) == NULL)
       env = ".";
    if (*env == '\0')              /* null string means "." */
      env = ".";
    ptr = fname;            /* copy name to fname */
    while (*env != '\0')
      *ptr++ = *env++;
    if (ptr[-1] != '\\' && ptr[-1] != '/')
      *ptr++ = '\\';        /* append backslash if not in env variable */
    /* Append a suitable file name */
    next_file_num++;        /* advance counter */
    sprintf(ptr, "JPG%03d.TMP", next_file_num);
    /* Probe to see if file name is already in use */
    if ((tfile = fopen(fname, READ_BINARY)) == NULL)
      break;
    fclose(tfile);          /* oops, it's there; close tfile & try again */
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

write_ems_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 516 of file jmemdos.c.

{
  EMScontext ctx;
  EMSspec spec;

  spec.length = byte_count;
  SRC_TYPE(spec) = 0;
  SRC_HANDLE(spec) = 0;
  SRC_PTR(spec)    = buffer_address;
  DST_TYPE(spec) = 1;
  DST_HANDLE(spec) = info->handle.ems_handle;
  DST_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);
  DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
  
  ctx.ds_si = (void far *) & spec;
  ctx.ax = 0x5700;          /* move memory region */
  jems_calldriver((EMScontext far *) & ctx);
  if (HIBYTE(ctx.ax) != 0)
    ERREXIT(cinfo, JERR_EMS_WRITE);
}

Here is the caller graph for this function:

write_file_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 259 of file jmemdos.c.

{
  if (jdos_seek(info->handle.file_handle, file_offset))
    ERREXIT(cinfo, JERR_TFILE_SEEK);
  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
  if (byte_count > 65535L)  /* safety check */
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  if (jdos_write(info->handle.file_handle, buffer_address,
               (unsigned short) byte_count))
    ERREXIT(cinfo, JERR_TFILE_WRITE);
}

Here is the caller graph for this function:

write_xms_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 366 of file jmemdos.c.

{
  XMScontext ctx;
  XMSspec spec;
  char endbuffer[2];

  /* The XMS driver can't cope with an odd length, so handle the last byte
   * specially if byte_count is odd.  We don't expect this to be common.
   */

  spec.length = byte_count & (~ 1L);
  spec.src_handle = 0;
  spec.src.ptr = buffer_address;
  spec.dst_handle = info->handle.xms_handle;
  spec.dst.offset = file_offset;

  ctx.ds_si = (void far *) & spec;
  ctx.ax = 0x0b00;          /* EMB move */
  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
  if (ctx.ax != 1)
    ERREXIT(cinfo, JERR_XMS_WRITE);

  if (ODD(byte_count)) {
    read_xms_store(cinfo, info, (void FAR *) endbuffer,
                 file_offset + byte_count - 1L, 2L);
    endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
    write_xms_store(cinfo, info, (void FAR *) endbuffer,
                  file_offset + byte_count - 1L, 2L);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int next_file_num [static]

Definition at line 125 of file jmemdos.c.

Definition at line 314 of file jmemdos.c.

You forgot to define USE_MSDOS_MEMMGR in jconfig h MAX_ALLOC_CHUNK should be less than typedef void far* XMSDRIVER

Definition at line 97 of file jmemdos.c.