summaryrefslogtreecommitdiff
path: root/board/MAI/bios_emulator/scitech/src/v86bios/command.c
blob: e2bce6df1ba247fb318b21ff85e15549f10db60e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <malloc.h>

#define PROMPT ">"


void
getline(char *buf,int *num,int max_num)
{
    static int line_len = 0;
    static char *line = NULL;
    static char *line_pointer = NULL;
    static int len = 0;
    int tmp_len;
    char *buff;

    if (len <= 0) {
    buff = readline(PROMPT);
    add_history(buff);

    if ((tmp_len = strlen(buff)) > line_len) {
	free(line);
	line = malloc(tmp_len);
	line_len = tmp_len;
    }
    sprintf(line,"%s\n",buff);
    free(buff);
    line_pointer = line;
    len = strlen(line);
    }

    *num = max_num > len? len : max_num;
    strncpy(buf,line_pointer,*num);
    line_pointer = line_pointer + *num;
    len = len - *num;
}