Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef PORTSH | |
4 | #define PORTSH | |
5 | /* Copyright (C) 1995,1996 Free Software Foundation, Inc. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2, or (at your option) | |
10 | * any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this software; see the file COPYING. If not, write to | |
19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | * | |
21 | * As a special exception, the Free Software Foundation gives permission | |
22 | * for additional uses of the text contained in its release of GUILE. | |
23 | * | |
24 | * The exception is that, if you link the GUILE library with other files | |
25 | * to produce an executable, this does not by itself cause the | |
26 | * resulting executable to be covered by the GNU General Public License. | |
27 | * Your use of that executable is in no way restricted on account of | |
28 | * linking the GUILE library code into it. | |
29 | * | |
30 | * This exception does not however invalidate any other reasons why | |
31 | * the executable file might be covered by the GNU General Public License. | |
32 | * | |
33 | * This exception applies only to the code released by the | |
34 | * Free Software Foundation under the name GUILE. If you copy | |
35 | * code from other Free Software Foundation releases into a copy of | |
36 | * GUILE, as the General Public License permits, the exception does | |
37 | * not apply to the code that you add in this way. To avoid misleading | |
38 | * anyone as to the status of such modified files, you must delete | |
39 | * this exception notice from them. | |
40 | * | |
41 | * If you write modifications of your own for GUILE, it is your choice | |
42 | * whether to permit this exception to apply to your modifications. | |
43 | * If you do not wish that, delete this exception notice. | |
44 | */ | |
45 | \f | |
46 | ||
cd4f61de | 47 | #include <libguile/__scm.h> |
0f2d19dd JB |
48 | #include "smob.h" |
49 | ||
50 | \f | |
51 | ||
52 | enum scm_port_representation_type | |
53 | { | |
54 | scm_regular_port, | |
55 | scm_mb_port, | |
56 | scm_wchar_port | |
57 | }; | |
58 | ||
59 | enum scm_string_representation_type | |
60 | { | |
61 | scm_regular_string = scm_regular_port, | |
62 | scm_mb_string = scm_mb_port, | |
63 | scm_wchar_string = scm_wchar_port | |
64 | }; | |
65 | ||
66 | ||
67 | struct scm_port_table | |
68 | { | |
69 | SCM port; /* Open port. */ | |
70 | int revealed; /* 0 not revealed, > 1 revealed. | |
71 | * Revealed ports do not get GC'd. | |
72 | */ | |
73 | ||
74 | SCM stream; | |
75 | SCM file_name; | |
76 | int unchr; /* pushed back character, if any */ | |
77 | ||
78 | int line_number; | |
79 | int column_number; | |
80 | ||
81 | enum scm_port_representation_type representation; | |
82 | }; | |
83 | ||
84 | extern struct scm_port_table **scm_port_table; | |
85 | extern scm_port_table_size; /* Number of ports in scm_port_table. */ | |
86 | ||
87 | ||
88 | \f | |
89 | ||
90 | /* PORT FLAGS | |
91 | * A set of flags caracterizes a port. | |
92 | */ | |
93 | #define SCM_OPN (1L<<16) /* Is the port open? */ | |
94 | #define SCM_RDNG (2L<<16) /* Is it a readable port? */ | |
95 | #define SCM_WRTNG (4L<<16) /* Is it writable? */ | |
96 | #define SCM_BUF0 (8L<<16) | |
97 | #define SCM_CRDY (32L<<16) /* Should char-ready? return #t? */ | |
98 | ||
99 | /* A mask used to clear the char-ready port flag. */ | |
100 | #define SCM_CUC 0x001fffffL | |
101 | ||
102 | #define SCM_PORTP(x) (SCM_TYP7(x)==scm_tc7_port) | |
103 | #define SCM_OPPORTP(x) (((0x7f | SCM_OPN) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN)) | |
104 | #define SCM_OPINPORTP(x) (((0x7f | SCM_OPN | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_RDNG)) | |
105 | #define SCM_OPOUTPORTP(x) (((0x7f | SCM_OPN | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_WRTNG)) | |
106 | #define SCM_FPORTP(x) (SCM_TYP16S(x)==scm_tc7_port) | |
107 | #define SCM_OPFPORTP(x) (((0xfeff | SCM_OPN) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN)) | |
108 | #define SCM_OPINFPORTP(x) (((0xfeff | SCM_OPN | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_RDNG)) | |
109 | #define SCM_OPOUTFPORTP(x) (((0xfeff | SCM_OPN | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_WRTNG)) | |
110 | ||
111 | #define SCM_INPORTP(x) (((0x7f | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_RDNG)) | |
112 | #define SCM_OUTPORTP(x) (((0x7f | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_WRTNG)) | |
113 | #define SCM_OPENP(x) (SCM_OPN & SCM_CAR(x)) | |
114 | #define SCM_CLOSEDP(x) (!SCM_OPENP(x)) | |
115 | #define SCM_PTAB_ENTRY(x) ((struct scm_port_table *)SCM_CDR(x)) | |
116 | #define SCM_SETPTAB_ENTRY(x,ent) SCM_SETCDR ((x), (SCM)(ent)) | |
117 | #define SCM_STREAM(x) SCM_PTAB_ENTRY(x)->stream | |
118 | #define SCM_SETSTREAM(x,s) (SCM_PTAB_ENTRY(x)->stream = s) | |
119 | #define SCM_LINUM(x) SCM_PTAB_ENTRY(x)->line_number | |
120 | #define SCM_COL(x) SCM_PTAB_ENTRY(x)->column_number | |
121 | #define SCM_REVEALED(x) SCM_PTAB_ENTRY(x)->revealed | |
122 | #define SCM_SETREVEALED(x,s) (SCM_PTAB_ENTRY(x)->revealed = s) | |
123 | #define SCM_PORT_REPRESENTATION(x) SCM_PTAB_ENTRY(x)->representation | |
124 | #define SCM_SET_PORT_REPRESENTATION(x,s) (SCM_PTAB_ENTRY(x)->representation = s) | |
125 | #define SCM_CRDYP(port) (SCM_CAR(port) & SCM_CRDY) | |
126 | #define SCM_CLRDY(port) {SCM_CAR(port) &= SCM_CUC;} | |
127 | #define SCM_SETRDY(port) {SCM_CAR(port) |= SCM_CRDY;} | |
128 | #define SCM_CUNGET(c,port) {SCM_PTAB_ENTRY(port)->unchr = c; SCM_SETRDY(port);} | |
129 | #define SCM_CGETUN(port) (SCM_PTAB_ENTRY(port)->unchr) | |
130 | ||
131 | #define SCM_INCLINE(port) {SCM_LINUM (port) += 1; SCM_COL (port) = 0;} | |
132 | #define SCM_INCCOL(port) {SCM_COL (port) += 1;} | |
133 | #define SCM_TABCOL(port) {SCM_COL (port) += (SCM_COL (port) + 1) % 8;} | |
134 | ||
135 | ||
136 | ||
137 | \f | |
138 | ||
139 | extern scm_ptobfuns *scm_ptobs; | |
140 | extern scm_sizet scm_numptob; | |
141 | extern int scm_port_table_room; | |
142 | ||
143 | \f | |
144 | #ifdef __STDC__ | |
145 | extern SCM scm_markstream (SCM ptr); | |
146 | extern long scm_newptob (scm_ptobfuns *ptob); | |
147 | extern void scm_fflush (SCM port); | |
148 | extern SCM scm_char_ready_p (SCM port); | |
149 | extern SCM scm_ungetc_char_ready_p (SCM port); | |
150 | extern SCM scm_current_input_port (void); | |
151 | extern SCM scm_current_output_port (void); | |
152 | extern SCM scm_current_error_port (void); | |
153 | extern SCM scm_set_current_input_port (SCM port); | |
154 | extern SCM scm_set_current_output_port (SCM port); | |
155 | extern SCM scm_set_current_error_port (SCM port); | |
156 | extern struct scm_port_table * scm_add_to_port_table (SCM port); | |
157 | extern void scm_remove_from_port_table (SCM port); | |
158 | extern SCM scm_pt_size (void); | |
159 | extern SCM scm_pt_member (SCM member); | |
160 | extern int scm_revealed_count (SCM port); | |
161 | extern SCM scm_port_revealed (SCM port); | |
162 | extern SCM scm_set_port_revealed_x (SCM port, SCM rcount); | |
163 | extern SCM scm_close_port (SCM port); | |
164 | extern SCM scm_input_port_p (SCM x); | |
165 | extern SCM scm_output_port_p (SCM x); | |
166 | extern SCM scm_eof_object_p (SCM x); | |
167 | extern SCM scm_force_output (SCM port); | |
168 | extern SCM scm_read_char (SCM port); | |
169 | extern SCM scm_peek_char (SCM port); | |
170 | extern SCM scm_unread_char (SCM cobj, SCM port); | |
171 | extern SCM scm_line_number (SCM port); | |
172 | extern SCM scm_column_number (SCM port); | |
173 | extern SCM scm_port_file_name (SCM port); | |
174 | extern void scm_prinport (SCM exp, SCM port, char *type); | |
175 | extern void scm_ports_prehistory (void); | |
176 | extern SCM scm_void_port (char * mode_str); | |
177 | extern SCM scm_sys_make_void_port (SCM mode); | |
178 | extern void scm_init_ports (void); | |
179 | ||
180 | #else /* STDC */ | |
181 | extern SCM scm_markstream (); | |
182 | extern long scm_newptob (); | |
183 | extern void scm_fflush (); | |
184 | extern SCM scm_char_ready_p (); | |
185 | extern SCM scm_ungetc_char_ready_p (); | |
186 | extern SCM scm_current_input_port (); | |
187 | extern SCM scm_current_output_port (); | |
188 | extern SCM scm_current_error_port (); | |
189 | extern SCM scm_set_current_input_port (); | |
190 | extern SCM scm_set_current_output_port (); | |
191 | extern SCM scm_set_current_error_port (); | |
192 | extern struct scm_port_table * scm_add_to_port_table (); | |
193 | extern void scm_remove_from_port_table (); | |
194 | extern SCM scm_pt_size (); | |
195 | extern SCM scm_pt_member (); | |
196 | extern int scm_revealed_count (); | |
197 | extern SCM scm_port_revealed (); | |
198 | extern SCM scm_set_port_revealed_x (); | |
199 | extern SCM scm_close_port (); | |
200 | extern SCM scm_input_port_p (); | |
201 | extern SCM scm_output_port_p (); | |
202 | extern SCM scm_eof_object_p (); | |
203 | extern SCM scm_force_output (); | |
204 | extern SCM scm_read_char (); | |
205 | extern SCM scm_peek_char (); | |
206 | extern SCM scm_unread_char (); | |
207 | extern SCM scm_line_number (); | |
208 | extern SCM scm_column_number (); | |
209 | extern SCM scm_port_file_name (); | |
210 | extern void scm_prinport (); | |
211 | extern void scm_ports_prehistory (); | |
212 | extern SCM scm_void_port (); | |
213 | extern SCM scm_sys_make_void_port (); | |
214 | extern void scm_init_ports (); | |
215 | ||
216 | #endif /* STDC */ | |
217 | ||
218 | ||
219 | ||
220 | ||
221 | ||
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | #endif /* PORTSH */ |