static int tag_line(GtIO *obo_file, GtStr *tag, GtStr *value, GtError *err) { int had_err; gt_error_check(err); gt_assert(obo_file && tag && value); do { had_err = proc_any_char(obo_file, tag, false, err); } while (!had_err && any_char(obo_file, false)); if (!had_err) had_err = gt_io_expect(obo_file, OBO_SEPARATOR_CHAR, err); while (!had_err && gt_io_peek(obo_file) == OBO_BLANK_CHAR) gt_io_next(obo_file); if (!had_err) { do { had_err = proc_any_char(obo_file, value, true, err); } while (!had_err && any_char(obo_file, true)); } if (!had_err) { if (gt_io_peek(obo_file) == OBO_COMMENT_CHAR) had_err = comment_line(obo_file, err); else had_err = gt_io_expect(obo_file, GT_END_OF_LINE, err); } return had_err; }
static int stanza(GtOBOParseTree *obo_parse_tree, GtIO *obo_file, GtError *err) { unsigned long stanza_line_number; int had_err; GtStr *type, *tag, *value; gt_error_check(err); gt_assert(obo_parse_tree && obo_file); type = gt_str_new(); tag = gt_str_new(); value = gt_str_new(); stanza_line_number = gt_io_get_line_number(obo_file); had_err = stanza_line(obo_file, type, err); if (!had_err) { GtOBOStanza *obo_stanza = gt_obo_stanza_new(gt_str_get(type), stanza_line_number, gt_io_get_filename_str(obo_file)); gt_obo_parse_tree_add_stanza(obo_parse_tree, obo_stanza); while (!had_err && (any_char(obo_file, false) || gt_io_peek(obo_file) == OBO_COMMENT_CHAR)) { gt_str_reset(tag); gt_str_reset(value); if (gt_io_peek(obo_file) == OBO_COMMENT_CHAR) had_err = comment_line(obo_file, err); else { had_err = tag_line(obo_file, tag, value, err); gt_obo_stanza_add(obo_stanza, gt_str_get(tag), gt_str_get(value)); } } } gt_str_delete(value); gt_str_delete(tag); gt_str_delete(type); return had_err; }
int get_perms(struct identity_downcall_data *data) { FILE *fp; char line[PATH_MAX]; fp = fopen(PERM_PATHNAME, "r"); if (fp == NULL) { if (errno == ENOENT) { return 0; } else { errlog("open %s failed: %s\n", PERM_PATHNAME, strerror(errno)); data->idd_err = errno; return -1; } } while (fgets(line, sizeof(line), fp)) { if (comment_line(line)) continue; if (parse_perm_line(data, line, sizeof(line))) { errlog("parse line %s failed!\n", line); data->idd_err = EINVAL; fclose(fp); return -1; } } fclose(fp); return 0; }
static bool ignored_line(GtIO *obo_file, GtError *err) { gt_error_check(err); if (gt_io_peek(obo_file) == OBO_BLANK_CHAR) return blank_line(obo_file, err); return comment_line(obo_file, err); }
int ConfigImpl::parse_comment_line() { Line line; string comment_line(&_lr->_linebuf[0], _lr->_linelimit); line.type = Line::COMMENT_LINE; line.comment = comment_line; _sections[_current_section].lines.push_back(line); return 0; }
static int parse_obo_file(GtOBOParseTree *obo_parse_tree, GtIO *obo_file, GtError *err) { int had_err = 0; gt_error_check(err); gt_assert(obo_parse_tree && obo_file); while (!had_err && ignored_char(obo_file)) { had_err = ignored_line(obo_file, err); } if (!had_err) had_err = header(obo_parse_tree, obo_file, err); while (!had_err && gt_io_has_char(obo_file)) { switch (gt_io_peek(obo_file)) { case OBO_BLANK_CHAR: had_err = blank_line(obo_file, err); break; case OBO_COMMENT_CHAR: had_err = comment_line(obo_file, err); break; case GT_CARRIAGE_RETURN: gt_io_next(obo_file); if (gt_io_peek(obo_file) == GT_END_OF_LINE) gt_io_next(obo_file); break; case GT_END_OF_LINE: gt_io_next(obo_file); break; default: had_err = stanza(obo_parse_tree, obo_file, err); } } if (!had_err) had_err = gt_io_expect(obo_file, GT_END_OF_FILE, err); if (!had_err) had_err = gt_obo_parse_tree_validate_stanzas(obo_parse_tree, err); return had_err; }
static int blank_line(GtIO *obo_file, GtError *err) { int had_err; gt_error_check(err); had_err = gt_io_expect(obo_file, OBO_BLANK_CHAR, err); while (!had_err) { char cc = gt_io_peek(obo_file); if (cc == OBO_COMMENT_CHAR) return comment_line(obo_file, err); else if (cc == GT_CARRIAGE_RETURN) { gt_io_next(obo_file); if (gt_io_peek(obo_file) == GT_END_OF_LINE) gt_io_next(obo_file); break; } else if ((cc == GT_END_OF_LINE) || (cc == GT_END_OF_FILE)) { gt_io_next(obo_file); break; } else had_err = gt_io_expect(obo_file, OBO_BLANK_CHAR, err); } return had_err; }
static int parse_next_token(void *lval, parser_ctx_t *ctx) { WCHAR c; skip_spaces(ctx); if(ctx->ptr == ctx->end) return ctx->last_token == tNL ? tEOF : tNL; c = *ctx->ptr; if('0' <= c && c <= '9') return parse_numeric_literal(ctx, lval); if(isalphaW(c)) { int ret = check_keywords(ctx); if(!ret) return parse_identifier(ctx, lval); if(ret != tREM) return ret; c = '\''; } switch(c) { case '\n': ctx->ptr++; return tNL; case '\'': return comment_line(ctx); case ':': case ')': case ',': case '=': case '+': case '*': case '/': case '^': case '\\': case '.': case '_': return *ctx->ptr++; case '-': if(ctx->is_html && ctx->ptr[1] == '-' && ctx->ptr[2] == '>') return comment_line(ctx); ctx->ptr++; return '-'; case '(': /* NOTE: * We resolve empty brackets in lexer instead of parser to avoid complex conflicts * in call statement special case |f()| without 'call' keyword */ ctx->ptr++; skip_spaces(ctx); if(*ctx->ptr == ')') { ctx->ptr++; return tEMPTYBRACKETS; } return '('; case '"': return parse_string_literal(ctx, lval); case '&': if(*++ctx->ptr == 'h' || *ctx->ptr == 'H') return parse_hex_literal(ctx, lval); return '&'; case '<': switch(*++ctx->ptr) { case '>': ctx->ptr++; return tNEQ; case '=': ctx->ptr++; return tLTEQ; case '!': if(ctx->is_html && ctx->ptr[1] == '-' && ctx->ptr[2] == '-') return comment_line(ctx); } return '<'; case '>': if(*++ctx->ptr == '=') { ctx->ptr++; return tGTEQ; } return '>'; default: FIXME("Unhandled char %c in %s\n", *ctx->ptr, debugstr_w(ctx->ptr)); } return 0; }
int main() { if (!strisprefix("", "")) error("\"\" is not a prefix of \"\""); if (!strisprefix("a", "")) error("\"\" is not a prefix of a"); if (!strisprefix("a", "a")) error("a is not a prefix of a"); if (!strisprefix("aa", "a")) error("a is not a prefix of aa"); if (strisprefix("a", "b")) error("b is a prefix of a"); if (strcmp(skip_ws(""), "")) error("skip_ws of \"\" is not \"\""); if (strcmp(skip_ws("\na"), "a")) error("skip_ws of \\na is not a"); if (strcmp(skip_ws("\n\na"), "a")) error("skip_ws of \\n\\na is not a"); if (strcmp(skip_ws("\n a"), "a")) error("skip_ws of \\n a is not a"); if (strcmp(skip_ws("\n \ta"), "a")) error("skip_ws of \\n \\ta is not a"); if (strcmp(skip_ws("\n \t"), "")) error("skip_ws of \\n \\t is not \"\""); if (strcmp(skip_ws(" "), "")) error("skip_ws of \" \" is not \"\""); if (strcmp(skip_nonws(""), "")) error("skip_nonws of \"\" is not \"\""); if (strcmp(skip_nonws("a"), "")) error("skip_nonws of a is not \"\""); if (strcmp(skip_nonws("\n"), "\n")) error("skip_nonws of \\n is not \\n"); if (strcmp(skip_nonws(" "), " ")) error("skip_nonws of \" \" is not \" \""); if (strcmp(skip_nonws("\t"), "\t")) error("skip_nonws of \\t is not \\t"); if (strcmp(skip_nonws("a\n"), "\n")) error("skip_nonws of a\\n is not \\n"); if (strcmp(skip_nonws("ab"), "")) error("skip_nonws of ab is not \"\""); if (!empty_line("")) error("empty_line is false for \"\""); if (!empty_line("\n\t ")) error("empty_line is false for \"\\n\\n \""); if (!empty_line(" ")) error("empty_line is false for \" \""); if (empty_line("\r")) error("empty_line is true for \\r"); if (comment_line("")) error("comment_line is true for \"\""); if (comment_line("\n")) error("comment_line is true for \n"); if (!comment_line("#")) error("comment_line is false for #"); if (!comment_line(" #")) error("comment_line is false for \" #\""); /* this is what the spec says */ if (!comment_line("\n#")) error("comment_line is false for \\n#"); if (!comment_line("\t#")) error("comment_line is false for \\t#"); return EXIT_SUCCESS; }
int main () { char in[80]; /* for reading data */ char out[80]; /* for reading data */ float **u; /* image */ long k; /* loop variable */ long nx, ny; /* image size in x, y direction */ float ht; /* time step size, 0 < ht <= 0.25 */ long kmax; /* largest iteration number */ float max, min; /* largest, smallest grey value */ float mean; /* average grey value */ float std; /* standard deviation */ char comments[1600]; /* string for comments */ printf ("\n"); printf ("ISOTROPIC LINEAR DIFFUSION FILTERING, EXPLICIT SCHEME\n\n"); printf ("*****************************************************\n\n"); printf (" Copyright 2014 by Joachim Weickert \n"); printf (" Dept. of Mathematics and Computer Science \n"); printf (" Saarland University, Saarbruecken, Germany \n\n"); printf (" All rights reserved. Unauthorized usage, \n"); printf (" copying, hiring, and selling prohibited. \n\n"); printf (" Send bug reports to \n"); printf (" [email protected] \n\n"); printf ("*****************************************************\n\n"); /* ---- read input image (pgm format P5) ---- */ printf ("input image (pgm): "); read_string (in); read_pgm_and_allocate_memory (in, &nx, &ny, &u); /* ---- read parameters ---- */ printf ("time step size (<=0.25) (float): "); read_float (&ht); printf ("number of iterations (integer): "); read_long (&kmax); printf ("output image (pgm): "); read_string (out); printf ("\n"); /* ---- process image ---- */ for (k=1; k<=kmax; k++) { /* perform one iteration */ printf ("iteration number: %5ld \n", k); lindiff (nx, ny, ht, 1.0, 1.0, u); /* ---- analyse filtered image ---- */ /* check minimum, maximum, mean, standard deviation */ analyse (u, nx, ny, &min, &max, &mean, &std); printf ("minimum: %8.2f \n", min); printf ("maximum: %8.2f \n", max); printf ("mean: %8.2f \n", mean); printf ("standard dev.: %8.2f \n\n", std); } /* ---- write output image (pgm format P5) ---- */ /* generate comment string */ comments[0]='\0'; comment_line (comments, "# isotropic linear diffusion filtering, explicit scheme\n"); comment_line (comments, "# initial image: %s\n", in); comment_line (comments, "# ht: %8.4f\n", ht); comment_line (comments, "# iterations: %8ld\n", kmax); comment_line (comments, "# min: %8.4f\n", min); comment_line (comments, "# max: %8.4f\n", max); comment_line (comments, "# mean: %8.4f\n", mean); comment_line (comments, "# standard dev.: %8.4f\n", std); /* write image */ write_pgm (u, nx, ny, out, comments); printf ("output image %s successfully written\n\n", out); /* ---- free memory ---- */ disalloc_matrix (u, nx+2, ny+2); return(0); }