char * io_get_token(){ int e; if(pos == -1){ do { bufr = io_get_line(); if(bufr == NULL) return NULL; // remove trailing spaces e = strlen(bufr) - 1; while(e >= 0 && isspace(bufr[e])) e--; } while(e == -1); bufr[e+1] = '\0'; pos = 0; } while(isspace(bufr[pos])) pos++; int i = 0; while(bufr[pos] > 32){ if(i >= MAX_TOKEN_SIZE - 1){ printf("\r\nMaximum token size exceeded"); bye(); } token[i++] = bufr[pos++]; } token[i] = '\0'; if(bufr[pos] == '\0') pos = -1; return token; }
static int io_load_file(struct io *io, const char *separators, size_t *lineno, io_read_fn read_property, void *data) { struct buffer buf; int state = OK; while (state == OK && io_get_line(io, &buf, '\n', lineno, TRUE)) { char *name; char *value; size_t namelen; size_t valuelen; name = chomp_string(buf.data); namelen = strcspn(name, separators); if (name[namelen]) { name[namelen] = 0; value = chomp_string(name + namelen + 1); valuelen = strlen(value); } else { value = ""; valuelen = 0; } state = read_property(name, namelen, value, valuelen, data); } if (state != ERR && io_error(io)) state = ERR; io_done(io); return state; }
static void xboard_get(xboard_t * xboard, char string[], int size) { ASSERT(xboard!=NULL); ASSERT(string!=NULL); ASSERT(size>=256); if (!io_get_line(xboard->io,string,size)) { // EOF my_log("POLYGLOT *** EOF from XBoard ***\n"); quit(); } }
void engine_get(engine_t * engine, char string[], int size) { ASSERT(engine_is_ok(engine)); ASSERT(string!=NULL); ASSERT(size>=256); while (!io_line_ready(engine->io)) { io_get_update(engine->io); } if (!io_get_line(engine->io,string,size)) { // EOF exit(EXIT_SUCCESS); } }
bool pipex_readln(pipex_t *pipex, char *string){ while (!io_line_ready(pipex->io)) { io_get_update(pipex->io); } if (!io_get_line(pipex->io,string,StringSize)) { // EOF string[0]='\0'; pipex->state|=PIPEX_EOF; return FALSE; } if(strncmp(PIPEX_MAGIC,string,strlen(PIPEX_MAGIC))==0){ my_fatal("%s\n",string+strlen(PIPEX_MAGIC)+1); } return TRUE; }
bool io_get(struct io *io, struct buffer *buf, int c, bool can_read) { return io_get_line(io, buf, c, NULL, can_read); }