Changeset 1ebc1a62 in mainline for uspace/app/sbi/src/input.c


Ignore:
Timestamp:
2010-03-29T20:30:29Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a95310e
Parents:
5da468e
Message:

Update SBI to rev. 157.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/input.c

    r5da468e r1ebc1a62  
    2929/** @file Input module
    3030 *
    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.
    3234 */
    3335
     
    3537#include <stdlib.h>
    3638#include "mytypes.h"
     39#include "os/os.h"
    3740#include "strtab.h"
    3841
    3942#include "input.h"
    4043
     44/** Size of input buffer. XXX This limits the maximum line length. */
    4145#define INPUT_BUFFER_SIZE 256
    4246
     
    4549static void input_init_string(input_t *input, const char *str);
    4650
    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 */
    4859int input_new_file(input_t **input, char *fname)
    4960{
     
    5566}
    5667
    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 */
    5873int input_new_interactive(input_t **input)
    5974{
     
    6681}
    6782
    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 */
    6989int input_new_string(input_t **input, const char *str)
    7090{
     
    7797}
    7898
    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*/
    80106static int input_init_file(input_t *input, char *fname)
    81107{
     
    92118        }
    93119
     120        input->str = NULL;
    94121        input->line_no = 0;
    95122        input->fin = f;
     
    97124}
    98125
    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 */
    100130static void input_init_interactive(input_t *input)
    101131{
     
    106136        }
    107137
     138        input->str = NULL;
    108139        input->line_no = 0;
    109140        input->fin = NULL;
    110141}
    111142
    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 */
    113148static void input_init_string(input_t *input, const char *str)
    114149{
     
    124159}
    125160
    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 */
    127173int input_get_line(input_t *input, char **line)
    128174{
    129175        const char *sp;
    130176        char *dp;
     177        char *line_p;
    131178        size_t cnt;
    132179
     
    166213                        printf("...  ");
    167214
    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)
    172217                        return EIO;
    173218
    174                 *line = input->buffer;
     219                *line = line_p;
    175220        }
    176221
     
    179224}
    180225
    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 */
    182232int input_get_line_no(input_t *input)
    183233{
Note: See TracChangeset for help on using the changeset viewer.