home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / UsingPDF / GhostScript / source / gs5.10 / gsdsrc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-01  |  3.9 KB  |  102 lines

  1. /* Copyright (C) 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gsdsrc.h */
  20. /* DataSource definitions */
  21.  
  22. #ifndef gsdsrc_INCLUDED
  23. #  define gsdsrc_INCLUDED
  24.  
  25. #include "gsstruct.h"
  26.  
  27. /* ---------------- Types and structures ---------------- */
  28.  
  29. /*
  30.  * A gs_data_source_t represents the data source for various constructs.
  31.  * Shading.  It can be either a string (either a gs_string or a byte-type
  32.  * object) or a positionable, non-procedure-based stream.  An ordinary
  33.  * positionable file stream will do, as long as the client doesn't attempt
  34.  * to read past the EOF.
  35.  */
  36.  
  37. #ifndef stream_DEFINED
  38. #  define stream_DEFINED
  39. typedef struct stream_s stream;
  40. #endif
  41.  
  42. /*
  43.  * Prepare to access a block of data from a source.  buf must be a client-
  44.  * supplied buffer of at least length bytes.  If ptr == 0, always copy the
  45.  * data into buf.  If ptr != 0, either copy the data into buf and set *ptr =
  46.  * buf, or set *ptr to point to the data (which might be invalidated by the
  47.  * next call).  Note that this procedure may or may not do bounds checking.
  48.  */
  49. #define data_source_proc_access(proc)\
  50.   int proc(P5(const gs_data_source_t *psrc, ulong start, uint length,\
  51.           byte *buf, const byte **ptr))
  52.  
  53. typedef struct gs_data_source_s gs_data_source_t;
  54. struct gs_data_source_s {
  55.   data_source_proc_access((*access));
  56.   union d_ {
  57.     gs_const_string str;    /* also used for byte objects */
  58.     stream *strm;
  59.   } data;
  60. };
  61.  
  62. #define data_source_access_only(psrc, start, length, buf, ptr)\
  63.   (*(psrc)->access)(psrc, (ulong)(start), length, buf, ptr)
  64. #define data_source_access(psrc, start, length, buf, ptr)\
  65.   do {\
  66.     int code_ = data_source_access_only(psrc, start, length, buf, ptr);\
  67.     if ( code_ < 0 ) return code_;\
  68.   } while ( 0 )
  69. #define data_source_copy_only(psrc, start, length, buf)\
  70.   data_source_access_only(psrc, start, length, buf, (const byte **)0)
  71. #define data_source_copy(psrc, start, length, buf)\
  72.   data_source_access(psrc, start, length, buf, (const byte **)0)
  73.  
  74. /*
  75.  * Data sources are always embedded in other structures, but they do have
  76.  * pointers that need to be traced and relocated, so they do have a GC
  77.  * structure type.
  78.  */
  79. extern_st(st_data_source);
  80. #define public_st_data_source()    /* in gsdsrc.c */\
  81.   gs_public_st_composite(st_data_source, gs_data_source_t, "gs_data_source_t",\
  82.     data_source_enum_ptrs, data_source_reloc_ptrs)
  83. #define st_data_source_max_ptrs 1
  84.  
  85. /* ---------------- Procedures ---------------- */
  86.  
  87. /* Initialize a data source of the various known types. */
  88. data_source_proc_access(data_source_access_string);
  89. #define data_source_init_string(psrc, strg)\
  90.   ((psrc)->data.str = strg, (psrc)->access = data_source_access_string)
  91. #define data_source_init_string2(psrc, bytes, len)\
  92.   ((psrc)->data.str.data = bytes, (psrc)->data.str.size = len,\
  93.    (psrc)->access = data_source_access_string)
  94. data_source_proc_access(data_source_access_bytes);
  95. #define data_source_init_bytes(psrc, bytes)\
  96.   ((psrc)->data.str.data = bytes, (psrc)->access = data_source_access_bytes)
  97. data_source_proc_access(data_source_access_stream);
  98. #define data_source_init_stream(psrc, s)\
  99.   ((psrc)->data.strm = s, (psrc)->access = data_source_access_stream)
  100.  
  101. #endif                    /* gsdsrc_INCLUDED */
  102.