exit command works
This commit is contained in:
parent
d94239679d
commit
3ee1d725a5
@ -32,6 +32,7 @@ struct shelldata{
|
|||||||
int pos;
|
int pos;
|
||||||
char esc[8];
|
char esc[8];
|
||||||
int escpos;
|
int escpos;
|
||||||
|
int quit;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sockdata{
|
struct sockdata{
|
||||||
@ -48,6 +49,7 @@ void set_cmd(struct shelldata *sd, const char * cmd);
|
|||||||
void del_cmd(struct shelldata *sd, const char * cmd);
|
void del_cmd(struct shelldata *sd, const char * cmd);
|
||||||
void send_cmd(struct shelldata *sd, const char * cmd);
|
void send_cmd(struct shelldata *sd, const char * cmd);
|
||||||
void wlan0_cmd(struct shelldata *sd, const char * cmd);
|
void wlan0_cmd(struct shelldata *sd, const char * cmd);
|
||||||
|
void exit_cmd(struct shelldata *sd, const char * cmd);
|
||||||
//void show_cfg (FILE *out, mavl_t ktv);
|
//void show_cfg (FILE *out, mavl_t ktv);
|
||||||
void show_aps (FILE *out);
|
void show_aps (FILE *out);
|
||||||
|
|
||||||
@ -59,6 +61,7 @@ struct command{
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct command cmdlist[]={
|
static struct command cmdlist[]={
|
||||||
|
{"exit",exit_cmd},
|
||||||
{"cfg", cfg_cmd },
|
{"cfg", cfg_cmd },
|
||||||
{"del", del_cmd },
|
{"del", del_cmd },
|
||||||
{"ucfg", ucfg_cmd},
|
{"ucfg", ucfg_cmd},
|
||||||
@ -85,6 +88,13 @@ void list_cmd(struct shelldata *sd, const char *cmd)
|
|||||||
show_aps(sd->out);
|
show_aps(sd->out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void exit_cmd(struct shelldata *sd, const char *cmd)
|
||||||
|
{
|
||||||
|
sd->quit=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cfg_cmd(struct shelldata *sd, const char *cmd)
|
void cfg_cmd(struct shelldata *sd, const char *cmd)
|
||||||
{
|
{
|
||||||
struct cw_Conn * conn;
|
struct cw_Conn * conn;
|
||||||
@ -371,7 +381,7 @@ void execute_cmd (struct shelldata * sd, const char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
fprintf(sd->out,"Unknown command: '%s'\n",cmd);
|
fprintf(sd->out,"Unknown command: '%s'\n\r",cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -478,10 +488,10 @@ static void get_line_char_mode(FILE * file, struct shelldata *sd)
|
|||||||
/* Put telnet into char mode */
|
/* Put telnet into char mode */
|
||||||
fprintf (file,"%c%c%c",IAC,WILL,TELOPT_ECHO );
|
fprintf (file,"%c%c%c",IAC,WILL,TELOPT_ECHO );
|
||||||
fprintf (file,"%c%c%c",IAC,WILL,TELOPT_SGA );
|
fprintf (file,"%c%c%c",IAC,WILL,TELOPT_SGA );
|
||||||
// fprintf (file,"%c%c%c",IAC,DONT,TELOPT_LINEMODE );
|
fprintf (file,"%c%c%c",IAC,DONT,TELOPT_LINEMODE );
|
||||||
|
|
||||||
|
|
||||||
fprintf (file, "\n\ractube[%s]:>", sd->prompt);
|
fprintf (file, "actube[%s]:>", sd->prompt);
|
||||||
fflush (file);
|
fflush (file);
|
||||||
|
|
||||||
while ( (c=fgetc(file))!= EOF){
|
while ( (c=fgetc(file))!= EOF){
|
||||||
@ -525,7 +535,10 @@ static void get_line_char_mode(FILE * file, struct shelldata *sd)
|
|||||||
if (!es){
|
if (!es){
|
||||||
if (c=='\r'){
|
if (c=='\r'){
|
||||||
printf("CMD: %s\n",sd->line);
|
printf("CMD: %s\n",sd->line);
|
||||||
fprintf (file, "\n\ractube[%s]:>", sd->prompt);
|
fprintf (file, "\n\r");
|
||||||
|
fflush(file);
|
||||||
|
//fprintf (file, "\n\ractube[%s]:>", sd->prompt);
|
||||||
|
return;
|
||||||
sd->pos=0;
|
sd->pos=0;
|
||||||
sd->line[0]=0;
|
sd->line[0]=0;
|
||||||
continue;
|
continue;
|
||||||
@ -548,7 +561,7 @@ static void get_line_char_mode(FILE * file, struct shelldata *sd)
|
|||||||
sd->line[sd->pos++]=c;
|
sd->line[sd->pos++]=c;
|
||||||
sd->line[sd->pos]=0;
|
sd->line[sd->pos]=0;
|
||||||
printf("putout: %c %02X\n",c,c);
|
printf("putout: %c %02X\n",c,c);
|
||||||
fprintf(file,"%c",c);
|
fprintf(file,"\x1b[1@%c",c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,22 +606,25 @@ void shell_loop (FILE *file)
|
|||||||
|
|
||||||
sd.out = file;
|
sd.out = file;
|
||||||
sprintf(sd.prompt,"%s","*");
|
sprintf(sd.prompt,"%s","*");
|
||||||
|
sd.quit=0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int c;
|
int c;
|
||||||
get_line_char_mode(file,&sd);
|
get_line_char_mode(file,&sd);
|
||||||
|
printf("THE CMD FROM LINE '%s'\n",sd.line);
|
||||||
|
|
||||||
str[0]=0;
|
str[0]=0;
|
||||||
// c=fgetc(file);
|
// c=fgetc(file);
|
||||||
|
|
||||||
printf("%c\n",c);
|
//printf("%c\n",c);
|
||||||
|
|
||||||
fgets (str, sizeof (str), file);
|
// fgets (str, sizeof (str), file);
|
||||||
|
|
||||||
printf("My String: %s\n",str);
|
// printf("My String: %s\n",str);
|
||||||
|
|
||||||
execute_cmd (&sd, str);
|
execute_cmd (&sd, sd.line);
|
||||||
|
if (sd.quit)
|
||||||
|
break;
|
||||||
|
|
||||||
} while (c != EOF);
|
} while (c != EOF);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user