]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/port.h
r4264@bucket (orig r254): kcr | 2008-01-20 22:11:44 -0500
[1ts-debian.git] / zephyr / zwgc / port.h
1 #ifndef port_TYPE
2 #define port_TYPE
3
4 /* This file is part of the Project Athena Zephyr Notification System.
5  * It is one of the source files comprising zwgc, the Zephyr WindowGram
6  * client.
7  *
8  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
9  *
10  *      $Id$
11  *
12  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
13  *      For copying and distribution information, see the file
14  *      "mit-copyright.h".
15  */
16
17
18 #include <zephyr/mit-copyright.h>
19
20 #include <stdio.h>
21 #include "new_string.h"
22 #include "string_stack.h"
23
24 union port__data {
25     struct {
26         FILE *input_connector;
27         FILE *output_connector;
28     } file;
29     struct {
30         string_stack waiting_packets;
31         string (*filter)(string);
32     } filter;
33     struct {
34         char *(*output)(string);
35     } output;
36 };
37
38 typedef struct port__struct {                /* PRIVATE */
39     char *(*get)(struct port__struct *, char **);
40     char *(*put)(struct port__struct *, char *, int);
41     char *(*close_input)(struct port__struct *);
42     char *(*close_output)(struct port__struct *);
43 #define  INPUT_CLOSED   0x1
44 #define  OUTPUT_CLOSED  0x2
45 #define  PORT_CLOSED    0x3
46     int status;
47     union port__data data;
48 } port;
49
50 /*
51  *    void init_ports()
52  *        Modifies: all ports
53  *        Effects: Closes all existing ports.  Must be called before
54  *                 any other port call is made.
55  */
56
57 extern void init_ports(void);
58
59 /*
60  *    string read_from_port(string name)
61  *        Requires: init_ports has been called
62  *        Modifies: the port named name if any, $error
63  *        Effects: If a port by name name does not exist, sets $error to
64  *                 "No such port" & returns "".  Otherwise, attempts to
65  *                 read from that port.  If an error occurs, $error is
66  *                 set to the error message and "" returned.  Otherwise
67  *                 the read string is returned.  The returned string is
68  *                 on the heap & must be eventually freed.
69  */
70
71 extern string read_from_port(string);
72
73 /*
74  *    void write_on_port(string name, char *text, int length)
75  *        Requires: init_ports has been called, length>=0
76  *        Modifies: the port named name if any, $error
77  *        Effects: If a port by name name does not exist, sets $error to
78  *                 "No such port" & returns.  Otherwise, attempts to
79  *                 write text[0..length-1] on that port.  If an error
80  *                 occurs, $error is set to the error message.
81  */
82
83 extern void write_on_port(string, char *, int);
84
85 /*
86  *    void close_port_input(string name)
87  *        Requires: init_ports has been called
88  *        Modifies: the port named name if any, $error
89  *        Effects: If a port by name name does not exist, sets $error to
90  *                 "No such port" & returns.  Otherwise, closes the
91  *                 input part of the port by name name.  When both a
92  *                 port's input & output parts have been closed, the
93  *                 port is deleted to save space.  If an error
94  *                 occurs, $error is set to the error message.
95  */
96
97 extern void close_port_input(string);
98
99 /*
100  *    void close_port_output(string name)
101  *        Requires: init_ports has been called
102  *        Modifies: the port named name if any, $error
103  *        Effects: If a port by name name does not exist, sets $error to
104  *                 "No such port" & returns.  Otherwise, closes the
105  *                 output part of the port by name name.  When both a
106  *                 port's input & output parts have been closed, the
107  *                 port is deleted to save space.  If an error
108  *                 occurs, $error is set to the error message.
109  */
110
111 extern void close_port_output(string);
112
113
114 extern void create_subprocess_port(string, char **);
115 extern void create_file_append_port(string, string);
116 extern void create_file_input_port(string, string);
117 extern void create_file_output_port(string, string);
118 extern void create_port_from_filter(string, string (*)(string));
119 extern void create_port_from_output_proc(string, char *(*)(string));
120
121 extern void init_standard_ports(int *, char **);
122 extern void create_port_from_files(string, FILE *, FILE *);
123
124 #endif