CMParser Class Reference

#include <Parser.h>

Public Member Functions

 CMParser (char *command)
 ~CMParser ()
void ShowUsage ()
int GetCMD ()
char * GetParam (int i)
char * GetOpt (char name, unsigned int NumOpt=0)

Private Attributes

char linebuf [MAXLINELEN]
int command
char * argv [MAXARG]
int argc
int optnum
int pnum
char params [MAXARG][MAXNAMELEN]
struct Option options [MAXARG]

Detailed Description

Definition at line 60 of file Parser.h.


Constructor & Destructor Documentation

CMParser::CMParser ( char *  command  ) 

Definition at line 74 of file Parser.cpp.

00075 {
00076     int i,j,k;
00077     bool eflag;
00078 
00079     this->command = INVCMD;
00080     pnum          = 0;
00081     optnum        = 0;
00082 
00083     strcpy( linebuf, command );
00084     //Parse it
00085     for( i=0, j=0, k=0, eflag = true; i< (signed) strlen(linebuf); i++ )
00086     {
00087         if( ( linebuf[i] == ' ' ) ||
00088              ( linebuf[i] == '\t' )
00089            )
00090         {
00091             eflag = true;
00092             continue;
00093         }
00094         else if( eflag == true )
00095         {
00096             argv[j] = new char[MAXNAMELEN];
00097             k       = 0;
00098             eflag   = false;
00099             j++;
00100         }
00101 
00102         argv[j-1][k++] = linebuf[i];
00103         argv[j-1][k]   = '\0';
00104     }
00105 
00106     argc = j;
00107 
00108     if(argc == 0)
00109     {
00110         this->command = INVCMD;
00111         return;
00112     }
00113 
00114     for( i=0; strlen( commandTable[i].name ) !=0; i++ )
00115     {
00116         if( !strcmp( commandTable[i].name, argv[0] ) )
00117         {
00118             this->command = commandTable[i].commandNo;
00119             break;
00120         }
00121     }
00122 
00123     if( strlen( commandTable[i].name ) == 0 )
00124     {
00125         this->command = INVCMD;
00126         return;
00127     }
00128 
00129     // seperate the option and parameters
00130     for( j=1, optnum=0, pnum=0; j<argc; j++ )
00131     {
00132         if( ( argv[j][0] == '-' ) &&
00133              ( strlen( argv[j] ) >= 2 ) &&
00134              ( strchr( commandTable[i].opt, argv[j][1] ) )
00135            )
00136         {
00137             // get options
00138             strcpy( options[optnum].value, &argv[j][2] );
00139             options[optnum].name=argv[j][1];
00140             optnum++;
00141         }
00142         else if( argv[j][0] != '-' )
00143         {
00144             // get parameters
00145             strcpy( params[pnum++], argv[j] );
00146         }
00147     }
00148 
00149     if( ( pnum < commandTable[i].argcLowerLimit ) ||
00150          ( pnum > commandTable[i].argcUpperLimit )
00151        )
00152     {
00153         if( GetOpt( '-' ) == 0 )
00154         {
00155             RioErr << argv[0] << ": argumento inv�lido ou faltando." << endl;
00156             RioErr << "Tente '" << argv[0] 
00157                    << " --ajuda' para maiores informa��es." << endl;
00158             this->command = HELPCMD;
00159         }
00160         return;
00161     }
00162 }

CMParser::~CMParser (  ) 

Definition at line 164 of file Parser.cpp.

00165 {
00166     for( int i=0; i < argc; i++ )
00167         delete argv[i];
00168 }


Member Function Documentation

int CMParser::GetCMD (  ) 

Definition at line 170 of file Parser.cpp.

00171 {
00172     return command;
00173 }

char * CMParser::GetOpt ( char  name,
unsigned int  NumOpt = 0 
)

Definition at line 175 of file Parser.cpp.

00176 {
00177     int i;
00178     unsigned int PosOpt;
00179 
00180     // Inicializa o parametro que indica qual opcao igual a que desejamos 
00181     // achamos na lista de opcoes. O parametro e inicializado para a primeira
00182     // opcao.
00183     PosOpt = 0;
00184 
00185     for( i=0; i < optnum; i++ )
00186         if( name == options[i].name )
00187         {
00188             if( PosOpt == NumOpt )
00189                 return options[i].value;
00190             else
00191                 PosOpt++;
00192         }    
00193 
00194     return 0;
00195 }

char * CMParser::GetParam ( int  i  ) 

Definition at line 197 of file Parser.cpp.

00198 {
00199     if( i < pnum )
00200         return params[i];
00201     else
00202         return 0;
00203 }

void CMParser::ShowUsage (  ) 

Definition at line 205 of file Parser.cpp.

00206 {
00207     switch( this->command )
00208     {
00209         case EXIT:
00210             cout <<"NOME\n\tsair, exit ou quit  - sai do riosh e retorna para o shell." << endl;
00211             break;
00212 
00213         case LS:
00214             cout <<"NOME\n\tls  -  lista conte�do do diret�rio." << endl;
00215             cout <<"               Se o nome do diret�rio � omitido, lista diret�rio corrente." << endl;
00216             cout <<"USO\n\tls [-l] [-e] [-h] [-B] [-r] [-s] [NOME_DO_DIRET�RIO]" << endl;
00217             cout <<"OP��ES\n\t-l\tlista metadados dos objetos (permiss�es, tamanho em bytes," << endl;
00218             cout <<"\t\tdata e hora do �ltimo acesso para escrita)" << endl;
00219             cout <<"\t-e\tmostra a taxa de transmissao do video (somente com a op��o -l)" << endl;
00220             cout <<"\t-h\tmostra tamanho em unidades de GB, MB ou KB (somente com a op��o -l)" << endl;
00221             cout <<"\t-B\tmostra tamanho em unidades de blocos (somente com a op��o -l)" << endl;
00222             cout <<"\t-r\tmostra recursivamente o conte�do do diret�rio)" << endl;
00223             cout <<"\t-s\tmostra a lista em formato simples e sem cores" << endl;
00224             break;
00225 
00226         case COPY:
00227             cout <<"NOME\n\tcp  -  copia arquivos e diret�rios." << endl;
00228             cout <<"USO\n\tcp [-f] [-r] [-uNOME] FONTE DESTINO" << endl;
00229             cout <<"\tFONTE ou DESTINO. Cada um pode ser um objeto do RIO ou um arquivo/diret�rio do Linux.";
00230             cout << endl;
00231             cout <<"\t\tobjeto do RIO  (incluindo o caminho relativo ou absoluto) pode ser:" << endl;
00232             cout <<"\t\t\tNOME_DO_OBJETO\tquando est� localizado no servidor em uso, ou" << endl;
00233             cout <<"\t\t\tNOME_DA_MAQUINA:NOME_DO_OBJETO\tquando est� localizado em um servidor remoto." << endl;
00234             cout <<"\t\tarquivo/diret�rio do Linux (incluindo o caminho relativo ou absoluto):" << endl;
00235             cout <<"\t\t\t:NOME" << endl;
00236             cout <<"OP��ES\n\t-f\tn�o pergunta confirma��o" << endl;
00237             cout <<"\t-r\tcopia  recursivamente (apenas diret�rios)" << endl;
00238             cout <<"\t-u\tnome de usu�rio usado quando FONTE ou DESTINO est� em um servidor remoto" << endl;
00239             //cout <<"\t-p\tpassword used when SOURCE or DEST is in a remote server" << endl;
00240             cout <<"EXEMPLOS\n\t(arquivo Linux para objeto Rio)\t\t\t\t'cp :/home/vod/teste.txt teste.txt'";
00241             cout << endl;
00242             cout <<"\t(objeto RIO remoto para objeto RIO local)\t\t'cp -uvod laguna:teste.txt teste.txt'" << endl;
00243             cout <<"\t(diret�rio Linux teste para diret�rio RIO local teste)\t'cp -r :/home/vod/teste .'" << endl;
00244             break;
00245 
00246         case CD:
00247             cout <<"NOME\n\tcd  -  troca diret�rio corrente. " << endl;
00248             cout <<"               Se o nome do diret�rio � omitido, troca para diret�rio inicial do usu�rio.";
00249             cout << endl;
00250             cout <<"USO\n\tcd [NOME_DO_DIRET�RIO]" << endl;
00251             break;
00252 
00253         case MKDIR:
00254             cout <<"NOME\n\tmkdir  -  cria diret�rio." << endl;
00255             cout <<"USO\n\tmkdir NOME_DO_DIRET�RIO" << endl;
00256             break;
00257 
00258         case CREATE:
00259             cout <<"NOME\n\tcreate  -  cria um objeto." << endl;
00260             cout <<"USO\n\tcreate NOME_DO_OBJETO TAMANHO" << endl;
00261             cout <<"\tTAMANHO deve ser em unidades de blocos (tamanho de um bloco = 128KB)" << endl;
00262             cout <<"EXEMPLO\n\t'create teste.txt 5'   (tamanho de teste.txt = 655360 bytes)" << endl;
00263             break;
00264 
00265         case DISPLAY:
00266             cout <<"NOME\n\tcat  -  mostra conte�do de um arquivo texto." << endl;
00267             cout <<"USO\n\tcat [-h] [-i<byte inicial>] [-s<N�mero de bytes>] NOME_DO_OBJETO" << endl;
00268             cout <<"OP��ES\n\t-i\tposi��o (em bytes) para come�o da visualiza��o (padr�o: 0)" << endl;
00269             cout <<"\t-s\ttamanho (em bytes) para visualizar" << endl;
00270             cout <<"\t-h\tmostra o conte�do em hexadecimal" << endl;
00271             cout <<"EXEMPLO\n\t'cat -i20 -s200 Makefile'   (come�a no byte 20, mostra 200 bytes)" << endl;
00272             break;
00273 
00274         case PERFORMANCE:
00275             break;
00276 
00277         case RM:
00278             cout <<"NOME\n\trm  -  remove um objeto." << endl;
00279             cout <<"USO\n\trm [-f] [-r] [NOME_DO_OBJETO]" << endl;
00280             cout <<"OP��ES\n\t-f\tn�o pergunta confirma��o" << endl;
00281             cout <<"\t-r\tremove cont�udo de um diret�rio recursivamente" << endl;
00282             break;
00283 
00284         case DF:
00285             cout <<"NOME\n\tdf  -  mostra o status dos discos do sistema (em bytes)." << endl;
00286             cout <<"USO\n\tdf [-h] [-B]" << endl;
00287             cout <<"\t-h\tmostra em unidades de GB ou MB" << endl;
00288             cout <<"\t-B\tmostra tamanho em unidades de blocos" << endl;
00289             break;
00290 
00291         case DU:
00292             cout <<"NOME\n\tdu  -  mostra o espa�o ocupado por um objeto (diret�rio/arquivo) (em bytes)." << endl;
00293             cout <<"USO\n\tdu [-B] [-a] [-h] NOME_DO_OBJETO" << endl;
00294             cout <<"OP��ES\n\t-h\tmostra em unidades de GB, MB ou KB" << endl;
00295             cout <<"\t-B\tmostra tamanho em unidades de blocos" << endl;
00296             cout <<"\t-a\tmostra todos os objetos" << endl;
00297             break;
00298 
00299         case SESSIONS:
00300             cout <<"NOME\n\tsessions  -  mostra o n�mero de sess�es ativas e n�mero m�ximo de sess�es no ";
00301             cout <<"servidor RIO." << endl;
00302             cout <<"USO\n\tsessions" << endl;
00303             break;
00304 
00305         case MEASURES:
00306             cout <<"NOME\n\tsalvarmedidas  -  salva medidas coletadas no servidor em arquivos." << endl;
00307             cout <<"USO\n\tsalvarmedidas" << endl;
00308             break;
00309 
00310         case MV:
00311             cout <<"NOME\n\tmv  -  Renomeia um objeto" << endl;
00312             cout <<"USO\n\tmv NOME_ATUAL NOVO_NOME" << endl;
00313             break;
00314             
00315         // Nova descricao para o comando changerate para alterar a taxa de
00316         // transmissao do video. Este comando e novo, e foi criado pela
00317         // implementacao do controle de fluxo.
00318         case CHANGERATE:
00319             cout << "NOME\n\tchangerate - Altera a taxa de transmissao de um " 
00320                  << "objeto." << endl;
00321             cout << "USO\n\tchangerate NOME_DO_OBJETO NOVA_TAXA" << endl;     
00322             break;
00323             
00324         // Nova descricao para o comando searchlogs, que faz buscas nos arquivos
00325         // de logs.
00326         case SEARCHLOGS:
00327             cout << "NOME\n\tsearchlogs - Faz buscas nos arquivos de logs dos "
00328                  << "servidores" << endl;
00329             cout << "USO\n\tsearchlogs TIPO_DE_BUSCA NOME_DO_SERVIDOR "
00330                  << "TEMPO_INICIAL TEMPO_FINAL ARQUIVO_RESULTADO\n\n"
00331                  << "\tTIPO_DE_BUSCA pode ser:\n\n\t\tclientlogs - busca nos "
00332                  << "logs de clientes conectados do servidor de despacho."
00333                  << "\n\t\ttrafficlogs - busca nos logs de trafego de um dos "
00334                  << "servidores de armazenamento." << endl << endl; 
00335             cout << "EXEMPLOS\n\tsearchlogs clientlogs itauna 1255699464 "
00336                  << "1255701393 clientlogs.gz\n\tsearchlogs trafficlogs "
00337                  << "genipabu 1255704347 1255706263 trafficlogs.gz" << endl;   
00338             break;    
00339 
00340         default:
00341             RioErr << "Comando inv�lido."<<endl;
00342     }
00343 }


Field Documentation

int CMParser::argc [private]

Definition at line 79 of file Parser.h.

char* CMParser::argv[MAXARG] [private]

Definition at line 78 of file Parser.h.

int CMParser::command [private]

Definition at line 77 of file Parser.h.

char CMParser::linebuf[MAXLINELEN] [private]

Definition at line 76 of file Parser.h.

struct Option CMParser::options[MAXARG] [private]

Definition at line 82 of file Parser.h.

int CMParser::optnum [private]

Definition at line 80 of file Parser.h.

char CMParser::params[MAXARG][MAXNAMELEN] [private]

Definition at line 81 of file Parser.h.

int CMParser::pnum [private]

Definition at line 80 of file Parser.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:31 2012 for RIO by  doxygen 1.6.3