void lex_quote (void) { current_agent(lexeme).type = QUOTED_STRING_LEXEME; get_next_char(); do { if ((current_agent(current_char)==EOF_AS_CHAR)||(current_agent(lexeme).length==MAX_LEXEME_LENGTH)) { print ("Error: opening '\"' without closing '\"'\n"); print_location_of_most_recent_lexeme(); /* BUGBUG if reading from top level, don't want to signal EOF */ current_agent(lexeme).type = EOF_LEXEME; current_agent(lexeme).string[0]=EOF_AS_CHAR; current_agent(lexeme).string[1]=0; current_agent(lexeme).length = 1; return; } if (current_agent(current_char)=='\\') { get_next_char(); current_agent(lexeme).string[current_agent(lexeme).length++] = (char)current_agent(current_char); get_next_char(); } else if (current_agent(current_char)=='"') { get_next_char(); break; } else { current_agent(lexeme).string[current_agent(lexeme).length++] = (char)current_agent(current_char); get_next_char(); } } while(TRUE); current_agent(lexeme).string[current_agent(lexeme).length]=0; }
static int get_extended_base_var(char *name, int baselen, int c) { do { if (c == '\n') return -1; c = get_next_char(); } while (isspace(c)); /* We require the format to be '[base "extension"]' */ if (c != '"') return -1; name[baselen++] = '.'; for (;;) { int ch = get_next_char(); if (ch == '\n') return -1; if (ch == '"') break; if (ch == '\\') { ch = get_next_char(); if (ch == '\n') return -1; } name[baselen++] = ch; if (baselen > MAXNAME / 2) return -1; } /* Final ']' */ if (get_next_char() != ']') return -1; return baselen; }
void lex_quote (agent* thisAgent) { thisAgent->lexeme.type = QUOTED_STRING_LEXEME; get_next_char(thisAgent); do { if ((thisAgent->current_char==EOF)||(thisAgent->lexeme.length==MAX_LEXEME_LENGTH)) { print (thisAgent, "Error: opening '\"' without closing '\"'\n"); print_location_of_most_recent_lexeme(thisAgent); /* BUGBUG if reading from top level, don't want to signal EOF */ thisAgent->lexeme.type = EOF_LEXEME; thisAgent->lexeme.string[0]=0; thisAgent->lexeme.length = 1; return; } if (thisAgent->current_char=='\\') { get_next_char(thisAgent); thisAgent->lexeme.string[thisAgent->lexeme.length++] = char(thisAgent->current_char); get_next_char(thisAgent); } else if (thisAgent->current_char=='"') { get_next_char(thisAgent); break; } else { thisAgent->lexeme.string[thisAgent->lexeme.length++] = char(thisAgent->current_char); get_next_char(thisAgent); } } while(TRUE); thisAgent->lexeme.string[thisAgent->lexeme.length]=0; }
static int get_value(config_fn_t fn, void *data, char *name, unsigned int len) { int c; char *value; /* Get the full name */ for (;;) { c = get_next_char(); if (config_file_eof) break; if (!iskeychar(c)) break; name[len++] = c; if (len >= MAXNAME) return -1; } name[len] = 0; while (c == ' ' || c == '\t') c = get_next_char(); value = NULL; if (c != '\n') { if (c != '=') return -1; value = parse_value(); if (!value) return -1; } return fn(name, value, data); }
static int get_next_char() { int c, nxt; c = fileGetc(); if (c == EOF) return c; nxt = fileGetc(); if (nxt == EOF) return c; fileUngetc(nxt); if (c == '-' && nxt == '-') { skip_rest_of_line(); return get_next_char(); } if (c == '{' && nxt == '-') { int last = '\0'; do { last = c; c = get_next_char(); } while (! (c == EOF || (last == '-' && c == '}'))); return get_next_char(); } return c; }
static char *parse_value(void) { static struct strbuf value = STRBUF_INIT; int quote = 0, comment = 0, space = 0; strbuf_reset(&value); for (;;) { int c = get_next_char(); if (c == '\n') { if (quote) return NULL; return value.buf; } if (comment) continue; if (isspace(c) && !quote) { if (value.len) space++; continue; } if (!quote) { if (c == ';' || c == '#') { comment = 1; continue; } } for (; space; space--) strbuf_addch(&value, ' '); if (c == '\\') { c = get_next_char(); switch (c) { case '\n': continue; case 't': c = '\t'; break; case 'b': c = '\b'; break; case 'n': c = '\n'; break; /* Some characters escape as themselves */ case '\\': case '"': break; /* Reject unknown escape sequences */ default: return NULL; } strbuf_addch(&value, c); continue; } if (c == '"') { quote = 1-quote; continue; } strbuf_addch(&value, c); } }
static int build_token_list_f( FILE *fp ) { int curr_char; int ident_pos; int current_line; if( !fp ) { return -1; } curr_char = get_next_char(fp); current_line = 1; while( curr_char != EOF ) { /* Ident builder */ if( isalpha(curr_char) ) { ident_pos = 0; do { ident_buf[ident_pos] = curr_char; ident_pos++; curr_char = get_next_char(fp); } while( curr_char != EOF && isalphanum(curr_char) && ident_pos < IDENTBUF_SIZE ); build_token_ident(ident_pos, current_line); continue; } /* Number builder */ else if( isnum(curr_char) || curr_char == '-' ) { ident_pos = 0; do { ident_buf[ident_pos] = curr_char; ident_pos++; curr_char = get_next_char(fp); } while( curr_char != EOF && isnum(curr_char) && ident_pos < IDENTBUF_SIZE ); build_token_num(ident_pos, current_line); continue; } /* Grab commas */ else if( curr_char == ',' ) { build_token_comma(current_line); } /* Grab semicolons */ else if( curr_char == ':' ) { build_token_colon(current_line); } /* Handle comments */ else if( curr_char == '#' ) { /* Eat everything until EOL */ do { curr_char = get_next_char(fp); } while( curr_char != EOF && curr_char != '\n' && curr_char != '\r' ); } if( curr_char == '\n' ) { current_line++; } curr_char = get_next_char(fp); } return 0; }
int XML::get_lexem() throw (TRequestExc) { char a; tag.clear(); text.clear(); a = get_ahead_char(); if( a == 0 ) { return 0; } else if( a == '<' ) { // Встречен тег bool basic_tag = true; // мы считываем основную часть тега a = get_next_char(); while( 1 ) { a = get_next_char(); if( a == '>' ) return 1; else if( a == '<' ) { sprintf( msg, "XML::get_lexem Символ '<' в имени тега. Файл %s. Строка %d.", file_name, line ); throw TRequestExc( 1, msg ); } else if( a == 0 ) { sprintf( msg, "XML::get_lexem Не закрыт тег. Файл %s. Строка %d.", file_name, line ); throw TRequestExc( 2, msg ); } else { text += a; if( basic_tag ) { if( a == ' ' ) basic_tag = false; else tag += a; } if( a == 10 ) line++; } } } else { /* Встречен текст */ while( 1 ) { if( a == '>' ) { sprintf( msg, "XML::get_lexem Символ '>' в тексте файла. Файл %s. Строка %d.", file_name, line ); throw TRequestExc( 3, msg ); } else if( a == '<' ) { return 2; } else if( a == 0 ) { return 2; } else { text += (a = get_next_char()); if( a == 10 ) line++; } a = get_ahead_char(); } } }
void lex_dollar (void) { current_agent(lexeme).type = DOLLAR_STRING_LEXEME; current_agent(lexeme).string[0] = '$'; current_agent(lexeme).length = 1; get_next_char(); /* consume the '$' */ while ((current_agent(current_char)!='\n') && (current_agent(current_char)!=EOF_AS_CHAR) && (current_agent(lexeme).length < MAX_LEXEME_LENGTH-1)) { current_agent(lexeme).string[current_agent(lexeme).length++] = current_agent(current_char); get_next_char(); } current_agent(lexeme).string[current_agent(lexeme).length] = '\0'; }
void lex_dollar (agent* thisAgent) { thisAgent->lexeme.type = DOLLAR_STRING_LEXEME; thisAgent->lexeme.string[0] = '$'; thisAgent->lexeme.length = 1; get_next_char(thisAgent); /* consume the '$' */ while ((thisAgent->current_char!='\n') && (thisAgent->current_char!=EOF) && (thisAgent->lexeme.length < MAX_LEXEME_LENGTH-1)) { thisAgent->lexeme.string[thisAgent->lexeme.length++] = char(thisAgent->current_char); get_next_char(thisAgent); } thisAgent->lexeme.string[thisAgent->lexeme.length] = '\0'; }
static char *read_string(port *in) { int ch, i = 0; char str[MAX_STR_LEN], *dst; if ((ch = get_next_char(in)) != '"') do { str[i++] = ch; } while ((ch = get_next_char(in)) != '"' && str[i - 1] != '\\'); str[i] = '\0'; memcpy((dst = alloc_strseg(i + 1)), str, i + 1); return dst; }
void insert_utf8(t_nboon *l, char *data, int size) { t_uint i; t_utf8 c; t_uint width; t_uint pos; i = 0; c = 1; while (c != 0) { c = get_next_char(data, &i); width = get_display_width(c); l->b_curor += width; l->b_curor_end += width; } i = 0; pos = l->b_len - l->b_pos; if (l->b_len != l->b_pos) nb_memmove(&l->buf[l->b_pos + size], &l->buf[l->b_pos], pos); while (data[i] != '\0') { l->buf[l->b_pos++] = data[i++]; l->b_len++; } l->buf[l->b_len] = '\0'; g_refresh_fn(l); }
// handle ESC], Operating System Command static void osc(void) { Rune ch, buf[BUFS+1]; int fd, osc, got, i; osc = number(&ch, &got); if(got) { switch(osc) { case 0: case 1: case 2: // set title i = 0; while((ch = get_next_char()) != '\a') { if(i < nelem(buf) - 1) { buf[i++] = ch; } } buf[i] = 0; if((fd = open("/dev/label", OWRITE)) >= 0) { fprint(fd, "%S", buf); close(fd); } break; default: fprint(2, "unknown osc escape %d\n", osc); break; } } }
static void skip_white_spc(port *in) { int ch; while ((ch = get_next_char(in)) != EOF && is_white_space(ch)) ; if (ch != EOF) push_back_char(in, ch); }
int detect_type_by_space_counting() { int nspace=0; char ch=getchar(); while (ch==' ') ch=getchar(); if (ch!=EOF) ungetc(ch, stdin); get_next_char(&nspace); return nspace; }
/* {{{ php_next_utf8_char * Public interface for get_next_char used with UTF-8 */ PHPAPI unsigned int php_next_utf8_char( const unsigned char *str, size_t str_len, size_t *cursor, int *status) { return get_next_char(cs_utf_8, str, str_len, cursor, status); }
void *console_thread(void *arg) #endif { int sockfd = *(int *)arg; char buffer[LINE_LENGTH + 1]; do { int i = 0; int c = 0; printf("%s", g_prompt); for (i = 0; (i < LINE_LENGTH) && ((c = getchar()) != EOF) && (c != '\n'); i++) buffer[i] = tolower(c); buffer[i] = '\0'; if (buffer[0] == 'q') { print_and_exit("Done\n"); } else if (buffer[0] == 'e') { tester_command_t cmd = AVB_TESTER_EXPECT_NORMAL; if (get_next_char(&buffer[1]) == 'o') cmd = AVB_TESTER_EXPECT_OVERSUBSCRIBED; xscope_ep_request_upload(sockfd, 4, (unsigned char *)&cmd); } else if (buffer[0] == 'x') { tester_command_t cmd = AVB_TESTER_XSCOPE_PACKETS_DISABLE; if (get_next_char(&buffer[1]) == 'e') cmd = AVB_TESTER_XSCOPE_PACKETS_ENABLE; xscope_ep_request_upload(sockfd, 4, (unsigned char *)&cmd); } else if ((buffer[0] == 'h') || (buffer[0] == '?')) { print_console_usage(); } else { printf("Unrecognised command '%s'\n", buffer); print_console_usage(); } } while (1); #ifdef _WIN32 return 0; #else return NULL; #endif }
char *collect_words(char *first) { /* Get all of the remaining characters from the current input line, and append them to the characters in first, and return a pointer to the result. */ char ch; char *scratch = (char*) MALLOC(SCRATCH_SIZE); char *temp; int scratch_index = 0; int scratch_length = SCRATCH_SIZE; char *ret_field=0; int ret_length = strlen (first)+1; if (scratch == NULL) return NULL; do { ch = get_next_char(); if (ch=='\n' || ch=='\0') break; scratch[scratch_index++] = ch; if (scratch_index > scratch_length) { temp = (char *) MALLOC (scratch_length+SCRATCH_SIZE); if (temp==NULL) return NULL; memset (temp, 0, scratch_length+SCRATCH_SIZE); memcpy (temp, scratch, scratch_length); scratch_length += SCRATCH_SIZE; FREE (scratch); } } while (TRUE); ret_length += scratch_index + 1; /* +1 for the trailing NULL */ ret_field = (char*) MALLOC (ret_length); if (ret_field == NULL) return NULL; strcpy (ret_field, first); if (scratch_index > 0) { strcat (ret_field, " "); memcpy (&ret_field[strlen(ret_field)], scratch, scratch_index); } ret_field[strlen(first)+1+scratch_index] = '\0'; FREE (scratch); set_new_line(); return ret_field; }
NEURON_OUTPUT GetNextChar(PARAM_LIST *pParamList) { NEURON_OUTPUT output; get_next_char(&character); output.ival = 0; return (output); }
size_t token_get_next( FILE *fp, char *buf, size_t size ) { size_t i = 0; char tmp; memset( buf, 0, size ); while ( tmp = get_next_char( fp ), tmp != ' ' && tmp != EOF && i < size-1 ) i++, *buf++ = tmp; *buf = '\0'; return i; }
static int perf_parse_file(config_fn_t fn, void *data) { int comment = 0; int baselen = 0; static char var[MAXNAME]; /* U+FEFF Byte Order Mark in UTF8 */ static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf"; const unsigned char *bomptr = utf8_bom; for (;;) { int c = get_next_char(); if (bomptr && *bomptr) { /* We are at the file beginning; skip UTF8-encoded BOM * if present. Sane editors won't put this in on their * own, but e.g. Windows Notepad will do it happily. */ if ((unsigned char) c == *bomptr) { bomptr++; continue; } else { /* Do not tolerate partial BOM. */ if (bomptr != utf8_bom) break; /* No BOM at file beginning. Cool. */ bomptr = NULL; } } if (c == '\n') { if (config_file_eof) return 0; comment = 0; continue; } if (comment || isspace(c)) continue; if (c == '#' || c == ';') { comment = 1; continue; } if (c == '[') { baselen = get_base_var(var); if (baselen <= 0) break; var[baselen++] = '.'; var[baselen] = 0; continue; } if (!isalpha(c)) break; var[baselen] = tolower(c); if (get_value(fn, data, var, baselen+1) < 0) break; } die("bad config file line %d in %s", config_linenr, config_file_name); }
t_utf8 get_prev_char(const char *s, t_uint *idx) { t_uint save; if (*idx == 0) return (0); while (*idx != 0 && (s[--*idx] & 0xC0) == 0x80) ; save = *idx; return (get_next_char(s, &save)); }
static enum TOK_T get_next_token(port *in, pointer *token) { char ch, *t; skip_white_spc(in); switch (ch = get_next_char(in)) { case EOF: return FILE_END; case '(': return LIST_START; case ')': return LIST_END; case '"': *token = mk_string(read_string(in)); return STRING; case '\'': return QUOTE; case '`': return BACKQUOTE; case ',': if ((ch = get_next_char(in)) == '@') return SPLICE; else { push_back_char(in, ch); return UNQUOTE; } case '.': return DOT; default: push_back_char(in, ch); t = get_char_until_delim(in); if (test_number(t)) { *token = mk_number(atoi(t)); return NUMBER; } else { *token = mk_symbol(t); return SYMBOL; } } }
uuid operator()(CharIterator begin, CharIterator end) const { typedef typename std::iterator_traits<CharIterator>::value_type char_type; // check open brace char_type c = get_next_char(begin, end); bool has_open_brace = is_open_brace(c); char_type open_brace_char = c; if (has_open_brace) { c = get_next_char(begin, end); } bool has_dashes = false; uuid u; int i=0; for (uuid::iterator it_byte=u.begin(); it_byte!=u.end(); ++it_byte, ++i) { if (it_byte != u.begin()) { c = get_next_char(begin, end); } if (i == 4) { has_dashes = is_dash(c); if (has_dashes) { c = get_next_char(begin, end); } } if (has_dashes) { if (i == 6 || i == 8 || i == 10) { if (is_dash(c)) { c = get_next_char(begin, end); } else { throw_invalid(); } } } *it_byte = get_value(c); c = get_next_char(begin, end); *it_byte <<= 4; *it_byte |= get_value(c); } // check close brace if (has_open_brace) { c = get_next_char(begin, end); check_close_brace(c, open_brace_char); } return u; }
/** read the rest of the key name and value from the the config file \param key key correspondig to value \param len number of chars already read into key \returns 0 if successful */ static int get_value(char *key, unsigned int len) { int c; char *value; /* Get the full key */ for (;;) { c = get_next_char(); if (file_EOF) break; if (!iskeychar(c)) break; key[len++] = tolower(c); if (len >= MAXNAME) return -1; } key[len] = 0; while (c == ' ' || c == '\t') c = get_next_char(); value = NULL; if (c != '\n') { /* uncomment this line and comment the ungetc line if you want to use "parameter = value" style in your config file */ /*if (c != '=') return -1;*/ ungetc(c, file_ptr); value = parse_value(); if (!value) return -1; } if (value != NULL) add_to_config_list(key, value); return 0; }
// Adapted from boost::uuids cql::cql_uuid_t::cql_uuid_t(const std::string& uuid_string) { typedef std::string::value_type char_type; std::string::const_iterator begin = uuid_string.begin(), end = uuid_string.end(); // check open brace char_type c = get_next_char(begin, end); bool has_open_brace = is_open_brace(c); char_type open_brace_char = c; if (has_open_brace) { c = get_next_char(begin, end); } bool has_dashes = false; size_t i = 0u; for (cql_byte_t* it_byte = _uuid; it_byte != _uuid+_size; ++it_byte, ++i) { if (it_byte != _uuid) { c = get_next_char(begin, end); } if (i == 4) { has_dashes = is_dash(c); if (has_dashes) { c = get_next_char(begin, end); } } if (has_dashes) { if (i == 6 || i == 8 || i == 10) { if (is_dash(c)) { c = get_next_char(begin, end); } else { throw std::invalid_argument("String to make UUID from has a misplaced dash"); } } } *it_byte = get_value(c); c = get_next_char(begin, end); *it_byte <<= 4; *it_byte |= get_value(c); } // check close brace if (has_open_brace) { c = get_next_char(begin, end); check_close_brace(c, open_brace_char); } }
static char *get_char_until_delim(port *in) { int i = 0, ch; char str[MAX_SYM_NUM_LEN], *dst; str[0] = '\0'; while ((ch = get_next_char(in)) != EOF && !is_white_space(ch) && ch != '(' && ch != ')') str[i++] = ch; str[i] = '\0'; memcpy((dst = alloc_strseg(i + 1)), str, i + 1); if (ch != EOF) push_back_char(in, ch); return dst; }
static int get_base_var(char *name) { int baselen = 0; for (;;) { int c = get_next_char(); if (c == EOF) return -1; if (c == ']') return baselen; if (!isalnum(c) && c != '.') return -1; if (baselen > MAXNAME / 2) return -1; name[baselen++] = tolower(c); } }
void lex_unknown (void) { if(reading_from_top_level() && current_agent(current_char) == 0) { } else { print ("Error: Unknown character encountered by lexer, code=%d\n", current_agent(current_char)); print ("File %s, line %lu, column %lu.\n", current_agent(current_file)->filename, current_agent(current_file)->current_line, current_agent(current_file)->current_column); if (! reading_from_top_level()) { respond_to_load_errors (); if (current_agent(load_errors_quit)) current_agent(current_char) = EOF_AS_CHAR; } } get_next_char(); get_lexeme(); }
void lex_unknown (agent* thisAgent) { if(reading_from_top_level(thisAgent) && thisAgent->current_char == 0) { } else { print (thisAgent, "Error: Unknown character encountered by lexer, code=%d\n", thisAgent->current_char); print (thisAgent, "File %s, line %lu, column %lu.\n", thisAgent->current_file->filename, thisAgent->current_file->current_line, thisAgent->current_file->current_column); if (! reading_from_top_level(thisAgent)) { //respond_to_load_errors (thisAgent); if (thisAgent->load_errors_quit) thisAgent->current_char = EOF; } } get_next_char(thisAgent); get_lexeme(thisAgent); }