From e0de52c28cef4c01cc73b00b3a4b3859d109e99f Mon Sep 17 00:00:00 2001 From: xiangfu Date: Tue, 28 Apr 2009 18:13:19 +0000 Subject: [PATCH] cleanup the code change all the function return 1 for success --- flash-tool/cmd_boot.c | 4 ++-- flash-tool/command_line.c | 32 +++++++++++++++----------------- flash-tool/main.c | 10 ++++------ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/flash-tool/cmd_boot.c b/flash-tool/cmd_boot.c index 273de0b..0b1db74 100644 --- a/flash-tool/cmd_boot.c +++ b/flash-tool/cmd_boot.c @@ -212,7 +212,7 @@ out: int boot(char *stage1_path, char *stage2_path, char *config_path ){ struct ingenic_dev ingenic_dev; - int res = EXIT_FAILURE; + int res = 0; int status; 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(); } - res = EXIT_SUCCESS; + res = 1; cleanup: if (ingenic_dev.file_buff) diff --git a/flash-tool/command_line.c b/flash-tool/command_line.c index 4b8d15a..ed88574 100644 --- a/flash-tool/command_line.c +++ b/flash-tool/command_line.c @@ -28,7 +28,7 @@ #include "config.h" static int com_argc; -static char com_argv[20][50]; +static char com_argv[9][100]; static const char COMMAND[][30]= { @@ -133,33 +133,32 @@ int command_input(char *buf) cptr = fgets(buf, 256, stdin); if (cptr != NULL) - return 0; - return 1; + return 1; + return 0; } int command_interpret(char * com_buf) { char *buf = com_buf; - int k, L, i=0, j = 0; + int k, L, i = 0, j = 0; L = (int)strlen(buf); buf[L]=' '; for (k = 0; k <= L; k++) { - if (*buf==' '|| *buf=='\n') { - while(*(++buf)==' '); - com_argv[i][j]='\0'; + if (*buf == ' ' || *buf == '\n') { + while ( *(++buf) == ' ' ); + com_argv[i][j] = '\0'; i++; - if (i>9) { + if (i > 9) { printf("\n Para is too much! About!"); return 0; } j=0; continue; } else { - com_argv[i][j]=*buf; + com_argv[i][j] = *buf; j++; - if (j>100) - { + if (j > 100) { printf("\n Para is too long! About!"); return 0; } @@ -167,10 +166,10 @@ int command_interpret(char * com_buf) buf++; } - com_argc=i; + com_argc = 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 COMMAND_NUM + 1; } @@ -178,9 +177,8 @@ int command_interpret(char * com_buf) int command_handle(char *buf) { int cmd = command_interpret(buf); - int result = 0; - if (!cmd) return 1; + if (!cmd) return -1; switch (cmd) { case 11: handle_nprog(); @@ -199,9 +197,9 @@ int command_handle(char *buf) break; default: printf("\n Command not support!"); - result = 1; + result = -1; break; } - return result; + return 1; } diff --git a/flash-tool/main.c b/flash-tool/main.c index a7c59f6..bf04fbe 100644 --- a/flash-tool/main.c +++ b/flash-tool/main.c @@ -70,12 +70,10 @@ int main(int argc, char **argv) switch (c) { case 'h': help(); - exit(0); - break; + exit(EXIT_SUCCESS); case 'v': print_version(); - exit(0); - break; + exit(EXIT_SUCCESS); default: help(); exit(2); @@ -88,11 +86,11 @@ int main(int argc, char **argv) while (1) { printf("\n inflash :> "); - if (command_input(com_buf)) + if (!command_input(com_buf)) continue; command_handle(com_buf); } - return 0; + return EXIT_SUCCESS; }