cstsql.cpp File Reference


Detailed Description

This file creates the executable cstsql.

Definition in file cstsql.cpp.

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include "clssdf.h"

Include dependency graph for cstsql.cpp:

Go to the source code of this file.

Functions

void usage ()
const char * get_inputfile (int argc, const char *argv[], int *argmask)
const char * get_deffile (int argc, const char *argv[], int *argmask)
const char * get_help (int argc, const char *argv[], int *argmask)
const char * get_outputfile (int argc, const char *argv[], int *argmask)
const char * get_appendfile (int argc, const char *argv[], int *argmask)
const char * get_outputformat (int argc, const char *argv[], int *argmask)
const char * get_lower_case_mysql_names (int argc, const char *argv[], int *argmask)
const char * get_outputclass (int argc, const char *argv[], int *argmask)
int main (int argc, const char *argv[])


Function Documentation

int main ( int  argc,
const char *  argv[] 
)

main This is the main function for cstsql.

Definition at line 125 of file cstsql.cpp.

References class_def::class_definition::_name, class_def::class_definition::_univ, class_def::error(), get_appendfile(), get_deffile(), get_help(), get_inputfile(), get_lower_case_mysql_names(), get_outputclass(), get_outputfile(), get_outputformat(), class_def::attribute::put_allow_custom_classes(), class_def::class_definition::set_lower_case_mysql_names(), class_def::class_definition::set_output_format(), and usage().

00125                                         {
00126   class_def::class_definition *_class_definition;
00127   const char *infile, *outputclass, *outfile, *appfile, *outputformat, *deffile, *lower_case_mysql_names;
00128   istream *in, *def;
00129   ostream *out;
00130   ifstream fin;
00131   ofstream fout;
00132   int argmask[10], i, k, errflag, class_found;
00133   vector<string> deffiles;
00134 
00135   argmask[0] = 1;
00136   for (i=1;i<10;i++) {
00137     argmask[i] = 0;
00138   }
00139 
00140   if (argc>10 || get_help( argc, argv, argmask)!=NULL) {
00141     usage();
00142     return 1;
00143   }
00144 
00145   infile       = get_inputfile(    argc, argv, argmask);
00146 
00147   deffile = get_deffile( argc, argv, argmask);
00148   while (deffile!=NULL) {
00149     deffiles.push_back( deffile);
00150     deffile = get_deffile( argc, argv, argmask);
00151   }
00152 
00153   outputformat           = get_outputformat( argc, argv, argmask);
00154   lower_case_mysql_names = get_lower_case_mysql_names( argc, argv, argmask);
00155   outputclass            = get_outputclass(  argc, argv, argmask);
00156   outfile                = get_outputfile(   argc, argv, argmask);
00157   appfile                = get_appendfile(   argc, argv, argmask);
00158 
00159   if (outfile!=NULL && appfile!=NULL) {
00160     cerr << "outputfile and appendfile are mutually exclusive" << endl;
00161     class_def::error();
00162   }
00163 
00164   for (errflag=0,i=1;i<argc;i++) {
00165     if (argmask[i]==0) {
00166       cerr << "error argument={" << argv[i] << "} was not recognized" << endl;
00167       errflag = 1;
00168     }
00169   }
00170   if (errflag) {
00171     return 2;
00172   }
00173 
00174   // read definition files to get definitions of parent classes
00175   for (i=k=0;k<deffiles.size();k++) {
00176     ifstream fdef( deffiles[k].c_str());
00177 
00178     if (!fdef.is_open()) {
00179       cerr << "can't open " << deffiles[i] << endl;
00180       return 3;
00181     }
00182     def = &fdef;
00183  
00184     while (*def) {
00185       try {
00186         _class_definition = new class_def::class_definition();
00187         *def >> *_class_definition;
00188         class_def::class_definition::_univ.push_back( _class_definition);
00189         i++;
00190       } catch (std::exception& xpt) {
00191         cerr << xpt.what();
00192         return 5;
00193       } catch (class_def::end_of_input) {
00194         break;
00195       } catch (class_def::comment cm) {
00196 
00197       } catch (...) {
00198         cerr << "unknown exception was thrown" << endl;
00199         break;
00200       }
00201     }
00202 
00203     fdef.close();
00204     def = NULL;
00205   }
00206 
00207   class_def::attribute::put_allow_custom_classes( 1);
00208 
00209   if (infile==NULL) {
00210     in = &cin;
00211   } else {
00212     fin.open( infile);
00213     if (!fin.is_open()) {
00214       cerr << "can't open " << infile << endl;
00215       return 3;
00216     }
00217     in = &fin;
00218   }
00219 
00220   if (outfile==NULL) {
00221     out = &cout;
00222   } else {
00223     fout.open( outfile, ios::binary);
00224     if (!fout.is_open()) {
00225       cerr << "can't open " << outfile << endl;
00226       return 4;
00227     }
00228     out = &fout;
00229   }
00230 
00231   if (appfile!=NULL) {
00232     fout.open( appfile, ios::app | ios::binary);
00233     if (!fout.is_open()) {
00234       cerr << "can't open " << outfile << endl;
00235       return 4;
00236     }
00237     out = &fout;
00238   }
00239 
00240   if (outputformat==NULL) {
00241     cerr << "output format must be specified" << endl;
00242     return 5;
00243   }
00244 
00245   if (outputclass==NULL) {
00246     cerr << "output class must be specified" << endl;
00247     return 5;
00248   }
00249 
00250   class_def::class_definition::set_output_format( outputformat);
00251 
00252   if (lower_case_mysql_names != NULL && strcmp( lower_case_mysql_names, "true")==0) {
00253     class_def::class_definition::set_lower_case_mysql_names( true);
00254   }
00255 
00256   class_found = 0;
00257   while (*in && class_found==0) {
00258     try {
00259       _class_definition = new class_def::class_definition();
00260       *in >> *_class_definition;
00261       class_def::class_definition::_univ.push_back( _class_definition);
00262       //i++;
00263     } catch (std::exception& xpt) {
00264       cerr << xpt.what();
00265       return 5;
00266     } catch (class_def::comment cm) {
00267       continue;
00268     } catch (class_def::end_of_input) {
00269       break;
00270     } catch (...) {
00271       cerr << "unknown exception was thrown" << endl;
00272       break;
00273     }
00274 
00275     if (strcmp( _class_definition->_name.c_str(), outputclass)==0) {
00276       try {
00277         *out << *_class_definition;
00278         class_found = 1;
00279       } catch (std::exception& xpt) {
00280         cerr << xpt.what();
00281         return 5;
00282       } catch (...) {
00283         cerr << "unknown exception was thrown" << endl;
00284         break;
00285       }
00286     }
00287   }
00288 
00289   if (class_found==0) {
00290     cerr << "class = " << outputclass << " was not found" << endl;
00291     class_def::error();
00292   }
00293 
00294   return 0;
00295 }

Here is the call graph for this function:


Generated on Tue Jul 14 12:22:31 2009 for cstpp by  doxygen 1.5.1