home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / SCOMMON.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  5KB  |  142 lines

  1. /* Copyright (C) 1994 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. /* scommon.h */
  20. /* Definitions common to clients and implementors of Ghostscript streams */
  21.  
  22. #ifndef scommon_DEFINED
  23. #  define scommon_DEFINED
  24.  
  25. #include "gsmemory.h"
  26. #include "gsstruct.h"            /* for extern_st */
  27.  
  28. /*
  29.  * There are three major structures involved in the stream package.
  30.  *
  31.  * A stream is an "object" that owns a buffer, which it uses to implement
  32.  * byte-oriented sequential access in a standard way, and a set of
  33.  * procedures that handle things like buffer refilling.  See stream.h
  34.  * for more information about streams.
  35.  */
  36. #ifndef stream_DEFINED
  37. #  define stream_DEFINED
  38. typedef struct stream_s stream;
  39. #endif
  40. /*
  41.  * A stream_state records the state specific to a given variety of stream.
  42.  * The buffer processing function of a stream maintains this state.
  43.  */
  44. typedef struct stream_state_s stream_state;
  45. /*
  46.  * A stream_template provides the information needed to create a stream.
  47.  * The client must fill in any needed setup parameters in the appropriate
  48.  * variety of stream_state, and then call the initialization function
  49.  * provided by the template.  See strimpl.h for more information about
  50.  * stream_templates.
  51.  */
  52. typedef struct stream_template_s stream_template;
  53.  
  54. /*
  55.  * The stream package works with bytes, not chars.
  56.  * This is to ensure unsigned representation on all systems.
  57.  * A stream currently can only be read or written, not both.
  58.  * Note also that the read procedure returns an int, not a char or a byte;
  59.  * we use negative values to indicate exceptional conditions.
  60.  * (We cast these values to int explicitly, because some compilers
  61.  * don't do this if the other arm of a conditional is a byte.)
  62.  */
  63. /* End of data */
  64. #define EOFC ((int)(-1))
  65. /* Error */
  66. #define ERRC ((int)(-2))
  67. /* Interrupt */
  68. #define INTC ((int)(-3))
  69. /****** INTC IS NOT USED YET ******/
  70. /* Callout */
  71. #define CALLC ((int)(-4))
  72. #define max_stream_exception 4
  73. /* The following hack is needed for initializing scan_char_array in iscan.c. */
  74. #define stream_exception_repeat(x) x, x, x, x
  75.  
  76. /*
  77.  * Define cursors for reading from or writing into a buffer.
  78.  * We lay them out this way so that we can alias
  79.  * the write pointer and the read limit.
  80.  */
  81. typedef struct stream_cursor_read_s {
  82.     const byte *ptr;
  83.     const byte *limit;
  84.     byte *_skip;
  85. } stream_cursor_read;
  86. typedef struct stream_cursor_write_s {
  87.     const byte *_skip;
  88.     byte *ptr;
  89.     byte *limit;
  90. } stream_cursor_write;
  91. typedef union stream_cursor_s {
  92.     stream_cursor_read r;
  93.     stream_cursor_write w;
  94. } stream_cursor;
  95.  
  96. /*
  97.  * Define the prototype for the procedures known to both the generic
  98.  * stream code and the stream implementations.
  99.  */
  100.  
  101. /* Initialize the stream state (after the client parameters are set). */
  102. #define stream_proc_init(proc)\
  103.   int proc(P1(stream_state *))
  104.  
  105. /* Process a buffer.  See strimpl.h for details. */
  106. #define stream_proc_process(proc)\
  107.   int proc(P4(stream_state *, stream_cursor_read *,\
  108.     stream_cursor_write *, bool))
  109.  
  110. /* Release the stream state when closing. */
  111. #define stream_proc_release(proc)\
  112.   void proc(P1(stream_state *))
  113.  
  114. /* Report an error.  Note that this procedure is stored in the state, */
  115. /* not in the main stream structure. */
  116. #define stream_proc_report_error(proc)\
  117.   int proc(P2(stream_state *, const char *))
  118. stream_proc_report_error(s_no_report_error);
  119.  
  120. /*
  121.  * Define a generic stream state.  If a processing procedure has no
  122.  * state of its own, it can use stream_state; otherwise, it must
  123.  * create a "subclass".  There is a hack in stream.h to allow the stream
  124.  * itself to serve as the "state" of a couple of heavily used stream types.
  125.  *
  126.  * In order to simplify the structure descriptors for concrete streams,
  127.  * we require that the generic stream state not contain any pointers
  128.  * to garbage-collectable storage.
  129.  */
  130. #define stream_state_common\
  131.     const stream_template *template;\
  132.     gs_memory_t *memory;\
  133.     stream_proc_report_error((*report_error))
  134. struct stream_state_s {
  135.     stream_state_common;
  136. };
  137. extern_st(st_stream_state);
  138. #define public_st_stream_state() /* in stream.c */\
  139.   gs_public_st_simple(st_stream_state, stream_state, "stream_state")
  140.  
  141. #endif                    /* scommon_INCLUDED */
  142.