Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef PORTSH | |
4 | #define PORTSH | |
89ea5b7c | 5 | /* Copyright (C) 1995,1996,1997 Free Software Foundation, Inc. |
0f2d19dd JB |
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 | |
82892bed JB |
19 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
20 | * Boston, MA 02111-1307 USA | |
0f2d19dd JB |
21 | * |
22 | * As a special exception, the Free Software Foundation gives permission | |
23 | * for additional uses of the text contained in its release of GUILE. | |
24 | * | |
25 | * The exception is that, if you link the GUILE library with other files | |
26 | * to produce an executable, this does not by itself cause the | |
27 | * resulting executable to be covered by the GNU General Public License. | |
28 | * Your use of that executable is in no way restricted on account of | |
29 | * linking the GUILE library code into it. | |
30 | * | |
31 | * This exception does not however invalidate any other reasons why | |
32 | * the executable file might be covered by the GNU General Public License. | |
33 | * | |
34 | * This exception applies only to the code released by the | |
35 | * Free Software Foundation under the name GUILE. If you copy | |
36 | * code from other Free Software Foundation releases into a copy of | |
37 | * GUILE, as the General Public License permits, the exception does | |
38 | * not apply to the code that you add in this way. To avoid misleading | |
39 | * anyone as to the status of such modified files, you must delete | |
40 | * this exception notice from them. | |
41 | * | |
42 | * If you write modifications of your own for GUILE, it is your choice | |
43 | * whether to permit this exception to apply to your modifications. | |
82892bed | 44 | * If you do not wish that, delete this exception notice. */ |
0f2d19dd JB |
45 | \f |
46 | ||
b4309c3c | 47 | #include "libguile/__scm.h" |
0f2d19dd | 48 | |
e0d86ad2 | 49 | #include "libguile/print.h" |
78446828 | 50 | #include "libguile/struct.h" |
e0d86ad2 | 51 | |
0f2d19dd JB |
52 | \f |
53 | ||
0f2d19dd JB |
54 | struct scm_port_table |
55 | { | |
56 | SCM port; /* Open port. */ | |
57 | int revealed; /* 0 not revealed, > 1 revealed. | |
58 | * Revealed ports do not get GC'd. | |
59 | */ | |
60 | ||
61 | SCM stream; | |
ebf7394e | 62 | SCM file_name; /* debugging support. */ |
0f2d19dd JB |
63 | int unchr; /* pushed back character, if any */ |
64 | ||
ebf7394e GH |
65 | int line_number; /* debugging support. */ |
66 | int column_number; /* debugging support. */ | |
0f2d19dd JB |
67 | }; |
68 | ||
69 | extern struct scm_port_table **scm_port_table; | |
0f82baf6 | 70 | extern int scm_port_table_size; /* Number of ports in scm_port_table. */ |
0f2d19dd JB |
71 | |
72 | ||
73 | \f | |
74 | ||
0c32d76c MD |
75 | #define SCM_EOF_OBJECT_P(x) ((x) == SCM_EOF_VAL) |
76 | ||
0f2d19dd | 77 | /* PORT FLAGS |
dbece3a2 | 78 | * A set of flags characterizes a port. |
0f2d19dd JB |
79 | */ |
80 | #define SCM_OPN (1L<<16) /* Is the port open? */ | |
81 | #define SCM_RDNG (2L<<16) /* Is it a readable port? */ | |
82 | #define SCM_WRTNG (4L<<16) /* Is it writable? */ | |
83 | #define SCM_BUF0 (8L<<16) | |
84 | #define SCM_CRDY (32L<<16) /* Should char-ready? return #t? */ | |
85 | ||
86 | /* A mask used to clear the char-ready port flag. */ | |
87 | #define SCM_CUC 0x001fffffL | |
88 | ||
89 | #define SCM_PORTP(x) (SCM_TYP7(x)==scm_tc7_port) | |
90 | #define SCM_OPPORTP(x) (((0x7f | SCM_OPN) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN)) | |
91 | #define SCM_OPINPORTP(x) (((0x7f | SCM_OPN | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_RDNG)) | |
92 | #define SCM_OPOUTPORTP(x) (((0x7f | SCM_OPN | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_WRTNG)) | |
93 | #define SCM_FPORTP(x) (SCM_TYP16S(x)==scm_tc7_port) | |
94 | #define SCM_OPFPORTP(x) (((0xfeff | SCM_OPN) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN)) | |
95 | #define SCM_OPINFPORTP(x) (((0xfeff | SCM_OPN | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_RDNG)) | |
96 | #define SCM_OPOUTFPORTP(x) (((0xfeff | SCM_OPN | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_WRTNG)) | |
97 | ||
98 | #define SCM_INPORTP(x) (((0x7f | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_RDNG)) | |
99 | #define SCM_OUTPORTP(x) (((0x7f | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_WRTNG)) | |
100 | #define SCM_OPENP(x) (SCM_OPN & SCM_CAR(x)) | |
101 | #define SCM_CLOSEDP(x) (!SCM_OPENP(x)) | |
102 | #define SCM_PTAB_ENTRY(x) ((struct scm_port_table *)SCM_CDR(x)) | |
103 | #define SCM_SETPTAB_ENTRY(x,ent) SCM_SETCDR ((x), (SCM)(ent)) | |
104 | #define SCM_STREAM(x) SCM_PTAB_ENTRY(x)->stream | |
105 | #define SCM_SETSTREAM(x,s) (SCM_PTAB_ENTRY(x)->stream = s) | |
d14af9f2 | 106 | #define SCM_FILENAME(x) SCM_PTAB_ENTRY(x)->file_name |
0f2d19dd JB |
107 | #define SCM_LINUM(x) SCM_PTAB_ENTRY(x)->line_number |
108 | #define SCM_COL(x) SCM_PTAB_ENTRY(x)->column_number | |
109 | #define SCM_REVEALED(x) SCM_PTAB_ENTRY(x)->revealed | |
110 | #define SCM_SETREVEALED(x,s) (SCM_PTAB_ENTRY(x)->revealed = s) | |
898a256f MD |
111 | #define SCM_CRDYP(port) (SCM_CAR (port) & SCM_CRDY) |
112 | #define SCM_CLRDY(port) {SCM_SETAND_CAR (port, SCM_CUC);} | |
113 | #define SCM_SETRDY(port) {SCM_SETOR_CAR (port, SCM_CRDY);} | |
0f2d19dd JB |
114 | #define SCM_CUNGET(c,port) {SCM_PTAB_ENTRY(port)->unchr = c; SCM_SETRDY(port);} |
115 | #define SCM_CGETUN(port) (SCM_PTAB_ENTRY(port)->unchr) | |
116 | ||
117 | #define SCM_INCLINE(port) {SCM_LINUM (port) += 1; SCM_COL (port) = 0;} | |
118 | #define SCM_INCCOL(port) {SCM_COL (port) += 1;} | |
d14af9f2 | 119 | #define SCM_TABCOL(port) {SCM_COL (port) += 8 - SCM_COL (port) % 8;} |
0f2d19dd JB |
120 | |
121 | ||
122 | ||
123 | \f | |
124 | ||
0f82baf6 JB |
125 | typedef struct scm_ptobfuns |
126 | { | |
1717856b JB |
127 | SCM (*mark) SCM_P ((SCM)); |
128 | int (*free) SCM_P ((SCM)); | |
129 | int (*print) SCM_P ((SCM exp, SCM port, scm_print_state *pstate)); | |
130 | SCM (*equalp) SCM_P ((SCM, SCM)); | |
131 | int (*fputc) SCM_P ((int, SCM stream)); | |
132 | int (*fputs) SCM_P ((char *, SCM stream)); | |
133 | scm_sizet (*fwrite) SCM_P ((char *ptr, scm_sizet size, scm_sizet nitems, SCM stream)); | |
134 | int (*fflush) SCM_P ((SCM stream)); | |
135 | int (*fgetc) SCM_P ((SCM stream)); | |
848f2a01 | 136 | char * (*fgets) SCM_P ((SCM stream, int *len)); |
1717856b | 137 | int (*fclose) SCM_P ((SCM stream)); |
0f82baf6 JB |
138 | } scm_ptobfuns; |
139 | ||
ce71f796 | 140 | #define SCM_PTOBNUM(x) (0x0ff & (SCM_CAR(x)>>8)) |
0f82baf6 JB |
141 | |
142 | \f | |
143 | ||
0f2d19dd | 144 | extern scm_ptobfuns *scm_ptobs; |
a1c95c45 | 145 | extern int scm_numptob; |
0f2d19dd JB |
146 | extern int scm_port_table_room; |
147 | ||
148 | \f | |
0f2d19dd | 149 | |
1717856b JB |
150 | extern SCM scm_markstream SCM_P ((SCM ptr)); |
151 | extern long scm_newptob SCM_P ((scm_ptobfuns *ptob)); | |
1717856b | 152 | extern SCM scm_char_ready_p SCM_P ((SCM port)); |
1717856b JB |
153 | extern SCM scm_current_input_port SCM_P ((void)); |
154 | extern SCM scm_current_output_port SCM_P ((void)); | |
155 | extern SCM scm_current_error_port SCM_P ((void)); | |
a1c95c45 | 156 | extern SCM scm_current_load_port SCM_P ((void)); |
1717856b JB |
157 | extern SCM scm_set_current_input_port SCM_P ((SCM port)); |
158 | extern SCM scm_set_current_output_port SCM_P ((SCM port)); | |
159 | extern SCM scm_set_current_error_port SCM_P ((SCM port)); | |
160 | extern struct scm_port_table * scm_add_to_port_table SCM_P ((SCM port)); | |
161 | extern void scm_remove_from_port_table SCM_P ((SCM port)); | |
162 | extern SCM scm_pt_size SCM_P ((void)); | |
163 | extern SCM scm_pt_member SCM_P ((SCM member)); | |
164 | extern int scm_revealed_count SCM_P ((SCM port)); | |
165 | extern SCM scm_port_revealed SCM_P ((SCM port)); | |
166 | extern SCM scm_set_port_revealed_x SCM_P ((SCM port, SCM rcount)); | |
eadd48de GH |
167 | extern long scm_mode_bits SCM_P ((char *modes)); |
168 | extern SCM scm_port_mode SCM_P ((SCM port)); | |
1717856b JB |
169 | extern SCM scm_close_port SCM_P ((SCM port)); |
170 | extern SCM scm_close_all_ports_except SCM_P ((SCM ports)); | |
171 | extern SCM scm_input_port_p SCM_P ((SCM x)); | |
172 | extern SCM scm_output_port_p SCM_P ((SCM x)); | |
173 | extern SCM scm_eof_object_p SCM_P ((SCM x)); | |
174 | extern SCM scm_force_output SCM_P ((SCM port)); | |
89ea5b7c | 175 | extern SCM scm_flush_all_ports SCM_P ((void)); |
1717856b JB |
176 | extern SCM scm_read_char SCM_P ((SCM port)); |
177 | extern SCM scm_peek_char SCM_P ((SCM port)); | |
178 | extern SCM scm_unread_char SCM_P ((SCM cobj, SCM port)); | |
848f2a01 | 179 | extern char *scm_generic_fgets SCM_P ((SCM port, int *len)); |
1717856b | 180 | extern SCM scm_port_line SCM_P ((SCM port)); |
a1c95c45 | 181 | extern SCM scm_set_port_line_x SCM_P ((SCM port, SCM line)); |
1717856b | 182 | extern SCM scm_port_column SCM_P ((SCM port)); |
a1c95c45 | 183 | extern SCM scm_set_port_column_x SCM_P ((SCM port, SCM line)); |
1717856b JB |
184 | extern SCM scm_port_filename SCM_P ((SCM port)); |
185 | extern SCM scm_set_port_filename_x SCM_P ((SCM port, SCM filename)); | |
186 | extern void scm_prinport SCM_P ((SCM exp, SCM port, char *type)); | |
187 | extern void scm_ports_prehistory SCM_P ((void)); | |
188 | extern SCM scm_void_port SCM_P ((char * mode_str)); | |
189 | extern SCM scm_sys_make_void_port SCM_P ((SCM mode)); | |
190 | extern void scm_init_ports SCM_P ((void)); | |
0f2d19dd JB |
191 | |
192 | #endif /* PORTSH */ |