Skip to content

Commit

Permalink
trurl: accept a bad URL
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
bagder committed Apr 3, 2023
1 parent 023c323 commit ebdec11
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions trurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static const struct var variables[] = {
};

#define ERROR_PREFIX PROGNAME " error: "
#define WARN_PREFIX PROGNAME " note: "

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

void errorf(int exit_code, char *fmt, ...)
static void warnf(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fputs(WARN_PREFIX, stderr);
vfprintf(stderr, fmt, ap);
fputs("\n", stderr);
va_end(ap);
}

static void errorf(int exit_code, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand Down Expand Up @@ -486,8 +496,10 @@ static void singleurl(struct option *o,
CURLUcode rc =
curl_url_set(uh, CURLUPART_URL, url,
CURLU_GUESS_SCHEME|CURLU_NON_SUPPORT_SCHEME);
if(rc)
errorf(ERROR_BADURL, "%s [%s]", curl_url_strerror(rc), url);
if(rc) {
warnf("%s [%s]", curl_url_strerror(rc), url);
return;
}
else {
if(o->redirect)
curl_url_set(uh, CURLUPART_URL, o->redirect,
Expand Down

0 comments on commit ebdec11

Please sign in to comment.