Skip to content

Commit

Permalink
text: Handle cases that "-" appears more than once
Browse files Browse the repository at this point in the history
Signed-off-by: jason23347 <jason23347@gmail.com>
  • Loading branch information
Jason23347 committed Apr 6, 2020
1 parent d9044cc commit 85fe36a
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ main(int argc, char *argv[])
{
char fn[MAX_STRING];
int do_search = 0;
search_t *search, *list;
search_t *search, *list, *tail;
search_t *tmp, *cur;
conf_t conf[1];
axel_t *axel;
Expand Down Expand Up @@ -248,27 +248,26 @@ main(int argc, char *argv[])
goto free_conf;
}

argv += optind;
/* if "-" is the only argument */
if (prealloc_num == 1 && argv[0][0] == '-' && !argv[0][1]) {
url_num = search_readlist(list, stdin);
if (url_num == 0) {
print_help();
goto free_conf;
}
tmp = list;
list = list->next;
free(tmp);
} else {
/* load URLs from argv and stdin */
tmp = cur = list;
for (; *argv; argv++) {
if (argv[0][0] == '-' && !argv[0][1]) {
/* add URL list from stdin to end of list */
/* "-" and the last node will be ignored */
url_num += search_readlist(list + prealloc_num - 2, stdin) - 1;
continue;
/* load URLs from argv and stdin */
tmp = cur = list;
tail = list + prealloc_num - 1;
for (argv += optind; *argv; argv++) {
if (argv[0][0] == '-' && !argv[0][1]) {
/* add URL list from stdin to end of list, "-"s will be ignored */
if (list + prealloc_num - 1 == tail) {
/* add nodes to end of the list */
url_num += search_readlist(list + prealloc_num - 1, stdin);
}
if (list == tail) { /* only "-"s in argument list */
list = list->next;
free(tail);
} else {
/* move forward, because "-" is ignored */
(tail - 1)->next = tail->next;
}
tail--;
url_num--;
} else {
/* add URL from argv */
strlcpy(tmp->url, *argv, sizeof(tmp->url));
cur->next = tmp++;
Expand Down

0 comments on commit 85fe36a

Please sign in to comment.