summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/dbparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/imxtools/sbtools/dbparser.c')
-rw-r--r--utils/imxtools/sbtools/dbparser.c56
1 files changed, 18 insertions, 38 deletions
diff --git a/utils/imxtools/sbtools/dbparser.c b/utils/imxtools/sbtools/dbparser.c
index 6cba91f34b..54939db6d2 100644
--- a/utils/imxtools/sbtools/dbparser.c
+++ b/utils/imxtools/sbtools/dbparser.c
@@ -419,44 +419,29 @@ struct cmd_option_t *db_find_option_by_id(struct cmd_option_t *opt, const char *
419 419
420#define INVALID_SB_SUBVERSION 0xffff 420#define INVALID_SB_SUBVERSION 0xffff
421 421
422static uint16_t parse_sb_subversion(char *str) 422static const char *parse_sb_subversion(const char *str, uint16_t *v)
423{ 423{
424 int len = strlen(str); 424 int len = 0;
425 uint16_t n = 0; 425 *v = 0;
426 if(len == 0 || len > 4) 426 while(isdigit(str[len]) && len < 3)
427 return INVALID_SB_SUBVERSION; 427 *v = (*v) << 4 | (str[len++] - '0');
428 for(int i = 0; i < len; i++) 428 if(len == 0)
429 { 429 *v = INVALID_SB_SUBVERSION;
430 if(!isdigit(str[i])) 430 return str + len;
431 return INVALID_SB_SUBVERSION;
432 n = n << 4 | (str[i] - '0');
433 }
434 return n;
435} 431}
436 432
437bool db_parse_sb_version(struct sb_version_t *ver, char *str) 433bool db_parse_sb_version(struct sb_version_t *ver, const char *str)
438{ 434{
439 int len = strlen(str); 435 str = parse_sb_subversion(str, &ver->major);
440 int cnt = 0; 436 if(ver->major == INVALID_SB_SUBVERSION || *str != '.')
441 int pos[2]; 437 return false;
442 438 str = parse_sb_subversion(str + 1, &ver->minor);
443 for(int i = 0; i < len; i++) 439 if(ver->minor == INVALID_SB_SUBVERSION || *str != '.')
444 {
445 if(str[i] != '.')
446 continue;
447 if(cnt == 2)
448 return false;
449 pos[cnt++] = i + 1;
450 str[i] = 0;
451 }
452 if(cnt != 2)
453 return false; 440 return false;
454 ver->major = parse_sb_subversion(str); 441 str = parse_sb_subversion(str + 1, &ver->revision);
455 ver->minor = parse_sb_subversion(str + pos[0]); 442 if(ver->revision == INVALID_SB_SUBVERSION || *str != 0)
456 ver->revision = parse_sb_subversion(str + pos[1]); 443 return false;
457 return ver->major != INVALID_SB_SUBVERSION && 444 return true;
458 ver->minor != INVALID_SB_SUBVERSION &&
459 ver->revision != INVALID_SB_SUBVERSION;
460} 445}
461 446
462static bool db_generate_sb_subversion(uint16_t subver, char *str) 447static bool db_generate_sb_subversion(uint16_t subver, char *str)
@@ -831,11 +816,6 @@ struct cmd_file_t *db_parse_file(const char *file)
831 return cmd_file; 816 return cmd_file;
832} 817}
833 818
834void db_generate_default_sb_version(struct sb_version_t *ver)
835{
836 ver->major = ver->minor = ver->revision = 0x999;
837}
838
839void db_free_option_list(struct cmd_option_t *opt_list) 819void db_free_option_list(struct cmd_option_t *opt_list)
840{ 820{
841 while(opt_list) 821 while(opt_list)