garg vikas wrote:
hi ........this patch will provide auto-completion on command-line. please give me suggestion on this patch.


diff -crB gpxe-1.0.0/src/hci/readline.c gpxe-1.0.0.new/src/hci/readline.c
*** gpxe-1.0.0/src/hci/readline.c    2010-02-02 21:42:44.000000000 +0530
--- gpxe-1.0.0.new/src/hci/readline.c    2010-04-06 19:55:23.000000000 +0530
***************
*** 25,30 ****
--- 25,31 ----
 #include <gpxe/keys.h>
 #include <gpxe/editstring.h>
 #include <readline/readline.h>
+ #include <gpxe/command.h>

 /** @file
  *
***************
*** 86,93 ****
 char * readline ( const char *prompt ) {
     char buf[READLINE_MAX];
     struct edit_string string;
!     int key;
     char *line;

     if ( prompt )
         printf ( "%s", prompt );
--- 87,98 ----
 char * readline ( const char *prompt ) {
     char buf[READLINE_MAX];
     struct edit_string string;
!     int key,tempkey;
     char *line;
+     int counter=0;
+     char *cmd=NULL;
+     struct command *command;
+     unsigned int hpos = 0,ref=0;

     if ( prompt )
         printf ( "%s", prompt );
***************
*** 98,104 ****
     buf[0] = '\0';

     while ( 1 ) {
!         key = edit_string ( &string, getkey() );
         sync_console ( &string );
         switch ( key ) {
         case CR:
--- 103,153 ----
     buf[0] = '\0';

     while ( 1 ) {
!          tempkey=getkey();
!         if(tempkey==TAB)

-----
Throughout this patch, there are portions where the coding style doesn't match the coding style given in the rest of the file, such as spacing and indentation. While an aesthetic criticism, it might be something to consider. Someone reading the code does not have to adapt if the coding style is consistent.
-----
! { ! ! counter=0;
!             for_each_table_entry ( command, COMMANDS )
! if(!strncmp(string.buf,command->name,strlen(string.buf))){ ! counter+=1;
!                 if(cmd!=NULL)
!                   free(cmd);
-----
A look at gpxe/src/core/malloc.c suggests that this NULL-check is not needed.
-----
!                 cmd=(char*)malloc(sizeof(command->name)+1);
!                 strcpy(cmd,command->name);}
-----
Are you overwriting random unallocated portions of the heap here? sizeof(command->name) will give you the sizeof a const char*. Perhaps you meant strlen()?
-----
!
!             if(counter==1 && cmd!=NULL)
! { ! for(ref=strlen(string.buf);ref<strlen(cmd);ref++)
!                      {
!                     edit_string ( &string,cmd[ref]);
!                     sync_console ( &string );
!                   }
! } ! else{
!                 printf("\n");
! for_each_table_entry ( command, COMMANDS ) { ! if(!strncmp(string.buf,command->name,strlen(string.buf)))
!                     hpos += printf ( "  %s", command->name );
! ! if ( hpos > ( 16 * 4 ) ) {
!                     printf ( "\n" );
!                     hpos = 0;}
!                      else {
!                         while ( hpos % 16 ) {
!                         printf ( " " );
!                         hpos++;
!                               }
!                            }
!                    }
!                 printf("\n");
!                 printf ( "%s%s", prompt,string.buf);
-----
You could combine these two printf()s.
-----
! ! } ! continue;
!         }
!
!         key = edit_string ( &string, tempkey);
         sync_console ( &string );
         switch ( key ) {
         case CR:

_______________________________________________
gPXE-devel mailing list
[email protected]
http://etherboot.org/mailman/listinfo/gpxe-devel

Reply via email to