本文整理汇总了C++中readchar函数的典型用法代码示例。如果您正苦于以下问题:C++ readchar函数的具体用法?C++ readchar怎么用?C++ readchar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readchar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_line
/*
* get_line:
* Reads the next line up to '\n' or EOF. Multiple spaces are
* compressed to one space; a space is inserted before a ','
*/
char *
get_line(void)
{
size_t pos;
int c, oy, ox;
WINDOW *oscr;
oscr = stdscr;
stdscr = Msgwin;
getyx(stdscr, oy, ox);
refresh();
/* loop reading in the string, and put it in a temporary buffer */
for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
if (c == erasechar()) { /* process erase character */
if (pos > 0) {
int i;
pos--;
for (i = strlen(unctrl(linebuf[pos])); i; i--)
addch('\b');
}
continue;
} else
if (c == killchar()) { /* process kill
* character */
pos = 0;
move(oy, ox);
continue;
} else
if (pos == 0 && c == ' ')
continue;
if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' '))
putchar(CTRL('G'));
else {
if (islower(c))
c = toupper(c);
linebuf[pos++] = c;
addstr(unctrl(c));
Mpos++;
}
}
linebuf[pos] = '\0';
stdscr = oscr;
return (linebuf);
}
示例2: xwaitforspace
/* s: chars allowed besides space or return */
void
xwaitforspace(char *s)
{
int c;
morc = 0;
while((c = readchar()) != '\n') {
if(flags.cbreak) {
if(c == ' ') break;
if(s && strchr(s,c)) {
morc = c;
break;
}
hackbell();
}
}
}
示例3: regname
char *
regname(int regnam)
{
static char buf[64];
char *p;
int c;
p = buf;
*p++ = regnam;
while (isalnum(c = readchar())) {
if (p >= buf+sizeof(buf)-1)
error("register name too long");
*p++ = c;
}
*p = 0;
reread();
return (buf);
}
示例4: findNonWs
static int findNonWs(FILETYPE f)
{
int c, cont = 1;
while (cont) {
switch ((c = readchar(f))) {
case 0:
c = RETURN_CODE_EOF;
break;
case -1:
c = RETURN_CODE_ERROR;
break;
default: ;
}
if (!isspace(c))
break;
}
return c;
}
示例5: newton_init
static int newton_init(int fd, unsigned long *id, unsigned long *extra)
{
int i;
unsigned char c;
unsigned char response[35] = {
0x16, 0x10, 0x02, 0x64, 0x5f, 0x69, 0x64, 0x00,
0x00, 0x00, 0x0c, 0x6b, 0x79, 0x62, 0x64, 0x61,
0x70, 0x70, 0x6c, 0x00, 0x00, 0x00, 0x01, 0x6e,
0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10,
0x03, 0xdd, 0xe7
};
for (i = 0; i < sizeof(response); i++)
if (readchar(fd, &c, 400) || c != response[i])
return -1;
return 0;
}
示例6: get_bool
/*
* get_bool:
* Allow changing a boolean option and print it out
*/
int
get_bool(void *vp, WINDOW *win)
{
bool *bp = (bool *) vp;
int oy, ox;
bool op_bad;
op_bad = TRUE;
getyx(win, oy, ox);
waddstr(win, *bp ? "True" : "False");
while (op_bad)
{
wmove(win, oy, ox);
wrefresh(win);
switch (readchar())
{
case 't':
case 'T':
*bp = TRUE;
op_bad = FALSE;
break;
case 'f':
case 'F':
*bp = FALSE;
op_bad = FALSE;
break;
case '\n':
case '\r':
op_bad = FALSE;
break;
case ESCAPE:
return QUIT;
case '-':
return MINUS;
default:
wmove(win, oy, ox + 10);
waddstr(win, "(T or F)");
}
}
wmove(win, oy, ox);
waddstr(win, *bp ? "True" : "False");
waddch(win, '\n');
return NORM;
}
示例7: get_bool
int
get_bool(void *vp, WINDOW *win)
{
int *bp = (int *) vp;
int oy, ox;
int op_bad;
op_bad = TRUE;
getyx(win, oy, ox);
waddstr(win, *bp ? "True" : "False");
while(op_bad)
{
wmove(win, oy, ox);
draw(win);
switch (readchar(win))
{
case 't':
case 'T':
*bp = TRUE;
op_bad = FALSE;
break;
case 'f':
case 'F':
*bp = FALSE;
op_bad = FALSE;
break;
case '\n':
case '\r':
op_bad = FALSE;
break;
case '\033':
case '\007':
return QUIT;
case '-':
return MINUS;
default:
mvwaddstr(win, oy, ox + 10, "(T or F)");
}
}
wmove(win, oy, ox);
waddstr(win, *bp ? "True" : "False");
waddch(win, '\n');
return NORM;
}
示例8: getchar
int
getchar(void)
{
char ch;
int len;
ch = readchar(); // read(STDIN_FILENO, &ch, 1);
// if (len<=0) {
// /* end of file or error */
// return EOF;
// }
/*
* Cast through unsigned char, to prevent sign extension. This
* sends back values on the range 0-255, rather than -128 to 127,
* so EOF can be distinguished from legal input.
*/
return (int)(unsigned char)ch;
}
示例9: sal_readchar
int sal_readchar(const char *prompt)
{
#ifdef INCLUDE_EDITLINE
extern int readchar(const char *prompt);
#else
char buf[64];
#endif
#ifdef INCLUDE_EDITLINE
return(readchar(prompt));
#else
printk("%s", prompt);
if (NULL == (sal_console_gets(buf, sizeof(buf)))) {
return(EOF);
} else {
return(buf[0]);
}
#endif
}
示例10: block_continueread
int block_continueread(FILETYPE f, int brace_count, char *data, int size,
char spacer)
{
char c;
int i;
if (!data || !size)
return RETURN_CODE_ERROR;
data[0] = 0;
if (brace_count == 0)
return 0;
/* scan block data until brace_count = 0 or space eaten up */
i = 0;
while (i < size - 1) {
if ((c = readchar(f)) <= 0) {
data[i] = 0;
return RETURN_CODE_ERROR;
}
if (c == '{') brace_count++;
if (c == '}') {
if (--brace_count == 0) {
/* read complete block, strip trailing whitespaces */
while (i > 1 && isspace(data[i - 1]))
i--;
data[i] = 0;
return 0;
}
}
if (c == spacer && brace_count == 1) {
data[i] = 0;
return brace_count;
}
data[i++] = c;
}
data[i] = 0;
return brace_count;
}
示例11: generic_led
static int generic_led(unsigned int l)
{
char c;
CSR_GPIO_OUT = l;
printf("Is the LED on? (y/n/s)\n");
while(1) {
c = readchar();
switch(c) {
case 'y':
CSR_GPIO_OUT = 0;
return TEST_STATUS_PASSED;
case 'n':
CSR_GPIO_OUT = 0;
return TEST_STATUS_FAILED;
case 's':
CSR_GPIO_OUT = 0;
return TEST_STATUS_NOT_DONE;
}
}
}
示例12: dump_init
int dump_init(int fd, long *id, long *extra)
{
unsigned char c, o = 0;
c = 0x80;
if (write(fd, &c, 1) != 1) /* Enable command */
return -1;
while (1)
if (!readchar(fd, &c, 1)) {
printf("%02x (%c) ", c, ((c > 32) && (c < 127)) ? c : 'x');
o = 1;
} else {
if (o) {
printf("\n");
o = 0;
}
}
}
示例13: inventory
void
inventory(struct linked_list *container, int type)
{
int cnt;
if (type == 0)
{
msg("What kind of item <%s> to inventory (* for all)?", type_list);
type = readchar();
if (type == ESCAPE)
{
after = FALSE;
msg("");
return;
}
}
/*
* Get a list of items to print out. If the user selects '*', list
* them all.
*/
if (type == '*')
type = 0; /* no type passed ->use them all */
mpos = 0;
if ((cnt = count_bag(container, type, NULL)) == 0)
msg("You don't have any %s.", name_type(type));
else
{
apply_to_bag(container, type, NULL, baf_print_item, &type);
end_line();
msg("");
}
return;
}
示例14: main
int
main(void)
{
int c;
bool leading = true;
while ((c = readchar()) != EOF) {
if (isspace(c))
/* Save whitespace. */
savewhite(c, leading);
else {
/* Reprint whitespace and print regular character. */
printwhite();
writechar(c);
leading = false;
}
}
/* Terminate non-empty files with a newline. */
if (!leading)
writechar('\n');
return (0);
}
示例15: test_user_abort
static int test_user_abort()
{
char c;
puts("I: Press Q or ESC to abort boot");
CSR_TIMER0_COUNTER = 0;
CSR_TIMER0_COMPARE = 2*brd_desc->clk_frequency;
CSR_TIMER0_CONTROL = TIMER_ENABLE;
while(CSR_TIMER0_CONTROL & TIMER_ENABLE) {
if(readchar_nonblock()) {
c = readchar();
if((c == 'Q')||(c == '\e')) {
puts("I: Aborted boot on user request");
vga_set_console(1);
return 0;
}
if(c == 0x07) {
vga_set_console(1);
netboot();
return 0;
}
}
}