Table::Ptr MetaDataConfig::parse_table(ElementTree::ElementPtr node) { String sequence_name, name, xml_name, class_name; bool autoinc = false; if (!node->has_attr(_T("name"))) throw MandatoryAttributeAbsent(_T("table"), _T("name")); name = node->get_attr(_T("name")); if (node->has_attr(_T("sequence"))) sequence_name = node->get_attr(_T("sequence")); if (node->has_attr(_T("autoinc"))) autoinc = true; if (node->has_attr(_T("xml-name"))) xml_name = node->get_attr(_T("xml-name")); else xml_name = mk_xml_name(name, _T("")); if (node->has_attr(_T("class"))) class_name = node->get_attr(_T("class")); else skip_generation_.push_back(name); Table::Ptr table_meta(new Table(name, xml_name, class_name)); table_meta->set_seq_name(sequence_name); table_meta->set_autoinc(autoinc); parse_column(node, *table_meta); return table_meta; }
/* parser and renderer for nested frames which use grouping */ int parse_frame_body_loop (const int subslide) { while (token != EOF) { switch (token) { case STRUCT: if (!parse_structure()) return 0; break; case IMAGE: if (!parse_figure()) return 0; break; case ANIMATION: if (!parse_animation()) return 0; break; case LISTING: if (!parse_listing()) return 0; break; case ITEM: if (!parse_item(1,item_type)) return 0; break; case URL: if (!parse_url()) return 0; break; case COLUMN: if (parse_column() == -1) return 0; break; case COLUMN_SEP: if (parse_column_sep() == -1) return 0; break; case END: if (parse_end() == -1) return 0; break; case CURLY_C_BRACE: return 1; case VALUE: // mirror value to output fprintf(ofile,"%s",string); token = yylex(); break; case NEWLINE: // ignore empty newline token = yylex(); break; default: fprintf(stderr, "<%s:%d> [%d] Frame mode: illegal token %s found.\n", __FILE__,__LINE__,yylineno, get_token_name(token)); fprintf(stderr, "Expected commands: uncover (+), overlay (#), only (~), structure ('), image, listing, item or URL\n"); fprintf(stderr, "\tor end frame mode with: New frame, section, title, author, date or an end of file\n"); return 0; } } return 1; }
/* * parse the content of a frame */ int parse_frame() { int subslide = 1; structure_count = 0; fprintf(ofile,"%% FRAME\n"); fprintf(ofile,"\\begin{frame}[fragile]\n"); if ((token = yylex()) == VALUE) { fprintf(ofile,"\\frametitle{%s}\n", string); token = yylex(); while (token != EOF) { switch (token) { case SUBTITLE: if (!parse_subtitle()) return 0; break; case UNCOVER: if (!parse_frame_body("uncover",subslide++)) return 0; break; case OVERLAY: if (!parse_frame_body("overlay",subslide++)) return 0; break; case ONLY: if (!parse_frame_body("only",subslide++)) return 0; break; case STRUCT: if (!parse_structure()) return 0; break; case IMAGE: if (!parse_figure()) return 0; break; case ANIMATION: if (!parse_animation()) return 0; break; case LISTING: if (!parse_listing()) return 0; break; case ITEM: if (!parse_item(1,item_type)) return 0; break; case URL: if (!parse_url()) return 0; break; case COPY: if (!parse_copy()) return 0; break; case COLUMN: if (parse_column() == -1) return 0; break; case COLUMN_SEP: if (parse_column_sep() == -1) return 0; break; case END: if (parse_end() == -1) return 0; break; case VALUE: // mirror value to output fprintf(ofile,"%s",string); token = yylex(); break; case FRAME: case SECTION: case TITLE: case AUTHOR: case DATE: case ZERO: case PART: fprintf(ofile,"\\end{frame}\n\n"); return 1; case NEWLINE: // ignore empty newline token = yylex(); break; default: fprintf(stderr, "<%s:%d> [%d] Frame mode: illegal token %s found.\n", __FILE__,__LINE__,yylineno, get_token_name(token)); fprintf(stderr, "Expected commands: uncover (+), overlay (#), only (~), structure ('), image, listing, item or URL\n"); fprintf(stderr, "\tor end frame mode with: New frame, section, title, author, date or an end of file\n"); return 0; } } return 1; } else { fprintf(stderr, "<%s:%d> [%d] Frame mode: expected value, but %s found.\n", __FILE__,__LINE__, yylineno, get_token_name(token)); return 0; } }
int main(int argc, char *argv[]) { struct libscols_table *tb; int c, n, nlines = 0; int parent_col = -1, id_col = -1; static const struct option longopts[] = { { "maxout", 0, NULL, 'm' }, { "column", 1, NULL, 'c' }, { "nlines", 1, NULL, 'n' }, { "width", 1, NULL, 'w' }, { "tree-parent-column", 1, NULL, 'p' }, { "tree-id-column", 1, NULL, 'i' }, { "json", 0, NULL, 'J' }, { "raw", 0, NULL, 'r' }, { "export", 0, NULL, 'E' }, { "colsep", 1, NULL, 'C' }, { "help", 0, NULL, 'h' }, { NULL, 0, NULL, 0 }, }; static const ul_excl_t excl[] = { /* rows and cols in ASCII order */ { 'E', 'J', 'r' }, { 0 } }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; setlocale(LC_ALL, ""); /* just to have enable UTF8 chars */ scols_init_debug(0); tb = scols_new_table(); if (!tb) err(EXIT_FAILURE, "failed to create output table"); while((c = getopt_long(argc, argv, "hCc:Ei:Jmn:p:rw:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); switch(c) { case 'c': /* add column from file */ { struct libscols_column *cl; FILE *f = fopen(optarg, "r"); if (!f) err(EXIT_FAILURE, "%s: open failed", optarg); cl = parse_column(f); if (cl && scols_table_add_column(tb, cl)) err(EXIT_FAILURE, "%s: failed to add column", optarg); scols_unref_column(cl); fclose(f); break; } case 'p': parent_col = strtou32_or_err(optarg, "failed to parse tree PARENT column"); break; case 'i': id_col = strtou32_or_err(optarg, "failed to parse tree ID column"); break; case 'J': scols_table_enable_json(tb, 1); scols_table_set_name(tb, "testtable"); break; case 'm': scols_table_enable_maxout(tb, TRUE); break; case 'r': scols_table_enable_raw(tb, TRUE); break; case 'E': scols_table_enable_export(tb, TRUE); break; case 'C': scols_table_set_column_separator(tb, optarg); break; case 'n': nlines = strtou32_or_err(optarg, "failed to parse number of lines"); break; case 'w': scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS); scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width")); break; case 'h': usage(); default: errtryhelp(EXIT_FAILURE); } } if (nlines <= 0) errx(EXIT_FAILURE, "--nlines not set"); for (n = 0; n < nlines; n++) { struct libscols_line *ln = scols_new_line(); if (!ln || scols_table_add_line(tb, ln)) err(EXIT_FAILURE, "failed to add a new line"); scols_unref_line(ln); } n = 0; while (optind < argc) { FILE *f = fopen(argv[optind], "r"); if (!f) err(EXIT_FAILURE, "%s: open failed", argv[optind]); parse_column_data(f, tb, n); optind++; n++; } if (scols_table_is_tree(tb) && parent_col >= 0 && id_col >= 0) compose_tree(tb, parent_col, id_col); scols_table_enable_colors(tb, isatty(STDOUT_FILENO)); scols_print_table(tb); scols_unref_table(tb); return EXIT_SUCCESS; }