gxiodev.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* Copyright (C) 1993, 1994, 1996, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gxiodev.h,v 1.2 2000/09/19 19:00:38 lpd Exp $ */
  16. /* Structure and default implementation of IODvices */
  17. /* Requires gsmemory.h */
  18. #ifndef gxiodev_INCLUDED
  19. # define gxiodev_INCLUDED
  20. #include "stat_.h"
  21. /*
  22. * Note that IODevices are not the same as Ghostscript output devices.
  23. * See section 3.8.2 of the PostScript Language Reference Manual,
  24. * Second Edition, for more information.
  25. */
  26. #ifndef gx_io_device_DEFINED
  27. # define gx_io_device_DEFINED
  28. typedef struct gx_io_device_s gx_io_device;
  29. #endif
  30. typedef struct gx_io_device_procs_s gx_io_device_procs; /* defined here */
  31. /* The IODevice table is defined in gconf.c; its extern is in gscdefs.h. */
  32. #ifndef file_enum_DEFINED /* also defined in gp.h */
  33. # define file_enum_DEFINED
  34. struct file_enum_s; /* opaque to client, defined by implementors */
  35. typedef struct file_enum_s file_enum;
  36. #endif
  37. /* Define an opaque type for parameter lists. */
  38. #ifndef gs_param_list_DEFINED
  39. # define gs_param_list_DEFINED
  40. typedef struct gs_param_list_s gs_param_list;
  41. #endif
  42. /* Define an opaque type for streams. */
  43. #ifndef stream_DEFINED
  44. # define stream_DEFINED
  45. typedef struct stream_s stream;
  46. #endif
  47. /* Definition of IODevice procedures */
  48. /* Note that file names for fopen, delete, rename, and status */
  49. /* are C strings, not pointer + length. */
  50. /* Note also that "streams" are a higher-level concept; */
  51. /* the open_device and open_file procedures are normally NULL. */
  52. struct gx_io_device_procs_s {
  53. #define iodev_proc_init(proc)\
  54. int proc(P2(gx_io_device *iodev, gs_memory_t *mem))
  55. iodev_proc_init((*init)); /* one-time initialization */
  56. #define iodev_proc_open_device(proc)\
  57. int proc(P4(gx_io_device *iodev, const char *access, stream **ps,\
  58. gs_memory_t *mem))
  59. iodev_proc_open_device((*open_device));
  60. #define iodev_proc_open_file(proc)\
  61. int proc(P6(gx_io_device *iodev, const char *fname, uint namelen,\
  62. const char *access, stream **ps, gs_memory_t *mem))
  63. iodev_proc_open_file((*open_file));
  64. /* fopen was changed in release 2.9.6, */
  65. /* and again in 3.20 to return the real fname separately */
  66. #define iodev_proc_fopen(proc)\
  67. int proc(P6(gx_io_device *iodev, const char *fname, const char *access,\
  68. FILE **pfile, char *rfname, uint rnamelen))
  69. iodev_proc_fopen((*fopen));
  70. #define iodev_proc_fclose(proc)\
  71. int proc(P2(gx_io_device *iodev, FILE *file))
  72. iodev_proc_fclose((*fclose));
  73. #define iodev_proc_delete_file(proc)\
  74. int proc(P2(gx_io_device *iodev, const char *fname))
  75. iodev_proc_delete_file((*delete_file));
  76. #define iodev_proc_rename_file(proc)\
  77. int proc(P3(gx_io_device *iodev, const char *from, const char *to))
  78. iodev_proc_rename_file((*rename_file));
  79. #define iodev_proc_file_status(proc)\
  80. int proc(P3(gx_io_device *iodev, const char *fname, struct stat *pstat))
  81. iodev_proc_file_status((*file_status));
  82. #define iodev_proc_enumerate_files(proc)\
  83. file_enum *proc(P4(gx_io_device *iodev, const char *pat, uint patlen,\
  84. gs_memory_t *mem))
  85. iodev_proc_enumerate_files((*enumerate_files));
  86. #define iodev_proc_enumerate_next(proc)\
  87. uint proc(P3(file_enum *pfen, char *ptr, uint maxlen))
  88. iodev_proc_enumerate_next((*enumerate_next));
  89. #define iodev_proc_enumerate_close(proc)\
  90. void proc(P1(file_enum *pfen))
  91. iodev_proc_enumerate_close((*enumerate_close));
  92. /* Added in release 2.9 */
  93. #define iodev_proc_get_params(proc)\
  94. int proc(P2(gx_io_device *iodev, gs_param_list *plist))
  95. iodev_proc_get_params((*get_params));
  96. #define iodev_proc_put_params(proc)\
  97. int proc(P2(gx_io_device *iodev, gs_param_list *plist))
  98. iodev_proc_put_params((*put_params));
  99. };
  100. /* The following typedef is needed because ansi2knr can't handle */
  101. /* iodev_proc_fopen((*procname)) in a formal argument list. */
  102. typedef iodev_proc_fopen((*iodev_proc_fopen_t));
  103. /* Default implementations of procedures */
  104. iodev_proc_init(iodev_no_init);
  105. iodev_proc_open_device(iodev_no_open_device);
  106. iodev_proc_open_file(iodev_no_open_file);
  107. iodev_proc_fopen(iodev_no_fopen);
  108. iodev_proc_fclose(iodev_no_fclose);
  109. iodev_proc_delete_file(iodev_no_delete_file);
  110. iodev_proc_rename_file(iodev_no_rename_file);
  111. iodev_proc_file_status(iodev_no_file_status);
  112. iodev_proc_enumerate_files(iodev_no_enumerate_files);
  113. iodev_proc_get_params(iodev_no_get_params);
  114. iodev_proc_put_params(iodev_no_put_params);
  115. /* The %os% implemention of fopen and fclose. */
  116. /* These are exported for pipes and for %null. */
  117. iodev_proc_fopen(iodev_os_fopen);
  118. iodev_proc_fclose(iodev_os_fclose);
  119. /* Get the N'th IODevice. */
  120. gx_io_device *gs_getiodevice(P1(int));
  121. #define iodev_default (gs_getiodevice(0))
  122. /* Look up an IODevice name. */
  123. gx_io_device *gs_findiodevice(P2(const byte *, uint));
  124. /* Get and put IODevice parameters. */
  125. int gs_getdevparams(P2(gx_io_device *, gs_param_list *));
  126. int gs_putdevparams(P2(gx_io_device *, gs_param_list *));
  127. /* Convert an OS error number to a PostScript error */
  128. /* if opening a file fails. */
  129. int gs_fopen_errno_to_code(P1(int));
  130. /* Test whether a string is equal to a character. */
  131. /* (This is used for access testing in file_open procedures.) */
  132. #define streq1(str, chr)\
  133. ((str)[0] == (chr) && (str)[1] == 0)
  134. /* Finally, the IODevice structure itself. */
  135. struct gx_io_device_s {
  136. const char *dname; /* the IODevice name */
  137. const char *dtype; /* the type returned by currentdevparams */
  138. gx_io_device_procs procs;
  139. void *state; /* (if the IODevice has state) */
  140. };
  141. #define private_st_io_device() /* in gsiodev.c */\
  142. gs_private_st_ptrs1(st_io_device, gx_io_device, "gx_io_device",\
  143. io_device_enum_ptrs, io_device_reloc_ptrs, state)
  144. #endif /* gxiodev_INCLUDED */