home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / files.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.3 KB  |  166 lines

  1. /* Copyright (C) 1989, 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: files.h,v 1.2 2000/09/19 19:00:11 lpd Exp $ */
  20. /* Definitions for interpreter support for file objects */
  21. /* Requires stream.h */
  22.  
  23. #ifndef files_INCLUDED
  24. #  define files_INCLUDED
  25.  
  26. /*
  27.  * File objects store a pointer to a stream in value.pfile.
  28.  * A file object is valid if its "size" matches the read_id or write_id
  29.  * (as appropriate) in the stream it points to.  This arrangement
  30.  * allows us to detect closed files reliably, while allowing us to
  31.  * reuse closed streams for new files.
  32.  */
  33. #define fptr(pref) (pref)->value.pfile
  34. #define make_file(pref,a,id,s)\
  35.   make_tasv(pref,t_file,a,id,pfile,s)
  36.  
  37. /* The stdxxx files.  We have to access them through procedures, */
  38. /* because they might have to be opened when referenced. */
  39. int zget_stdin(P2(i_ctx_t *, stream **));
  40. int zget_stdout(P2(i_ctx_t *, stream **));
  41. int zget_stderr(P2(i_ctx_t *, stream **));
  42. extern bool gs_stdin_is_interactive;
  43. /* Test whether a stream is stdin. */
  44. bool zis_stdin(P1(const stream *));
  45.  
  46. /* Define access to the stdio refs for operators. */
  47. #define ref_stdio (i_ctx_p->stdio)
  48. #define ref_stdin ref_stdio[0]
  49. #define ref_stdout ref_stdio[1]
  50. #define ref_stderr ref_stdio[2]
  51. /* An invalid (closed) file. */
  52. #define avm_invalid_file_entry avm_foreign
  53. extern stream *const invalid_file_entry;
  54. /* Make an invalid file object. */
  55. void make_invalid_file(P1(ref *));
  56.  
  57. /*
  58.  * Macros for checking file validity.
  59.  * NOTE: in order to work around a bug in the Borland 5.0 compiler,
  60.  * you must use file_is_invalid rather than !file_is_valid.
  61.  */
  62. #define file_is_valid(svar,op)\
  63.   (svar = fptr(op), (svar->read_id | svar->write_id) == r_size(op))
  64. #define file_is_invalid(svar,op)\
  65.   (svar = fptr(op), (svar->read_id | svar->write_id) != r_size(op))
  66. #define check_file(svar,op)\
  67.   BEGIN\
  68.     check_type(*(op), t_file);\
  69.     if ( file_is_invalid(svar, op) ) return_error(e_invalidaccess);\
  70.   END
  71.  
  72. /*
  73.  * If a file is open for both reading and writing, its read_id, write_id,
  74.  * and stream procedures and modes reflect the current mode of use;
  75.  * an id check failure will switch it to the other mode.
  76.  */
  77. int file_switch_to_read(P1(const ref *));
  78.  
  79. #define check_read_file(svar,op)\
  80.   BEGIN\
  81.     check_read_type(*(op), t_file);\
  82.     check_read_known_file(svar, op, return);\
  83.   END
  84. #define check_read_known_file(svar,op,error_return)\
  85.   check_read_known_file_else(svar, op, error_return, svar = invalid_file_entry)
  86. #define check_read_known_file_else(svar,op,error_return,invalid_action)\
  87.   BEGIN\
  88.     svar = fptr(op);\
  89.     if (svar->read_id != r_size(op)) {\
  90.     if (svar->read_id == 0 && svar->write_id == r_size(op)) {\
  91.         int fcode = file_switch_to_read(op);\
  92. \
  93.         if (fcode < 0)\
  94.          error_return(fcode);\
  95.     } else {\
  96.         invalid_action;    /* closed or reopened file */\
  97.     }\
  98.     }\
  99.   END
  100. int file_switch_to_write(P1(const ref *));
  101.  
  102. #define check_write_file(svar,op)\
  103.   BEGIN\
  104.     check_write_type(*(op), t_file);\
  105.     check_write_known_file(svar, op, return);\
  106.   END
  107. #define check_write_known_file(svar,op,error_return)\
  108.   BEGIN\
  109.     svar = fptr(op);\
  110.     if ( svar->write_id != r_size(op) )\
  111.     {    int fcode = file_switch_to_write(op);\
  112.         if ( fcode < 0 ) error_return(fcode);\
  113.     }\
  114.   END
  115.  
  116. /* Data exported by zfile.c. */
  117.     /* for zfilter.c and ziodev.c */
  118. extern const uint file_default_buffer_size;
  119.  
  120. /* Procedures exported by zfile.c. */
  121.     /* for imainarg.c */
  122. FILE *lib_fopen(P1(const char *));
  123.  
  124.     /* for imain.c */
  125. int lib_file_open(P7(const char *, uint, byte *, uint, uint *, ref *,
  126.              gs_memory_t *));
  127.  
  128.     /* for imain.c */
  129. #ifndef gs_ref_memory_DEFINED
  130. #  define gs_ref_memory_DEFINED
  131. typedef struct gs_ref_memory_s gs_ref_memory_t;
  132. #endif
  133. int file_read_string(P4(const byte *, uint, ref *, gs_ref_memory_t *));
  134.  
  135.     /* for os_open in ziodev.c */
  136. #ifdef iodev_proc_fopen        /* in gxiodev.h */
  137. int file_open_stream(P7(const char *, uint, const char *, uint,
  138.             stream **, iodev_proc_fopen_t, gs_memory_t *));
  139. #endif
  140.  
  141.     /* for zfilter.c */
  142. int filter_open(P7(const char *, uint, ref *, const stream_procs *,
  143.            const stream_template *, const stream_state *,
  144.            gs_memory_t *));
  145.  
  146.     /* for zfileio.c */
  147. void make_stream_file(P3(ref *, stream *, const char *));
  148.  
  149.     /* for ziodev.c */
  150. int file_close_finish(P1(stream *));
  151. int file_close_disable(P1(stream *));
  152. int file_close_file(P1(stream *));
  153.  
  154.     /* for gsmain.c, interp.c */
  155. int file_close(P1(ref *));
  156.  
  157.     /* for zfproc.c, ziodev.c */
  158. stream *file_alloc_stream(P2(gs_memory_t *, client_name_t));
  159.  
  160. /* Procedures exported by zfileio.c. */
  161.     /* for ziodev.c */
  162. int zreadline_from(P5(stream *s, gs_string *buf, gs_memory_t *bufmem,
  163.               uint *pcount, bool *pin_eol));
  164.  
  165. #endif /* files_INCLUDED */
  166.