diff options
author | Christophe Grenier <grenier@cgsecurity.org> | 2018-03-17 17:29:28 +0100 |
---|---|---|
committer | Christophe Grenier <grenier@cgsecurity.org> | 2018-03-17 17:29:28 +0100 |
commit | 09ecae700f224a23cfd8f63f98cebeccbe768cc0 (patch) | |
tree | 83fbfb551cc9330a02dfb6762e2c4b8e6015eecb | |
parent | 331f0ef77e62140d0ee9252c33b23b383aa73084 (diff) |
Use new functions check_command(), skip_comma_in_command() and get_int_from_command() to parse command line arguments
-rw-r--r-- | src/adv.c | 28 | ||||
-rw-r--r-- | src/chgarch.c | 9 | ||||
-rw-r--r-- | src/chgtype.c | 22 | ||||
-rw-r--r-- | src/common.c | 25 | ||||
-rw-r--r-- | src/common.h | 3 | ||||
-rw-r--r-- | src/dirpart.c | 12 | ||||
-rw-r--r-- | src/fat1x.c | 18 | ||||
-rw-r--r-- | src/fat32.c | 21 | ||||
-rw-r--r-- | src/fat_adv.c | 15 | ||||
-rw-r--r-- | src/geometry.c | 31 | ||||
-rw-r--r-- | src/intrf.c | 7 | ||||
-rw-r--r-- | src/intrface.c | 6 | ||||
-rw-r--r-- | src/ntfs_adv.c | 15 | ||||
-rw-r--r-- | src/ntfs_udl.c | 6 | ||||
-rw-r--r-- | src/partgpt.c | 12 | ||||
-rw-r--r-- | src/parthumax.c | 12 | ||||
-rw-r--r-- | src/parti386.c | 24 | ||||
-rw-r--r-- | src/partmac.c | 12 | ||||
-rw-r--r-- | src/partsun.c | 12 | ||||
-rw-r--r-- | src/partxbox.c | 12 | ||||
-rw-r--r-- | src/phcli.c | 75 | ||||
-rw-r--r-- | src/photorec.c | 3 | ||||
-rw-r--r-- | src/phrecn.c | 27 | ||||
-rw-r--r-- | src/poptions.c | 27 | ||||
-rw-r--r-- | src/ppartseln.c | 5 | ||||
-rw-r--r-- | src/psearchn.c | 2 | ||||
-rw-r--r-- | src/tanalyse.c | 6 | ||||
-rw-r--r-- | src/tdiskop.c | 31 | ||||
-rw-r--r-- | src/tdisksel.c | 3 | ||||
-rw-r--r-- | src/testdisk.c | 6 | ||||
-rw-r--r-- | src/texfat.c | 12 | ||||
-rw-r--r-- | src/thfs.c | 12 | ||||
-rw-r--r-- | src/tntfs.c | 27 | ||||
-rw-r--r-- | src/toptions.c | 23 | ||||
-rw-r--r-- | src/tpartwr.c | 18 |
35 files changed, 216 insertions, 363 deletions
@@ -219,49 +219,39 @@ static int adv_string_to_command(char**current_cmd, list_part_t **current_elemen do { keep_asking=0; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"type",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"type",4)==0) { - (*current_cmd)+=4; command='t'; } - else if(strncmp(*current_cmd,"addpart",7)==0) + else if(check_command(current_cmd,"addpart",7)==0) { - (*current_cmd)+=7; command='a'; } - else if(strncmp(*current_cmd,"boot",4)==0) + else if(check_command(current_cmd,"boot",4)==0) { - (*current_cmd)+=4; command='b'; } - else if(strncmp(*current_cmd,"copy",4)==0) + else if(check_command(current_cmd,"copy",4)==0) { - (*current_cmd)+=4; command='c'; } - else if(strncmp(*current_cmd,"list",4)==0) + else if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; command='l'; } - else if(strncmp(*current_cmd,"undelete",8)==0) + else if(check_command(current_cmd,"undelete",8)==0) { - (*current_cmd)+=8; command='u'; } - else if(strncmp(*current_cmd,"superblock",10)==0) + else if(check_command(current_cmd,"superblock",10)==0) { - (*current_cmd)+=10; command='s'; } else if(isdigit(*current_cmd[0])) { list_part_t *element; - const unsigned int order= atoi(*current_cmd); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + const unsigned int order= get_int_from_command(current_cmd); for(element=list_part; element!=NULL && element->part->order!=order; element=element->next); diff --git a/src/chgarch.c b/src/chgarch.c index 0df69ca..9359692 100644 --- a/src/chgarch.c +++ b/src/chgarch.c @@ -58,18 +58,15 @@ int change_arch_type_cli(disk_t *disk, const int verbose, char**current_cmd) { int i; keep_asking=0; - while(*current_cmd[0]==',') - (*current_cmd)++; + skip_comma_in_command(current_cmd); for(i=0;arch_list[i]!=NULL;i++) - if(strncmp(*current_cmd, arch_list[i]->part_name_option, strlen(arch_list[i]->part_name_option))==0) + if(check_command(current_cmd, arch_list[i]->part_name_option, strlen(arch_list[i]->part_name_option))==0) { - (*current_cmd)+=strlen(arch_list[i]->part_name_option); disk->arch=arch_list[i]; keep_asking=1; } - if(strncmp(*current_cmd, "ask_type", 8)==0) + if(check_command(current_cmd, "ask_type", 8)==0) { - (*current_cmd)+=8; return 1; } } while(keep_asking>0); diff --git a/src/chgtype.c b/src/chgtype.c index 5db0301..243faa3 100644 --- a/src/chgtype.c +++ b/src/chgtype.c @@ -37,6 +37,14 @@ extern const arch_fnct_t arch_gpt; extern const arch_fnct_t arch_none; +static int get_hex_from_command(char **current_cmd) +{ + const int tmp=strtol(*current_cmd, NULL, 16); + while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') + (*current_cmd)++; + return tmp; +} + void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char **current_cmd) { assert(current_cmd!=NULL); @@ -48,12 +56,9 @@ void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char ** if(partition->arch==&arch_gpt) { partition->arch=&arch_none; - while(*current_cmd[0]==',') - (*current_cmd)++; + skip_comma_in_command(current_cmd); { - int tmp_val= strtol(*current_cmd, NULL, 16); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + const int tmp_val=get_hex_from_command(current_cmd); partition->arch->set_part_type(partition,tmp_val); } log_info("Change partition type:\n"); @@ -63,12 +68,9 @@ void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char ** } if(partition->arch->set_part_type==NULL) return ; - while(*current_cmd[0]==',') - (*current_cmd)++; + skip_comma_in_command(current_cmd); { - int tmp_val= strtol(*current_cmd, NULL, 16); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + const int tmp_val=get_hex_from_command(current_cmd); partition->arch->set_part_type(partition,tmp_val); } log_info("Change partition type:\n"); diff --git a/src/common.c b/src/common.c index 2e12b07..3b1f45b 100644 --- a/src/common.c +++ b/src/common.c @@ -286,3 +286,28 @@ time_t td_ntfs2utc (int64_t ntfstime) { return (ntfstime - (NTFS_TIME_OFFSET)) / 10000000; } + +int check_command(char **current_cmd, const char *cmd, size_t n) +{ + const int res=strncmp(*current_cmd, cmd, n); + if(res==0) + (*current_cmd)+=n; + return res; +} + +void skip_comma_in_command(char **current_cmd) +{ + while(*current_cmd[0]==',') + (*current_cmd)++; +} + +uint64_t get_int_from_command(char **current_cmd) +{ + uint64_t tmp=0; + while(*current_cmd[0] >='0' && *current_cmd[0] <= '9') + { + tmp = tmp * 10 + *current_cmd[0] - '0'; + (*current_cmd)++; + } + return tmp; +} diff --git a/src/common.h b/src/common.h index a4a0654..a10107e 100644 --- a/src/common.h +++ b/src/common.h @@ -523,6 +523,9 @@ struct tm *localtime_r(const time_t *timep, struct tm *result); (void) (&_x == &_y); \ _x > _y ? _x : _y; }) +int check_command(char **current_cmd, const char *cmd, size_t n); +void skip_comma_in_command(char **current_cmd); +uint64_t get_int_from_command(char **current_cmd); #ifdef __cplusplus } /* closing brace for extern "C" */ #endif diff --git a/src/dirpart.c b/src/dirpart.c index 7380dd5..e4c09e9 100644 --- a/src/dirpart.c +++ b/src/dirpart.c @@ -173,23 +173,19 @@ dir_partition_t dir_partition(disk_t *disk, const partition_t *partition, const do { do_continue=0; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"recursive",9)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"recursive",9)==0) { - (*current_cmd)+=9; recursive=1; do_continue=1; } - else if(strncmp(*current_cmd,"fullpathname",12)==0) + else if(check_command(current_cmd,"fullpathname",12)==0) { - (*current_cmd)+=12; dir_data.param|=FLAG_LIST_PATHNAME; do_continue=1; } - else if(strncmp(*current_cmd, "filecopy", 8)==0) + else if(check_command(current_cmd, "filecopy", 8)==0) { - (*current_cmd)+=8; copy_files=1; do_continue=1; } diff --git a/src/fat1x.c b/src/fat1x.c index 4af020a..a3500e1 100644 --- a/src/fat1x.c +++ b/src/fat1x.c @@ -138,33 +138,27 @@ int fat1x_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos if(*current_cmd!=NULL) { command=0; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"rebuildbs",9)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"rebuildbs",9)==0) { - (*current_cmd)+=9; command='R'; } - else if(strncmp(*current_cmd,"dump",4)==0) + else if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; command='D'; } - else if(strncmp(*current_cmd,"list",4)==0) + else if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; if(strchr(options,'L')!=NULL) command='L'; } - else if(strncmp(*current_cmd,"repairfat",9)==0) + else if(check_command(current_cmd,"repairfat",9)==0) { - (*current_cmd)+=9; if(strchr(options,'C')!=NULL) command='C'; } - else if(strncmp(*current_cmd,"initroot",8)==0) + else if(check_command(current_cmd,"initroot",8)==0) { - (*current_cmd)+=8; if(strchr(options,'I')!=NULL) command='I'; } diff --git a/src/fat32.c b/src/fat32.c index f6aca69..73d309a 100644 --- a/src/fat32.c +++ b/src/fat32.c @@ -212,39 +212,32 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos if(*current_cmd!=NULL) { command=0; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"rebuildbs",9)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"rebuildbs",9)==0) { - (*current_cmd)+=9; command='R'; } - else if(strncmp(*current_cmd,"dump",4)==0) + else if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; command='D'; } - else if(strncmp(*current_cmd,"list",4)==0) + else if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; if(strchr(options,'L')!=NULL) command='L'; } - else if(strncmp(*current_cmd,"repairfat",9)==0) + else if(check_command(current_cmd,"repairfat",9)==0) { - (*current_cmd)+=9; if(strchr(options,'C')!=NULL) command='C'; } - else if(strncmp(*current_cmd,"originalfat",11)==0) + else if(check_command(current_cmd,"originalfat",11)==0) { - (*current_cmd)+=11; if(strchr(options,'O')!=NULL) command='O'; } - else if(strncmp(*current_cmd,"backupfat",9)==0) + else if(check_command(current_cmd,"backupfat",9)==0) { - (*current_cmd)+=9; if(strchr(options,'B')!=NULL) command='B'; } diff --git a/src/fat_adv.c b/src/fat_adv.c index 8444263..65d8bbe 100644 --- a/src/fat_adv.c +++ b/src/fat_adv.c @@ -967,28 +967,23 @@ static void menu_write_fat_boot_sector(disk_t *disk_car, partition_t *partition, if(*current_cmd!=NULL) { command='Q'; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"list",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; command='L'; } - else if(strncmp(*current_cmd,"dump",4)==0) + else if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; command='D'; } - else if(strncmp(*current_cmd,"noconfirm",9)==0) + else if(check_command(current_cmd,"noconfirm",9)==0) { command=0; /* do nothing */ no_confirm=1; - (*current_cmd)+=9; } - else if(strncmp(*current_cmd,"write",5)==0) + else if(check_command(current_cmd,"write",5)==0) { command='W'; - (*current_cmd)+=5; } } else diff --git a/src/geometry.c b/src/geometry.c index e2becc2..470ab60 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -82,14 +82,10 @@ int change_geometry_cli(disk_t *disk_car, char ** current_cmd) log_info("Current geometry\n%s sector_size=%u\n", disk_car->description(disk_car), disk_car->sector_size); while (done==0) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"C,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"C,",2)==0) { - (*current_cmd)+=2; - tmp_val = atol(*current_cmd); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + tmp_val = get_int_from_command(current_cmd); if (tmp_val > 0) { disk_car->geom.cylinders = tmp_val; @@ -100,12 +96,9 @@ int change_geometry_cli(disk_t *disk_car, char ** current_cmd) else log_error("Illegal cylinders value\n"); } - else if(strncmp(*current_cmd,"H,",2)==0) + else if(check_command(current_cmd,"H,",2)==0) { - (*current_cmd)+=2; - tmp_val = atoi(*current_cmd); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + tmp_val = get_int_from_command(current_cmd); if (tmp_val > 0 && tmp_val <= MAX_HEADS) { disk_car->geom.heads_per_cylinder = tmp_val; @@ -117,12 +110,9 @@ int change_geometry_cli(disk_t *disk_car, char ** current_cmd) else log_error("Illegal heads value\n"); } - else if(strncmp(*current_cmd,"S,",2)==0) + else if(check_command(current_cmd,"S,",2)==0) { - (*current_cmd)+=2; - tmp_val = atoi(*current_cmd); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + tmp_val = get_int_from_command(current_cmd); /* SUN partition can have more than 63 sectors */ if (tmp_val > 0) { disk_car->geom.sectors_per_head = tmp_val; @@ -133,12 +123,9 @@ int change_geometry_cli(disk_t *disk_car, char ** current_cmd) } else log_error("Illegal sectors value\n"); } - else if(strncmp(*current_cmd,"N,",2)==0) + else if(check_command(current_cmd,"N,",2)==0) { - (*current_cmd)+=2; - tmp_val = atoi(*current_cmd); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + tmp_val = get_int_from_command(current_cmd); if(change_sector_size(disk_car, cyl_modified, tmp_val)) log_error("Illegal sector size\n"); else diff --git a/src/intrf.c b/src/intrf.c index fe5e822..3905015 100644 --- a/src/intrf.c +++ b/src/intrf.c @@ -214,11 +214,8 @@ uint64_t ask_number_cli(char **current_cmd, const uint64_t val_cur, const uint64 if(*current_cmd!=NULL) { uint64_t tmp_val; - while(*current_cmd[0]==',') - (*current_cmd)++; - tmp_val = atouint64(*current_cmd); - while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') - (*current_cmd)++; + skip_comma_in_command(current_cmd); + tmp_val = get_int_from_command(current_cmd); if (val_min==val_max || (tmp_val >= val_min && tmp_val <= val_max)) return tmp_val; else diff --git a/src/intrface.c b/src/intrface.c index 25ca3a8..12b3ab5 100644 --- a/src/intrface.c +++ b/src/intrface.c @@ -80,11 +80,9 @@ void interface_list(disk_t *disk, const int verbose, const int saveheader, const static list_part_t *ask_structure_cli(disk_t *disk_car,list_part_t *list_part, const int verbose, char **current_cmd) { const list_part_t *pos=list_part; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"list",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; if(pos!=NULL) { const partition_t *partition=pos->part; diff --git a/src/ntfs_adv.c b/src/ntfs_adv.c index d248592..1a30c0f 100644 --- a/src/ntfs_adv.c +++ b/src/ntfs_adv.c @@ -136,26 +136,21 @@ static void menu_write_ntfs_boot_sector_cli(disk_t *disk_car, partition_t *parti { log_ntfs_info(ntfs_header); } - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"list",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; ntfs_list(disk_car, partition, newboot, current_cmd); } - else if(strncmp(*current_cmd,"dump",4)==0) + else if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; ntfs_dump(disk_car, partition, orgboot, newboot, current_cmd); } - else if(strncmp(*current_cmd,"noconfirm,",10)==0) + else if(check_command(current_cmd,"noconfirm,",10)==0) { - (*current_cmd)+=10; no_confirm=1; } - else if(strncmp(*current_cmd,"write",5)==0) + else if(check_command(current_cmd,"write",5)==0) { - (*current_cmd)+=5; if(no_confirm!=0 #ifdef HAVE_NCURSES || ask_confirmation("Write new NTFS boot sector, confirm ? (Y/N)")!=0 diff --git a/src/ntfs_udl.c b/src/ntfs_udl.c index d16fa94..37d0a50 100644 --- a/src/ntfs_udl.c +++ b/src/ntfs_udl.c @@ -1617,11 +1617,9 @@ static void ntfs_undelete_menu(disk_t *disk_car, const partition_t *partition, d log_list_file(disk_car, partition, dir_data, dir_list); if(*current_cmd!=NULL) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"allundelete",11)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"allundelete",11)==0) { - (*current_cmd)+=11; ntfs_undelete_cli(dir_data, dir_list); } return; /* Quit */ diff --git a/src/partgpt.c b/src/partgpt.c index 4947f57..806ac75 100644 --- a/src/partgpt.c +++ b/src/partgpt.c @@ -341,14 +341,12 @@ list_part_t *add_partition_gpt_cli(disk_t *disk_car,list_part_t *list_part, char new_partition=partition_new(&arch_gpt); new_partition->part_offset=disk_car->sector_size; new_partition->part_size=disk_car->disk_size-new_partition->part_offset; - while(*current_cmd[0]==',') - (*current_cmd)++; while(1) { - if(strncmp(*current_cmd,"s,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"s,",2)==0) { uint64_t part_offset; - (*current_cmd)+=2; part_offset=new_partition->part_offset; new_partition->part_offset=(uint64_t)ask_number_cli( current_cmd, @@ -359,9 +357,8 @@ list_part_t *add_partition_gpt_cli(disk_t *disk_car,list_part_t *list_part, char (uint64_t)disk_car->sector_size; new_partition->part_size=new_partition->part_size + part_offset - new_partition->part_offset; } - else if(strncmp(*current_cmd,"S,",2)==0) + else if(check_command(current_cmd,"S,",2)==0) { - (*current_cmd)+=2; new_partition->part_size=(uint64_t)ask_number_cli( current_cmd, (new_partition->part_offset+new_partition->part_size-1)/disk_car->sector_size, @@ -371,9 +368,8 @@ list_part_t *add_partition_gpt_cli(disk_t *disk_car,list_part_t *list_part, char (uint64_t)disk_car->sector_size + disk_car->sector_size - new_partition->part_offset; } - else if(strncmp(*current_cmd,"T,",2)==0) + else if(check_command(current_cmd,"T,",2)==0) { - (*current_cmd)+=2; change_part_type_cli(disk_car,new_partition,current_cmd); } else if(new_partition->part_size>0 && guid_cmp(new_partition->part_type_gpt, GPT_ENT_TYPE_UNUSED)!=0) diff --git a/src/parthumax.c b/src/parthumax.c index c9af332..86b3cd4 100644 --- a/src/parthumax.c +++ b/src/parthumax.c @@ -194,23 +194,19 @@ list_part_t *add_partition_humax_cli(disk_t *disk_car,list_part_t *list_part, ch end.cylinder=disk_car->geom.cylinders-1; end.head=disk_car->geom.heads_per_cylinder-1; end.sector=disk_car->geom.sectors_per_head; - while(*current_cmd[0]==',') - (*current_cmd)++; while(1) { - if(strncmp(*current_cmd,"c,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"c,",2)==0) { - (*current_cmd)+=2; start.cylinder=ask_number_cli(current_cmd, start.cylinder,0,disk_car->geom.cylinders-1,"Enter the starting cylinder "); } - else if(strncmp(*current_cmd,"C,",2)==0) + else if(check_command(current_cmd,"C,",2)==0) { - (*current_cmd)+=2; end.cylinder=ask_number_cli(current_cmd, end.cylinder,start.cylinder,disk_car->geom.cylinders-1,"Enter the ending cylinder "); } - else if(strncmp(*current_cmd,"T,",2)==0) + else if(check_command(current_cmd,"T,",2)==0) { - (*current_cmd)+=2; change_part_type_cli(disk_car,new_partition,current_cmd); } else if((CHS2offset(disk_car,&end)>new_partition->part_offset) && diff --git a/src/parti386.c b/src/parti386.c index 211686e..350a38b 100644 --- a/src/parti386.c +++ b/src/parti386.c @@ -1234,49 +1234,41 @@ list_part_t *add_partition_i386_cli(disk_t *disk_car, list_part_t *list_part, ch end.cylinder=disk_car->geom.cylinders-1; end.head=disk_car->geom.heads_per_cylinder-1; end.sector=disk_car->geom.sectors_per_head; - while(*current_cmd[0]==',') - (*current_cmd)++; while(1) { - if(strncmp(*current_cmd,"c,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"c,",2)==0) { - (*current_cmd)+=2; start.cylinder=ask_number_cli(current_cmd, start.cylinder, 0, disk_car->geom.cylinders-1, "Enter the starting cylinder "); } - else if(strncmp(*current_cmd,"h,",2)==0) + else if(check_command(current_cmd,"h,",2)==0) { - (*current_cmd)+=2; start.head=ask_number_cli(current_cmd, start.head, 0, disk_car->geom.heads_per_cylinder-1, "Enter the starting head "); } - else if(strncmp(*current_cmd,"s,",2)==0) + else if(check_command(current_cmd,"s,",2)==0) { - (*current_cmd)+=2; start.sector=ask_number_cli(current_cmd, start.sector, 1, disk_car->geom.sectors_per_head, "Enter the starting sector "); } - else if(strncmp(*current_cmd,"C,",2)==0) + else if(check_command(current_cmd,"C,",2)==0) { - (*current_cmd)+=2; end.cylinder=ask_number_cli(current_cmd, end.cylinder, start.cylinder, disk_car->geom.cylinders-1, "Enter the ending cylinder "); } - else if(strncmp(*current_cmd,"H,",2)==0) + else if(check_command(current_cmd,"H,",2)==0) { - (*current_cmd)+=2; end.head=ask_number_cli(current_cmd, end.head, 0, disk_car->geom.heads_per_cylinder-1, "Enter the ending head "); } - else if(strncmp(*current_cmd,"S,",2)==0) + else if(check_command(current_cmd,"S,",2)==0) { - (*current_cmd)+=2; end.sector=ask_number_cli(current_cmd, end.sector, 1, disk_car->geom.sectors_per_head-1, "Enter the ending sector "); } - else if(strncmp(*current_cmd,"T,",2)==0) + else if(check_command(current_cmd,"T,",2)==0) { - (*current_cmd)+=2; change_part_type_cli(disk_car,new_partition,current_cmd); } else if((CHS2offset(disk_car,&end)>new_partition->part_offset) && diff --git a/src/partmac.c b/src/partmac.c index f3f86e7..36e5e19 100644 --- a/src/partmac.c +++ b/src/partmac.c @@ -216,14 +216,12 @@ list_part_t *add_partition_mac_cli(disk_t *disk_car,list_part_t *list_part, char assert(current_cmd!=NULL); new_partition->part_offset=disk_car->sector_size; new_partition->part_size=disk_car->disk_size-disk_car->sector_size; - while(*current_cmd[0]==',') - (*current_cmd)++; while(1) { - if(strncmp(*current_cmd,"s,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"s,",2)==0) { uint64_t part_offset; - (*current_cmd)+=2; part_offset=new_partition->part_offset; new_partition->part_offset=(uint64_t)ask_number_cli( current_cmd, @@ -234,9 +232,8 @@ list_part_t *add_partition_mac_cli(disk_t *disk_car,list_part_t *list_part, char (uint64_t)disk_car->sector_size; new_partition->part_size=new_partition->part_size + part_offset - new_partition->part_offset; } - else if(strncmp(*current_cmd,"S,",2)==0) + else if(check_command(current_cmd,"S,",2)==0) { - (*current_cmd)+=2; new_partition->part_size=(uint64_t)ask_number_cli( current_cmd, (new_partition->part_offset+new_partition->part_size-1)/disk_car->sector_size, @@ -246,9 +243,8 @@ list_part_t *add_partition_mac_cli(disk_t *disk_car,list_part_t *list_part, char (uint64_t)disk_car->sector_size + disk_car->sector_size - new_partition->part_offset; } - else if(strncmp(*current_cmd,"T,",2)==0) + else if(check_command(current_cmd,"T,",2)==0) { - (*current_cmd)+=2; change_part_type_cli(disk_car,new_partition,current_cmd); } else if(new_partition->part_size>0 && new_partition->part_type_mac>0) diff --git a/src/partsun.c b/src/partsun.c index 1c2e4c8..113cbe6 100644 --- a/src/partsun.c +++ b/src/partsun.c @@ -228,23 +228,19 @@ list_part_t *add_partition_sun_cli(disk_t *disk_car,list_part_t *list_part, char end.cylinder=disk_car->geom.cylinders-1; end.head=disk_car->geom.heads_per_cylinder-1; end.sector=disk_car->geom.sectors_per_head; - while(*current_cmd[0]==',') - (*current_cmd)++; while(1) { - if(strncmp(*current_cmd,"c,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"c,",2)==0) { - (*current_cmd)+=2; start.cylinder=ask_number_cli(current_cmd, start.cylinder,0,disk_car->geom.cylinders-1,"Enter the starting cylinder "); } - else if(strncmp(*current_cmd,"C,",2)==0) + else if(check_command(current_cmd,"C,",2)==0) { - (*current_cmd)+=2; end.cylinder=ask_number_cli(current_cmd, end.cylinder,start.cylinder,disk_car->geom.cylinders-1,"Enter the ending cylinder "); } - else if(strncmp(*current_cmd,"T,",2)==0) + else if(check_command(current_cmd,"T,",2)==0) { - (*current_cmd)+=2; change_part_type_cli(disk_car,new_partition,current_cmd); } else if((CHS2offset(disk_car,&end)>new_partition->part_offset) && diff --git a/src/partxbox.c b/src/partxbox.c index 699264d..4cd1817 100644 --- a/src/partxbox.c +++ b/src/partxbox.c @@ -151,14 +151,12 @@ list_part_t *add_partition_xbox_cli(disk_t *disk_car,list_part_t *list_part, cha assert(current_cmd!=NULL); new_partition->part_offset=disk_car->sector_size; new_partition->part_size=disk_car->disk_size-disk_car->sector_size; - while(*current_cmd[0]==',') - (*current_cmd)++; while(1) { - if(strncmp(*current_cmd,"s,",2)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"s,",2)==0) { uint64_t part_offset; - (*current_cmd)+=2; part_offset=new_partition->part_offset; new_partition->part_offset=(uint64_t)ask_number_cli( current_cmd, @@ -169,9 +167,8 @@ list_part_t *add_partition_xbox_cli(disk_t *disk_car,list_part_t *list_part, cha (uint64_t)disk_car->sector_size; new_partition->part_size=new_partition->part_size + part_offset - new_partition->part_offset; } - else if(strncmp(*current_cmd,"S,",2)==0) + else if(check_command(current_cmd,"S,",2)==0) { - (*current_cmd)+=2; new_partition->part_size=(uint64_t)ask_number_cli( current_cmd, (new_partition->part_offset+new_partition->part_size-1)/disk_car->sector_size, @@ -181,9 +178,8 @@ list_part_t *add_partition_xbox_cli(disk_t *disk_car,list_part_t *list_part, cha (uint64_t)disk_car->sector_size + disk_car->sector_size - new_partition->part_offset; } - else if(strncmp(*current_cmd,"T,",2)==0) + else if(check_command(current_cmd,"T,",2)==0) { - (*current_cmd)+=2; change_part_type_cli(disk_car,new_partition,current_cmd); } else if(new_partition->part_size>0 && new_partition->part_type_xbox>0) diff --git a/src/phcli.c b/src/phcli.c index 7440e43..c11d574 100644 --- a/src/phcli.c +++ b/src/phcli.c @@ -62,25 +62,20 @@ static int file_select_cli(file_enable_t *files_enable, char**current_cmd) { file_enable_t *file_enable; keep_asking=0; - while(*current_cmd[0]==',') - (*current_cmd)++; + skip_comma_in_command(current_cmd); if(*current_cmd[0]=='\0') return 0; - if(strncmp(*current_cmd,"everything",10)==0) + if(check_command(current_cmd,"everything",10)==0) { int enable_status; keep_asking=1; - (*current_cmd)+=10; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"enable",6)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"enable",6)==0) { - (*current_cmd)+=6; enable_status=1; } - else if(strncmp(*current_cmd,"disable",7)==0) + else if(check_command(current_cmd,"disable",7)==0) { - (*current_cmd)+=7; enable_status=0; } else @@ -100,20 +95,16 @@ static int file_select_cli(file_enable_t *files_enable, char**current_cmd) { if(file_enable->file_hint->extension!=NULL && strlen(file_enable->file_hint->extension)==cmd_length && - memcmp(file_enable->file_hint->extension,*current_cmd,cmd_length)==0) + check_command(current_cmd, file_enable->file_hint->extension, cmd_length)==0) { keep_asking=1; - (*current_cmd)+=cmd_length; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"enable",6)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"enable",6)==0) { - (*current_cmd)+=6; file_enable->enable=1; } - else if(strncmp(*current_cmd,"disable",7)==0) + else if(check_command(current_cmd,"disable",7)==0) { - (*current_cmd)+=7; file_enable->enable=0; } else @@ -135,13 +126,11 @@ int menu_photorec_cli(list_part_t *list_part, struct ph_param *params, struct ph params->partition=(list_part->next!=NULL ? list_part->next->part : list_part->part); while(1) { - while(params->cmd_run[0]==',') - params->cmd_run++; + skip_comma_in_command(¶ms->cmd_run); if(params->cmd_run[0]=='\0') return 0; - if(strncmp(params->cmd_run,"search",6)==0) + if(check_command(¶ms->cmd_run,"search",6)==0) { - params->cmd_run+=6; if(mode_init_space==INIT_SPACE_EXT2_GROUP) { params->blocksize=ext2_fix_group(list_search_space, params->disk, params->partition); @@ -172,52 +161,41 @@ int menu_photorec_cli(list_part_t *list_part, struct ph_param *params, struct ph params->blocksize=user_blocksize; return 1; } - else if(strncmp(params->cmd_run,"options",7)==0) + else if(check_command(¶ms->cmd_run,"options",7)==0) { - params->cmd_run+=7; interface_options_photorec_cli(options, ¶ms->cmd_run); } - else if(strncmp(params->cmd_run,"fileopt",7)==0) + else if(check_command(¶ms->cmd_run,"fileopt",7)==0) { - params->cmd_run+=7; if(file_select_cli(options->list_file_format, ¶ms->cmd_run) < 0) return -1; } - else if(strncmp(params->cmd_run,"blocksize,",10)==0) + else if(check_command(¶ms->cmd_run,"blocksize,",10)==0) { - params->cmd_run+=10; - user_blocksize=atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; + user_blocksize=get_int_from_command(¶ms->cmd_run); } - else if(strncmp(params->cmd_run,"geometry,",9)==0) + else if(check_command(¶ms->cmd_run,"geometry,",9)==0) { - params->cmd_run+=9; change_geometry_cli(params->disk, ¶ms->cmd_run); } - else if(strncmp(params->cmd_run,"inter",5)==0) + else if(check_command(¶ms->cmd_run,"inter",5)==0) { /* Start interactive mode */ params->cmd_run=NULL; return 0; } - else if(strncmp(params->cmd_run,"wholespace",10)==0) + else if(check_command(¶ms->cmd_run,"wholespace",10)==0) { - params->cmd_run+=10; params->carve_free_space_only=0; } - else if(strncmp(params->cmd_run,"freespace",9)==0) + else if(check_command(¶ms->cmd_run,"freespace",9)==0) { - params->cmd_run+=9; params->carve_free_space_only=1; } - else if(strncmp(params->cmd_run,"ext2_group,",11)==0) + else if(check_command(¶ms->cmd_run,"ext2_group,",11)==0) { unsigned int groupnr; - params->cmd_run+=11; options->mode_ext2=1; - groupnr=atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; + groupnr=get_int_from_command(¶ms->cmd_run); if(mode_init_space==INIT_SPACE_WHOLE) mode_init_space=INIT_SPACE_EXT2_GROUP; if(mode_init_space==INIT_SPACE_EXT2_GROUP) @@ -233,14 +211,11 @@ int menu_photorec_cli(list_part_t *list_part, struct ph_param *params, struct ph free(new_free_space); } } - else if(strncmp(params->cmd_run,"ext2_inode,",11)==0) + else if(check_command(¶ms->cmd_run,"ext2_inode,",11)==0) { unsigned int inodenr; - params->cmd_run+=11; options->mode_ext2=1; - inodenr=atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; + inodenr=get_int_from_command(¶ms->cmd_run); if(mode_init_space==INIT_SPACE_WHOLE) mode_init_space=INIT_SPACE_EXT2_INODE; if(mode_init_space==INIT_SPACE_EXT2_INODE) @@ -259,9 +234,7 @@ int menu_photorec_cli(list_part_t *list_part, struct ph_param *params, struct ph else if(isdigit(params->cmd_run[0])) { list_part_t *element; - const unsigned int order= atoi(params->cmd_run); - while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0') - params->cmd_run++; + const unsigned int order=get_int_from_command(¶ms->cmd_run); for(element=list_part;element!=NULL && element->part->order!=order;element=element->next); if(element!=NULL) params->partition=element->part; diff --git a/src/photorec.c b/src/photorec.c index 31ffbb2..5b316f4 100644 --- a/src/photorec.c +++ b/src/photorec.c @@ -748,8 +748,7 @@ uint64_t set_search_start(struct ph_param *params, alloc_data_t **new_current_se else if(params->cmd_run!=NULL && params->cmd_run[0]!='\0') { offset=0; - while(*params->cmd_run==',') - params->cmd_run++; + skip_comma_in_command(¶ms->cmd_run); while(*params->cmd_run >= '0' && *params->cmd_run <= '9') { offset=offset * 10 + (*params->cmd_run - '0'); diff --git a/src/phrecn.c b/src/phrecn.c index 6d32b67..d5b12fd 100644 --- a/src/phrecn.c +++ b/src/phrecn.c @@ -236,47 +236,38 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da params_reset(params, options); if(params->cmd_run!=NULL && params->cmd_run[0]!='\0') { - while(params->cmd_run[0]==',') - params->cmd_run++; - if(strncmp(params->cmd_run,"status=unformat",15)==0) + skip_comma_in_command(¶ms->cmd_run); + if(check_command(¶ms->cmd_run,"status=unformat",15)==0) { params->status=STATUS_UNFORMAT; - params->cmd_run+=15; } - else if(strncmp(params->cmd_run,"status=find_offset",18)==0) + else if(check_command(¶ms->cmd_run,"status=find_offset",18)==0) { params->status=STATUS_FIND_OFFSET; - params->cmd_run+=18; } - else if(strncmp(params->cmd_run,"status=ext2_on_bf",17)==0) + else if(check_command(¶ms->cmd_run,"status=ext2_on_bf",17)==0) { params->status=STATUS_EXT2_ON_BF; - params->cmd_run+=17; } - else if(strncmp(params->cmd_run,"status=ext2_on_save_everything",30)==0) + else if(check_command(¶ms->cmd_run,"status=ext2_on_save_everything",30)==0) { params->status=STATUS_EXT2_ON_SAVE_EVERYTHING; - params->cmd_run+=30; } - else if(strncmp(params->cmd_run,"status=ext2_on",14)==0) + else if(check_command(¶ms->cmd_run,"status=ext2_on",14)==0) { params->status=STATUS_EXT2_ON; - params->cmd_run+=14; } - else if(strncmp(params->cmd_run,"status=ext2_off_bf",18)==0) + else if(check_command(¶ms->cmd_run,"status=ext2_off_bf",18)==0) { params->status=STATUS_EXT2_OFF_BF; - params->cmd_run+=18; } - else if(strncmp(params->cmd_run,"status=ext2_off_save_everything",31)==0) + else if(check_command(¶ms->cmd_run,"status=ext2_off_save_everything",31)==0) { params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING; - params->cmd_run+=31; } - else if(strncmp(params->cmd_run,"status=ext2_off",15)==0) + else if(check_command(¶ms->cmd_run,"status=ext2_off",15)==0) { params->status=STATUS_EXT2_OFF; - params->cmd_run+=15; } } else diff --git a/src/poptions.c b/src/poptions.c index 9105a14..97cb3d9 100644 --- a/src/poptions.c +++ b/src/poptions.c @@ -40,51 +40,42 @@ void interface_options_photorec_cli(struct ph_options *options, char **current_c return ; while(1) { - while(*current_cmd[0]==',') - (*current_cmd)++; + skip_comma_in_command(current_cmd); /* paranoid, longer option first */ - if(strncmp(*current_cmd,"paranoid_no",11)==0) + if(check_command(current_cmd,"paranoid_no",11)==0) { - (*current_cmd)+=11; options->paranoid=0; } - else if(strncmp(*current_cmd,"paranoid_bf",11)==0) + else if(check_command(current_cmd,"paranoid_bf",11)==0) { - (*current_cmd)+=11; options->paranoid=2; } - else if(strncmp(*current_cmd,"paranoid",8)==0) + else if(check_command(current_cmd,"paranoid",8)==0) { - (*current_cmd)+=8; options->paranoid=1; } /* keep_corrupted_file */ - else if(strncmp(*current_cmd,"keep_corrupted_file_no",22)==0) + else if(check_command(current_cmd,"keep_corrupted_file_no",22)==0) { - (*current_cmd)+=22; options->keep_corrupted_file=0; } - else if(strncmp(*current_cmd,"keep_corrupted_file",19)==0) + else if(check_command(current_cmd,"keep_corrupted_file",19)==0) { - (*current_cmd)+=19; options->keep_corrupted_file=1; } /* mode_ext2 */ - else if(strncmp(*current_cmd,"mode_ext2",9)==0) + else if(check_command(current_cmd,"mode_ext2",9)==0) { - (*current_cmd)+=9; options->mode_ext2=1; } /* expert */ - else if(strncmp(*current_cmd,"expert",6)==0) + else if(check_command(current_cmd,"expert",6)==0) { - (*current_cmd)+=6; options->expert=1; } /* lowmem */ - else if(strncmp(*current_cmd,"lowmem",6)==0) + else if(check_command(current_cmd,"lowmem",6)==0) { - (*current_cmd)+=6; options->lowmem=1; } else diff --git a/src/ppartseln.c b/src/ppartseln.c index e134f1b..da3dced 100644 --- a/src/ppartseln.c +++ b/src/ppartseln.c @@ -115,9 +115,8 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da } if(params->cmd_run!=NULL) { - while(params->cmd_run[0]==',') - params->cmd_run++; - if(strncmp(params->cmd_run,"inter",5)==0) + skip_comma_in_command(¶ms->cmd_run); + if(check_command(¶ms->cmd_run,"inter",5)==0) { /* Start interactive mode */ params->cmd_run=NULL; } diff --git a/src/psearchn.c b/src/psearchn.c index 562a707..553d050 100644 --- a/src/psearchn.c +++ b/src/psearchn.c @@ -115,7 +115,7 @@ pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options { pfstatus_t file_recovered=PFSTATUS_BAD; uint64_t old_offset=offset; - int res=DC_SCAN; + data_check_t res=DC_SCAN; #ifdef DEBUG log_debug("sector %llu\n", (unsigned long long)((offset-params->partition->part_offset)/params->disk->sector_size)); diff --git a/src/tanalyse.c b/src/tanalyse.c index a65e111..8732c42 100644 --- a/src/tanalyse.c +++ b/src/tanalyse.c @@ -76,11 +76,9 @@ static list_part_t *interface_analyse_ncurses(disk_t *disk_car, const int verbos command='Q'; if(*current_cmd!=NULL) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"backup",6)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"backup",6)==0) { - (*current_cmd)+=6; if(list_part!=NULL) command='B'; } diff --git a/src/tdiskop.c b/src/tdiskop.c index 8717d64..332850f 100644 --- a/src/tdiskop.c +++ b/src/tdiskop.c @@ -59,41 +59,32 @@ static int menu_disk_cli(disk_t *disk_car, const int verbose,int dump_ind, const unsigned int expert=0; while(1) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"analyze",7)==0 || strncmp(*current_cmd,"analyse",7)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"analyze",7)==0 || check_command(current_cmd,"analyse",7)==0) { - (*current_cmd)+=7; - { - list_part_t *list_part; - list_part=interface_analyse(disk_car, verbose, saveheader, current_cmd); - interface_recovery(disk_car, list_part, verbose, dump_ind, align, ask_part_order, expert, current_cmd); - part_free_list(list_part); - } + list_part_t *list_part; + list_part=interface_analyse(disk_car, verbose, saveheader, current_cmd); + interface_recovery(disk_car, list_part, verbose, dump_ind, align, ask_part_order, expert, current_cmd); + part_free_list(list_part); } - else if(strncmp(*current_cmd,"geometry,",9)==0) + else if(check_command(current_cmd,"geometry,",9)==0) { - (*current_cmd)+=9; change_geometry_cli(disk_car, current_cmd); } - else if(strncmp(*current_cmd,"advanced",8)==0) + else if(check_command(current_cmd,"advanced",8)==0) { - (*current_cmd)+=8; interface_adv(disk_car, verbose, dump_ind, expert,current_cmd); } - else if(strncmp(*current_cmd,"options,",8)==0) + else if(check_command(current_cmd,"options,",8)==0) { - (*current_cmd)+=8; interface_options(&dump_ind, &align, &expert,current_cmd); } - else if(strncmp(*current_cmd,"delete",6)==0) + else if(check_command(current_cmd,"delete",6)==0) { - (*current_cmd)+=6; write_clean_table(disk_car); } - else if(strncmp(*current_cmd,"mbr_code",8)==0) + else if(check_command(current_cmd,"mbr_code",8)==0) { - (*current_cmd)+=8; write_MBR_code(disk_car); } else diff --git a/src/tdisksel.c b/src/tdisksel.c index 14170ad..7bebd3f 100644 --- a/src/tdisksel.c +++ b/src/tdisksel.c @@ -241,8 +241,7 @@ static int testdisk_disk_selection_cli(int verbose,int dump_ind, const list_disk } if(*current_cmd!=NULL) { - while(*current_cmd[0]==',') - (*current_cmd)++; + skip_comma_in_command(current_cmd); { disk_t *disk=current_disk->disk; autodetect_arch(disk, NULL); diff --git a/src/testdisk.c b/src/testdisk.c index bcaffe3..891833a 100644 --- a/src/testdisk.c +++ b/src/testdisk.c @@ -471,11 +471,9 @@ int main( int argc, char **argv ) int command='Q'; if(cmd_run!=NULL) { - while(cmd_run[0]==',') - (cmd_run)++; - if(strncmp(cmd_run,"list",4)==0) + skip_comma_in_command(&cmd_run); + if(check_command(&cmd_run,"list",4)==0) { - (cmd_run)+=4; command='L'; } else if(cmd_run[0]!='\0') diff --git a/src/texfat.c b/src/texfat.c index 65b860b..f626117 100644 --- a/src/texfat.c +++ b/src/texfat.c @@ -75,22 +75,18 @@ static void exFAT_dump(disk_t *disk, const partition_t *partition, const unsigne static int exFAT_boot_sector_command(char **current_cmd, const char *options) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"dump",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; return 'D'; } - else if(strncmp(*current_cmd,"originalexFAT",13)==0) + else if(check_command(current_cmd,"originalexFAT",13)==0) { - (*current_cmd)+=13; if(strchr(options,'O')!=NULL) return 'O'; } - else if(strncmp(*current_cmd,"backupexFAT",11)==0) + else if(check_command(current_cmd,"backupexFAT",11)==0) { - (*current_cmd)+=11; if(strchr(options,'B')!=NULL) return 'B'; } @@ -76,22 +76,18 @@ static void hfs_dump(disk_t *disk_car, const partition_t *partition, const unsig static int HFS_HFSP_boot_sector_command(char **current_cmd, const char *options) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"dump",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; return 'D'; } - else if(strncmp(*current_cmd,"originalhfsp",11)==0) + else if(check_command(current_cmd,"originalhfsp",11)==0) { - (*current_cmd)+=11; if(strchr(options,'O')!=NULL) return 'O'; } - else if(strncmp(*current_cmd,"backuphfsp",9)==0) + else if(check_command(current_cmd,"backuphfsp",9)==0) { - (*current_cmd)+=9; if(strchr(options,'B')!=NULL) return 'B'; } diff --git a/src/tntfs.c b/src/tntfs.c index 18ec2c0..9594f8e 100644 --- a/src/tntfs.c +++ b/src/tntfs.c @@ -74,38 +74,31 @@ static void dump_NTFS(disk_t *disk_car, const partition_t *partition, const unsi static int ntfs_boot_sector_command(char **current_cmd, const char *options) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"rebuildbs",9)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"rebuildbs",9)==0) { - (*current_cmd)+=9; return 'R'; } - else if(strncmp(*current_cmd,"dump",4)==0) + else if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; return 'D'; } - else if(strncmp(*current_cmd,"list",4)==0) + else if(check_command(current_cmd,"list",4)==0) { - (*current_cmd)+=4; return 'L'; } - else if(strncmp(*current_cmd,"originalntfs",12)==0) + else if(check_command(current_cmd,"originalntfs",12)==0) { - (*current_cmd)+=12; if(strchr(options,'O')!=NULL) return 'O'; } - else if(strncmp(*current_cmd,"backupntfs",10)==0) + else if(check_command(current_cmd,"backupntfs",10)==0) { - (*current_cmd)+=10; if(strchr(options,'B')!=NULL) return 'B'; } - else if(strncmp(*current_cmd,"repairmft",9)==0) + else if(check_command(current_cmd,"repairmft",9)==0) { - (*current_cmd)+=9; if(strchr(options,'M')!=NULL) return 'M'; } @@ -114,11 +107,9 @@ static int ntfs_boot_sector_command(char **current_cmd, const char *options) static int is_no_confirm_command(char **current_cmd) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"noconfirm",9)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"noconfirm",9)==0) { - (*current_cmd)+=9; return 1; } return 0; diff --git a/src/toptions.c b/src/toptions.c index 70b5a67..232f414 100644 --- a/src/toptions.c +++ b/src/toptions.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <string.h> +#include <assert.h> #include "types.h" #include "common.h" #include "intrf.h" @@ -81,41 +82,35 @@ static void interface_options_ncurses(int *dump_ind, int *align, unsigned int *e void interface_options(int *dump_ind, int *align, unsigned int *expert, char**current_cmd) { + assert(current_cmd!=NULL); if(*current_cmd!=NULL) { int keep_asking=1; do { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"dump",4)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"dump",4)==0) { - (*current_cmd)+=4; *dump_ind=1; } - else if(strncmp(*current_cmd,"nodump",6)==0) + else if(check_command(current_cmd,"nodump",6)==0) { - (*current_cmd)+=6; *dump_ind=0; } - else if(strncmp(*current_cmd,"align",5)==0) + else if(check_command(current_cmd,"align",5)==0) { - (*current_cmd)+=5; *align=1; } - else if(strncmp(*current_cmd,"noalign",7)==0) + else if(check_command(current_cmd,"noalign",7)==0) { - (*current_cmd)+=7; *align=0; } - else if(strncmp(*current_cmd,"expert",6)==0) + else if(check_command(current_cmd,"expert",6)==0) { - (*current_cmd)+=6; *expert=1; } - else if(strncmp(*current_cmd,"noexpert",8)==0) + else if(check_command(current_cmd,"noexpert",8)==0) { - (*current_cmd)+=6; *expert=0; } else diff --git a/src/tpartwr.c b/src/tpartwr.c index f32fd3b..d3517b9 100644 --- a/src/tpartwr.c +++ b/src/tpartwr.c @@ -75,11 +75,9 @@ int interface_write(disk_t *disk_car,list_part_t *list_part,const int can_search screen_buffer_to_log(); if(*current_cmd!=NULL) { - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"search",6)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"search",6)==0) { - (*current_cmd)+=6; command='S'; } } @@ -98,23 +96,19 @@ int interface_write(disk_t *disk_car,list_part_t *list_part,const int can_search do { command='Q'; - while(*current_cmd[0]==',') - (*current_cmd)++; - if(strncmp(*current_cmd,"search",6)==0) + skip_comma_in_command(current_cmd); + if(check_command(current_cmd,"search",6)==0) { - (*current_cmd)+=6; if(can_search_deeper) command='S'; } - else if(strncmp(*current_cmd,"noconfirm",9)==0) + else if(check_command(current_cmd,"noconfirm",9)==0) { command=0; /* do nothing */ (*no_confirm)=1; - (*current_cmd)+=9; } - else if(strncmp(*current_cmd,"write",5)==0) + else if(check_command(current_cmd,"write",5)==0) { - (*current_cmd)+=5; if(disk_car->arch->write_part!=NULL) command='W'; } |