1 /******************************** -*- C -*- **************************** 2 * 3 * External definitions for the input module. 4 * 5 * 6 ***********************************************************************/ 7 8 /*********************************************************************** 9 * 10 * Copyright 2001, 2002, 2003, 2006, 2008 Free Software Foundation, Inc. 11 * Written by Paolo Bonzini. 12 * 13 * This file is part of GNU Smalltalk. 14 * 15 * GNU Smalltalk is free software; you can redistribute it and/or modify it 16 * under the terms of the GNU General Public License as published by the Free 17 * Software Foundation; either version 2, or (at your option) any later 18 * version. 19 * 20 * Linking GNU Smalltalk statically or dynamically with other modules is 21 * making a combined work based on GNU Smalltalk. Thus, the terms and 22 * conditions of the GNU General Public License cover the whole 23 * combination. 24 * 25 * In addition, as a special exception, the Free Software Foundation 26 * give you permission to combine GNU Smalltalk with free software 27 * programs or libraries that are released under the GNU LGPL and with 28 * independent programs running under the GNU Smalltalk virtual machine. 29 * 30 * You may copy and distribute such a system following the terms of the 31 * GNU GPL for GNU Smalltalk and the licenses of the other code 32 * concerned, provided that you include the source code of that other 33 * code when and as the GNU GPL requires distribution of source code. 34 * 35 * Note that people who make modified versions of GNU Smalltalk are not 36 * obligated to grant this special exception for their modified 37 * versions; it is their choice whether to do so. The GNU General 38 * Public License gives permission to release a modified version without 39 * this exception; this exception also makes it possible to release a 40 * modified version which carries forward this exception. 41 * 42 * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT 43 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 45 * more details. 46 * 47 * You should have received a copy of the GNU General Public License along with 48 * GNU Smalltalk; see the file COPYING. If not, write to the Free Software 49 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 50 * 51 ***********************************************************************/ 52 53 54 #ifndef GST_INPUT_H 55 #define GST_INPUT_H 56 57 typedef enum 58 { 59 STREAM_UNKNOWN, 60 STREAM_FILE, 61 STREAM_STRING, 62 STREAM_OOP 63 #ifdef HAVE_READLINE 64 , STREAM_READLINE 65 #endif /* HAVE_READLINE */ 66 } 67 stream_type; 68 69 /* If true, readline is suppressed. */ 70 extern mst_Boolean _gst_no_tty 71 ATTRIBUTE_HIDDEN; 72 73 /* Pass file descriptor FD, printed as file name FILENAME, to the 74 parser. */ 75 extern void _gst_push_unix_file (int fd, 76 const char *fileName) 77 ATTRIBUTE_HIDDEN; 78 79 /* Return the current line and column into Y and X, respectively. 80 Also sets the method_start_pos pointer. */ 81 extern YYLTYPE _gst_get_location (void) 82 ATTRIBUTE_HIDDEN; 83 84 /* Pass the OOP to the parser; it must respond to #nextHunk. */ 85 extern void _gst_push_stream_oop (OOP oop) 86 ATTRIBUTE_HIDDEN; 87 88 /* Pass the contents of the Smalltalk String STRINGOOP to the parser. 89 While the String is being parsed, it can change because it is 90 saved. The String should not contain nulls. */ 91 extern void _gst_push_smalltalk_string (OOP stringOOP) 92 ATTRIBUTE_HIDDEN; 93 94 /* Pass the contents of the null-terminated String STRING to the 95 parser. While the String is being parsed, it can change because it 96 is saved. */ 97 extern void _gst_push_cstring (const char *string) 98 ATTRIBUTE_HIDDEN; 99 100 /* Pass the contents of stdin (either through the readline interface 101 or as a vanilla file descriptor) to the parser. The readline 102 interface is used if the Emacs interface is not active and stdin is 103 a tty. */ 104 extern void _gst_push_stdin_string (void) 105 ATTRIBUTE_HIDDEN; 106 107 /* Restores the previous stream on the stack, optionally closing the 108 topmost one if CLOSEIT is true. */ 109 extern void _gst_pop_stream (mst_Boolean closeIt) 110 ATTRIBUTE_HIDDEN; 111 112 /* This function resets the file type information for the current 113 stream. It is typically used by fileIn type methods when filing in 114 a subsection of a real file via a temporary file what the real 115 source of the text is. */ 116 extern void _gst_set_stream_info (int line, 117 OOP fileOOP, 118 OOP fileNameOOP, 119 int fileOffset) 120 ATTRIBUTE_HIDDEN; 121 122 /* Emits a warning, with the current file and line in front of it, on 123 the standard error descriptor. */ 124 extern void _gst_warningf (const char *str, 125 ...) 126 ATTRIBUTE_PRINTF_1 127 ATTRIBUTE_HIDDEN; 128 129 /* Emits a warning, with the current file and the given LINE in front 130 of it, on the standard error descriptor. */ 131 extern void _gst_warningf_at (int line, 132 const char *str, 133 ...) 134 ATTRIBUTE_PRINTF_2 135 ATTRIBUTE_HIDDEN; 136 137 /* Emits an error, with the current file and line in front of it, on 138 the standard error descriptor. */ 139 extern void _gst_errorf (const char *str, 140 ...) 141 ATTRIBUTE_PRINTF_1 142 ATTRIBUTE_HIDDEN; 143 144 /* Emits an error, with the current file and the given LINE in front 145 of it, on the standard error descriptor. */ 146 extern void _gst_errorf_at (int line, 147 const char *str, 148 ...) 149 ATTRIBUTE_PRINTF_2 150 ATTRIBUTE_HIDDEN; 151 152 /* Interface to the Bison-generated parser. */ 153 extern void _gst_yyerror (const char *s) 154 ATTRIBUTE_HIDDEN; 155 156 /* Push character 'ic' back into the input queue. Allows for two 157 character pushback currently. This solves the problem of lexing 158 3. and then finding out that what we should have lexed was 3 159 followed by . as a statement terminator. */ 160 extern void _gst_unread_char (int ic) 161 ATTRIBUTE_HIDDEN; 162 163 /* Return the next character from the topmost stream in the stack. */ 164 extern int _gst_next_char (void) 165 ATTRIBUTE_HIDDEN; 166 167 /* Return whether the topmost stream is an interactive one. */ 168 extern mst_Boolean _gst_get_cur_stream_prompt (void) 169 ATTRIBUTE_PURE 170 ATTRIBUTE_HIDDEN; 171 172 /* Return the type of the topmost stream in the stack. */ 173 extern stream_type _gst_get_cur_stream_type (void) 174 ATTRIBUTE_PURE 175 ATTRIBUTE_HIDDEN; 176 177 /* Returns an OOP containing the string of the topmost stream if it is 178 a STREAM_STRING, STREAM_OOP or STREAM_READLINE, or if it has a filename; 179 nil otherwise. */ 180 extern OOP _gst_get_source_string (off_t startPos, off_t endPos) 181 ATTRIBUTE_HIDDEN; 182 183 #ifdef HAVE_READLINE 184 /* Initialize the completion interface for Readline. */ 185 extern void _gst_initialize_readline (void) 186 ATTRIBUTE_HIDDEN; 187 188 /* Look at the first LEN bytes starting at STR, and add the 189 colon-separated keywords, or the whole string if it starts with an 190 uppercase character AND it contains no colons. */ 191 extern void _gst_add_symbol_completion (const char *str, 192 int len) 193 ATTRIBUTE_HIDDEN; 194 195 /* Add 1 to the completion-enabling flag. The flag starts at 1 196 (completions are active) and completions are enabled until the flag 197 falls below this value. */ 198 extern void _gst_enable_completion (void) 199 ATTRIBUTE_HIDDEN; 200 201 /* Subtract 1 from the completion-enabling flag. The flag starts at 1 202 (completions are active) and if completions are disabled, they are 203 not enabled while the flag is below this value. */ 204 extern void _gst_disable_completion (void) 205 ATTRIBUTE_HIDDEN; 206 207 #endif /* HAVE_READLINE */ 208 209 210 /* Parse the Smalltalk source code read from stdin, showing the 211 PROMPT that is passed. */ 212 extern void _gst_process_stdin (const char *prompt) 213 ATTRIBUTE_HIDDEN; 214 215 /* Parse the Smalltalk source code read from file FILE found within 216 the search path DIR. */ 217 extern mst_Boolean _gst_process_file (const char *fileName, 218 enum gst_file_dir dir) 219 ATTRIBUTE_HIDDEN; 220 221 222 #endif 223