static unsigned char * str_rd(struct option *opt, unsigned char **file, int *line) { unsigned char *str = *file; struct string str2; if (!init_string(&str2)) return NULL; /* We're getting used in some parser functions in conf.c as well, and * that's w/ opt == NULL; so don't rely on opt to point anywhere. */ if (!commandline) { if (!isquote(*str)) { done_string(&str2); return NULL; } str++; } while (*str && (commandline || !isquote(*str))) { if (*str == '\\') { /* FIXME: This won't work on crlf systems. */ if (str[1] == '\n') { str[1] = ' '; str++; (*line)++; } /* When there's quote char, we will just move on there, * thus we will never test for it in while () condition * and we will treat it just as '"', ignoring the * backslash itself. */ else if (isquote(str[1])) str++; /* \\ means \. */ else if (str[1] == '\\') str++; } if (*str == '\n') (*line)++; add_char_to_string(&str2, *str); str++; } if (!commandline && !*str) { done_string(&str2); *file = str; return NULL; } str++; /* Skip the quote. */ if (!commandline) *file = str; if (opt && opt->max && str2.length >= opt->max) { done_string(&str2); return NULL; } return str2.source; }
/* * accumulate a blockquote. * * one sick horrible thing about blockquotes is that even though * it just takes ^> to start a quote, following lines, if quoted, * assume that the prefix is ``> ''. This means that code needs * to be indented *5* spaces from the leading '>', but *4* spaces * from the start of the line. This does not appear to be * documented in the reference implementation, but it's the * way the markdown sample web form at Daring Fireball works. */ static Line * quoteblock(Paragraph *p, DWORD flags) { Line *t, *q; int qp; for ( t = p->text; t ; t = q ) { if ( isquote(t) ) { /* clip leading spaces */ for (qp = 0; T(t->text)[qp] != '>'; qp ++) /* assert: the first nonblank character on this line * will be a > */; /* clip '>' */ qp++; /* clip next space, if any */ if ( T(t->text)[qp] == ' ' ) qp++; CLIP(t->text, 0, qp); UNCHECK(t); t->dle = mkd_firstnonblank(t); } q = skipempty(t->next); if ( (q == 0) || ((q != t->next) && (!isquote(q) || isdivmarker(q,1,flags))) ) { ___mkd_freeLineRange(t, q); t = q; break; } } if ( isdivmarker(p->text,0,flags) ) { char *prefix = "class"; int i; q = p->text; p->text = p->text->next; if ( (i = szmarkerclass(1+T(q->text))) == 3 ) /* and this would be an "%id:" prefix */ prefix="id"; if ( p->ident = malloc(4+strlen(prefix)+S(q->text)) ) sprintf(p->ident, "%s=\"%.*s\"", prefix, S(q->text)-(i+2), T(q->text)+(i+1) ); ___mkd_freeLine(q); } return t; }
static gmx_bool parse_string(char **string, int *nr, int ngrps, char **grpname) { char *s, *sp; char c; while ((*string)[0] == ' ') { (*string)++; } (*nr) = NOTSET; if (isquote((*string)[0])) { c = (*string)[0]; (*string)++; s = strdup((*string)); sp = strchr(s, c); if (sp != NULL) { (*string) += sp-s + 1; sp[0] = '\0'; (*nr) = find_group(s, ngrps, grpname); } } return (*nr) != NOTSET; }
/* * Set each of the char*'s in args to point to each of the words in cmd, * ignoring empty strings and preserving quoted strings. */ void convert_to_argument_list (char **args, char *cmd) { int i; int count; int size; char within_quotes; args[0] = cmd; within_quotes = 0; size = strlen(cmd); for (count = i = 0; i < size; i++) { if (isquote(cmd[i])) { if (cmd[i] == within_quotes) { within_quotes = 0; add_arg_to_list(cmd, i, args, &count); } else if (!within_quotes) { within_quotes = cmd[i]; add_arg_to_list(cmd, i, args, &count); } } else if (isspace(cmd[i]) && !within_quotes) { add_arg_to_list(cmd, i, args, &count); if (count > ARG_MAX) { fprintf(stderr, "warning: the command exceeds the maximum number of\n" " arguments (%d) allowed by run4; truncating\n", ARG_MAX); break; } } } args[count+1] = NULL; }
static signed gettoken (char * string) { extern unsigned line; signed c; do { c = getc (stdin); if (c == '\n') { line++; } } while (isspace (c)); if (isalpha (c) || (c == '_')) { do { * string++ = c; c = getc (stdin); } while (isalnum (c) || (c == '.') || (c == ':') || (c == '_') || (c == '-')); ungetc (c, stdin); c = 'A'; } else if (isdigit (c)) { do { * string++ = c; c = getc (stdin); } while (isdigit (c) || (c == '.')); ungetc (c, stdin); c = '0'; } else if (isquote (c)) { char o = getc (stdin);; while ((o != c) && (c != EOF)) { if (o == '\\') { o = getc (stdin); } * string++ = o; o = getc (stdin); } } else { * string++ = c; } * string++ = (char) (0); return (c); }
/** Skip to the next newline or comment that is not part of a quoted * string. When ELinks hits a parse error in the configuration file, * it calls this in order to find the place where is should resume * parsing. This is intended to prevent ELinks from treating words * in strings as commands. */ static void skip_to_unquoted_newline_or_comment(struct conf_parsing_pos *pos) { while (*pos->look && *pos->look != '#' && *pos->look != '\n') { if (isquote(*pos->look)) skip_quoted(pos); else pos->look++; } }
/* TODO Optimize later --pasky */ struct string * add_quoted_to_string(struct string *string, const unsigned char *src, int len) { for (; len; len--, src++) { if (isquote(*src) || *src == '\\') add_char_to_string(string, '\\'); add_char_to_string(string, *src); } return string; }
/** Skip a quoted string. * This function allows "mismatching quotes' because str_rd() does so. */ static void skip_quoted(struct conf_parsing_pos *pos) { assert(isquote(*pos->look)); if_assert_failed return; pos->look++; for (;;) { if (!*pos->look) return; if (isquote(*pos->look)) { pos->look++; return; } if (*pos->look == '\\' && pos->look[1]) pos->look++; if (*pos->look == '\n') pos->line++; pos->look++; } }
/** Skip the value of an option. * * This job is normally done by the reader function that corresponds * to the type of the option. However, if ELinks does not recognize * the name of the option, it cannot look up the type and has to use * this function instead. */ static void skip_option_value(struct conf_parsing_pos *pos) { if (isquote(*pos->look)) { /* Looks like OPT_STRING, OPT_CODEPAGE, OPT_LANGUAGE, * or OPT_COLOR. */ skip_quoted(pos); } else { /* Looks like OPT_BOOL, OPT_INT, or OPT_LONG. */ while (isasciialnum(*pos->look) || *pos->look == '.' || *pos->look == '+' || *pos->look == '-') pos->look++; } }
/* Parse string param="value", return value as new string or NULL if any * error. */ unsigned char * get_header_param(unsigned char *e, unsigned char *name) { unsigned char *n, *start; again: while (*e && c_toupper(*e++) != c_toupper(*name)); if (!*e) return NULL; n = name + 1; while (*n && c_toupper(*e) == c_toupper(*n)) e++, n++; if (*n) goto again; skip_space(e); if (*e++ != '=') return NULL; skip_space(e); start = e; if (!isquote(*e)) { skip_nonspace(e); } else { unsigned char uu = *e++; start++; while (*e != uu) { if (!*e) return NULL; e++; } } while (start < e && *start == ' ') start++; while (start < e && *(e - 1) == ' ') e--; if (start == e) return NULL; n = mem_alloc(e - start + 1); if (n) { int i = 0; while (start < e) { n[i++] = (*start < ' ') ? '.' : *start; start++; } n[i] = '\0'; } return n; }
static int endoftextblock(Line *t, int toplevelblock, DWORD flags) { int z; if ( end_of_block(t) || isquote(t) ) return 1; /* HORRIBLE STANDARDS KLUDGES: * 1. non-toplevel paragraphs absorb adjacent code blocks * 2. Toplevel paragraphs eat absorb adjacent list items, * but sublevel blocks behave properly. * (What this means is that we only need to check for code * blocks at toplevel, and only check for list items at * nested levels.) */ return toplevelblock ? 0 : islist(t,&z,flags,&z); }
static int endoftextblock(Line *t, int toplevelblock, DWORD flags) { int z; if ( blankline(t)||isquote(t)||ishdr(t,&z)||ishr(t) ) return 1; /* HORRIBLE STANDARDS KLUDGE: non-toplevel paragraphs absorb adjacent * code blocks */ if ( toplevelblock && iscode(t) ) return 1; /* HORRIBLE STANDARDS KLUDGE: Toplevel paragraphs eat absorb adjacent * list items, but sublevel blocks behave properly. */ return toplevelblock ? 0 : islist(t,&z,flags, &z); }
static bool needSpace(int c, IOSTREAM *s) { if ( c == EOF ) { s->lastc = EOF; return FALSE; } if ( s->lastc == PREFIX_SIGN ) /* avoid passing to is*W() functions */ { if ( isDigit(c) || isSymbolW(c) ) return TRUE; return FALSE; } if ( s->lastc != EOF && ((isAlphaW(s->lastc) && isAlphaW(c)) || (isSymbolW(s->lastc) && isSymbolW(c)) || (s->lastc != '(' && !isBlank(s->lastc) && c == '(') || (c == '\'' && (isDigit(s->lastc))) || (isquote(c) && s->lastc == c) ) ) return TRUE; return FALSE; }
/* * break a collection of markdown input into * blocks of lists, code, html, and text to * be marked up. */ static Paragraph * compile(Line *ptr, int toplevel, MMIOT *f) { ParagraphRoot d = { 0, 0 }; Paragraph *p = 0; Line *r; int para = toplevel; int blocks = 0; int hdr_type, list_type, list_class, indent; ptr = consume(ptr, ¶); while ( ptr ) { if ( iscode(ptr) ) { p = Pp(&d, ptr, CODE); if ( f->flags & MKD_1_COMPAT) { /* HORRIBLE STANDARDS KLUDGE: the first line of every block * has trailing whitespace trimmed off. */ ___mkd_tidy(&p->text->text); } ptr = codeblock(p); } #if WITH_FENCED_CODE else if ( iscodefence(ptr,3,0) && (p=fencedcodeblock(&d, &ptr)) ) /* yay, it's already done */ ; #endif else if ( ishr(ptr) ) { p = Pp(&d, 0, HR); r = ptr; ptr = ptr->next; ___mkd_freeLine(r); } else if ( list_class = islist(ptr, &indent, f->flags, &list_type) ) { if ( list_class == DL ) { p = Pp(&d, ptr, DL); ptr = definition_block(p, indent, f, list_type); } else { p = Pp(&d, ptr, list_type); ptr = enumerated_block(p, indent, f, list_class); } } else if ( isquote(ptr) ) { p = Pp(&d, ptr, QUOTE); ptr = quoteblock(p, f->flags); p->down = compile(p->text, 1, f); p->text = 0; } else if ( ishdr(ptr, &hdr_type) ) { p = Pp(&d, ptr, HDR); ptr = headerblock(p, hdr_type); } else { p = Pp(&d, ptr, MARKUP); ptr = textblock(p, toplevel, f->flags); /* tables are a special kind of paragraph */ if ( actually_a_table(f, p->text) ) p->typ = TABLE; } if ( (para||toplevel) && !p->align ) p->align = PARA; blocks++; para = toplevel || (blocks > 1); ptr = consume(ptr, ¶); if ( para && !p->align ) p->align = PARA; } return T(d); }
static inline void scan_css_token(struct scanner *scanner, struct scanner_token *token) { const unsigned char *string = scanner->position; unsigned char first_char = *string; enum css_token_type type = CSS_TOKEN_GARBAGE; int real_length = -1; assert(first_char); token->string = string++; if (is_css_char_token(first_char)) { type = first_char; } else if (is_css_digit(first_char) || first_char == '.') { scan_css(scanner, string, CSS_CHAR_DIGIT); /* First scan the full number token */ if (*string == '.') { string++; if (is_css_digit(*string)) { type = CSS_TOKEN_NUMBER; scan_css(scanner, string, CSS_CHAR_DIGIT); } } /* Check what kind of number we have */ if (*string == '%') { if (first_char != '.') type = CSS_TOKEN_PERCENTAGE; string++; } else if (!is_css_ident_start(*string)) { type = CSS_TOKEN_NUMBER; } else { const unsigned char *ident = string; scan_css(scanner, string, CSS_CHAR_IDENT); type = map_scanner_string(scanner, ident, string, CSS_TOKEN_DIMENSION); } } else if (is_css_ident_start(first_char)) { scan_css(scanner, string, CSS_CHAR_IDENT); if (*string == '(') { const unsigned char *function_end = string + 1; /* Make sure that we have an ending ')' */ skip_css(scanner, function_end, ')'); if (*function_end == ')') { type = map_scanner_string(scanner, token->string, string, CSS_TOKEN_FUNCTION); /* If it is not a known function just skip the * how arg stuff so we don't end up generating * a lot of useless tokens. */ if (type == CSS_TOKEN_FUNCTION) { string = function_end; } else if (type == CSS_TOKEN_URL) { /* Extracting the URL first removes any * leading or ending whitespace and * then see if the url is given in a * string. If that is the case the * string delimiters are also trimmed. * This is not totally correct because * we should of course handle escape * sequences .. but that will have to * be fixed later. */ const unsigned char *from = string + 1; const unsigned char *to = function_end - 1; scan_css(scanner, from, CSS_CHAR_WHITESPACE); scan_back_css(scanner, to, CSS_CHAR_WHITESPACE); if (isquote(*from)) from++; if (isquote(*to)) to--; token->string = from; /* Given "url( )", @to and @from will * cross when they scan forwards and * backwards, respectively, for a non- * whitespace character, and @to - @from * will be negative. If there is * anything between the parentheses, * @to and @from will not cross and @to * - @from will not become negative. */ real_length = int_max(0, to - from + 1); string = function_end; } assert(type != CSS_TOKEN_RGB || *string == '('); assert(type != CSS_TOKEN_URL || *string == ')'); assert(type != CSS_TOKEN_FUNCTION || *string == ')'); } string++; } else { type = CSS_TOKEN_IDENT; } } else if (!is_css_token_start(first_char)) { /* TODO: Better composing of error tokens. For now we just * split them down into char tokens */ } else if (first_char == '#') { /* Check whether it is hexcolor or hash token */ if (is_css_hexdigit(*string)) { int hexdigits; scan_css(scanner, string, CSS_CHAR_HEX_DIGIT); /* Check that the hexdigit sequence is either 3 or 6 * chars and it isn't just start of some non-hex ident * string. */ hexdigits = string - token->string - 1; if ((hexdigits == 3 || hexdigits == 6) && !is_css_ident(*string)) { type = CSS_TOKEN_HEX_COLOR; } else { scan_css(scanner, string, CSS_CHAR_IDENT); type = CSS_TOKEN_HASH; } } else if (is_css_ident(*string)) { /* Not *_ident_start() because hashes are #<name>. */ scan_css(scanner, string, CSS_CHAR_IDENT); type = CSS_TOKEN_HASH; } } else if (first_char == '@') { /* Compose token containing @<ident> */ if (is_css_ident_start(*string)) { const unsigned char *ident = string; /* Scan both ident start and ident */ scan_css(scanner, string, CSS_CHAR_IDENT); type = map_scanner_string(scanner, ident, string, CSS_TOKEN_AT_KEYWORD); } } else if (first_char == '*') { if (*string == '=') { type = CSS_TOKEN_SELECT_CONTAINS; string++; } else { type = CSS_TOKEN_IDENT; } } else if (first_char == '^') { if (*string == '=') { type = CSS_TOKEN_SELECT_BEGIN; string++; } } else if (first_char == '$') { if (*string == '=') { type = CSS_TOKEN_SELECT_END; string++; } } else if (first_char == '|') { if (*string == '=') { type = CSS_TOKEN_SELECT_HYPHEN_LIST; string++; } } else if (first_char == '!') { scan_css(scanner, string, CSS_CHAR_WHITESPACE); if (!c_strncasecmp(string, "important", 9)) { type = CSS_TOKEN_IMPORTANT; string += 9; } } else if (isquote(first_char)) { /* TODO: Escaped delimiters --jonas */ int size = scanner->end - string; unsigned char *string_end = memchr(string, first_char, size); if (string_end) { /* We don't want the delimiters in the token */ token->string++; real_length = string_end - token->string; string = string_end + 1; type = CSS_TOKEN_STRING; } } else if (first_char == '<' || first_char == '-') { /* Try to navigate SGML tagsoup */ if (*string == '/') { /* Some kind of SGML tag end ... better bail out screaming */ type = CSS_TOKEN_NONE; } else { const unsigned char *sgml = string; /* Skip anything looking like SGML "<!--" and "-->" * comments + <![CDATA[ and ]]> notations. */ scan_css(scanner, sgml, CSS_CHAR_SGML_MARKUP); if (sgml - string >= 2 && ((first_char == '<' && *string == '!') || (first_char == '-' && sgml[-1] == '>'))) { type = CSS_TOKEN_SKIP; string = sgml; } } } else if (first_char == '/') { /* Comments */ if (*string == '*') { type = CSS_TOKEN_SKIP; for (string++; string < scanner->end; string++) if (*string == '*' && string[1] == '/') { string += 2; break; } } } else { INTERNAL("Someone forgot to put code for recognizing tokens " "which start with '%c'.", first_char); } token->type = type; token->length = real_length > 0 ? real_length : string - token->string; token->precedence = get_css_precedence(type); scanner->position = string; }
void Tscriptsourceview::draw(CDC *dc, RECT &updaterect) { int xp,yp,kwstart,kwend; StrChar ch; bool insel; QString kw; TQXColor curtextcol,keywordcol; bool inkeyword,instring,istextstring,incomment,textstarted; TQXColor backcolor=G_QXSys().G_color(TQXSys::CL_WINDOWBACK1); TQXColor textcolor=G_QXSys().G_color(TQXSys::CL_TEXT); // TQXColor selcolor(0.6f,0.8f,1.0f); TQXColor selcolor=G_QXSys().G_color(TQXSys::CL_WINDOWHIGHLIGHT); TQXColor stringcolor1(0,0.6f,0); TQXColor stringcolor2(0.3f,0.6f,0); TQXColor commentcolor(0.7f,0,0); TQXColor signcolor=2*backcolor+textcolor; dc->SelectObject(G_QXSys().G_font(TQXSys::FNT_FIXED)); dc->SetBkMode(TRANSPARENT); // dc->FillSolidRect(0-G_offsetx(),0,300,300,RGB(255,0,0)); TQXColor debugbackcol=3*backcolor+TQXColor(0,1,0); stringcolor1=TQXColor(0,0.75,0.25)+textcolor; stringcolor2=TQXColor(0.5,1,0)+textcolor; commentcolor=TQXColor(1,0,0)+textcolor; if (script==NULL) { dc->FillSolidRect(&updaterect,G_QXSys().G_color(TQXSys::CL_WINDOWBACK2)); return; } TSC_source &source=script->G_source(); if (source.readonly) { textcolor=G_QXSys().G_color(TQXSys::CL_TEXT)+backcolor; } dc->SetTextColor(textcolor); int sel1line,sel1col,sel2line,sel2col; source.G_sel(sel1line,sel1col,sel2line,sel2col); if (Isactiveview()) { yp=source.G_cursor_linenr()*ysep-G_offsety(); xp=marginx+source.G_cursor_colnr()*xsep-G_offsetx(); dc->FillSolidRect(xp-0,yp,1,ysep,textcolor); } for (int linenr=0; linenr<source.G_linecount(); linenr++) { yp=linenr*ysep-G_offsety(); if ((yp>=updaterect.top-20)&&(yp<=updaterect.bottom+20)) { if (linenr==source.G_debugline()) dc->FillSolidRect(0,yp,10000,ysep,debugbackcol); const QString *line=source.G_line(linenr); dc->FillSolidRect(marginx-G_offsetx()-8,yp+ysep/2,4,1,signcolor); dc->FillSolidRect(marginx-G_offsetx()-6,yp+ysep/2-1,1,1,signcolor); dc->FillSolidRect(marginx-G_offsetx()-6,yp+ysep/2+1,1,1,signcolor); inkeyword=false;instring=false;incomment=false;istextstring=false; textstarted=false; for (int colnr=0; colnr<line->G_length(); colnr++) { curtextcol=textcolor; xp=marginx+colnr*xsep-G_offsetx(); insel=true; if (linenr<sel1line) insel=false; if ((linenr==sel1line)&&(colnr<sel1col)) insel=false; if (linenr>sel2line) insel=false; if ((linenr==sel2line)&&(colnr>sel2col)) insel=false; if (insel) dc->FillSolidRect(xp,yp,xsep,ysep,selcolor); ch=line->G_char(colnr); if (ch!=' ') textstarted=true; if ((!instring)&&(ch=='#')/*&&(line->G_char(colnr+1)=='/')*/) { incomment=true; } if (incomment) curtextcol=commentcolor; if (instring) { curtextcol=stringcolor1; if (istextstring) curtextcol=stringcolor2; } if ((!incomment)&&(isquote(ch))) { if (!instring) { instring=true;istextstring=false; curtextcol=stringcolor1; if (isquotesingle(ch)) { istextstring=true; curtextcol=stringcolor2; } } else { if ((colnr==0)||(line->G_char(colnr-1)!=ESCCHAR)) instring=false; } } if ((!instring)&&(!incomment)) { if (Qisalphanumerical(ch)) { if ((colnr==0)||(!Qisalphanumerical(line->G_char(colnr-1)))) { kwstart=colnr;kwend=colnr; while ((kwend<line->G_length()-1)&&(Qisalphanumerical(line->G_char(kwend+1)))) kwend++; if (kwend>kwstart) { kw.clear(); for (int kwct=kwstart; kwct<=kwend; kwct++) kw+=line->G_char(kwct); if (script->G_keyword(kw,keywordcol)) inkeyword=true; } } } else { inkeyword=false; } if (inkeyword) curtextcol=keywordcol; } if (source.readonly) dc->SetTextColor(2*curtextcol+backcolor); else dc->SetTextColor(curtextcol); dc->TextOut(xp,yp+4,&ch,1); if (ch==' ') { dc->FillSolidRect(xp+xsep/2,yp+ysep/2,1,1,signcolor); if ((!textstarted)&&(colnr%3==2)) dc->FillSolidRect(xp+xsep/2,yp,1,ysep,signcolor); } } } } }
int parse(int *argc, char ***argv, char *str) { int ac; char *val, *p, *q, *copy = NULL; size_t i = 0; char token, tmp, quote, *buf; enum { STR, VAR, WHITE } state; ac = *argc = 0; quote = 0; if (!str || (p = copy = backslash(str)) == NULL) return 1; /* Initialize vector and state */ clean(); state = STR; buf = (char *)alloc(PARSE_BUFSIZE); token = 0; /* And awaaaaaaaaay we go! */ while (*p) { switch (state) { case STR: if ((*p == '\\') && p[1]) { p++; PARSE_FAIL(i == (PARSE_BUFSIZE - 1)); buf[i++] = *p++; } else if (isquote(*p)) { quote = quote ? 0 : *p; ++p; } else if (isspace(*p) && !quote) { state = WHITE; if (i) { buf[i] = '\0'; PARSE_FAIL(insert(&ac, buf)); i = 0; } ++p; } else if (*p == '$') { token = isdelim(*(p + 1)); if (token) p += 2; else ++p; state = VAR; } else { PARSE_FAIL(i == (PARSE_BUFSIZE - 1)); buf[i++] = *p++; } break; case WHITE: if (isspace(*p)) ++p; else state = STR; break; case VAR: if (token) { PARSE_FAIL((q = strchr(p, token)) == NULL); } else { q = p; while (*q && !isspace(*q)) ++q; } tmp = *q; *q = '\0'; if ((val = variable_lookup(p)) != NULL) { size_t len = strlen(val); strncpy(buf + i, val, PARSE_BUFSIZE - (i + 1)); i += min(len, PARSE_BUFSIZE - 1); } *q = tmp; /* restore value */ p = q + (token ? 1 : 0); state = STR; break; } } /* If at end of token, add it */ if (i && state == STR) { buf[i] = '\0'; PARSE_FAIL(insert(&ac, buf)); } args[ac] = NULL; *argc = ac; *argv = (char **)alloc((sizeof(char *) * ac + 1)); bcopy(args, *argv, sizeof(char *) * ac + 1); free(buf); free(copy); return 0; }
void function (char * fullpath, char const * vector []) { FILE * fp; char buffer [CSOURCE]; char * sp; char * cp; signed c; if ((fp = efopen (fullpath, "rb"))) { char pathname [FILENAME_MAX]; for (sp = cp = strcpy (pathname, fullpath); * cp; ++ cp) { if (* cp == '/') { sp = cp; } } * sp = (char)(0); c = getc (fp); while (c != EOF) { sp = buffer; if (isspace (c)) { do { putc (c, stdout); c = getc (fp); } while (isspace (c)); continue; } if (isalpha (c)) { do { putc (c, stdout); c = getc (fp); } while (isalnum (c)); continue; } if (isdigit (c)) { do { putc (c, stdout); c = getc (fp); } while (isdigit (c)); continue; } if (c == '#') { * sp++ = (char)(c); c = getc (fp); while (isblank (c)) { * sp++ = (char)(c); c = getc (fp); } cp = sp; while (isalpha (c)) { * sp++ = (char) (c); c = getc (fp); } * sp = (char)(0); if (strcmp ("include", cp)) { while (nobreak (c)) { * sp++ = (char) (c); c = getc (fp); } * sp++ = (char)(c); for (cp = buffer; cp < sp; putc (* cp++, stdout)); c = getc (fp); continue; } while (isblank (c)) { * sp++ = (char) (c); c = getc (fp); } if (c == '\"') { size_t index; char filename [FILENAME_MAX]; cp = filename; c = getc (fp); while ((c != '\"') && (c != EOF)) { * cp++ = * sp++ = (char) (c); c = getc (fp); } * cp = (char) (0); makepath (fullpath, pathname, filename); for (index = 0; vector [index] != (char *)(0); index++) { if (!strcmp (fullpath, vector [index])) { break; } } if (vector [index] == (char *)(0)) { vector [index++] = strdup (fullpath); vector [index] = (char *)(0); function (fullpath, vector); } while (nobreak (c)) { * sp++ = (char) (c); c = getc (fp); } * sp++ = (char) (c); } else { while (nobreak (c)) { * sp++ = (char) (c); c = getc (fp); } * sp++ = (char) (c); for (cp = buffer; cp < sp; putc (* cp++, stdout)); } c = getc (fp); continue; } if (isquote (c)) { signed o = getc (fp); putc (c, stdout); while ((o != c) && (c != EOF)) { if (o == '\\') { putc (o, stdout); o = getc (fp); } putc (o, stdout); o = getc (fp); } putc (c, stdout); c = getc (fp); continue; } if (c == '/') { putc (c, stdout); c = getc (fp); if (c == '/') { while (nobreak (c)) { putc (c, stdout); c = getc (fp); } putc ('\n', stdout); c = getc (fp); continue; } if (c == '*') { while (nomatch (c, '/')) { while (nomatch (c, '*')) { putc (c, stdout); c = getc (fp); } putc (c, stdout); c = getc (fp); } putc ('/', stdout); c = getc (fp); continue; } putc (c, stdout); c = getc (fp); continue; } putc (c, stdout); c = getc (fp); } fclose (fp); } return; }
int G_site_put_new(FILE * fptr, Site * s, int has_cat) /* Writes a site to file open on fptr. */ { char ebuf[MAX_SITE_STRING], nbuf[MAX_SITE_STRING]; char xbuf[MAX_SITE_STRING], buf[MAX_SITE_LEN]; static int format_double(); int fmt, i, j, k; int G_format_northing(), G_format_easting(), G_projection(); fmt = G_projection(); G_format_northing(s->north, nbuf, fmt); G_format_easting(s->east, ebuf, fmt); sprintf(buf, "%s|%s|", ebuf, nbuf); for (i = 0; i < s->dim_alloc; ++i) { format_double(s->dim[i], nbuf); sprintf(xbuf, "%s|", nbuf); strcat(buf, xbuf); } if (has_cat) { switch (s->cattype) { case CELL_TYPE: sprintf(xbuf, "#%d ", s->ccat); strcat(buf, xbuf); break; case FCELL_TYPE: sprintf(xbuf, "#%g ", s->fcat); strcat(buf, xbuf); break; case DCELL_TYPE: sprintf(xbuf, "#%g ", s->dcat); strcat(buf, xbuf); break; } } else { /* no cat there, so data in plain x,y,z format will be imported 12/99 MN */ /* we create a #cat entry in site_list from the current site number 11/99 */ sprintf(xbuf, "#%d ", loop); loop++; strcat(buf, xbuf); } /* now import attributes */ for (i = 0; i < s->dbl_alloc; ++i) { format_double(s->dbl_att[i], nbuf); sprintf(xbuf, "%%%s ", nbuf); strcat(buf, xbuf); } for (i = 0; i < s->str_alloc; ++i) { if (strlen(s->str_att[i]) != 0) { /* escape double quotes */ j = k = 0; if (G_index(s->str_att[i], DQUOTE) != (char *)NULL) { while (!isnull(s->str_att[i][j])) { if (isquote(s->str_att[i][j])) { xbuf[k++] = BSLASH; xbuf[k++] = DQUOTE; } else if (isbslash(s->str_att[i][j])) { xbuf[k++] = BSLASH; xbuf[k++] = BSLASH; } else xbuf[k++] = s->str_att[i][j]; j++; } xbuf[k] = (char)NULL; } else strcpy(xbuf, s->str_att[i]); strcpy(s->str_att[i], xbuf); if (G_index(s->str_att[i], SPACE) != (char *)NULL) sprintf(xbuf, "@\"%s\" ", s->str_att[i]); else sprintf(xbuf, "@%s ", s->str_att[i]); strcat(buf, xbuf); } } fprintf(fptr, "%s\n", buf); return 0; }
/* * Parse the configuration file and set up variables */ int dlg_parse_rc(void) { int i; int l = 1; PARSE_LINE parse; char str[MAX_LEN + 1]; char *var; char *value; char *tempptr; int result = 0; FILE *rc_file = 0; char *params; /* * At startup, dialog determines the settings to use as follows: * * a) if the environment variable $DIALOGRC is set, its value determines * the name of the configuration file. * * b) if the file in (a) can't be found, use the file $HOME/.dialogrc * as the configuration file. * * c) if the file in (b) can't be found, try using the GLOBALRC file. * Usually this will be /etc/dialogrc. * * d) if the file in (c) cannot be found, use the compiled-in defaults. */ /* try step (a) */ if ((tempptr = getenv("DIALOGRC")) != NULL) rc_file = fopen(tempptr, "rt"); if (rc_file == NULL) { /* step (a) failed? */ /* try step (b) */ if ((tempptr = getenv("HOME")) != NULL && strlen(tempptr) < MAX_LEN - (sizeof(DIALOGRC) + 3)) { if (tempptr[0] == '\0' || lastch(tempptr) == '/') sprintf(str, "%s%s", tempptr, DIALOGRC); else sprintf(str, "%s/%s", tempptr, DIALOGRC); rc_file = fopen(tempptr = str, "rt"); } } if (rc_file == NULL) { /* step (b) failed? */ /* try step (c) */ strcpy(str, GLOBALRC); if ((rc_file = fopen(tempptr = str, "rt")) == NULL) return 0; /* step (c) failed, use default values */ } DLG_TRACE(("opened rc file \"%s\"\n", tempptr)); /* Scan each line and set variables */ while ((result == 0) && (fgets(str, MAX_LEN, rc_file) != NULL)) { DLG_TRACE(("rc:%s", str)); if (*str == '\0' || lastch(str) != '\n') { /* ignore rest of file if line too long */ fprintf(stderr, "\nParse error: line %d of configuration" " file too long.\n", l); result = -1; /* parse aborted */ break; } lastch(str) = '\0'; if (begins_with(str, "bindkey", ¶ms)) { if (!dlg_parse_bindkey(params)) { fprintf(stderr, "\nParse error: line %d of configuration\n", l); result = -1; } continue; } parse = parse_line(str, &var, &value); /* parse current line */ switch (parse) { case LINE_EMPTY: /* ignore blank lines and comments */ break; case LINE_EQUALS: /* search table for matching config variable name */ if ((i = find_vars(var)) >= 0) { switch (vars[i].type) { case VAL_INT: *((int *) vars[i].var) = atoi(value); break; case VAL_STR: if (!isquote(value[0]) || !isquote(lastch(value)) || strlen(value) < 2) { fprintf(stderr, "\nParse error: string value " "expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { /* remove the (") quotes */ value++; lastch(value) = '\0'; strcpy((char *) vars[i].var, value); } break; case VAL_BOOL: if (!dlg_strcmp(value, "ON")) *((bool *) vars[i].var) = TRUE; else if (!dlg_strcmp(value, "OFF")) *((bool *) vars[i].var) = FALSE; else { fprintf(stderr, "\nParse error: boolean value " "expected at line %d of configuration " "file (found %s).\n", l, value); result = -1; /* parse aborted */ } break; } #ifdef HAVE_COLOR } else if ((i = find_color(var)) >= 0) { int fg = 0; int bg = 0; int hl = 0; if (str_to_attr(value, &fg, &bg, &hl) == -1) { fprintf(stderr, "\nParse error: attribute " "value expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { dlg_color_table[i].fg = fg; dlg_color_table[i].bg = bg; dlg_color_table[i].hilite = hl; } } else { #endif /* HAVE_COLOR */ fprintf(stderr, "\nParse error: unknown variable " "at line %d of configuration file:\n\t%s\n", l, var); result = -1; /* parse aborted */ } break; case LINE_ERROR: fprintf(stderr, "\nParse error: syntax error at line %d of " "configuration file.\n", l); result = -1; /* parse aborted */ break; } l++; /* next line */ } (void) fclose(rc_file); return result; }
inline int isseparator (char c) { return (isspace(c) || isquote(c) || c == '\0'); }
static signed program (signed c, signed e) { extern unsigned level; c = preamble (c); while ((c != e) && (c != EOF)) { if (c == '#') { c = fortran (c); continue; } if (c == '/') { c = comment (c); continue; } if (c == '{') { level++; c = keep (c); c = program (c, '}'); c = keep (c); level--; c = preamble (c); continue; } if (c == '(') { c = context ('(', ')'); continue; } if (c == '[') { c = context ('[', ']'); continue; } if (isquote (c)) { c = literal (c); continue; } if (isalnum (c) || (c == '_') || (c == '.')) { char string [100]; char * sp = string; do { * sp++ = c; c = keep (c); } while (isalnum (c) || (c == '_') || (c == '.')); * sp = (char) (0); if (! strcmp (string, "while")) { c = condition (c); c = statement (c); continue; } if (! strcmp (string, "for")) { c = condition (c); c = statement (c); continue; } if (! strcmp (string, "if")) { c = condition (c); c = statement (c); continue; } if (! strcmp (string, "else")) { c = statement (c); continue; } if (! strcmp (string, "do")) { c = statement (c); continue; } if (! strcmp (string, "return")) { c = condition (c); continue; } if (! strcmp (string, "exit")) { c = condition (c); continue; } continue; } c = keep (c); } return (e); }
/* * break a collection of markdown input into * blocks of lists, code, html, and text to * be marked up. */ static Paragraph * compile(Line *ptr, int toplevel, MMIOT *f) { ParagraphRoot d = { 0, 0 }; Paragraph *p = 0; Line *r; int para = toplevel; int blocks = 0; int hdr_type, list_type, list_class, indent; ptr = consume(ptr, ¶); while ( ptr ) { if ( iscode(ptr) ) { p = Pp(&d, ptr, CODE); if ( f->flags & MKD_1_COMPAT) { /* HORRIBLE STANDARDS KLUDGE: the first line of every block * has trailing whitespace trimmed off. */ ___mkd_tidy(&p->text->text); } ptr = codeblock(p); } else if ( ishr(ptr) ) { p = Pp(&d, 0, HR); r = ptr; ptr = ptr->next; ___mkd_freeLine(r); } else if (( list_class = islist(ptr, &indent, f->flags, &list_type) )) { if ( list_class == DL ) { p = Pp(&d, ptr, DL); ptr = definition_block(p, indent, f, list_type); } else { p = Pp(&d, ptr, list_type); ptr = enumerated_block(p, indent, f, list_class); } } else if ( isquote(ptr) ) { p = Pp(&d, ptr, QUOTE); ptr = quoteblock(p, f->flags); p->down = compile(p->text, 1, f); p->text = 0; } else if ( ishdr(ptr, &hdr_type) ) { p = Pp(&d, ptr, HDR); ptr = headerblock(p, hdr_type); } else if ( istable(ptr) && !(f->flags & (MKD_STRICT|MKD_NOTABLES)) ) { p = Pp(&d, ptr, TABLE); ptr = tableblock(p); } else { p = Pp(&d, ptr, MARKUP); ptr = textblock(p, toplevel, f->flags); } if ( (para||toplevel) && !p->align ) p->align = PARA; blocks++; para = toplevel || (blocks > 1); ptr = consume(ptr, ¶); if ( para && !p->align ) p->align = PARA; } return T(d); }
unsigned function (char const * oldname, char const * newname) { unsigned count = 0; signed c = getc (stdin); while (c != EOF) { if (isspace (c)) { do { putc (c, stdout); c = getc (stdin); } while (isspace (c)); continue; } if (isalpha (c) || (c == '_')) { char string [255]; char * sp = string; do { * sp++ = (char) (c); c = getc (stdin); } while (isalnum (c) || (c == '_')); * sp = (char) (0); if (! strcmp (string, oldname)) { count++; fputs (newname, stdout); continue; } fputs (string, stdout); continue; } if (isdigit (c)) { do { putc (c, stdout); c = getc (stdin); } while (isdigit (c) || (c == '.')); if ((c == 'x') || (c == 'X')) { do { putc (c, stdout); c = getc (stdin); } while (isxdigit (c)); } if ((c == 'e') || (c == 'E')) { putc (c, stdout); c = getc (stdin); if ((c == '+') || (c == '-')) { putc (c, stdout); c = getc (stdin); } while (isdigit (c)) { putc (c, stdout); c = getc (stdin); } } continue; } if (isquote (c)) { signed o; putc (c, stdout); o = getc (stdin); while (nomatch (o, c)) { if ((char) (o) == '\\') { putc (o, stdout); o = getc (stdin); } putc (o, stdout); o = getc (stdin); } putc (c, stdout); c = getc (stdin); continue; } if (c == '/') { putc (c, stdout); c = getc (stdin); if (c == '/') { while (nobreak (c)) { putc (c, stdout); c = getc (stdin); } putc ('\n', stdout); c = getc (stdin); continue; } if (c == '*') { while (nomatch (c, '/')) { while (nomatch (c, '*')) { putc (c, stdout); c = getc (stdin); } putc (c, stdout); c = getc (stdin); } putc ('/', stdout); c = getc (stdin); continue; } continue; } putc (c, stdout); c = getc (stdin); } return (count); }
int handle_quoted_text(FILE *fp, struct emailinfo *email, const struct body *bp, char *line, int inquote, int quote_num, bool replace_quoted, int maybe_reply) { char *url1; int quoting_msgnum = email->msgnum; const struct body *last_quoted_line = bp; int count_quoted_lines = 0; char *fmt2; char *cvtd_line = ConvURLsString(unquote(line), email->msgid, email->subject, email->charset); char *buffer1; trio_asprintf(&fmt2, set_iquotes ? "<em class=\"%s\">%%s</em><br>" : "<span class=\"%s\">%%s</span><br>", find_quote_class(line)); trio_asprintf(&buffer1, fmt2, cvtd_line ? cvtd_line : ""); if (cvtd_line) free(cvtd_line); found_quote = (quote_num > 0); while (last_quoted_line && isquote(last_quoted_line->line)) { ++count_quoted_lines; last_quoted_line = last_quoted_line->next; } cvtd_line = unquote_and_strip(line); if (strlen(cvtd_line) < 5 && (!replace_quoted || !inquote)) { char *parsed = ConvURLsString(line, email->msgid, email->subject, email->charset); if (parsed) { fprintf(fp, fmt2, parsed); free(parsed); } } else if ((!inquote || !found_quote) && (url1 = url_replying_to(email, buffer1, cvtd_line, bp, ++quote_num, "ing_msgnum, count_quoted_lines, maybe_reply))) { static const char *fmt1 = "<a href=\"%s\">%s</a>%s<br>\n"; char *tmpline; char *p2; bool replacing = replace_quoted && set_quote_link_string && set_quote_link_string[0]; char *part2 = strcasestr(line, "<a href="); if (!part2) { part2 = ""; tmpline = strsav(line); } else { tmpline = (char *)emalloc(part2 - line + 1); strncpy(tmpline, line, part2 - line); tmpline[part2 - line] = 0; } if (set_link_to_replies) fprintf(fp, "<a name=\"qlink%d\"></a>", quote_num); p2 = ConvURLsString(part2, email->msgid, email->subject, email->charset); if (replacing) fprintf(fp, fmt1, url1, set_quote_link_string, p2 ? p2 : ""); else { char *tmpptr = convchars(tmpline, email->charset); if (tmpptr) { fprintf(fp, fmt1, url1, tmpptr, p2 ? p2 : ""); free(tmpptr); } } free(url1); free(tmpline); if (p2) free(p2); free(cvtd_line); free(buffer1); free(fmt2); return 1; } else if (!replace_quoted || !inquote) { char *parsed = ConvURLsString(bp->line, email->msgid, email->subject, email->charset); if (parsed) { fprintf(fp, quoting_msgnum >= 0 ? fmt2 : "%s<br>\n", parsed); free(parsed); } } free(cvtd_line); free(buffer1); free(fmt2); return 0; }
/* * Parse the configuration file and set up variables */ int parse_rc(void) { int i, l = 1, parse, fg, bg, hl; unsigned char str[MAX_LEN+1], *var, *value, *tempptr; FILE *rc_file = NULL; /* * * At start, 'dialog' determines the settings to use as follows: * * a) if environment variable DIALOGRC is set, it's value determines the * name of the configuration file. * * b) if the file in (a) can't be found, use the file $HOME/.dialogrc * as the configuration file. * * c) if the file in (b) can't be found, use compiled in defaults. * */ if ((tempptr = getenv("DIALOGRC")) != NULL) rc_file = fopen(tempptr, "rt"); if (tempptr == NULL || rc_file == NULL) { /* step (a) failed? */ /* try step (b) */ if ((tempptr = getenv("HOME")) == NULL) return 0; /* step (b) failed, use default values */ if (tempptr[0] == '\0' || lastch(tempptr) == '/') sprintf(str, "%s%s", tempptr, DIALOGRC); else sprintf(str, "%s/%s", tempptr, DIALOGRC); if ((rc_file = fopen(str, "rt")) == NULL) return 0; /* step (b) failed, use default values */ } /* Scan each line and set variables */ while (fgets(str, MAX_LEN, rc_file) != NULL) { if (lastch(str) != '\n') { /* ignore rest of file if line too long */ fprintf(stderr, "\nParse error: line %d of configuration file too long.\n", l); fclose(rc_file); return -1; /* parse aborted */ } else { lastch(str) = '\0'; parse = parse_line(str, &var, &value); /* parse current line */ switch (parse) { case LINE_BLANK: /* ignore blank lines and comments */ case LINE_COMMENT: break; case LINE_OK: /* search table for matching config variable name */ for (i = 0; i < VAR_COUNT && strcmp(vars[i].name, var); i++); if (i == VAR_COUNT) { /* no match */ fprintf(stderr, "\nParse error: unknown variable at line %d of configuration file.\n", l); return -1; /* parse aborted */ } else { /* variable found in table, set run time variables */ switch (vars[i].type) { case VAL_INT: *((int *) vars[i].var) = atoi(value); break; case VAL_STR: if (!isquote(value[0]) || !isquote(lastch(value)) || strlen(value) < 2) { fprintf(stderr, "\nParse error: string value expected at line %d of configuration file.\n", l); return -1; /* parse aborted */ } else { /* remove the (") quotes */ value++; lastch(value) = '\0'; strcpy((unsigned char *) vars[i].var, value); } break; case VAL_BOOL: if (!strcasecmp(value, "ON")) *((bool *) vars[i].var) = TRUE; else if (!strcasecmp(value, "OFF")) *((bool *) vars[i].var) = FALSE; else { fprintf(stderr, "\nParse error: boolean value expected at line %d of configuration file.\n", l); return -1; /* parse aborted */ } break; case VAL_ATTR: if (str_to_attr(value, &fg, &bg, &hl) == -1) { fprintf(stderr, "\nParse error: attribute value expected at line %d of configuration file.\n", l); return -1; /* parse aborted */ } ((int *) vars[i].var)[0] = fg; ((int *) vars[i].var)[1] = bg; ((int *) vars[i].var)[2] = hl; break; } } break; case LINE_ERROR: fprintf(stderr, "\nParse error: syntax error at line %d of configuration file.\n", l); return -1; /* parse aborted */ } } l++; /* next line */ } fclose(rc_file); return 0; /* parse successful */ }
int get_delim_str(char **rtokptr, const char **rval, const char **err) { char *tokptr = *rtokptr; char endc; char *rv = NULL; while (isspace(*tokptr)) tokptr++; if (*tokptr == '\0') { *err = "missing string value"; return -1; } for (;;) { const char *val; if (*tokptr == '$') { char oldc; tokptr++; val = tokptr; while (*tokptr && *tokptr != '$' && !isspace(*tokptr) && !isquote(*tokptr)) { tokptr++; } oldc = *tokptr; *tokptr = '\0'; val = find_variable(val); if (!val) return -1; *tokptr = oldc; } else if (isquote(*tokptr)) { endc = *tokptr; tokptr++; val = tokptr; while (*tokptr != endc) { if (*tokptr == '\0') { *err = "End of line in string"; return -1; } tokptr++; } *tokptr = '\0'; tokptr++; } else { *err = "string value must start with '\"' or '''"; return -1; } if (rv) { char *newrv = malloc(strlen(rv) + strlen(val) + 1); if (!newrv) { *err = "Out of memory copying string"; return -1; } strcpy(newrv, rv); strcat(newrv, val); free(rv); rv = newrv; } else { rv = strdup(val); if (!rv) { *err = "Out of memory copying string"; return -1; } } if (*tokptr == '\0' || isspace(*tokptr)) break; } *rtokptr = tokptr; *rval = rv; return 0; }
int parse_sysconf(const char* file) { FILE* fp; char line[1024]; char* p; if ((fp = fopen(file, "r")) == 0) { fprintf(stderr, "error opening: %s: %s\n", file, strerror(errno)); return 0; } while (readline(fp, line, sizeof(line))) { if (!*line) continue; for (p = line; *p == ' '; ++p); if (!*p || *p == '#') continue; if (!strncmp(p, "PERMISSION_SECURITY=", 20)) { if (force_level) continue; p+=20; if (isquote(*p)) ++p; p = strtok(p, " "); if (p && !isquote(*p)) { do { if (isquote(p[strlen(p)-1])) { p[strlen(p)-1] = '\0'; } if (*p && strcmp(p, "local")) add_level(p); } while ((p = strtok(NULL, " "))); } } else if (!strncmp(p, "CHECK_PERMISSIONS=", 18)) { p+=18; if (isquote(*p)) ++p; if (!strncmp(p, "set", 3)) { p+=3; if (isquote(*p) || !*p) default_set=1; } else if ((!strncmp(p, "no", 2) && (!p[3] || isquote(p[3]))) || !*p || isquote(*p)) { p+=2; if (isquote(*p) || !*p) { default_set = -1; } } else { //fprintf(stderr, "invalid value for CHECK_PERMISSIONS (must be 'set', 'warn' or 'no')\n"); } } #define FSCAPSENABLE "PERMISSION_FSCAPS=" else if (have_fscaps == -1 && !strncmp(p, FSCAPSENABLE, strlen(FSCAPSENABLE))) { p+=strlen(FSCAPSENABLE); if (isquote(*p)) ++p; if (!strncmp(p, "yes", 3)) { p+=3; if (isquote(*p) || !*p) have_fscaps=1; } else if (!strncmp(p, "no", 2)) { p+=2; if (isquote(*p) || !*p) have_fscaps=0; } else have_fscaps=1; /* default */ } } fclose(fp); return 0; }
// parse CIF contents bool cif_file::parse() { char *p = contents; char quote; char prev = '\0'; std::vector<bool> keypossible; // tokenize while (true) { while (iswhitespace(*p)) prev = *(p++); if (!*p) break; if (*p == '#') { while (!(islinefeed0(*++p))); prev = *p; } else if (isquote(*p)) { // will NULL the closing quote quote = *p; keypossible.push_back(false); tokens.push_back(p + 1); while (*++p && !(*p == quote && iswhitespace0(p[1]))); if (*p) *(p++) = 0; prev = *p; } else if (*p == ';' && islinefeed(prev)) { // will NULL the line feed before the closing semicolon keypossible.push_back(false); tokens.push_back(p + 1); while (*++p && !(islinefeed(*p) && p[1] == ';')); if (*p) { *p = 0; p += 2; } prev = ';'; } else { // will null the whitespace char * q = p++; while (!iswhitespace0(*p)) ++p; prev = *p; if (p - q == 1 && (*q == '?' || *q == '.')) { // store values '.' (inapplicable) and '?' (unknown) as null-pointers q = nullptr; keypossible.push_back(false); } else { if (*p) *(p++) = 0; keypossible.push_back(true); } tokens.push_back(q); } } cif_data *current_data = nullptr, *current_frame = nullptr, *global_block = nullptr; // parse into dictionary for (unsigned int i = 0, n = tokens.size(); i < n; i++) { if (!keypossible[i]) { std::cout << "ERROR" << std::endl; break; } else if (tokens[i][0] == '_') { if (i + 1 == n) { std::cout << "ERROR truncated" << std::endl; break; } if (current_frame) { tolowerinplace(tokens[i]); current_frame->dict[tokens[i]].set_value(tokens[i + 1]); } i++; } else if (strcasecmp("loop_", tokens[i]) == 0) { int ncols = 0; int nrows = 0; cif_loop *loop = nullptr; // loop data if (current_frame) { loop = new cif_loop; // add to loops list current_frame->loops.push_back(loop); } // columns while (++i < n && keypossible[i] && tokens[i][0] == '_') { tolowerinplace(tokens[i]); if (current_frame) { current_frame->dict[tokens[i]].set_loop(loop, ncols); } ncols++; } if (loop) { // loop data loop->values = (const char **) &tokens[i]; loop->ncols = ncols; } // rows while (i < n && !(keypossible[i] && isspecial(tokens[i]))) { i += ncols; if (i > n) { std::cout << "ERROR truncated loop" << std::endl; break; } nrows++; } // loop data if (loop) { loop->nrows = nrows; } i--; } else if (strncasecmp("data_", tokens[i], 5) == 0) { const char * key(tokens[i] + 5); datablocks[key] = current_data = current_frame = new cif_data; } else if (strncasecmp("global_", tokens[i], 5) == 0) { // STAR feature, not supported in CIF global_block = current_data = current_frame = new cif_data; } else if (strncasecmp("save_", tokens[i], 5) == 0) { if (tokens[i][5] && current_data) { // begin const char * key(tokens[i] + 5); current_data->saveframes[key] = current_frame = new cif_data; } else { // end current_frame = current_data; } } else { std::cout << "ERROR" << std::endl; break; } } if (global_block) delete global_block; return true; }