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 File Reference

#include <j2k/Fred/Standard.hpp>
#include <j2k/Fred/Error/JError.cpp>
#include <j2k/Net/TFTP/TFTP_Option.hpp>
#include <iomanip.h>

Go to the source code of this file.

Functions

void TFTP_client_shell ()
char * cleanParam (char *param)
void arange_shell (char *command)
char getkey ()
void safePrint (const char *s)


Function Documentation

void TFTP_client_shell  
 

Definition at line 24 of file TFTP_shell.cpp.

Referenced by TFTP::TFTP().

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 }

void arange_shell char *    command
 

Definition at line 72 of file TFTP_shell.cpp.

Referenced by TFTP_client_shell().

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 }

char * cleanParam char *    param
 

Definition at line 45 of file TFTP_shell.cpp.

Referenced by arange_shell().

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 }

char getkey  
 

Definition at line 17 of file TFTP_shell.cpp.

00018 {
00019    register int c = getchar();
00020    fflush( stdin );
00021    return (char)c;
00022 }

void safePrint const char *    s
 

Definition at line 63 of file TFTP_shell.cpp.

Referenced by arange_shell(), and TFTP_Parser::parseOptions().

00064 {
00065   if ( s != NULL ) {
00066     printf( "[%s]", s );
00067   } else {
00068     printf("<NULL>", s );
00069   }
00070 }


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