/* Create table using CSV files. The table has the same fonctionality as the bullet and graph where stuff shows up progressivly. Cell spanning multiple lines and rows are supported using a simple a visual syntax. */ #include #include #include #include #include #include #include #include "util.h" using namespace std; #if 0 static int graph_splitrepl ( const char *&ptline, bool &equal, string &word1, string &word2, string &word3) { int ret = -1; const char *line = ptline; if (*line == '/'){ line++; equal = false; if (*line == '='){ equal = true; line++; } const char *end = str_skipdig(line); if (end > line && *end == '/'){ int num = atoi(line); end++; line = end; while (*end != '\0' && *end != '/') end++; if (*end == '/'){ word1 = string(line,end-line); end++; line = end; while (*end != '\0' && *end != '/') end++; if (*end == '/'){ word2 = string(line,end-line); end++; line = end; while (*end != '\0' && *end != '/') end++; if (*end == '/'){ word3 = string(line,end-line); ret = num; ptline = end+1; } } } } } return ret; } static void graph_repl ( const char *line, char *out, const int highlit, const int nbshow) { char *pt = out; while (*line != '\0'){ if (*line == '/'){ string word1,word2,word3; bool equal; int num = graph_splitrepl(line,equal,word1,word2,word3); if (num != -1){ if (highlit != -1){ if (num == highlit){ pt = stpcpy (pt,word3.c_str()); }else{ pt = stpcpy (pt,word1.c_str()); } }else if (equal && num != nbshow){ pt = stpcpy (pt,word2.c_str()); }else if (num <= nbshow){ pt = stpcpy (pt,word1.c_str()); }else{ pt = stpcpy (pt,word2.c_str()); } }else{ *pt++ = *line++; } }else{ *pt++ = *line++; } } *pt = '\0'; } #endif static unsigned table_cnv2cells (const char *line, vector &cells) { while (1){ line = str_skip(line); if (*line == '\0') break; const char *start = line; if (*line == '"'){ line++; string tmp; while (*line != '\0'){ if (*line != '"'){ tmp += *line; line++; }else{ if (line[1] == '"'){ tmp += *line; line += 2; }else{ line++; break; } } } while (*line != '\0' && *line != ',') tmp += *line++; cells.push_back(tmp); }else{ while (*line != '\0' && *line != ',') line++; cells.push_back(string(start,line-start)); } if (*line == ',' ) line++; } return cells.size(); } struct ROW{ string font; int seqnum; vector cells; }; int main (int argc, char *argv[]) { glocal int ret = -1; glocal.ret = (argc,argv); presentation_setarg (this); navigation_setarg (this); setgrouparg ("Misc."); int ret = -1; if (argc != 1){ usage(); }else{ glocal bool header_seen = false; glocal vector intro; // Text before the table glocal string title; glocal string font; glocal int step = 1; glocal vector comments; glocal vector table; glocal unsigned maxcells = 0; glocal int highlit = navigation_gethighlit(); glocal int nbshow = navigation_getnbshow(); (argv[0],true); if (strncmp(line,"title:",6)==0){ glocal.title = str_skip(line+6); }else if (strncmp(line,"font:",5)==0){ glocal.font = str_skip(line+5); }else if (strncmp(line,"step:",5)==0){ glocal.step = atoi(str_skip(line+5)); }else if (strncmp(line,"table:",6)==0){ glocal.header_seen = true; }else{ const char *pt = str_skip(line); if (*pt == '#'){ glocal.comments.push_back(pt+1); }else if(*pt != '\0'){ ROW row; bool header = pt[0] == 'h' && pt[1] == ':'; if (!glocal.header_seen && ! header){ glocal.intro.push_back(pt); }else{ if (header){ // This is a header glocal.header_seen = true; row.seqnum = -1; pt += 2; }else{ row.seqnum = glocal.step; glocal.step++; } //char out[strlen(line)+1]; //graph_repl (pt,out,glocal.highlit,glocal.nbshow); row.font = glocal.font; unsigned nbcell = table_cnv2cells (pt,row.cells); if (nbcell > glocal.maxcells) glocal.maxcells = nbcell; glocal.table.push_back(row); } } } return 0; navigation_setsteps(glocal.table.size()); glocal.highlit = navigation_gethighlit(); glocal.nbshow = navigation_getnbshow(); if (navigation_getshowtitle()){ printf ("%s\n",glocal.title.c_str()); exit (0); }else if (navigation_getcomments()){ for (unsigned i=0; i%s\n",glocal.comments[i].c_str()); } exit (0); } printf ("\n"); printf ("\n"); navigation_print (argv[0],glocal.step-1); printf ("\n"); printf ("\n"); util_format_title (glocal.title.c_str()); printf ("
\n"); if (glocal.intro.size() > 0){ printf ("\n"); for (unsigned i=0; i\n"); printf ("

\n"); } printf ("
\n"); printf ("\n"); int itemsize=6; int viewwidth = util_get_viewwidth(); if (viewwidth < 700){ itemsize = 1; }else if (viewwidth < 1900){ itemsize = 4; } for (unsigned i=0; i &cells = row.cells; const char *font = row.font.c_str(); const char *color = "black"; if (glocal.nbshow != -1 && row.seqnum > glocal.nbshow) color = "white"; if (glocal.highlit != -1 && glocal.highlit == row.seqnum) color = "red"; const char *td = row.seqnum == -1 ? "th" : "td"; printf (""); unsigned j; for (j=0; j%s ",td,colspan,font,itemsize,color,p); } } for ( ; j ",td,font,itemsize); printf ("\n"); } printf ("
\n"); printf ("
\n"); printf ("\n"); printf ("\n"); } return ret;
return glocal.ret; }