|
|
00001 #ifndef port_TYPE 00002 #define port_TYPE 00003 00004 /* 00005 * Copyright (c) 1989 by the Massachusetts Institute of Technology. 00006 * For copying and distribution information, see the file 00007 * "mit-copyright.h". 00008 * 00009 * Modified for jwgc by Daniel Henninger. 00010 */ 00011 00012 #include "mit-copyright.h" 00013 00014 #include <stdio.h> 00015 #include "new_string.h" 00016 #include "string_stack.h" 00017 00018 union port__data { 00019 struct { 00020 FILE *input_connector; 00021 FILE *output_connector; 00022 } file; 00023 struct { 00024 string_stack waiting_packets; 00025 string (*filter)(); 00026 } filter; 00027 struct { 00028 char *(*output)(); 00029 } output; 00030 }; 00031 00032 typedef struct { /* PRIVATE */ 00033 char *(*get)(); 00034 char *(*put)(); 00035 char *(*close_input)(); 00036 char *(*close_output)(); 00037 #define INPUT_CLOSED 0x1 00038 #define OUTPUT_CLOSED 0x2 00039 #define PORT_CLOSED 0x3 00040 int status; 00041 union port__data data; 00042 } port; 00043 00044 /* 00045 * void init_ports() 00046 * Modifies: all ports 00047 * Effects: Closes all existing ports. Must be called before 00048 * any other port call is made. 00049 */ 00050 00051 extern void init_ports(); 00052 00053 /* 00054 * string read_from_port(string name) 00055 * Requires: init_ports has been called 00056 * Modifies: the port named name if any, $error 00057 * Effects: If a port by name name does not exist, sets $error to 00058 * "No such port" & returns "". Otherwise, attempts to 00059 * read from that port. If an error occurs, $error is 00060 * set to the error message and "" returned. Otherwise 00061 * the read string is returned. The returned string is 00062 * on the heap & must be eventually freed. 00063 */ 00064 00065 extern string read_from_port(); 00066 00067 /* 00068 * void write_on_port(string name, char *text, int length) 00069 * Requires: init_ports has been called, length>=0 00070 * Modifies: the port named name if any, $error 00071 * Effects: If a port by name name does not exist, sets $error to 00072 * "No such port" & returns. Otherwise, attempts to 00073 * write text[0..length-1] on that port. If an error 00074 * occurs, $error is set to the error message. 00075 */ 00076 00077 extern void write_on_port(); 00078 00079 /* 00080 * void close_port_input(string name) 00081 * Requires: init_ports has been called 00082 * Modifies: the port named name if any, $error 00083 * Effects: If a port by name name does not exist, sets $error to 00084 * "No such port" & returns. Otherwise, closes the 00085 * input part of the port by name name. When both a 00086 * port's input & output parts have been closed, the 00087 * port is deleted to save space. If an error 00088 * occurs, $error is set to the error message. 00089 */ 00090 00091 extern void close_port_input(); 00092 00093 /* 00094 * void close_port_output(string name) 00095 * Requires: init_ports has been called 00096 * Modifies: the port named name if any, $error 00097 * Effects: If a port by name name does not exist, sets $error to 00098 * "No such port" & returns. Otherwise, closes the 00099 * output part of the port by name name. When both a 00100 * port's input & output parts have been closed, the 00101 * port is deleted to save space. If an error 00102 * occurs, $error is set to the error message. 00103 */ 00104 00105 extern void close_port_output(); 00106 00107 00108 extern void create_subprocess_port(); 00109 extern void create_file_append_port(); 00110 extern void create_file_input_port(); 00111 extern void create_file_output_port(); 00112 extern void create_port_from_filter(); 00113 extern void create_port_from_output_proc(); 00114 00115 extern void init_standard_ports(); 00116 extern void create_port_from_files(); 00117 00118 #endif
Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |