1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-26 13:05:01 +02:00

cleanup the code

change all the function return 1 for success
This commit is contained in:
xiangfu 2009-04-28 18:13:19 +00:00
parent 1275a789b7
commit e0de52c28c
3 changed files with 21 additions and 25 deletions

View File

@ -212,7 +212,7 @@ out:
int boot(char *stage1_path, char *stage2_path, char *config_path ){ int boot(char *stage1_path, char *stage2_path, char *config_path ){
struct ingenic_dev ingenic_dev; struct ingenic_dev ingenic_dev;
int res = EXIT_FAILURE; int res = 0;
int status; int status;
memset(&ingenic_dev, 0, sizeof(struct ingenic_dev)); memset(&ingenic_dev, 0, sizeof(struct ingenic_dev));
@ -272,7 +272,7 @@ int boot(char *stage1_path, char *stage2_path, char *config_path ){
check_dump_cfg(); check_dump_cfg();
} }
res = EXIT_SUCCESS; res = 1;
cleanup: cleanup:
if (ingenic_dev.file_buff) if (ingenic_dev.file_buff)

View File

@ -28,7 +28,7 @@
#include "config.h" #include "config.h"
static int com_argc; static int com_argc;
static char com_argv[20][50]; static char com_argv[9][100];
static const char COMMAND[][30]= static const char COMMAND[][30]=
{ {
@ -133,33 +133,32 @@ int command_input(char *buf)
cptr = fgets(buf, 256, stdin); cptr = fgets(buf, 256, stdin);
if (cptr != NULL) if (cptr != NULL)
return 0; return 1;
return 1; return 0;
} }
int command_interpret(char * com_buf) int command_interpret(char * com_buf)
{ {
char *buf = com_buf; char *buf = com_buf;
int k, L, i=0, j = 0; int k, L, i = 0, j = 0;
L = (int)strlen(buf); L = (int)strlen(buf);
buf[L]=' '; buf[L]=' ';
for (k = 0; k <= L; k++) { for (k = 0; k <= L; k++) {
if (*buf==' '|| *buf=='\n') { if (*buf == ' ' || *buf == '\n') {
while(*(++buf)==' '); while ( *(++buf) == ' ' );
com_argv[i][j]='\0'; com_argv[i][j] = '\0';
i++; i++;
if (i>9) { if (i > 9) {
printf("\n Para is too much! About!"); printf("\n Para is too much! About!");
return 0; return 0;
} }
j=0; j=0;
continue; continue;
} else { } else {
com_argv[i][j]=*buf; com_argv[i][j] = *buf;
j++; j++;
if (j>100) if (j > 100) {
{
printf("\n Para is too long! About!"); printf("\n Para is too long! About!");
return 0; return 0;
} }
@ -167,10 +166,10 @@ int command_interpret(char * com_buf)
buf++; buf++;
} }
com_argc=i; com_argc = i;
for (i = 1; i <= COMMAND_NUM; i++) for (i = 1; i <= COMMAND_NUM; i++)
if (!strcmp(COMMAND[i],com_argv[0])) if (!strcmp(COMMAND[i], com_argv[0]))
return i; return i;
return COMMAND_NUM + 1; return COMMAND_NUM + 1;
} }
@ -178,9 +177,8 @@ int command_interpret(char * com_buf)
int command_handle(char *buf) int command_handle(char *buf)
{ {
int cmd = command_interpret(buf); int cmd = command_interpret(buf);
int result = 0;
if (!cmd) return 1; if (!cmd) return -1;
switch (cmd) { switch (cmd) {
case 11: case 11:
handle_nprog(); handle_nprog();
@ -199,9 +197,9 @@ int command_handle(char *buf)
break; break;
default: default:
printf("\n Command not support!"); printf("\n Command not support!");
result = 1; result = -1;
break; break;
} }
return result; return 1;
} }

View File

@ -70,12 +70,10 @@ int main(int argc, char **argv)
switch (c) { switch (c) {
case 'h': case 'h':
help(); help();
exit(0); exit(EXIT_SUCCESS);
break;
case 'v': case 'v':
print_version(); print_version();
exit(0); exit(EXIT_SUCCESS);
break;
default: default:
help(); help();
exit(2); exit(2);
@ -88,11 +86,11 @@ int main(int argc, char **argv)
while (1) { while (1) {
printf("\n inflash :> "); printf("\n inflash :> ");
if (command_input(com_buf)) if (!command_input(com_buf))
continue; continue;
command_handle(com_buf); command_handle(com_buf);
} }
return 0; return EXIT_SUCCESS;
} }