Skip to content

Commit ebdec11

Browse files
committed
trurl: accept a bad URL
... and keep going so that it can continue handling subsequent URLs, like when reading from a file or stdin. This also makes it not return error for a single bad URL.
1 parent 023c323 commit ebdec11

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

trurl.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static const struct var variables[] = {
6767
};
6868

6969
#define ERROR_PREFIX PROGNAME " error: "
70+
#define WARN_PREFIX PROGNAME " note: "
7071

7172
/* error codes */
7273
#define ERROR_FILE 1
@@ -76,9 +77,18 @@ static const struct var variables[] = {
7677
#define ERROR_SET 5 /* a --set problem */
7778
#define ERROR_MEM 6 /* out of memory */
7879
#define ERROR_URL 7 /* could not get a URL out of the set components */
79-
#define ERROR_BADURL 8 /* failed to parse the given URL */
8080

81-
void errorf(int exit_code, char *fmt, ...)
81+
static void warnf(char *fmt, ...)
82+
{
83+
va_list ap;
84+
va_start(ap, fmt);
85+
fputs(WARN_PREFIX, stderr);
86+
vfprintf(stderr, fmt, ap);
87+
fputs("\n", stderr);
88+
va_end(ap);
89+
}
90+
91+
static void errorf(int exit_code, char *fmt, ...)
8292
{
8393
va_list ap;
8494
va_start(ap, fmt);
@@ -486,8 +496,10 @@ static void singleurl(struct option *o,
486496
CURLUcode rc =
487497
curl_url_set(uh, CURLUPART_URL, url,
488498
CURLU_GUESS_SCHEME|CURLU_NON_SUPPORT_SCHEME);
489-
if(rc)
490-
errorf(ERROR_BADURL, "%s [%s]", curl_url_strerror(rc), url);
499+
if(rc) {
500+
warnf("%s [%s]", curl_url_strerror(rc), url);
501+
return;
502+
}
491503
else {
492504
if(o->redirect)
493505
curl_url_set(uh, CURLUPART_URL, o->redirect,

0 commit comments

Comments
 (0)