Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Net/TFTP/TFTP_shell.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__TFTP_Shell_CPP__
00002 #define __J2K__TFTP_Shell_CPP__
00003 
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <j2k/Fred/Error/JError.cpp>
00006 
00007 #include <j2k/Net/TFTP/TFTP_Option.hpp>
00008 #include <iomanip.h>
00009 
00010 __J2K__EXTERN_C
00011 
00012 void  TFTP_client_shell();
00013 char* cleanParam( char* param );
00014 void  arange_shell( char* command );
00015 char  getkey();
00016  
00017 char getkey()
00018 {
00019    register int c = getchar();
00020    fflush( stdin );
00021    return (char)c;
00022 }
00023 
00024 void TFTP_client_shell()
00025 {
00026    char command[161];
00027    memset( command, 0, 161 );
00028    int rc = 0;
00029    printf("\n>");
00030    while( 1 )
00031    {
00032      // A filename cannot be composed of ^[]+? or accentuate chars.
00033 
00034      memset( command, 0, 161 );
00035      rc = scanf( "%[abcdefghijklmnopqrstuvwxyz0123456789~'`()|{}<>;" 
00036                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ=-#$.:&_@%/\\ ]"
00037                    , command );
00038 
00039      fflush( stdin );
00040      rc = 0;
00041      arange_shell( command );     
00042    }
00043 }
00044 
00045 char* cleanParam( char* param )
00046 {
00047    char* s = param;
00048    BOOL arranged = FALSE;
00049 
00050    while( !arranged )
00051    {
00052      if (      *s == '-'  ) s++;
00053      else if ( *s == ' '  ) s++;
00054      else if ( *s == '\n' ) s++;
00055      else if ( *s == '\r' ) s++;
00056      else if ( *s == '\t' ) s++;
00057      else arranged = TRUE;
00058    }
00059 
00060    return s;
00061 }
00062 
00063 void safePrint( const char* s )
00064 {
00065   if ( s != NULL ) {
00066     printf( "[%s]", s );
00067   } else {
00068     printf("<NULL>", s );
00069   }
00070 }
00071 
00072 void arange_shell( char* command ) 
00073 {
00074    char* commandLine[10];
00075    char* delims = " =";
00076    char* s      = cleanParam( command );
00077    char* buffer = strdup( s );
00078    char* p      = strtok( buffer, delims );
00079 
00080    commandLine[0] = p;
00081 
00082    int k = 1;
00083    for( ; p != NULL; k++ ) 
00084    {
00085      p  = strtok( NULL, delims );
00086      commandLine[k] = strlwr( p ); 
00087    }
00088 
00089    int l = 0;
00090 
00091    if ( commandLine[0] == NULL ) return;
00092 
00093    if ( !strcmp( commandLine[l], "set" ) ) l++;
00094 
00095    char* opt = NULL;
00096 
00097 
00098    s = commandLine[l];
00099    if ( s == NULL ) return;
00100    if ( (l+1) < k ) opt = commandLine[ l+1 ];
00101 
00102    if ( !strcmp( s, "quit" ) || !strcmp( s, "exit" ) ) 
00103    {
00104       option.state = TFTP_Finished;
00105       exit( 1 );
00106    }
00107 
00108    if ( !strcmp( s, "show" ) ) {
00109      option.showOptions();
00110    }
00111 
00112    safePrint( s );
00113    safePrint( opt );
00114 
00115    option.ArgDetect( s, opt );
00116 
00117    printf("\n>");
00118    fflush( stdout );
00119 }
00120 
00121 __J2K__END_C
00122 
00123 #endif

Generated on Sun Oct 14 18:46:35 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001