00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef HK_UTILITIES
00012 #define HK_UTILITIES
00013 #ifdef HAVE_ARGP
00014 #include <argp.h>
00015 #endif
00016 #include <cassert>
00017 #include "hk_drivermanager.h"
00018 #include "hk_connection.h"
00019 #include "hk_database.h"
00020 #include "hk_string.h"
00021 #include "config.h"
00022 #include <cassert>
00023 #define DEFAULTPARAMETER {"driver",'d',"DRIVERNAME",0,"Name of the database driver"},{"list",'l',0,1,"List available database drivers"},{"host",'h',"HOST",0,"IP-number or name of hosts"},{"port",'r',"PORT",0,"TCP-port on host"},{"user",'u',"USERNAME",0,"user name"},{"password",'p',"PASSWORD",0,"user password"},{"database",'b',"DATABASE",0,"database name"},{"version",10,0,1,"version and author of hk_classes"}
00024
00030 class argumentclass
00031 {
00032 public:
00033 hk_string driver,host,port,user,password,database,filter;
00034 };
00035 #ifdef HAVE_ARGP
00036
00039 inline static error_t parse_generaloptions (int key,char* arg, struct argp_state* state)
00040 {
00041 struct argumentclass* arguments=(argumentclass*)state->input;
00042 assert(arguments);
00043 switch (key)
00044 {
00045
00046 case 10 :
00047 cout <<"Version "<<VERSION<<"\nAuthor: Horst Knorr <hk_classes@knoda.org>\nhttp://hk-classes.sourceforge.net"<<endl;
00048 exit(0);
00049 break;
00050 case 'l' :
00051 {
00052 vector<hk_string>* l = hk_drivermanager::driverlist();
00053 vector<hk_string>::iterator it=l->begin();
00054 while (it!=l->end())
00055 {
00056 cout <<*it<<endl;
00057 ++it;
00058 }
00059 exit(0);
00060 }
00061
00062 break;
00063 case 'd' : arguments->driver=arg;
00064 break;
00065 case 'h' : arguments->host=arg;
00066 break;
00067 case 'r' : arguments->port=arg;
00068 break;
00069 case 'u' : arguments->user=arg;
00070 break;
00071 case 'p' : arguments->password=arg;
00072 break;
00073 case 'f' : arguments->filter=arg;
00074 break;
00075 case 'b' : arguments->database=arg;
00076 break;
00077 default : return ARGP_ERR_UNKNOWN;
00078 }
00079 return 0;
00080 }
00081
00082
00083 bool verify_generalarguments(argumentclass& arguments)
00084 {
00085 if (arguments.driver.size()==0)
00086 {
00087 cerr << "No driver selected"<<endl;
00088 return false;
00089 }
00090 if (arguments.database.size()==0)
00091 {
00092 cerr << "No database selected"<<endl;
00093 return false;
00094 }
00095
00096 return true;
00097 }
00098 #endif //HAVE_ARGP
00099
00100 bool is_localfile(const hk_string& file)
00101 {
00102 return (file.find('/')!=hk_string::npos);
00103 }
00104
00105
00106 bool load_file(const hk_string &name,hk_string &file)
00107 {
00108 if (name.size()==0) return false;
00109 ifstream ifs(name.c_str(),ios::in);
00110 if (ifs)
00111 {
00112 char c;
00113 file="";
00114 while (ifs.get(c))
00115 file+=c;
00116 }
00117 else return false;
00118 return true;
00119
00120 }
00121 #endif