本文整理汇总了C++中readch函数的典型用法代码示例。如果您正苦于以下问题:C++ readch函数的具体用法?C++ readch怎么用?C++ readch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: word
static MNCL_DATA *
word(MNCL_DATA_PARSE_CTX *ctx, int scan)
{
const char *s = ctx->s + ctx->i;
if (*s == 'n' && ctx->i + 4 <= ctx->size && !strncmp(s, "null", 4)) {
int i;
MNCL_DATA *result;
for (i = 0; i < 4; ++i) {
readch(ctx);
}
if (scan) {
return mncl_data_ok;
}
result = (MNCL_DATA *)malloc(sizeof(MNCL_DATA));
if (!result) {
snprintf(error_str, 512, "%d:%d: Out of memory", ctx->line, ctx->col);
return NULL;
}
result->tag = MNCL_DATA_NULL;
return result;
} else if (*s == 't' && ctx->i + 4 <= ctx->size && !strncmp(s, "true", 4)) {
int i;
MNCL_DATA *result;
for (i = 0; i < 4; ++i) {
readch(ctx);
}
if (scan) {
return mncl_data_ok;
}
result = (MNCL_DATA *)malloc(sizeof(MNCL_DATA));
if (!result) {
snprintf(error_str, 512, "%d:%d: Out of memory", ctx->line, ctx->col);
return NULL;
}
result->tag = MNCL_DATA_BOOLEAN;
result->value.boolean = 1;
return result;
} else if (*s == 'f' && ctx->i + 5 <= ctx->size && !strncmp(s, "false", 5)) {
int i;
MNCL_DATA *result;
for (i = 0; i < 5; ++i) {
readch(ctx);
}
if (scan) {
return mncl_data_ok;
}
result = (MNCL_DATA *)malloc(sizeof(MNCL_DATA));
if (!result) {
snprintf(error_str, 512, "%d:%d: Out of memory", ctx->line, ctx->col);
return NULL;
}
result->tag = MNCL_DATA_BOOLEAN;
result->value.boolean = 0;
return result;
}
snprintf(error_str, 512, "%d:%d: Expected value", ctx->line, ctx->col);
return NULL;
}
示例2: skip_until_mark
static void
skip_until_mark(void)
{
int ch;
for (;;) {
ch = readch();
switch (ch) {
case 'M':
return;
case EOF:
errx(1, "mark not found");
return;
case 'l':
case 'L':
case 's':
case 'S':
case ':':
case ';':
case '<':
case '>':
case '=':
(void)readreg();
if (readch() == 'e')
(void)readreg();
else
unreadch();
break;
case '[':
free(read_string(&bmachine.readstack[bmachine.readsp]));
break;
case '!':
switch (ch = readch()) {
case '<':
case '>':
case '=':
(void)readreg();
if (readch() == 'e')
(void)readreg();
else
unreadch();
break;
default:
free(readline());
break;
}
break;
default:
break;
}
}
}
示例3: mncl_data_strcpy
/* The buffer dst must have been pre-sized by a call to
* mncl_data_str_size. This function returns 0 on failure, >= 0 on
* success. */
static int
mncl_data_strcpy(char *dst, MNCL_DATA_PARSE_CTX *ctx) {
int c = readch(ctx); /* Skip the leading quote */
while(1) {
c = readch(ctx);
if (c == '\"') {
*dst++ = '\0';
return 1;
} else if (c == '\\') {
int ch;
c = readch(ctx);
switch(c) {
case 'u':
ch = hex_decode(ctx);
if (ch < 0) {
return 0;
} else if (ch < 0x80) {
*dst++ = ch;
} else if (ch < 0x800) {
*dst++ = (((ch >> 6) & 0xff) | 0xC0);
*dst++ = (ch & 0x3f) | 0x80;
} else {
*dst++ = (((ch >> 12) & 0xff) | 0xe0);
*dst++ = ((ch >> 6) & 0x3f) | 0x80;
*dst++ = (ch & 0x3f) | 0x80;
}
break;
case '\"':
case '\\':
case '/':
*dst++ = c;
break;
case 'b':
*dst++ = '\b';
break;
case 'f':
*dst++ = '\f';
break;
case 'n':
*dst++ = '\n';
break;
case 'r':
*dst++ = '\r';
break;
case 't':
*dst++ = '\t';
break;
default:
snprintf(error_str, 512, "%d:%d: Illegal string escape '%c'", ctx->line, ctx->col, c);
return 0;
}
示例4: main
int main()
{
char c,ext;
c=readch(); // <---- getch()
if(c!=27)
printf("Caracter: %c - ASCII: %d\n\n",c,c);
else {
ext=readch();
printf("Caracteres: %d - %d\n\n",c,ext);
ext=readch();
printf("Caracteres: %d - %d\n\n",c,ext);
}
}
示例5: getcard
CARD
getcard()
{
int c, c1;
for (;;) {
while ((c = readch()) == '\n' || c == '\r' || c == ' ')
continue;
if (islower(c))
c = toupper(c);
if (c == killchar() || c == erasechar())
return -1;
addstr(unctrl(c));
clrtoeol();
switch (c) {
case '1': case '2': case '3':
case '4': case '5': case '6':
c -= '0';
break;
case '0': case 'P': case 'p':
c = 0;
break;
default:
beep();
addch('\b');
if (!isprint(c))
addch('\b');
c = -1;
break;
}
refresh();
if (c >= 0) {
while ((c1 = readch()) != '\r' && c1 != '\n' && c1 != ' ')
if (c1 == killchar())
return -1;
else if (c1 == erasechar()) {
addch('\b');
clrtoeol();
refresh();
goto cont;
}
else
beep();
return c;
}
cont: ;
}
}
示例6: on_keypress
// return value: 0:running; not 0:quit;
static int on_keypress()
{
int ch = 0;
static char keybuf[32] = {0};
static int cursor = 0;
Win *win = get_win("RCMD");
if (NULL == win) {
return 0;
}
ch = readch();
keybuf[cursor++] = ch;
if (ch == '\n' || cursor >= (int)sizeof(keybuf) - 1) {
cursor = 0;
process_command(keybuf);
memset(keybuf, 0, sizeof(keybuf));
werase(win->win);
wclear(win->win);
mvwaddch(win->win, 1, 1, '>');
wrefresh(win->win);
} else {
waddch(win->win, ch);
wrefresh(win->win);
}
return ch != 'q';
}
示例7: _getch
int _getch() {
init_keyboard();
kbhit();
char c = readch();
close_keyboard();
return c;
}
示例8: wait_user_cmd
// return value: 0:running; not 0:quit;
static int wait_user_cmd(char *keybuf, size_t buflen)
{
int ch = 0;
int cursor = 0;
while(1) {
ch = readch();
keybuf[cursor++] = ch;
if (ch == '\n' || cursor >= buflen - 1) {
wclear(win_input->win);
wrefresh(win_input->win);
return cursor;
} else if (ch == KEY_BACKSPACE || ch == 127) {
keybuf[cursor] = '\0';
cursor--;
if (cursor < 0) {
cursor = 0;
}
}
if (NULL != win_input) {
wclear(win_input->win);
mvwaddstr(win_input->win, 1, 1, keybuf);
wrefresh(win_input->win);
}
};
return cursor;
}
示例9: endgame
/*
* endgame:
* Do what's necessary at the end of the game
*/
void
endgame()
{
char ch;
prman();
if (Errors >= MAXERRS)
Errors = MAXERRS + 2;
prword();
prdata();
move(MESGY, MESGX);
if (Errors > MAXERRS)
printw("Sorry, the word was \"%s\"\n", Word);
else
printw("You got it!\n");
for (;;) {
mvaddstr(MESGY + 1, MESGX, "Another word? ");
leaveok(stdscr, FALSE);
refresh();
if ((ch = readch()) == 'n')
die(0);
else
if (ch == 'y')
break;
mvaddstr(MESGY + 2, MESGX, "Please type 'y' or 'n'");
}
leaveok(stdscr, TRUE);
move(MESGY, MESGX);
deleteln();
deleteln();
deleteln();
}
示例10: eval
void
eval(void)
{
int ch;
for (;;) {
ch = readch();
if (ch == EOF) {
if (bmachine.readsp == 0)
return;
src_free();
bmachine.readsp--;
continue;
}
#ifdef DEBUGGING
fprintf(stderr, "# %c\n", ch);
stack_print(stderr, &bmachine.stack, "* ",
bmachine.obase);
fprintf(stderr, "%zd =>\n", bmachine.readsp);
#endif
if (0 <= ch && ch < (signed)UCHAR_MAX)
(*jump_table[ch])();
else
warnx("internal error: opcode %d", ch);
#ifdef DEBUGGING
stack_print(stderr, &bmachine.stack, "* ",
bmachine.obase);
fprintf(stderr, "%zd ==\n", bmachine.readsp);
#endif
}
}
示例11: eval_string
static void
eval_string(char *p)
{
int ch;
if (bmachine.readsp > 0) {
/* Check for tail call. Do not recurse in that case. */
ch = readch();
if (ch == EOF) {
src_free();
src_setstring(&bmachine.readstack[bmachine.readsp], p);
return;
} else
unreadch();
}
if (bmachine.readsp == bmachine.readstack_sz - 1) {
size_t newsz = bmachine.readstack_sz * 2;
struct source *stack;
stack = reallocarray(bmachine.readstack, newsz,
sizeof(struct source));
if (stack == NULL)
err(1, "recursion too deep");
bmachine.readstack_sz = newsz;
bmachine.readstack = stack;
}
src_setstring(&bmachine.readstack[++bmachine.readsp], p);
}
示例12: main
int main(void)
{
int XMax,YMax;
Getborder(&XMax,&YMax);
srand((unsigned int)time(0));
RP r={0,0};
RP *rp=&r;
SNode *sp=NULL;
Initheadtail(&sp);
Randpoint(rp,sp,XMax,YMax);
initscr();
initkeyboard();
//----------------------
int ch=0;
while(ch!='q')
{
ch=0;
if(kbhit())
ch=readch();
// printf("%c\n",ch);
// read(0,&ch,1);
switch(ch){
case 'w':
sp->direction=N;
break;
case 's':
sp->direction=S;
break;
case 'a':
sp->direction=W;
break;
case 'd':
sp->direction=E;
break;
}
// printw("%d\n",sp->direction);
switch(Checkhead(sp,rp)){
case -1:
goto END;
case 0:
break;
case 1:
Eatpoint(&sp,rp,XMax,YMax);
break;
}
Freshsanke(&sp);
Convertborder(sp,XMax,YMax);
Printscr(sp);
Printpoint(r);
refresh();
clear();
usleep(100000);
}
//----------------------
END:closekeyboard();
endwin();
Freenode(sp);
return 0;
}
示例13: colon
/*
* Execute a colon-prefixed command.
* Returns <0 if not a command that should cause
* more of the file to be printed.
*/
int
colon(char *filename, int cmd, int nlines)
{
int ch;
if (cmd == 0)
ch = readch();
else
ch = cmd;
lastcolon = ch;
switch (ch) {
case 'f':
kill_line();
if (!no_intty)
promptlen =
printf("\"%s\" line %lld", fnames[fnum],
(long long)Currline);
else
promptlen = printf("[Not a file] line %lld",
(long long)Currline);
fflush(stdout);
return (-1);
case 'n':
if (nlines == 0) {
if (fnum >= nfiles - 1)
end_it();
nlines++;
}
putchar('\r');
erasep(0);
skipf(nlines);
return (0);
case 'p':
if (no_intty) {
write(STDERR_FILENO, &bell, 1);
return (-1);
}
putchar('\r');
erasep(0);
if (nlines == 0)
nlines++;
skipf (-nlines);
return (0);
case '!':
if (do_shell(filename) < 0) {
kill_line();
prompt(filename);
}
return (-1);
case 'q':
case 'Q':
end_it();
/*FALLTHROUGH*/
default:
write(STDERR_FILENO, &bell, 1);
return (-1);
}
}
示例14: space
/* Skip whitespace */
static void
space (MNCL_DATA_PARSE_CTX *ctx)
{
while (1) {
int c = peekch(ctx);
if (!c || !isspace(c)) {
break;
}
readch(ctx);
}
}
示例15: readreg
static int
readreg(void)
{
int index, ch1, ch2;
index = readch();
if (index == 0xff && bmachine.extended_regs) {
ch1 = readch();
ch2 = readch();
if (ch1 == EOF || ch2 == EOF) {
warnx("unexpected eof");
index = -1;
} else
index = (ch1 << 8) + ch2 + UCHAR_MAX + 1;
}
if (index < 0 || index >= bmachine.reg_array_size) {
warnx("internal error: reg num = %d", index);
index = -1;
}
return index;
}