simplification de human

master
karchnu 2015-12-04 01:54:50 +01:00
parent 5cb230bd63
commit 907b78afaa
1 changed files with 9 additions and 26 deletions

View File

@ -84,6 +84,8 @@ print_token_to_human (const char *token)
printf("%s ", stmp); printf("%s ", stmp);
free(stmp); free(stmp);
} }
// TODO prints error then exits
} }
void void
@ -107,11 +109,10 @@ print_delim (char *s, const char *delim, const struct fields *f)
// check if we need to print the current token humanized // check if we need to print the current token humanized
int found = 0; int found = 0;
for (j = 0 ; j < f->nbfields ; j++ ) { for (j = 0 ; j < f->nbfields && found == 0; j++ ) {
if( i == f->fields[j] ) { if( i == f->fields[j] ) {
print_token_to_human(token); print_token_to_human(token);
found = 1; found = 1;
break;
} }
} }
@ -122,21 +123,6 @@ print_delim (char *s, const char *delim, const struct fields *f)
} }
} }
/*
* print every line, with the first token humanized
* there is a split in the line by the space character to get tokens
*/
void
print_human (char *s)
{
struct fields f;
f.nbfields = 1;
f.fields = malloc(sizeof(unsigned int) * 1);
f.fields[0] = 1;
print_delim (s, " ", &f);
}
// get the index of every token to humanize // get the index of every token to humanize
int int
get_tok_to_humanize (char *s, struct fields *f) get_tok_to_humanize (char *s, struct fields *f)
@ -197,20 +183,17 @@ main (int argc, char *argv[])
} }
while(fgets(strtmp, BUFSIZ, stdin)) { while(fgets(strtmp, BUFSIZ, stdin)) {
chomp(strtmp); chomp(strtmp);
print_delim (strtmp, delim, &fields);
if(delim) {
print_delim (strtmp, delim, &fields);
}
else {
print_human (strtmp);
}
printf("\n"); printf("\n");
} }
free(strtmp); free(strtmp);
free(fields.fields);
if(argc == 2)
free(delim);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }