<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body text="#000000" bgcolor="#ffffff">
garg vikas wrote:
<blockquote type="cite" cite="mid:951511.28156.qm@web95209.mail.in2.yahoo.com">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td valign="top" style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;">hi ........this patch will provide auto-completion on
command-line. please give me suggestion on this patch.</td>
</tr>
</tbody>
</table>
</blockquote>
<br>
diff -crB gpxe-1.0.0/src/hci/readline.c
gpxe-1.0.0.new/src/hci/readline.c<br>
*** gpxe-1.0.0/src/hci/readline.c 2010-02-02 21:42:44.000000000 +0530<br>
--- gpxe-1.0.0.new/src/hci/readline.c 2010-04-06 19:55:23.000000000
+0530<br>
***************<br>
*** 25,30 ****<br>
--- 25,31 ----<br>
#include <gpxe/keys.h><br>
#include <gpxe/editstring.h><br>
#include <readline/readline.h><br>
+ #include <gpxe/command.h><br>
<br>
/** @file<br>
*<br>
***************<br>
*** 86,93 ****<br>
char * readline ( const char *prompt ) {<br>
char buf[READLINE_MAX];<br>
struct edit_string string;<br>
! int key;<br>
char *line;<br>
<br>
if ( prompt )<br>
printf ( "%s", prompt );<br>
--- 87,98 ----<br>
char * readline ( const char *prompt ) {<br>
char buf[READLINE_MAX];<br>
struct edit_string string;<br>
! int key,tempkey;<br>
char *line;<br>
+ int counter=0;<br>
+ char *cmd=NULL;<br>
+ struct command *command;<br>
+ unsigned int hpos = 0,ref=0;<br>
<br>
if ( prompt )<br>
printf ( "%s", prompt );<br>
***************<br>
*** 98,104 ****<br>
buf[0] = '\0';<br>
<br>
while ( 1 ) {<br>
! key = edit_string ( &string, getkey() );<br>
sync_console ( &string );<br>
switch ( key ) {<br>
case CR:<br>
--- 103,153 ----<br>
buf[0] = '\0';<br>
<br>
while ( 1 ) {<br>
! tempkey=getkey();<br>
! if(tempkey==TAB)<br>
<br>
-----<br>
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.<br>
-----<br>
! { <br>
! <br>
! counter=0;<br>
! for_each_table_entry ( command, COMMANDS ) <br>
!
if(!strncmp(string.buf,command->name,strlen(string.buf))){
<br>
! counter+=1;<br>
! if(cmd!=NULL)<br>
! free(cmd);<br>
-----<br>
A look at gpxe/src/core/malloc.c suggests that this NULL-check is not
needed.<br>
-----<br>
! cmd=(char*)malloc(sizeof(command->name)+1);<br>
! strcpy(cmd,command->name);}<br>
-----<br>
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()?<br>
-----<br>
! <br>
! if(counter==1 && cmd!=NULL)<br>
! { <br>
!
for(ref=strlen(string.buf);ref<strlen(cmd);ref++)<br>
! {<br>
! edit_string ( &string,cmd[ref]);<br>
! sync_console ( &string );<br>
! }<br>
! } <br>
! else{<br>
! printf("\n");<br>
! for_each_table_entry ( command, COMMANDS ) {
<br>
!
if(!strncmp(string.buf,command->name,strlen(string.buf)))<br>
! hpos += printf ( " %s", command->name );<br>
! <br>
! if ( hpos > ( 16 * 4 ) ) {<br>
! printf ( "\n" );<br>
! hpos = 0;}<br>
! else {<br>
! while ( hpos % 16 ) {<br>
! printf ( " " );<br>
! hpos++;<br>
! }<br>
! }<br>
! }<br>
! printf("\n");<br>
! printf ( "%s%s", prompt,string.buf);<br>
-----<br>
You could combine these two printf()s.<br>
-----<br>
! <br>
! } <br>
! continue;<br>
! }<br>
! <br>
! key = edit_string ( &string, tempkey);<br>
sync_console ( &string );<br>
switch ( key ) {<br>
case CR:<br>
<br>
</body>
</html>