COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/widesheet/widesheet.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <getopt.h>
00003 
00004 #include <coopy/Dbg.h>
00005 
00006 #include <string>
00007 
00008 #include "WideSheetManager.h"
00009 
00010 using namespace std;
00011 
00012 void showStatus(WideSheetManager& ws, const char *key) {
00013   string link = ws.getPropertyWithDefault(key);
00014   if (link=="") {
00015     printf("No %s setting.\n", key);
00016   } else {
00017     printf("%s %s\n", key, link.c_str());
00018   }
00019 }
00020 
00021 int main(int argc, char *argv[]) {
00022   bool verbose = false;
00023 
00024   while (true) {
00025     int option_index = 0;
00026     static struct option long_options[] = {
00027       {"verbose", 0, 0, 'v'},
00028       {0, 0, 0, 0}
00029     };
00030 
00031     int c = getopt_long(argc, argv, "",
00032                         long_options, &option_index);
00033     if (c==-1) break;
00034     switch (c) {
00035     case 'v':
00036       verbose = true;
00037       coopy_set_verbose(true);
00038       break;
00039     default:
00040       fprintf(stderr, "Unrecognized option\n");
00041       return 1;
00042     }
00043   }
00044 
00045   argc -= optind;
00046   argv += optind;
00047 
00048   if (argc<1) {
00049     fprintf(stderr,"Welcome to widesheet. Usage:\n");
00050     fprintf(stderr,"  widesheet                    # this help message\n");
00051     fprintf(stderr,"  widesheet init               # create workspace, a widesheet.sqlite file\n");
00052     fprintf(stderr,"  widesheet status             # see workspace settings\n");
00053     fprintf(stderr,"  widesheet local <filename>   # user file, .xls etc, any directory\n");
00054     fprintf(stderr,"  widesheet remote <filename>  # controlled file, .csv[s], current directory\n");
00055     fprintf(stderr,"  widesheet pivot <filename>   # checkpoint file, will copy controlled file\n");
00056     fprintf(stderr,"  offer                        # update controlled file from user file\n");
00057     fprintf(stderr,"  accepted                     # copy pivot file from remote file\n");
00058     fprintf(stderr,"  diff                         # see difference between local and remote\n");
00059     return 1;
00060   }
00061 
00062   string arg = argv[0];
00063   argc--;
00064   argv++;
00065 
00066   if (arg=="init") {
00067     WideSheetManager ws(true);
00068     if (!ws.isValid()) {
00069       return 1;
00070     }
00071     return 0;
00072   }
00073 
00074   WideSheetManager ws(false);
00075   if (!ws.isValid()) {
00076     return 1;
00077   }
00078 
00079   if (arg=="local") {
00080     if (argc==1) {
00081       return ws.setProperty("local",argv[0])?0:1;
00082     }
00083     if (argc!=0) {
00084       fprintf(stderr,"Wrong number of arguments\n");
00085       return 1;
00086     }
00087     showStatus(ws,"local");
00088   }
00089 
00090   if (arg=="remote") {
00091     if (argc==1) {
00092       return ws.setProperty("remote",argv[0])?0:1;
00093     }
00094     if (argc!=0) {
00095       fprintf(stderr,"Wrong number of arguments\n");
00096       return 1;
00097     }
00098     showStatus(ws,"remote");
00099   }
00100 
00101   if (arg=="pivot") {
00102     if (argc==1) {
00103       return ws.setProperty("pivot",argv[0])?0:1;
00104     }
00105     if (argc!=0) {
00106       fprintf(stderr,"Wrong number of arguments\n");
00107       return 1;
00108     }
00109     showStatus(ws,"pivot");
00110   }
00111 
00112   if (arg=="status") {
00113     showStatus(ws,"local");
00114     showStatus(ws,"remote");
00115     showStatus(ws,"pivot");
00116     return 0;
00117   }
00118 
00119   if (arg=="offer") {
00120     return ws.exportSheet()?0:1;
00121   }
00122 
00123   if (arg=="accepted") {
00124     return ws.acceptSheet()?0:1;
00125   }
00126 
00127   if (arg=="diff") {
00128     return ws.diffSheet()?0:1;
00129   }
00130 
00131   fprintf(stderr, "Unknown operation.\n");
00132   return 1;
00133 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines