00001 #include <iostream.h>
00002 #include <qstring.h>
00003 #include <qmemarray.h>
00004 #include <qptrvector.h>
00005 #include "../header/database.h"
00006
00007
00008 void fExecuteCommand( const QString qs_Command, const QMemArray<bool> &qma_Opts, const QString qs_CommandMore );
00009 void fSearchClass( const QMemArray<bool> &qma_Opts, const QString qs_String );
00010 void fSearchSoftware( const QMemArray<bool> &qma_Opts, const QString qs_String );
00011 void fShowClass( const QMemArray<bool> &qma_Opts, const QString qs_String );
00012 void fShowSoftware( const QMemArray<bool> &qma_Opts, const QString qs_String );
00013 void fUpdate( const QMemArray<bool> &qma_Opts );
00014
00019
00020
00031 int main( int argc, char *argv[] )
00032 {
00034 QString qs_Usage( "class-soft version 0.01 purple\n\
00035 Usage: class-soft [options] command\n\
00036 Commands:\n\
00037 search-software<string>\t\tSearch for a particular piece of software\n\
00038 search-class <string>\t\tSearch for a particulare class by name\n\
00039 show-software <string>\t\tShow the information on a give piece of software\n\
00040 show-class <string>\t\tShow the pieces of software for a given class\n\
00041 Options:\n\
00042 <insert command line options here>\n" );
00043
00044 QMemArray<bool> qma_Opts( 5 );
00045
00046 QString qs_Command("");
00047
00048 QString qs_CommandMore("");
00049
00050 int c = 0;
00051
00052 if( argc < 2 )
00053 {
00054 cout << qs_Usage;
00055 exit(1);
00056 }
00057
00058 for( c = 0; c < argc; c++ )
00059 {
00060 if( '-' == argv[c][0] )
00061 {
00062 switch (argv[c][1])
00063 {
00064
00065 case 'a':
00066 qma_Opts[0] = true;
00067 cout << "I got an a!\n";
00068 break;
00069 case 'b':
00070 qma_Opts[1] = true;
00071 cout << "I got a b!\n";
00072 break;
00073 case 'c':
00074 qma_Opts[2] = true;
00075 cout << "I got a c!\n";
00076 break;
00077 default:
00078 cout << "I got something else :-(\n";
00079 break;
00080 }
00081 }
00082 }
00083
00084 c = 1;
00085 while( (c < argc) && ('-' == argv[c][0]) )
00086 {
00087 c++;
00088 }
00089 if( argc == c )
00090 {
00091 cout << qs_Usage;
00092 exit(1);
00093 }
00094 qs_Command = argv[c];
00095 if( argc - 1 > c )
00096 qs_CommandMore = argv[++c];
00097 fExecuteCommand( qs_Command, qma_Opts, qs_CommandMore );
00098 }
00099
00102
00103
00108 void fExecuteCommand( const QString qs_Command, const QMemArray<bool> &qma_Opts, const QString qs_CommandMore )
00109 {
00110
00111 if( "search-class" == qs_Command )
00112 fSearchClass( qma_Opts, qs_CommandMore );
00113 else if( "search-software" == qs_Command )
00114 fSearchSoftware( qma_Opts, qs_CommandMore );
00115 else if( "show-class" == qs_Command )
00116 fShowClass( qma_Opts, qs_CommandMore );
00117 else if( "show-software" == qs_Command )
00118 fShowSoftware( qma_Opts, qs_CommandMore );
00119 else if( "update" == qs_Command )
00120 fUpdate( qma_Opts );
00121 else
00122 cout << "Unknown command \"" << qs_Command << "\"!\n";
00123 }
00124
00126
00130 void fSearchClass( const QMemArray<bool> &qma_Opts, const QString qs_String )
00131 {
00132 database db;
00133 QPtrVector<QString> qpv_Results;
00134 int x = 0;
00135
00136 if( "" == qs_String )
00137 {
00138 cerr << "You must specify a search term!\n";
00139 exit(1);
00140 }
00141
00142 qpv_Results = db.search_class( qs_String );
00143
00144 cout << "Results for search string \"" << qs_String << "\":\n";
00145
00146 for( x = 0; x < qpv_Results.size(); x++ )
00147 cout << *(qpv_Results[x]) << endl;
00148 }
00149
00151
00155 void fSearchSoftware( const QMemArray<bool> &qma_Opts, const QString qs_String )
00156 {
00157 database db;
00158 QPtrVector<QString> qpv_Results;
00159 int x = 0;
00160
00161 if( "" == qs_String )
00162 {
00163 cerr << "You must specify a search term!\n";
00164 exit(1);
00165 }
00166
00167 qpv_Results = db.search_software( qs_String );
00168
00169 cout << "Results for search string \"" << qs_String << "\":\n";
00170
00171 for( x = 0; x < qpv_Results.size(); x++ )
00172 cout << *(qpv_Results[x]) << endl;
00173 }
00174
00176
00180 void fShowClass( const QMemArray<bool> &qma_Opts, const QString qs_String )
00181 {
00182 database db;
00183 QPtrVector<QString> qpv_Results;
00184 int x = 0;
00185
00186 if( "" == qs_String )
00187 {
00188 cerr << "You must specify a class to show!\n";
00189 exit(1);
00190 }
00191
00192 qpv_Results = db.get_class( qs_String );
00193
00194 if( qpv_Results.count() == 0 )
00195 {
00196 cerr << "Your class wasn't found :-(\n";
00197 exit(1);
00198 }
00199
00200 cout << qs_String << " - " << *(qpv_Results[0]) << endl;
00201
00202 for( x = 1; x < qpv_Results.count(); x++ )
00203 {
00204 cout << *(qpv_Results[x]) << endl;
00205 }
00206 }
00207
00209
00213 void fShowSoftware( const QMemArray<bool> &qma_Opts, const QString qs_String )
00214 {
00215 database db;
00216 QPtrVector<QString> qpv_Results( 5 );
00217
00218 if( "" == qs_String )
00219 {
00220 cerr << "You must specify a package to show!\n";
00221 exit(1);
00222 }
00223
00224 qpv_Results = db.get_software( qs_String );
00225
00226 if( "" == *(qpv_Results[0]) )
00227 {
00228 cerr << "Unable to find a package matching \"" << qs_String << "\"!\n";
00229 exit(1);
00230 }
00231
00232 cout << "Package Name: " << *(qpv_Results[0]) << endl;
00233 cout << "Name: " << *(qpv_Results[1]) << endl;
00234 cout << "Version: " << *(qpv_Results[2]) << endl;
00235 cout << "Description: " << *(qpv_Results[3]) << endl;
00236 cout << "URL: " << *(qpv_Results[4]) << endl;
00237 }
00238
00240
00243 void fUpdate( const QMemArray<bool> &qma_Opts )
00244 {
00245 database db;
00246 bool b_Result;
00247
00248
00249 if( !b_Result )
00250 cout << "Failed to update properlly :-(\n";
00251 }
00252