summaryrefslogtreecommitdiffstats
path: root/main/glib/pollconsole.c
blob: 927999d8d632337d83044acda6b37cffdd682248 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
#include "config.h"
#include <ctype.h>
#include "ether.h"
#include "genlib.h"
#include "stddefs.h"
#include "timer.h"

/* pollConsole():
 * Common function used to query the console port with a message.
 * If after about a 2-second period (or the time specified by POLLTIMEOUT),
 * there is no response from the console, then return 0; else return
 * the character that was received.
 */
int
pollConsole(char *msg)
{
    char    *env;
    int     pollval, msec;
    struct elapsed_tmr tmr;

    env = getenv("POLLTIMEOUT");
    if(env) {
        msec = strtol(env,0,0);
    } else {
        msec = 2000;
    }

    pollval = 0;
    printf("%s",msg);
    startElapsedTimer(&tmr,msec);
    while(!msecElapsed(&tmr)) {
        if(gotachar()) {
            while(gotachar()) {
                pollval = getchar();
            }
            break;
        }
        pollethernet();
    }
    putstr("\r\n");

    if(ELAPSED_TIMEOUT(&tmr)) {
        return(0);
    }

    return(pollval);
}