本文整理汇总了C++中readch函数的典型用法代码示例。如果您正苦于以下问题:C++ readch函数的具体用法?C++ readch怎么用?C++ readch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:jerith,项目名称:monocle,代码行数:58,代码来源:json.c
示例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;
}
}
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:52,代码来源:bcode.c
示例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;
}
开发者ID:jerith,项目名称:monocle,代码行数:54,代码来源:json.c
示例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);
}
}
开发者ID:pjalbert,项目名称:check,代码行数:15,代码来源:ioloop.c
示例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: ;
}
}
开发者ID:mikekmv,项目名称:aeriebsd-src,代码行数:48,代码来源:misc.c
示例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';
}
开发者ID:pengyuwei,项目名称:hackathon2014,代码行数:29,代码来源:h.c
示例7: _getch
int _getch() {
init_keyboard();
kbhit();
char c = readch();
close_keyboard();
return c;
}
开发者ID:JakaCikac,项目名称:katana_300_ros,代码行数:7,代码来源:keyboard.cpp
示例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;
}
开发者ID:pengyuwei,项目名称:hackathon2014,代码行数:29,代码来源:g.c
示例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();
}
开发者ID:carriercomm,项目名称:BSDGames,代码行数:38,代码来源:endgame.c
示例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
}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:33,代码来源:bcode.c
示例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);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:27,代码来源:bcode.c
示例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;
}
开发者ID:shixv,项目名称:test,代码行数:59,代码来源:snake.c
示例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);
}
}
开发者ID:jyin0813,项目名称:OpenBSD-src,代码行数:63,代码来源:more.c
示例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);
}
}
开发者ID:jerith,项目名称:monocle,代码行数:12,代码来源:json.c
示例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;
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:21,代码来源:bcode.c
示例16: readreg
static int
readreg(void)
{
int ch1, ch2, idx;
idx = readch();
if (idx == 0xff && bmachine.extended_regs) {
ch1 = readch();
ch2 = readch();
if (ch1 == EOF || ch2 == EOF) {
warnx("unexpected eof");
idx = -1;
} else
idx = (ch1 << 8) + ch2 + UCHAR_MAX + 1;
}
if (idx < 0 || (unsigned)idx >= bmachine.reg_array_size) {
warnx("internal error: reg num = %d", idx);
idx = -1;
}
return (idx);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:21,代码来源:bcode.c
示例17: bitmap_play
int bitmap_play(char * filename)
{
char ch;
if (fb_init())
{
printf ("Unable to init framebuffer device\n");
return 2;
}
fb_pixel * bmp_buffer;
if ((bmp_buffer = bitmap_load(filename)) == NULL)
{
fb_uninit();
printf ("Error while reading bitmap\n");
return 1;
}
fb_clear_screen(screen);
bitmap_render(bmp_buffer);
init_keyboard();
ch=0;
while (1)
{
if (!kbhit())
{
ch = readch();
if (ch == KEY_ESC) break;
if (ch == KEY_UP && position_y >= JUMP_SIZE) position_y-=JUMP_SIZE;
if (ch == KEY_DOWN && fb_yres <= (bmp_info.bi_height-position_y-JUMP_SIZE)) position_y+=JUMP_SIZE;
if (ch == KEY_LEFT && position_x >= JUMP_SIZE) position_x-=JUMP_SIZE;
if (ch == KEY_RIGHT && fb_xres <= (bmp_info.bi_width-position_x-JUMP_SIZE)) position_x+=JUMP_SIZE;
ch = 0;
bitmap_render(bmp_buffer);
}
}
close_keyboard();
fflush(stdin);
fb_clear_screen(screen);
bitmap_free(bmp_buffer);
fb_uninit();
return 0;
}
开发者ID:dugoh,项目名称:tcb,代码行数:51,代码来源:bitmap.c
示例18: while
void *keyboard_thread(void *) {
while (1) {
key = readch();
if (key == 27) {
pt.running = 0;
}
if (key == 32) {
pt.PT_paused = !pt.PT_paused;
}
}
return NULL;
}
开发者ID:rlfbckr,项目名称:p5terminal,代码行数:14,代码来源:p5terminal.c
示例19: main
int main(int argc, char **argv)
{
struct sigaction handler;
char num[100];
int n = 0;
// Set Interrrupt Signal Handler
memset(&handler, 0, sizeof(struct sigaction));
handler.sa_handler = SignalCatcher;
sigfillset(&handler.sa_mask);
sigaction(SIGINT, &handler, 0);
sigaction(SIGTERM, &handler, 0);
tcgetattr(0, &oldtio);
init_keyboard();
for(;!m_bExitSignalPending;)
{
display_menu();
memset(num, 0, 100);
n = readch();
printf("\r\n");
switch(n) {
case '0' :
m_bExitSignalPending = 1;
break;
case '1' :
if(m_bFirmwareInstalled) break;
printf("\r\n");
system("/usr/bin/tftp -g -r factoryInstall 192.168.10.20");
system("chmod +x /tmp/factoryInstall");
system("/tmp/factoryInstall factory");
printf("\r\n");
break;
case '2' :
if(!m_bFirmwareInstalled) break;
system("/app/sw/hwtest");
break;
}
}
close_keyboard();
return 0;
}
开发者ID:bearxiong99,项目名称:new_swamm,代码行数:49,代码来源:install.cpp
示例20: compare
static void
compare(enum bcode_compare type)
{
int index, elseindex;
struct number *a, *b;
bool ok;
struct value *v;
elseindex = NO_ELSE;
index = readreg();
if (readch() == 'e')
elseindex = readreg();
else
unreadch();
a = pop_number();
if (a == NULL)
return;
b = pop_number();
if (b == NULL) {
push_number(a);
return;
}
ok = compare_numbers(type, a, b);
if (!ok && elseindex != NO_ELSE)
index = elseindex;
if (index >= 0 && (ok || (!ok && elseindex != NO_ELSE))) {
v = stack_tos(&bmachine.reg[index]);
if (v == NULL)
warnx("register '%c' (0%o) is empty", index, index);
else {
switch(v->type) {
case BCODE_NONE:
warnx("register '%c' (0%o) is empty",
index, index);
break;
case BCODE_NUMBER:
warn("eval called with non-string argument");
break;
case BCODE_STRING:
eval_string(bstrdup(v->u.string));
break;
}
}
}
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:49,代码来源:bcode.c
注:本文中的readch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论