1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-10-31 15:45:03 -04:00

Convert strtrim/strlen paired calls to only strtrim

This utilizes the new return value so we don't have to find the length
of the string again.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-12-23 14:47:30 -06:00
parent 38143770a9
commit c34b69b5c7
2 changed files with 11 additions and 10 deletions

View File

@ -726,8 +726,7 @@ static int _parseconfig(const char *file, struct section_t *section,
*ptr = '\0';
}
strtrim(line);
line_len = strlen(line);
line_len = strtrim(line);
if(line_len == 0) {
continue;

View File

@ -1228,14 +1228,14 @@ static int multiselect_parse(char *array, int count, char *response)
for(str = response; ; str = NULL) {
int include = 1;
int start, end;
size_t len;
char *ends = NULL;
char *starts = strtok_r(str, " ", &saveptr);
if(starts == NULL) {
break;
}
strtrim(starts);
int len = strlen(starts);
len = strtrim(starts);
if(len == 0)
continue;
@ -1314,6 +1314,7 @@ int multiselect_question(char *array, int count)
if(fgets(response, response_len, stdin)) {
const size_t response_incr = 64;
size_t len;
/* handle buffer not being large enough to read full line case */
while(*lastchar == '\0' && lastchar[-1] != '\n') {
response_len += response_incr;
@ -1330,8 +1331,9 @@ int multiselect_question(char *array, int count)
return -1;
}
}
strtrim(response);
if(strlen(response) > 0) {
len = strtrim(response);
if(len > 0) {
if(multiselect_parse(array, count, response) == -1) {
/* only loop if user gave an invalid answer */
continue;
@ -1374,8 +1376,8 @@ int select_question(int count)
flush_term_input();
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) > 0) {
size_t len = strtrim(response);
if(len > 0) {
int n;
if(parseindex(response, &n, 1, count) != 0)
continue;
@ -1423,8 +1425,8 @@ static int question(short preset, char *fmt, va_list args)
flush_term_input();
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) == 0) {
size_t len = strtrim(response);
if(len == 0) {
return preset;
}