astyle applied to try and match current OpenRTX style - just doesn't work on the header block

This commit is contained in:
tarxvf 2021-08-25 01:58:36 -04:00 committed by Silvano Seva
parent f451ff8aae
commit 588265fa3d
2 changed files with 259 additions and 185 deletions

11
.astylerc Normal file
View File

@ -0,0 +1,11 @@
style=allman
indent=spaces=4
pad-comma
pad-oper
add-braces
keep-one-line-blocks
keep-one-line-statements
add-one-line-braces
align-pointer=name
align-reference=name
verbose

View File

@ -36,88 +36,101 @@ radio_state Radio_State = {12, 8.2f, 3, 4, 1, false};
extern int screenshot_display(const char *filename); extern int screenshot_display(const char *filename);
typedef int (*_climenu_fn)(void* self, int argc, char ** argv ); typedef int (*_climenu_fn)(void *self, int argc, char **argv);
typedef struct { typedef struct
char * name; {
char * description; char *name;
void * var; char *description;
void *var;
_climenu_fn fn; _climenu_fn fn;
} _climenu_option; } _climenu_option;
enum shell_retvals { enum shell_retvals
SH_ERR=-1, {
SH_CONTINUE=0, SH_ERR = -1,
SH_WHAT=1, SH_CONTINUE = 0,
SH_EXIT_OK=2, SH_WHAT = 1,
SH_EXIT_OK = 2,
}; };
keyboard_t _shellkeyq[25] = {0}; keyboard_t _shellkeyq[25] = {0};
int _skq_cap = 25; int _skq_cap = 25;
int _skq_head; int _skq_head;
int _skq_tail; int _skq_tail;
int _skq_in; int _skq_in;
int _skq_out; int _skq_out;
void _dump_skq(){ void _dump_skq()
for( int i = 0; i < _skq_cap; i++){ {
for(int i = 0; i < _skq_cap; i++)
{
printf("skq[%d] == %d\n", i, _shellkeyq[i]); printf("skq[%d] == %d\n", i, _shellkeyq[i]);
} }
} }
void shellkeyq_put(keyboard_t keys){ void shellkeyq_put(keyboard_t keys)
{
//note - we must allow keys == 0 to be inserted because otherwise a queue full of //note - we must allow keys == 0 to be inserted because otherwise a queue full of
// [1,1,1,1,1] is simulating HOLDING 1, and we sometimes (well, often) want // [1,1,1,1,1] is simulating HOLDING 1, and we sometimes (well, often) want
// [1,0,1,0,1,0] to simulate separate keypresses // [1,0,1,0,1,0] to simulate separate keypresses
// this, of course, relies on the kbd_thread getting just one element off the queue // this, of course, relies on the kbd_thread getting just one element off the queue
// for every kbd_getKeys(). // for every kbd_getKeys().
if( _skq_in > _skq_out + _skq_cap ){ if(_skq_in > _skq_out + _skq_cap)
{
printf("too many keys!\n"); printf("too many keys!\n");
return; return;
} }
_shellkeyq[ _skq_tail ] = keys; _shellkeyq[ _skq_tail ] = keys;
_skq_in++; _skq_in++;
_skq_tail = (_skq_tail + 1 ) % _skq_cap; _skq_tail = (_skq_tail + 1) % _skq_cap;
/*printf("head: %d tail: %d in %d out %d\n", _skq_head, _skq_tail, _skq_in, _skq_out);*/ /*printf("head: %d tail: %d in %d out %d\n", _skq_head, _skq_tail, _skq_in, _skq_out);*/
} }
keyboard_t shellkeyq_get(){ keyboard_t shellkeyq_get()
if( _skq_in > _skq_out ){ {
if(_skq_in > _skq_out)
{
//only if we've fallen behind and there's data in there: //only if we've fallen behind and there's data in there:
keyboard_t out = _shellkeyq[ _skq_head ]; keyboard_t out = _shellkeyq[ _skq_head ];
_shellkeyq[ _skq_head ] = 0; _shellkeyq[ _skq_head ] = 0;
_skq_out++; _skq_out++;
_skq_head = (_skq_head + 1 ) % _skq_cap; _skq_head = (_skq_head + 1) % _skq_cap;
/*printf("head: %d tail: %d in %d out %d\n", _skq_head, _skq_tail, _skq_in, _skq_out);*/ /*printf("head: %d tail: %d in %d out %d\n", _skq_head, _skq_tail, _skq_in, _skq_out);*/
/*_dump_skq();*/ /*_dump_skq();*/
return out; return out;
} else { }
else
{
return 0; //no keys return 0; //no keys
} }
} }
void _test_skq(){ void _test_skq()
for(int i = 0; i < 257; i++){ {
shellkeyq_put(i+1); for(int i = 0; i < 257; i++)
{
shellkeyq_put(i + 1);
} }
//clear it out now //clear it out now
while( shellkeyq_get() ); while(shellkeyq_get());
} }
int shell_ready( void * _self, int _argc, char ** _argv ){
int shell_ready(void *_self, int _argc, char **_argv)
{
(void) _self; (void) _self;
(void) _argc; (void) _argc;
(void) _argv; (void) _argv;
while( _skq_in > _skq_out ){ while(_skq_in > _skq_out)
usleep(10*1000); //sleep until keyboard is caught up {
usleep(10 * 1000); //sleep until keyboard is caught up
} }
return SH_CONTINUE; return SH_CONTINUE;
} }
keyboard_t keyname2keyboard(char * name){ keyboard_t keyname2keyboard(char *name)
/*The line noise at the end of this comment is a vim macro for taking the keyboard.h {
/* The line noise at the end of this comment is a vim macro for taking the keyboard.h
interface and putting it into the format further below interface and putting it into the format further below
You can load it into vim register k with "kyy You can load it into vim register k with "kyy
and run the macro with @k (and then you can repeat a macro register application with @@ ) and run the macro with @k (and then you can repeat a macro register application with @@ )
@ -127,15 +140,18 @@ keyboard_t keyname2keyboard(char * name){
_i"ElC", _i"ElC",
*/ */
char * names[] = { char *names[] =
{
"KEY_0", "KEY_1", "KEY_2", "KEY_3", "KEY_4", "KEY_5", "KEY_6", "KEY_7", "KEY_0", "KEY_1", "KEY_2", "KEY_3", "KEY_4", "KEY_5", "KEY_6", "KEY_7",
"KEY_8", "KEY_9", "KEY_STAR", "KEY_HASH", "KEY_ENTER", "KEY_ESC", "KEY_UP", "KEY_8", "KEY_9", "KEY_STAR", "KEY_HASH", "KEY_ENTER", "KEY_ESC", "KEY_UP",
"KEY_DOWN", "KEY_LEFT", "KEY_RIGHT", "KEY_MONI", "KEY_F1", "KEY_F2", "KEY_F3", "KEY_DOWN", "KEY_LEFT", "KEY_RIGHT", "KEY_MONI", "KEY_F1", "KEY_F2", "KEY_F3",
"KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", "KNOB_LEFT", "KNOB_RIGHT", "KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", "KNOB_LEFT", "KNOB_RIGHT",
}; };
int numnames = sizeof(names)/sizeof(char*); int numnames = sizeof(names) / sizeof(char *);
for( int i = 0; i < numnames; i++ ){ for(int i = 0; i < numnames; i++)
if( strcasecmp(name,names[i]+4) == 0 || strcasecmp(name, names[i]) == 0 ){ //notice case insensitive {
if(strcasecmp(name, names[i] + 4) == 0 || strcasecmp(name, names[i]) == 0) //notice case insensitive
{
/*printf("MATCH with %s\n", names[i]);*/ /*printf("MATCH with %s\n", names[i]);*/
//+4 to skip the KEY_ on all the names, non +4 to allow for KNOB_LEFT. //+4 to skip the KEY_ on all the names, non +4 to allow for KNOB_LEFT.
//This also means you can write KEY_LEFT as "KEY_LEFT", or "LEFT" and KNOB_LEFT as "KNOB_LEFT" or "_LEFT" //This also means you can write KEY_LEFT as "KEY_LEFT", or "LEFT" and KNOB_LEFT as "KNOB_LEFT" or "_LEFT"
@ -154,17 +170,21 @@ keyboard_t keyname2keyboard(char * name){
return 0; return 0;
} }
int pressKey( void * _self, int _argc, char ** _argv ){ int pressKey(void *_self, int _argc, char **_argv)
{
(void) _self; (void) _self;
//press a couple keys in sequence //press a couple keys in sequence
/*_climenu_option * self = (_climenu_option*) _self;*/ /*_climenu_option * self = (_climenu_option*) _self;*/
printf("Press Keys: [\n"); printf("Press Keys: [\n");
keyboard_t last = 0; keyboard_t last = 0;
for( int i = 0; i < _argc; i++ ){ for(int i = 0; i < _argc; i++)
if( _argv[i] != NULL ){ {
if(_argv[i] != NULL)
{
printf("\t%s, \n", _argv[i]); printf("\t%s, \n", _argv[i]);
keyboard_t press = keyname2keyboard( _argv[i] ); keyboard_t press = keyname2keyboard(_argv[i]);
if( press == last ){ if(press == last)
{
//otherwise if you send key ENTER DOWN DOWN DOWN DOWN DOWN //otherwise if you send key ENTER DOWN DOWN DOWN DOWN DOWN
//it will just hold DOWN for (5/(kbd_task_hz)) seconds //it will just hold DOWN for (5/(kbd_task_hz)) seconds
//so we need to give it a 0 value to get a 'release' //so we need to give it a 0 value to get a 'release'
@ -172,31 +192,34 @@ int pressKey( void * _self, int _argc, char ** _argv ){
//we only need to do this if we have two identical keys back to back, //we only need to do this if we have two identical keys back to back,
//because keyboard_t will have a zero for this key's //because keyboard_t will have a zero for this key's
//flag on other keys, which gives us the release we need //flag on other keys, which gives us the release we need
shellkeyq_put( 0 ); shellkeyq_put(0);
} }
shellkeyq_put(press); shellkeyq_put(press);
last = press; last = press;
} }
} }
printf("\t]\n"); printf("\t]\n");
shell_ready(NULL,0,NULL); shell_ready(NULL, 0, NULL);
return SH_CONTINUE; // continue return SH_CONTINUE; // continue
} }
int pressMultiKeys( void * _self, int _argc, char ** _argv ){ int pressMultiKeys(void *_self, int _argc, char **_argv)
{
//pressMultiKeys allows for key combos by sending all the keys specified in one keyboard_t //pressMultiKeys allows for key combos by sending all the keys specified in one keyboard_t
/*_climenu_option * self = (_climenu_option*) _self;*/ /*_climenu_option * self = (_climenu_option*) _self;*/
(void) _self; (void) _self;
printf("Press Keys: [\n"); printf("Press Keys: [\n");
keyboard_t combo = 0; keyboard_t combo = 0;
for( int i = 0; i < _argc; i++ ){ for(int i = 0; i < _argc; i++)
if( _argv[i] != NULL ){ {
if(_argv[i] != NULL)
{
printf("\t%s, \n", _argv[i]); printf("\t%s, \n", _argv[i]);
combo |= keyname2keyboard( _argv[i] ); combo |= keyname2keyboard(_argv[i]);
} }
} }
shellkeyq_put( combo ); shellkeyq_put(combo);
printf("\t]\n"); printf("\t]\n");
shell_ready(NULL,0,NULL); shell_ready(NULL, 0, NULL);
return SH_CONTINUE; // continue return SH_CONTINUE; // continue
} }
//need another function to press them in sequence by loading up a queue for keypress_from_shell to pull from //need another function to press them in sequence by loading up a queue for keypress_from_shell to pull from
@ -204,29 +227,34 @@ int pressMultiKeys( void * _self, int _argc, char ** _argv ){
int template(void * _self, int _argc, char ** _argv ){ int template(void *_self, int _argc, char **_argv)
_climenu_option * self = (_climenu_option*) _self; {
printf( "%s\n\t%s\n" , self->name, self->description); _climenu_option *self = (_climenu_option *) _self;
printf("%s\n\t%s\n", self->name, self->description);
for( int i = 0; i < _argc; i++ ){ for(int i = 0; i < _argc; i++)
if( _argv[i] != NULL ){ {
if(_argv[i] != NULL)
{
printf("\tArgs:\t%s\n", _argv[i]); printf("\tArgs:\t%s\n", _argv[i]);
} }
} }
return SH_CONTINUE; // continue return SH_CONTINUE; // continue
} }
int screenshot(void * _self, int _argc, char ** _argv ){ int screenshot(void *_self, int _argc, char **_argv)
{
(void) _self; (void) _self;
char * filename = "screenshot.bmp"; char *filename = "screenshot.bmp";
if( _argc && _argv[0] != NULL ){ if(_argc && _argv[0] != NULL)
{
filename = _argv[0]; filename = _argv[0];
} }
return screenshot_display(filename) == 0 ? SH_CONTINUE : SH_ERR; return screenshot_display(filename) == 0 ? SH_CONTINUE : SH_ERR;
//screenshot_display returns 0 if ok, which is same as SH_CONTINUE //screenshot_display returns 0 if ok, which is same as SH_CONTINUE
} }
/* /*
int record_start(void * _self, int _argc, char ** _argv ){ int record_start(void * _self, int _argc, char ** _argv ){
char * filename = "screen.mkv"; char * filename = "screen.mkv";
if( _argc && _argv[0] != NULL ){ if( _argc && _argv[0] != NULL ){
filename = _argv[0]; filename = _argv[0];
@ -235,37 +263,44 @@ int record_start(void * _self, int _argc, char ** _argv ){
//system("ffmpeg -f x11grab -show_region 1 -region_border 10 -window_id 0x2600016 -i :0.0 out.mkv"); //system("ffmpeg -f x11grab -show_region 1 -region_border 10 -window_id 0x2600016 -i :0.0 out.mkv");
//https://stackoverflow.com/questions/14764873/how-do-i-detect-when-the-contents-of-an-x11-window-have-changed //https://stackoverflow.com/questions/14764873/how-do-i-detect-when-the-contents-of-an-x11-window-have-changed
return SH_ERR; return SH_ERR;
} }
int record_stop( int record_stop(
void * _self, void * _self,
int _argc, int _argc,
char ** _argv ){ char ** _argv ){
return SH_ERR; return SH_ERR;
} }
*/ */
int setFloat(void * _self, int _argc, char ** _argv ){ int setFloat(void *_self, int _argc, char **_argv)
_climenu_option * self = (_climenu_option*) _self; {
_climenu_option *self = (_climenu_option *) _self;
if( _argc <= 0 || _argv[0] == NULL ){ if(_argc <= 0 || _argv[0] == NULL)
printf("%s is %f\n", self->name, *(float*)(self->var)); {
} else { printf("%s is %f\n", self->name, *(float *)(self->var));
}
else
{
sscanf(_argv[0], "%f", (float *)self->var); sscanf(_argv[0], "%f", (float *)self->var);
printf("%s is %f\n", self->name, *(float*)(self->var)); printf("%s is %f\n", self->name, *(float *)(self->var));
} }
return SH_CONTINUE; // continue return SH_CONTINUE; // continue
} }
int toggleVariable( void * _self, int _argc, char ** _argv ){ int toggleVariable(void *_self, int _argc, char **_argv)
{
(void) _argc; (void) _argc;
(void) _argv; (void) _argv;
_climenu_option * self = (_climenu_option*) _self; _climenu_option *self = (_climenu_option *) _self;
*(int*)self->var = ! *(int*)self->var; //yeah, maybe this got a little out of hand *(int *)self->var = ! *(int *)self->var; //yeah, maybe this got a little out of hand
return SH_CONTINUE; // continue return SH_CONTINUE; // continue
} }
int shell_sleep( void * _self, int _argc, char ** _argv ){ int shell_sleep(void *_self, int _argc, char **_argv)
{
(void) _self; (void) _self;
if( ! _argc || _argv[0] == NULL ){ if(! _argc || _argv[0] == NULL)
{
printf("Provide a number in milliseconds to sleep as an argument\n"); printf("Provide a number in milliseconds to sleep as an argument\n");
return SH_ERR; return SH_ERR;
} }
@ -273,10 +308,8 @@ int shell_sleep( void * _self, int _argc, char ** _argv ){
usleep(sleepus); usleep(sleepus);
return SH_CONTINUE; return SH_CONTINUE;
} }
int shell_quit( int shell_quit( void *_self, int _argc, char **_argv)
void * _self, {
int _argc,
char ** _argv ){
(void) _self; (void) _self;
(void) _argc; (void) _argc;
(void) _argv; (void) _argv;
@ -284,10 +317,7 @@ int shell_quit(
//could remove history entries here, if we wanted //could remove history entries here, if we wanted
return SH_EXIT_OK; //normal quit return SH_EXIT_OK; //normal quit
} }
int printState( int printState( void *_self, int _argc, char **_argv)
void * _self,
int _argc,
char **_argv)
{ {
(void) _self; (void) _self;
(void) _argc; (void) _argc;
@ -301,10 +331,8 @@ int printState(
printf("PTT : %s\n\n", Radio_State.PttStatus ? "true" : "false"); printf("PTT : %s\n\n", Radio_State.PttStatus ? "true" : "false");
return SH_CONTINUE; return SH_CONTINUE;
} }
int shell_nop( int shell_nop( void *_self, int _argc, char **_argv)
void * _self, {
int _argc,
char ** _argv ){
(void) _self; (void) _self;
(void) _argc; (void) _argc;
(void) _argv; (void) _argv;
@ -312,62 +340,75 @@ int shell_nop(
return SH_CONTINUE; return SH_CONTINUE;
} }
int shell_help(void * _self, int _argc, char ** _argv ); int shell_help(void *_self, int _argc, char **_argv);
_climenu_option _options[] = { _climenu_option _options[] =
/* name/shortcut description var reference, if available method to call */ {
{"rssi", "Set rssi", (void*)&Radio_State.RSSI, setFloat }, /* name/shortcut description var reference, if available method to call */
{"vbat", "Set vbat", (void*)&Radio_State.Vbat, setFloat }, {"rssi", "Set rssi", (void *) &Radio_State.RSSI, setFloat },
{"mic", "Set miclevel", (void*)&Radio_State.micLevel, setFloat }, {"vbat", "Set vbat", (void *) &Radio_State.Vbat, setFloat },
{"volume", "Set volume", (void*)&Radio_State.volumeLevel,setFloat }, {"mic", "Set miclevel", (void *) &Radio_State.micLevel, setFloat },
{"channel", "Set channel", (void*)&Radio_State.chSelector, setFloat }, {"volume", "Set volume", (void *) &Radio_State.volumeLevel, setFloat },
{"ptt", "Toggle PTT", (void*)&Radio_State.PttStatus, toggleVariable }, {"channel", "Set channel", (void *) &Radio_State.chSelector, setFloat },
{"key", "Press keys in sequence (e.g. 'key ENTER DOWN ENTER' will descend through two menus)", {"ptt", "Toggle PTT", (void *) &Radio_State.PttStatus, toggleVariable },
NULL, pressKey }, {
{"keycombo", "Press a bunch of keys simultaneously ", "key", "Press keys in sequence (e.g. 'key ENTER DOWN ENTER' will descend through two menus)",
NULL, pressMultiKeys }, NULL, pressKey
{"show", "Show current radio state (ptt, rssi, etc)", },
NULL, printState }, {
"keycombo", "Press a bunch of keys simultaneously ",
NULL, pressMultiKeys
},
{
"show", "Show current radio state (ptt, rssi, etc)",
NULL, printState
},
{"screenshot","[screenshot.bmp] Save screenshot to first arg or screenshot.bmp if none given", {
NULL, screenshot }, "screenshot", "[screenshot.bmp] Save screenshot to first arg or screenshot.bmp if none given",
NULL, screenshot
},
/*{"record_start", "[screen.mkv] Automatically save a video of the remaining session (or until record_stop is called)",*/ /*{"record_start", "[screen.mkv] Automatically save a video of the remaining session (or until record_stop is called)",*/
/*NULL, record_start },*/ /*NULL, record_start },*/
/*{"record_stop", "Stop the running recording, or no-op if none started",*/ /*{"record_stop", "Stop the running recording, or no-op if none started",*/
/*NULL, record_stop },*/ /*NULL, record_stop },*/
{"sleep", "Wait some number of ms", NULL, shell_sleep }, {"sleep", "Wait some number of ms", NULL, shell_sleep },
{"help", "Print this help", NULL, shell_help }, {"help", "Print this help", NULL, shell_help },
{"nop", "Do nothing (useful for comments)", {
NULL, shell_nop }, "nop", "Do nothing (useful for comments)",
NULL, shell_nop
},
/*{"ready", */ /*{"ready", */
/*"Wait until ready. Currently supports keyboard, so will wait until all keyboard events are processed,"*/ /*"Wait until ready. Currently supports keyboard, so will wait until all keyboard events are processed,"*/
/*"but is already implied by key and keycombo so there's not much direct use for it right now",*/ /*"but is already implied by key and keycombo so there's not much direct use for it right now",*/
/*NULL, shell_ready },*/ /*NULL, shell_ready },*/
{"quit", "Quit, close the emulator", NULL, shell_quit }, {"quit", "Quit, close the emulator", NULL, shell_quit },
}; };
int num_options = (sizeof( _options )/ sizeof(_climenu_option)); int num_options = (sizeof(_options) / sizeof(_climenu_option));
int shell_help( int shell_help( void *_self, int _argc, char **_argv)
void * _self, {
int _argc,
char ** _argv ){
(void) _self; (void) _self;
(void) _argc; (void) _argc;
(void) _argv; (void) _argv;
printf("OpenRTX emulator shell\n\n"); printf("OpenRTX emulator shell\n\n");
for( int i = 0; i < num_options; i++ ){ for(int i = 0; i < num_options; i++)
_climenu_option * o = &_options[i]; {
_climenu_option *o = &_options[i];
printf("%10s -> %s\n", o->name, o->description); printf("%10s -> %s\n", o->name, o->description);
} }
return SH_CONTINUE; return SH_CONTINUE;
} }
_climenu_option * findMenuOption(char * tok){ _climenu_option *findMenuOption(char *tok)
for( int i = 0; i < num_options; i++ ){ {
_climenu_option * o = &_options[i]; for(int i = 0; i < num_options; i++)
if( strncmp(tok, o->name, strlen(tok)) == 0 ){ {
_climenu_option *o = &_options[i];
if(strncmp(tok, o->name, strlen(tok)) == 0)
{
//strncmp like this allows for typing shortcuts like just "r" instead of the full "rssi" //strncmp like this allows for typing shortcuts like just "r" instead of the full "rssi"
//priority for conflicts (like if there's "s" which could mean //priority for conflicts (like if there's "s" which could mean
// either "show" or "screenshot" ) // either "show" or "screenshot" )
@ -378,66 +419,87 @@ _climenu_option * findMenuOption(char * tok){
return NULL; return NULL;
} }
void striptoken(char * token){ void striptoken(char *token)
for( size_t i = 0; i < strlen(token); i++ ){ {
if( token[i] == '\n' ){ for(size_t i = 0; i < strlen(token); i++)
{
if(token[i] == '\n')
{
token[i] = 0; token[i] = 0;
} }
} }
} }
int process_line(char * line){ int process_line(char *line)
char * token = strtok( line, " "); {
if( token == NULL ){ char *token = strtok(line, " ");
if(token == NULL)
{
return SH_ERR; return SH_ERR;
} }
striptoken(token); striptoken(token);
_climenu_option * o = findMenuOption(token); _climenu_option *o = findMenuOption(token);
char * args[12] = {NULL}; char *args[12] = {NULL};
int i = 0; int i = 0;
for( i = 0; i < 12; i++ ){ for(i = 0; i < 12; i++)
{
//immediately strtok again since first is a command rest are args //immediately strtok again since first is a command rest are args
token = strtok(NULL, " "); token = strtok(NULL, " ");
if( token == NULL ){ if(token == NULL)
{
break; break;
} }
striptoken(token); striptoken(token);
args[i] = token; args[i] = token;
} }
if( token != NULL ){ if(token != NULL)
{
printf("\nGot too many arguments, args truncated \n"); printf("\nGot too many arguments, args truncated \n");
} }
if( o != NULL ){ if(o != NULL)
if( o->fn != NULL ){ {
if(o->fn != NULL)
{
return o->fn(o, i, args); return o->fn(o, i, args);
} else { }
else
{
printf("Bad fn for o, check option array for bad data\n"); printf("Bad fn for o, check option array for bad data\n");
return SH_ERR; return SH_ERR;
} }
} else { }
else
{
return SH_WHAT; //not understood return SH_WHAT; //not understood
} }
} }
void *startCLIMenu() void *startCLIMenu()
{ {
printf("\n\n"); printf("\n\n");
char * histfile = ".emulatorsh_history"; char *histfile = ".emulatorsh_history";
shell_help(NULL,0,NULL); shell_help(NULL, 0, NULL);
/*printf("\n> ");*/ /*printf("\n> ");*/
int ret = SH_CONTINUE; int ret = SH_CONTINUE;
using_history(); using_history();
read_history(histfile); read_history(histfile);
do { do
{
/*char * r = fgets(shellbuf, 255, stdin);*/ /*char * r = fgets(shellbuf, 255, stdin);*/
char * r = readline(">"); char *r = readline(">");
if( r == NULL ){ if(r == NULL)
{
ret = SH_EXIT_OK; ret = SH_EXIT_OK;
} else if( strlen(r) > 0 ){ }
else if(strlen(r) > 0)
{
add_history(r); add_history(r);
ret = process_line(r); ret = process_line(r);
} else { }
else
{
ret = SH_CONTINUE; ret = SH_CONTINUE;
} }
switch(ret){ switch(ret)
{
default: default:
fflush(stdout); fflush(stdout);
break; break;
@ -459,7 +521,8 @@ void *startCLIMenu()
break; break;
} }
free(r); //free the string allocated by readline free(r); //free the string allocated by readline
} while ( ret == SH_CONTINUE ); }
while(ret == SH_CONTINUE);
fflush(stdout); fflush(stdout);
write_history(histfile); write_history(histfile);
exit(0); exit(0);