COOPY » Guide
version 0.6.5
|
00001 #include <coopy/LogDiffRender.h> 00002 #include <coopy/HtmlDiffRender.h> 00003 #include <coopy/Coopy.h> 00004 #include <coopy/FileIO.h> 00005 00006 #include <stdio.h> 00007 00008 using namespace coopy::app; 00009 using namespace coopy::store; 00010 using namespace coopy::light; 00011 using namespace std; 00012 00013 class LightTable : public Table { 00014 public: 00015 PolySheet sheet; 00016 00017 virtual int width() const { return sheet.width(); } 00018 virtual int height() const { return sheet.height(); } 00019 00020 virtual Cell get_cell(int x, int y) const { 00021 Cell cell = { "", false }; 00022 SheetCell cell2 = sheet.cellSummary(x,y); 00023 cell.txt = cell2.text; 00024 cell.is_null = cell2.escaped; 00025 return cell; 00026 } 00027 }; 00028 00029 int main(int argc, char *argv[]) { 00030 if (argc<2||argc>4) return 1; 00031 const char *in_name = argv[1]; 00032 char format = 'l'; // "log" or "html" 00033 const char *out_name = "-"; 00034 if (argc>=3) { 00035 format = argv[2][0]; 00036 } 00037 if (argc==4) { 00038 out_name = argv[3]; 00039 } 00040 Coopy coopy; 00041 PolyBook book = coopy.loadBook(in_name); 00042 if (!book.isValid()) return 2; 00043 if (book.getSheetCount()!=1) return 3; 00044 PolySheet sheet = book.readSheetByIndex(0); 00045 LightTable table; 00046 table.sheet = sheet; 00047 DiffRender *render = NULL; 00048 if (format=='l') render = new LogDiffRender(); 00049 if (format=='h') render = new HtmlDiffRender(); 00050 if (!render) return 4; 00051 render->render(table); 00052 FileIO fout; 00053 if (!fout.openForWrite(out_name,Property())) { 00054 return 5; 00055 } 00056 fprintf(fout.get(),"%s",render->to_string().c_str()); 00057 delete render; 00058 render = NULL; 00059 return 0; 00060 }