Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| char *__malloc | readline (const char *prompt) |
| Read line from console. | |
Definition in file readline.h.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| char* __malloc readline | ( | const char * | prompt | ) |
Read line from console.
| prompt | Prompt string |
| line | Line read from console (excluding terminating newline) |
Definition at line 86 of file readline.c.
References CR, CTRL_C, edit_string(), getkey(), LF, memset(), NULL, printf(), putchar(), READLINE_MAX, strdup(), and sync_console().
Referenced by shell().
00086 { 00087 char buf[READLINE_MAX]; 00088 struct edit_string string; 00089 int key; 00090 char *line; 00091 00092 if ( prompt ) 00093 printf ( "%s", prompt ); 00094 00095 memset ( &string, 0, sizeof ( string ) ); 00096 string.buf = buf; 00097 string.len = sizeof ( buf ); 00098 buf[0] = '\0'; 00099 00100 while ( 1 ) { 00101 key = edit_string ( &string, getkey() ); 00102 sync_console ( &string ); 00103 switch ( key ) { 00104 case CR: 00105 case LF: 00106 putchar ( '\n' ); 00107 line = strdup ( buf ); 00108 if ( ! line ) 00109 printf ( "Out of memory\n" ); 00110 return line; 00111 case CTRL_C: 00112 putchar ( '\n' ); 00113 return NULL; 00114 default: 00115 /* Do nothing */ 00116 break; 00117 } 00118 } 00119 }
1.5.7.1