home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / FILES.H < prev    next >
C/C++ Source or Header  |  1992-07-20  |  2KB  |  57 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* files.h */
  21. /* Common declarations for zfile.c and zfileio.c */
  22. /* Requires stream.h */
  23.  
  24. /* File objects store a pointer to a stream in value.pfile. */
  25. /* A file object is valid if its "size" matches the read_id or write_id */
  26. /* (as appropriate) in the stream it points to.  This arrangement */
  27. /* allows us to detect closed files reliably, while allowing us to */
  28. /* reuse closed streams for new files. */
  29. #define fptr(pref) (pref)->value.pfile
  30. #define make_file(pref,a,id,s)\
  31.   make_tasv(pref,t_file,a,id,pfile,s)
  32.  
  33. /* The standard files.  0 is %stdin, 1 is %stdout. */
  34. extern stream std_files[];
  35. /* An invalid file. */
  36. extern stream invalid_file_entry;
  37.  
  38. /* Macros for checking file validity */
  39. #define check_file_access(svar,op,acc)\
  40.    {    svar = fptr(op);    /* do first, acc may refer to it */\
  41.     if ( !(acc) ) return e_invalidaccess;\
  42.    }
  43. #define check_file_ref(svar,op,acc)\
  44.    {    if ( !r_has_type(op, t_file) ) return e_typecheck;\
  45.     check_file_access(svar,op,acc);\
  46.    }
  47. #define check_file(svar,op)\
  48.     check_file_ref(svar, op, (svar->read_id | svar->write_id) == r_size(op))
  49. #define check_read_file(svar,op)\
  50.    {    check_read_type(*(op), t_file);\
  51.     check_file_access(svar, op, svar->read_id == r_size(op));\
  52.    }
  53. #define check_write_file(svar,op)\
  54.    {    check_write_type(*(op), t_file);\
  55.     check_file_access(svar, op, svar->write_id == r_size(op));\
  56.    }
  57.