COOPY » Guide
version 0.6.5
|
00001 #include <stdio.h> 00002 #include <getopt.h> 00003 00004 #include <coopy/Dbg.h> 00005 #include <coopy/CsvRender.h> 00006 #include <coopy/PolyBook.h> 00007 00008 using namespace std; 00009 using namespace coopy::store; 00010 00011 int main(int argc, char *argv[]) { 00012 bool verbose = false; 00013 bool decorate = false; 00014 bool full = false; 00015 bool header = false; 00016 bool dox = false; 00017 00018 while (true) { 00019 int option_index = 0; 00020 static struct option long_options[] = { 00021 {"full", 0, 0, 'f'}, 00022 {"decorate", 0, 0, 'd'}, 00023 {"header", 0, 0, 'h'}, 00024 {"verbose", 0, 0, 'v'}, 00025 {"dox", 0, 0, 'x'}, 00026 {0, 0, 0, 0} 00027 }; 00028 00029 int c = getopt_long(argc, argv, "", 00030 long_options, &option_index); 00031 if (c==-1) break; 00032 switch (c) { 00033 case 'v': 00034 verbose = true; 00035 break; 00036 case 'f': 00037 full = true; 00038 decorate = true; 00039 break; 00040 case 'd': 00041 decorate = true; 00042 break; 00043 case 'h': 00044 header = true; 00045 break; 00046 case 'x': 00047 dox = true; 00048 break; 00049 00050 default: 00051 fprintf(stderr, "Unrecognized option\n"); 00052 return 1; 00053 } 00054 } 00055 00056 if (optind<argc-1) { 00057 fprintf(stderr, "Options not understood\n"); 00058 return 1; 00059 } 00060 argc -= optind; 00061 argv += optind; 00062 00063 if (argc<1) { 00064 printf("Generate HTML for a table:\n"); 00065 printf(" ss2html [--decorate] [--full] table.csv\n"); 00066 printf(" ss2html [--decorate] [--full] table.xls\n"); 00067 return 1; 00068 } 00069 00070 if (verbose) { 00071 coopy_set_verbose(verbose); 00072 } 00073 00074 const char *fname = "-"; 00075 if (argc>0) { 00076 fname = argv[0]; 00077 } 00078 PolyBook book; 00079 if (!book.read(fname)) { 00080 fprintf(stderr,"Failed to read input\n"); 00081 return 1; 00082 } 00083 int sz = (int)book.getNames().size(); 00084 /* 00085 if (sz>1) { 00086 fprintf(stderr,"Too many sheets\n"); 00087 return 1; 00088 } 00089 */ 00090 if (sz==0) { 00091 fprintf(stderr,"No sheet available\n"); 00092 return 1; 00093 } 00094 00095 CsvRender render; 00096 render.setDecorate(decorate); 00097 render.setFull(full); 00098 render.setHeader(header); 00099 render.setDox(dox); 00100 00101 vector<string> names = book.getNames(); 00102 render.setCaption(names.size()>1); 00103 00104 for (int i=0; i<(int)names.size(); i++) { 00105 if (i>0) printf("\n"); 00106 PolySheet sheet = book.readSheet(names[i]); 00107 if (header) { 00108 bool ok = false; 00109 if (sheet.height()>0 && sheet.width()>0) { 00110 string n = sheet.cellString(0,0); 00111 if (n!=""&&n!="NULL"&&n!="!"&&n!="@"&&n!="@@"&&n.substr(0,5)!="Allow") { 00112 sheet.mustHaveSchema(); 00113 sheet.hideHeaders(); 00114 } 00115 } 00116 } 00117 string result = render.renderHtml(sheet,names[i]); 00118 printf("%s", result.c_str()); 00119 } 00120 return 0; 00121 }