Changeset 1ebc1a62 in mainline for uspace/app/sbi/src/input.c
- Timestamp:
- 2010-03-29T20:30:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a95310e
- Parents:
- 5da468e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/input.c
r5da468e r1ebc1a62 29 29 /** @file Input module 30 30 * 31 * Reads source code from a file. 31 * Reads source code. Currently input can be read from a file (standard 32 * case), from a string literal (when parsing builtin code) or interactively 33 * from the user. 32 34 */ 33 35 … … 35 37 #include <stdlib.h> 36 38 #include "mytypes.h" 39 #include "os/os.h" 37 40 #include "strtab.h" 38 41 39 42 #include "input.h" 40 43 44 /** Size of input buffer. XXX This limits the maximum line length. */ 41 45 #define INPUT_BUFFER_SIZE 256 42 46 … … 45 49 static void input_init_string(input_t *input, const char *str); 46 50 47 /** Create new input object for reading from file. */ 51 /** Create new input object for reading from file. 52 * 53 * @param input Place to store pointer to new input object. 54 * @param fname Name of file to read from. 55 * 56 * @return EOK on success, ENOMEM when allocation fails, 57 * ENOENT when opening file fails. 58 */ 48 59 int input_new_file(input_t **input, char *fname) 49 60 { … … 55 66 } 56 67 57 /** Create new input object for reading from interactive input. */ 68 /** Create new input object for reading from interactive input. 69 * 70 * @param input Place to store pointer to new input object. 71 * @return EOK on success, ENOMEM when allocation fails. 72 */ 58 73 int input_new_interactive(input_t **input) 59 74 { … … 66 81 } 67 82 68 /** Create new input object for reading from string. */ 83 /** Create new input object for reading from string. 84 * 85 * @param input Place to store pointer to new input object. 86 * @param str String literal from which to read input. 87 * @return EOK on success, ENOMEM when allocation fails. 88 */ 69 89 int input_new_string(input_t **input, const char *str) 70 90 { … … 77 97 } 78 98 79 /** Initialize input object for reading from file. */ 99 /** Initialize input object for reading from file. 100 * 101 * @param input Input object. 102 * @param fname Name of file to read from. 103 * 104 * @return EOK on success, ENOENT when opening file fails. 105 */ 80 106 static int input_init_file(input_t *input, char *fname) 81 107 { … … 92 118 } 93 119 120 input->str = NULL; 94 121 input->line_no = 0; 95 122 input->fin = f; … … 97 124 } 98 125 99 /** Initialize input object for reading from interactive input. */ 126 /** Initialize input object for reading from interactive input. 127 * 128 * @param input Input object. 129 */ 100 130 static void input_init_interactive(input_t *input) 101 131 { … … 106 136 } 107 137 138 input->str = NULL; 108 139 input->line_no = 0; 109 140 input->fin = NULL; 110 141 } 111 142 112 /** Initialize input object for reading from string. */ 143 /** Initialize input object for reading from string. 144 * 145 * @param input Input object. 146 * @param str String literal from which to read input. 147 */ 113 148 static void input_init_string(input_t *input, const char *str) 114 149 { … … 124 159 } 125 160 126 /** Get next line of input. */ 161 /** Get next line of input. 162 * 163 * The pointer stored in @a line is owned by @a input and is valid until the 164 * next call to input_get_line(). The caller is not to free it. The returned 165 * line is terminated with '\n' if another line is coming (potentially empty). 166 * An empty line ("") signals end of input. 167 * 168 * @param input Input object. 169 * @param line Place to store pointer to next line. 170 * 171 * @return EOK on success, EIO on failure. 172 */ 127 173 int input_get_line(input_t *input, char **line) 128 174 { 129 175 const char *sp; 130 176 char *dp; 177 char *line_p; 131 178 size_t cnt; 132 179 … … 166 213 printf("... "); 167 214 168 if (fgets(input->buffer, INPUT_BUFFER_SIZE, stdin) == NULL) 169 input->buffer[0] = '\0'; 170 171 if (ferror(stdin)) 215 fflush(stdout); 216 if (os_input_line(&line_p) != EOK) 172 217 return EIO; 173 218 174 *line = input->buffer;219 *line = line_p; 175 220 } 176 221 … … 179 224 } 180 225 181 /** Get number of the last provided line of input. */ 226 /** Get number of the last provided line of input. 227 * 228 * @param input Input module. 229 * @return Line number of the last provided input line (counting 230 * from 1 up). 231 */ 182 232 int input_get_line_no(input_t *input) 183 233 {
Note:
See TracChangeset
for help on using the changeset viewer.