use skip_whitespace where appropriate

This commit is contained in:
Denis Vlasenko 2006-10-25 12:46:03 +00:00
parent c8400a2162
commit d18a3a20db
8 changed files with 98 additions and 105 deletions

View File

@ -1470,7 +1470,7 @@ static int awk_split(char *s, node *spl, char **slist)
}
} else { /* space split */
while (*s) {
while (isspace(*s)) s++;
s = skip_whitespace(s);
if (! *s) break;
n++;
while (*s && !isspace(*s))

View File

@ -420,7 +420,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
} else if (strchr(":btT", sed_cmd->cmd)) {
int length;
while(isspace(*cmdstr)) cmdstr++;
cmdstr = skip_whitespace(cmdstr);
length = strcspn(cmdstr, semicolon_whitespace);
if (length) {
sed_cmd->string = xstrndup(cmdstr, length);
@ -517,7 +517,7 @@ static void add_cmd(char *cmdstr)
}
/* skip whitespace before the command */
while (isspace(*cmdstr)) cmdstr++;
cmdstr = skip_whitespace(cmdstr);
/* Check for inversion flag */
if (*cmdstr == '!') {
@ -525,7 +525,7 @@ static void add_cmd(char *cmdstr)
cmdstr++;
/* skip whitespace before the command */
while (isspace(*cmdstr)) cmdstr++;
cmdstr = skip_whitespace(cmdstr);
}
/* last part (mandatory) will be a command */
@ -1167,15 +1167,23 @@ int sed_main(int argc, char **argv)
FILE *file;
for (i = optind; i < argc; i++) {
struct stat statbuf;
int nonstdoutfd;
if(!strcmp(argv[i], "-") && !bbg.in_place) {
add_input_file(stdin);
process_files();
} else {
continue;
}
file = bb_wfopen(argv[i], "r");
if (file) {
if(bbg.in_place) {
struct stat statbuf;
int nonstdoutfd;
if (!file) {
status = EXIT_FAILURE;
continue;
}
if(!bbg.in_place) {
add_input_file(file);
continue;
}
bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
strcat(bbg.outname,"XXXXXX");
@ -1196,11 +1204,6 @@ int sed_main(int argc, char **argv)
rename(bbg.outname,argv[i]);
free(bbg.outname);
bbg.outname=0;
} else add_input_file(file);
} else {
status = EXIT_FAILURE;
}
}
}
if(bbg.input_file_count>bbg.current_input_file) process_files();
}

View File

@ -180,9 +180,9 @@ static void stack_machine(const char *argument)
static char *get_token(char **buffer)
{
char *start = NULL;
char *current = *buffer;
char *current;
while (isspace(*current)) { current++; }
current = skip_whitespace(*buffer);
if (*current != 0) {
start = current;
while (!isspace(*current) && *current != 0) { current++; }

View File

@ -76,15 +76,13 @@ static int parse_tag_value ( char *buffer, char **ptag, char **pvalue )
{
char *tag, *value;
while ( isspace ( *buffer ))
buffer++;
buffer = skip_whitespace ( buffer );
tag = value = buffer;
while ( !isspace ( *value ))
if (!*value) return 0;
else value++;
*value++ = 0;
while ( isspace ( *value ))
value++;
value = skip_whitespace ( value );
if (!*value) return 0;
*ptag = tag;
@ -311,11 +309,9 @@ static void include_conf ( struct dep_t **first, struct dep_t **current, char *b
}
}
else if (( strncmp ( buffer, "include", 7 ) == 0 ) && isspace ( buffer [7] )) {
int fdi; char *filename;
int fdi; char *filename = buffer + 8;
while ( isspace ( *filename ))
filename++;
filename = skip_whitespace ( buffer + 8 );
if (( fdi = open ( filename, O_RDONLY )) >= 0 ) {
include_conf(first, current, buffer, buflen, fdi);

View File

@ -572,10 +572,7 @@ static char *next_word(char **buf)
}
/* Skip over leading whitespace */
word = *buf;
while (isspace(*word)) {
++word;
}
word = skip_whitespace(*buf);
/* Skip over comments */
if (*word == '#') {
@ -712,9 +709,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
}
/* ship any trailing whitespace */
while (isspace(*buf_ptr)) {
++buf_ptr;
}
buf_ptr = skip_whitespace(buf_ptr);
if (buf_ptr[0] != '\0') {
bb_error_msg("too many parameters \"%s\"", buf);

View File

@ -302,7 +302,7 @@ int wget_main(int argc, char **argv)
s = buf;
while (*s != '\0' && !isspace(*s)) ++s;
while (isspace(*s)) ++s;
s = skip_whitespace(s);
// FIXME: no error check
// xatou wouldn't work: "200 OK"
status = atoi(s);

View File

@ -119,7 +119,7 @@ static char *parse_pipeline(char *cmdline, struct pipeline *line)
char *end;
// Skip leading whitespace and detect end of line.
while (isspace(*start)) start++;
start = skip_whitespace(start);
if (!*start || *start=='#') {
if (ENABLE_BBSH_JOBCTL) line->cmdlinelen = start-cmdline;
return 0;

View File

@ -203,8 +203,7 @@ static llist_t *get_block_backed_filesystems(void)
while ((buf = xmalloc_getline(f)) != 0) {
if (!strncmp(buf, "nodev", 5) && isspace(buf[5]))
continue;
fs = buf;
while (isspace(*fs)) fs++;
fs = skip_whitespace(buf);
if (*fs=='#' || *fs=='*' || !*fs) continue;
llist_add_to_end(&list, xstrdup(fs));