예제 #1
0
파일: xbee.cpp 프로젝트: jwatte/xbee
void do_load() {
    FILE *f = openfile("rb", stdin);
    cmdmode();
    char line[1024];
    while (true) {
        line[0] = 0;
        fgets(line, 1024, f);
        if (line[0] == 0) {
            break;
        }
        if (line[0] != '#' && line[0] != '\n') {
            translate(line, '\n', '\r');
            pwrite(line);
            pread();
            if (strcmp(pline, "OK\r")) {
                fprintf(stderr, "Command failed: %s: %s\n", line, pline);
                exit(EXIT_FAILURE);
            }
        }
    }
    pwrite("ATWR\r");
    pread();
    exitcmd();
    if (strcmp(pline, "OK\r")) {
        fprintf(stderr, "Could not write changes: %s\n", pline);
        exit(EXIT_FAILURE);
    }
    if (f != stdin) {
        fclose(f);
    }
}
예제 #2
0
파일: xbee.cpp 프로젝트: jwatte/xbee
void do_dump() {
    FILE *f = openfile("wb", stdout);
    cmdmode();
    for (size_t i = 0; i != sizeof(cmds)/sizeof(cmds[0]); ++i) {
        pwrite(cmds[i]);
        pwrite("\r");
        pread();
        translate(pline, '\r', '\n');
        fprintf(f, "%s%s", cmds[i], pline);
    }
    exitcmd();
    fflush(f);
    if (f != stdout) {
        fclose(f);
    }
}
예제 #3
0
파일: ttydriv.c 프로젝트: OlliL/P8000
/* Process any keyboard input - removed from main() to make accessable
 * by other processes - K5JB
 */
void
check_kbd()
{
    char *ttybuf;
    int c;
    int16 cnt;
    int ttydriv(),cmdparse(),kbread();
#ifdef  FLOW
    extern int ttyflow;
#endif
    extern struct cmds cmds[];
    extern char prompt[];
#ifdef  SYS5
#ifdef USE_QUIT
    if(reportquit_flag)	/* set by quit signal and report is deferred */
        report_quit();		/* until now */
#endif
    /* note that if shellpid, kbread() always returns -1 */
    while((background == 0) && ((c = kbread()) != -1))
#else
    while((c = kbread()) != -1)
#endif
    {
#ifdef MSDOS
        /* c == -2 means the command escape key (F10) */
        Keyhit = c;	/* a global we use for haktc */
        if(c == -2) {
            if(mode != CMD_MODE) {
#ifdef CUTE_VIDEO
                putca('\n',saved_attrib); /* in case we were in session */
#else
                printf("\n");
#endif
                cmdmode();
            }
            continue;
        }
#endif
#if defined(UNIX) || defined(_OSK)
        if(c == escape && escape != 0) {
            if(mode != CMD_MODE) {
                printf("\n");
                cmdmode();
            }
            continue;
        }
#endif   /* UNIX or _OSK */

#ifndef FLOW
        if ((cnt = ttydriv(c, &ttybuf)) == 0)
            continue;
#else
        cnt = ttydriv(c, &ttybuf);
        if (ttyflow && (mode != CMD_MODE))
            go();           /* display pending chars */
        if (cnt == 0)
            continue;
#endif  /* FLOW */
        switch(mode) {
        case CMD_MODE:
            (void)cmdparse(cmds,ttybuf);
            fflush(stdout);
            break;
        case CONV_MODE:
            if(current->parse != NULLFP)
                (*current->parse)(ttybuf,cnt);
            break;
        }
#if defined(FORKSHELL) && defined(SYS5)
        if(mode == CMD_MODE && !shellpid)
#else
        if(mode == CMD_MODE)
#endif
        {
            if(noprompt)	/* k35 */
                noprompt = 0;
            else {
                printf(prompt);
                fflush(stdout);
            }
        }
    }  /* while */
}