Subversion Repositories HelenOS

Rev

Rev 3275 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3275 Rev 3304
Line 30... Line 30...
30
 */
30
 */
31
 
31
 
32
#include <stdio.h>
32
#include <stdio.h>
33
#include <stdlib.h>
33
#include <stdlib.h>
34
#include <string.h>
34
#include <string.h>
35
 
-
 
36
#ifdef HELENOS
-
 
37
#include <io/stream.h>
35
#include <io/stream.h>
38
#endif
-
 
39
 
36
 
40
#include "config.h"
37
#include "config.h"
41
#include "util.h"
38
#include "util.h"
42
#include "scli.h"
39
#include "scli.h"
43
#include "input.h"
40
#include "input.h"
Line 119... Line 116...
119
        free(tmp);
116
        free(tmp);
120
 
117
 
121
    return rc;
118
    return rc;
122
}
119
}
123
 
120
 
124
#ifdef HELENOS
-
 
125
/* Borrowed from Jiri Svoboda's 'cli' uspace app */
121
/* Borrowed from Jiri Svoboda's 'cli' uspace app */
126
void read_line(char *buffer, int n)
122
void read_line(char *buffer, int n)
127
{
123
{
128
    char c;
124
    char c;
129
    int chars;
125
    int chars;
Line 146... Line 142...
146
        buffer[chars++] = c;
142
        buffer[chars++] = c;
147
    }
143
    }
148
    putchar('\n');
144
    putchar('\n');
149
    buffer[chars] = '\0';
145
    buffer[chars] = '\0';
150
}
146
}
151
#endif
-
 
152
 
147
 
153
/* This is soupy, fix me */
-
 
154
void get_input(cliuser_t *usr)
148
void get_input(cliuser_t *usr)
155
{
149
{
156
    char line[INPUT_MAX];
150
    char line[INPUT_MAX];
157
    size_t len = 0;
151
    size_t len = 0;
158
 
152
 
159
    printf("%s", usr->prompt);
153
    printf("%s", usr->prompt);
160
#ifdef HELENOS
-
 
161
    read_line(line, INPUT_MAX);
154
    read_line(line, INPUT_MAX);
162
#else
-
 
163
    fgets(line, INPUT_MAX, stdin);
-
 
164
#endif
-
 
165
    len = strlen(line);
155
    len = strlen(line);
166
    /* Make sure we don't have rubbish or a C/R happy user */
156
    /* Make sure we don't have rubbish or a C/R happy user */
167
    if (len == 0 || line[0] == '\n')
157
    if (len == 0 || line[0] == '\n')
168
        return;
158
        return;
169
    if (len == 1 && line[len-1] == '\n')
159
    if (len == 1 && line[len-1] == '\n')
170
        return;
160
        return;
171
#ifndef HELENOS
-
 
172
    /* Null terminate line */
-
 
173
    if (len > 0 && line[len-1] == '\n')
-
 
174
        line[len-1] = '\0';
-
 
175
#endif
-
 
176
    usr->line = cli_strdup(line);
161
    usr->line = cli_strdup(line);
-
 
162
 
177
    return;
163
    return;
178
}
164
}
179
 
165