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

  1. /* Copyright (C) 1993, 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. /* ziodev2.c */
  20. /* (Level 2) IODevice operators */
  21. #include "string_.h"
  22. #include "ghost.h"
  23. #include "gp.h"
  24. #include "errors.h"
  25. #include "oper.h"
  26. #include "stream.h"
  27. #include "gxiodev.h"
  28. #include "files.h"                /* for file_open_stream */
  29. #include "iparam.h"
  30. #include "iutil2.h"
  31. #include "store.h"
  32.  
  33. /* ------ %null% ------ */
  34.  
  35. /* This represents the null output file. */
  36. private iodev_proc_open_device(null_open);
  37. gx_io_device gs_iodev_null =
  38.   { "%null%", "FileSystem",
  39.      { iodev_no_init, null_open, iodev_no_open_file,
  40.        iodev_os_fopen, iodev_os_fclose,
  41.        iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  42.        iodev_no_enumerate_files, NULL, NULL,
  43.        iodev_no_get_params, iodev_no_put_params
  44.      }
  45.   };
  46.  
  47. private int
  48. null_open(gx_io_device *iodev, const char *access, stream **ps,
  49.   gs_memory_t *mem)
  50. {    if ( !streq1(access, 'w') )
  51.         return_error(e_invalidfileaccess);
  52.     return file_open_stream(gp_null_file_name,
  53.                 strlen(gp_null_file_name),
  54.                 access, 256 /* arbitrary */, ps,
  55.                 iodev->procs.fopen);
  56. }
  57.  
  58. /* ------ %ram% ------ */
  59.  
  60. /* This is an IODevice with no interesting parameters for the moment. */
  61. gx_io_device gs_iodev_ram =
  62.   { "%ram%", "Special",
  63.      { iodev_no_init, iodev_no_open_device, iodev_no_open_file,
  64.        iodev_no_fopen, iodev_no_fclose,
  65.        iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  66.        iodev_no_enumerate_files, NULL, NULL,
  67.        iodev_no_get_params, iodev_no_put_params
  68.      }
  69.   };
  70.  
  71. /* ------ Operators ------ */
  72.  
  73. /* <iodevice> .getdevparams <mark> <name> <value> ... */
  74. int
  75. zgetdevparams(os_ptr op)
  76. {    gx_io_device *iodev;
  77.     stack_param_list list;
  78.     gs_param_string ts;
  79.     int code;
  80.     ref *pmark;
  81.     check_read_type(*op, t_string);
  82.     iodev = gs_findiodevice(op->value.bytes, r_size(op));
  83.     if ( iodev == 0 )
  84.       return_error(e_undefinedfilename);
  85.     stack_param_list_write(&list, &o_stack, NULL);
  86. #define plist ((gs_param_list *)&list)
  87.     param_string_from_string(ts, iodev->dtype);
  88.     if ( (code = param_write_name(plist, "Type", &ts)) < 0 ||
  89.          (code = (*iodev->procs.get_params)(iodev, plist)) < 0
  90.        )
  91.     {    ref_stack_pop(&o_stack, list.count * 2);
  92.         return code;
  93.     }
  94. #undef plist
  95.     pmark = ref_stack_index(&o_stack, list.count * 2);
  96.     make_mark(pmark);
  97.     return 0;
  98. }
  99.  
  100. /* <mark> <name> <value> ... <iodevice> .putdevparams */
  101. int
  102. zputdevparams(os_ptr op)
  103. {    gx_io_device *iodev;
  104.     stack_param_list list;
  105.     int code;
  106.     check_read_type(*op, t_string);
  107.     iodev = gs_findiodevice(op->value.bytes, r_size(op));
  108.     if ( iodev == 0 )
  109.       return_error(e_undefinedfilename);
  110.     code = stack_param_list_read(&list, &o_stack, 1, NULL);
  111.     if ( code < 0 )
  112.       return code;
  113. #define plist ((gs_param_list *)&list)
  114.     code = param_check_password(plist, &SystemParamsPassword);
  115.     if ( code != 0 )
  116.       return_error(code < 0 ? code : e_invalidaccess);
  117.     code = (*iodev->procs.put_params)(iodev, plist);
  118.     if ( code < 0 )
  119.       return code;
  120. #undef plist
  121.     ref_stack_pop(&o_stack, list.count * 2 + 2);
  122.     return 0;
  123. }
  124.  
  125. /* ------ Initialization procedure ------ */
  126.  
  127. op_def ziodev2_l2_op_defs[] = {
  128.         op_def_begin_level2(),
  129.     {"1.getdevparams", zgetdevparams},
  130.     {"2.putdevparams", zputdevparams},
  131.     op_def_end(0)
  132. };
  133.