/* Read a braced string (a la Tcl) onto the obstack. Caller has scanned the leading brace. Note that unlike quoted strings, the outermost braces _are_ included in the string constant. */ static char * read_braced_string (struct obstack *ob, FILE *infile) { int c; int brace_depth = 1; /* caller-processed */ unsigned long starting_read_rtx_lineno = read_rtx_lineno; obstack_1grow (ob, '{'); while (brace_depth) { c = getc (infile); /* Read the string */ if (c == '\n') read_rtx_lineno++; else if (c == '{') brace_depth++; else if (c == '}') brace_depth--; else if (c == '\\') { read_escape (ob, infile); continue; } else if (c == EOF) fatal_with_file_and_line (infile, "missing closing } for opening brace on line %lu", starting_read_rtx_lineno); obstack_1grow (ob, c); } obstack_1grow (ob, 0); return obstack_finish (ob); }
Value * read_string(Globals *g) { int strpos = 0; Value *v; char c; #define ADD_CHAR(c) \ if (strpos >= g->strbuflen) \ expand_strbuf(g); \ g->strbuf[strpos++] = (c) while (1) { switch (PEEK_CHAR(g)) { case '\"': NEXT_CHAR(g); v = ALLOC_VALUE(); v->tag = string; v->value.s.length = strpos; v->value.s.string = (char *) malloc(v->value.s.length); bcopy(g->strbuf, v->value.s.string, v->value.s.length); return v; break; case '\\': NEXT_CHAR(g); if (read_escape(g, &c)) ADD_CHAR(c); break; default: ADD_CHAR(PEEK_CHAR(g)); NEXT_CHAR(g); break; } } }
// Reads a string quoted with delim. Returns the contents without // quotes. std::string read_quoted_string(std::istream & ifs, char delim = '"') { int c = ifs.get(); SPRITE_SKIPSPACE_EXPECTING(delim) std::stringstream tmp; c = ifs.get(); while(c && c != delim) { if(c == '\\') tmp.put(read_escape(ifs)); else tmp.put(c); c = ifs.get(); } return tmp.str(); }
/* Read a double-quoted string onto the obstack. Caller has scanned the leading quote. */ static char * read_quoted_string (struct obstack *ob, FILE *infile) { int c; while (1) { c = getc (infile); /* Read the string */ if (c == '\n') read_rtx_lineno++; else if (c == '\\') { read_escape (ob, infile); continue; } else if (c == '"') break; obstack_1grow (ob, c); } obstack_1grow (ob, 0); return obstack_finish (ob); }