⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chario.c

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 C
字号:
/* chario.c: *  This code supports some basic character io functionality. * *  General notice: *  This code is part of a boot-monitor package developed as a generic base *  platform for embedded system designs.  As such, it is likely to be *  distributed to various projects beyond the control of the original *  author.  Please notify the author of any enhancements made or bugs found *  so that all may benefit from the changes.  In addition, notification back *  to the author will allow the new user to pick up changes that may have *  been made by other users after this version of the code was distributed. * *  Note1: the majority of this code was edited with 4-space tabs. *  Note2: as more and more contributions are accepted, the term "author" *         is becoming a mis-representation of credit. * *  Original author:    Ed Sutter *  Email:              esutter@lucent.com *  Phone:              908-582-2351 */#include "config.h"#include "cpuio.h"#include "genlib.h"#include "stddefs.h"#define CTLC    0x03    /* control-c */int (*remoterawon)();int (*remoterawoff)();int (*remoteputchar)();int (*remotegetchar)();int (*remotegotachar)();/* putchar(): *  Output a character to the stdout RS232 port.  If char is '\n' *  then precede it with '\r'; */intputchar(uchar c){    RedirectCharacter(c);    if (c == '\n')        rputchar('\r');    rputchar(c);    return((int)c);}/* puts(): *  Use putchar() to output an "assumed-to-be" null-terminated string.*/voidputs(char *string){    while(*string) {        putchar(*string);        string++;    }}/* _getline(): * Basic line retrieval; but with a few options... * This function is accessed through the getline_xx functions * below. * Args... *  buf:     pointer to buffer to be used to place the incoming characters. *  max:     size of the buffer. *  ledit:   if set, then allow the line-editor to be used if ESC is input. *  timeout: if set, then after 'timeout' number of seconds waiting, giveup. *  prefill: if set, prefill the buffer with that string and show the user. */static int_getline(char *buf,int max,int ledit, int timeout,char *prefill){    static  unsigned char  crlf;    int     tmt, tot, idx;    char    *base;    tot = idx = 0;    base = buf;    max -= 1;       /* Make sure there is space for the null terminator. */    if (prefill) {        strcpy(base,prefill);        tot = strlen(prefill);        puts(prefill);        buf += tot;        idx = tot;    }    for(;idx<max;idx++) {        if (timeout > 0) {            for(tmt=timeout;tmt>0;tmt--) {                if (gotachar())                    break;            }            if (tmt == 0) {                *buf = 0;                return(0);            }        }        *buf = (char)getchar();        if (!*buf) {            idx--;            continue;        }#if INCLUDE_LINEEDIT        if ((*buf == 0x1b) && (ledit)) {            (void)line_edit(base);            break;        }        else#endif        {            if ((*buf == '\r') || (*buf == '\n')) {                if ((crlf) && (*buf != crlf)) {                    crlf = 0;                    continue;                }                puts("\r\n");                crlf = *buf;                *buf = 0;                break;            }            if (*buf == '\b') {                if (tot) {                    idx -= 2;                    buf--;                     tot--;                    puts("\b \b");                }            }            else if (*buf == CTLC) {                puts("^C\n");                *base = 0;                return(0);            }            else {                putchar(*buf);                tot++;                 buf++;            }            crlf = 0;        }    }    if (idx == max) {        printf("\007\nInput too long (exceeds %d bytes).\n",max+1);        *buf = 0;        return(0);    }    return(strlen(base));}intgetline(char *buf, int max, int ledit){    return(_getline(buf,max,ledit,0,0));}intgetline_t(char *buf, int max, int timeout){    return(_getline(buf,max,0,timeout,0));}intgetline_p(char *buf, int max, int ledit, char *prefill){    return(_getline(buf,max,ledit,0,prefill));}/* getpass(): */char *getpass(prompt,buf,max)int     max;char    *prompt, *buf;{    int     i;    char    *bp;    bp = buf;    puts(prompt);    for (i=0;i<max;i++) {        *bp = (char)getchar();        if ((*bp == '\r') || (*bp == '\n')) {            puts("\r\n");            break;        }        bp++;    }    *bp = 0;    return(buf);}/* getbytes(): *  Similar to gets() except that the caller specifies the number *  of characters and whether or not to block. */intgetbytes(char *buf,int cnt,int block){    int i;    for(i=0;i<cnt;i++) {        if (block)            while(!gotachar());        else if (!gotachar())            break;        buf[i] = (char)getchar();    }    return(i);}intputbytes(char *buf, int cnt){    char *end;    end = buf + cnt;    while(buf < end) {        putchar(*buf++);    }    return(cnt);}intaskuser(msg)char    *msg;{    int yes, len;    puts(msg);    len = strlen(msg);    switch((char)getchar()) {    case ' ':    case 'y':    case '\r':    case '\n':        yes = 1;        break;    default:        yes = 0;        break;    }    while(len) {        puts("\b \b");        len--;    }    return(yes);}intMore(){    return(askuser("more?"));}inthitakey(){    return(askuser("hit any key to continue..."));}/* RemoteIO functions: * The idea of "remote io" is to allow the monitor commands to still * run when the application has taken over the system.  The monitor's * connection to the serial port is a simple polled interface.  When  * the application comes up, it is very likely that it will overlay a * new driver onto the serial port.  If this happens, and the user at * the console interface of the application wants to execute a monitor * command, then the monitor's putchar/getchar/gotachar functions must * use functions that are part of the application.  These remote io * function pointers, if set, will point to those functions. */voidInitRemoteIO(void){    /* Null out the remote put/getchar functions. */    remoterawon = 0;    remoterawoff = 0;    remoteputchar = 0;    remotegetchar = 0;    remotegotachar = 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -