1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

curl tool: reviewed code moved to tool_*.[ch] files

This commit is contained in:
Yang Tse 2011-10-05 20:16:16 +02:00
parent 0f19e0145a
commit 6c849321d7
7 changed files with 118 additions and 85 deletions

View File

@ -8,7 +8,7 @@ UID 0x00000000 0xF0206442
SOURCEPATH ../../../src SOURCEPATH ../../../src
SOURCE \ SOURCE \
hugehelp.c urlglob.c writeout.c writeenv.c \ hugehelp.c writeout.c writeenv.c \
getpass.c homedir.c curlutil.c xattr.c \ getpass.c homedir.c curlutil.c xattr.c \
tool_binmode.c \ tool_binmode.c \
tool_bname.c \ tool_bname.c \
@ -39,6 +39,7 @@ SOURCE \
tool_parsecfg.c \ tool_parsecfg.c \
tool_setopt.c \ tool_setopt.c \
tool_sleep.c \ tool_sleep.c \
tool_urlglob.c \
tool_vms.c tool_vms.c
SOURCEPATH ../../../lib SOURCEPATH ../../../lib

View File

@ -14,7 +14,7 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
$(top_srcdir)/lib/rawstr.c \ $(top_srcdir)/lib/rawstr.c \
$(top_srcdir)/lib/nonblock.c $(top_srcdir)/lib/nonblock.c
CURL_CFILES = hugehelp.c urlglob.c writeout.c writeenv.c \ CURL_CFILES = hugehelp.c writeout.c writeenv.c \
getpass.c homedir.c curlutil.c xattr.c \ getpass.c homedir.c curlutil.c xattr.c \
tool_binmode.c \ tool_binmode.c \
tool_bname.c \ tool_bname.c \
@ -45,10 +45,11 @@ CURL_CFILES = hugehelp.c urlglob.c writeout.c writeenv.c \
tool_parsecfg.c \ tool_parsecfg.c \
tool_setopt.c \ tool_setopt.c \
tool_sleep.c \ tool_sleep.c \
tool_urlglob.c \
tool_vms.c tool_vms.c
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \ CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
config-riscos.h urlglob.h version.h xattr.h \ config-riscos.h version.h xattr.h \
writeout.h writeenv.h getpass.h homedir.h curlutil.h \ writeout.h writeenv.h getpass.h homedir.h curlutil.h \
tool_binmode.h \ tool_binmode.h \
tool_bname.h \ tool_bname.h \
@ -80,6 +81,7 @@ CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
tool_sdecls.h \ tool_sdecls.h \
tool_setopt.h \ tool_setopt.h \
tool_sleep.h \ tool_sleep.h \
tool_urlglob.h \
tool_vms.h tool_vms.h
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES) curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)

View File

@ -169,8 +169,8 @@ RELEASE_OBJS= \
tool_parsecfgr.obj \ tool_parsecfgr.obj \
tool_setoptr.obj \ tool_setoptr.obj \
tool_sleepr.obj \ tool_sleepr.obj \
tool_urlglobr.obj \
tool_vmsr.obj \ tool_vmsr.obj \
urlglobr.obj \
writeoutr.obj \ writeoutr.obj \
xattrr.obj \ xattrr.obj \
curlr.res curlr.res
@ -212,8 +212,8 @@ DEBUG_OBJS= \
tool_parsecfgd.obj \ tool_parsecfgd.obj \
tool_setoptd.obj \ tool_setoptd.obj \
tool_sleepd.obj \ tool_sleepd.obj \
tool_urlglobd.obj \
tool_vmsd.obj \ tool_vmsd.obj \
urlglobd.obj \
writeoutd.obj \ writeoutd.obj \
xattrd.obj \ xattrd.obj \
curld.res curld.res
@ -342,8 +342,6 @@ hugehelpr.obj: hugehelp.c
$(CCR) $(CFLAGS) /Zm200 /Fo"$@" hugehelp.c $(CCR) $(CFLAGS) /Zm200 /Fo"$@" hugehelp.c
writeoutr.obj: writeout.c writeoutr.obj: writeout.c
$(CCR) $(CFLAGS) /Fo"$@" writeout.c $(CCR) $(CFLAGS) /Fo"$@" writeout.c
urlglobr.obj: urlglob.c
$(CCR) $(CFLAGS) /Fo"$@" urlglob.c
getpassr.obj: getpass.c getpassr.obj: getpass.c
$(CCR) $(CFLAGS) /Fo"$@" getpass.c $(CCR) $(CFLAGS) /Fo"$@" getpass.c
homedirr.obj: homedir.c homedirr.obj: homedir.c
@ -414,6 +412,8 @@ tool_setoptr.obj: tool_setopt.c
$(CCR) $(CFLAGS) /Fo"$@" tool_setopt.c $(CCR) $(CFLAGS) /Fo"$@" tool_setopt.c
tool_sleepr.obj: tool_sleep.c tool_sleepr.obj: tool_sleep.c
$(CCR) $(CFLAGS) /Fo"$@" tool_sleep.c $(CCR) $(CFLAGS) /Fo"$@" tool_sleep.c
tool_urlglobr.obj: tool_urlglob.c
$(CCR) $(CFLAGS) /Fo"$@" tool_urlglob.c
tool_vmsr.obj: tool_vms.c tool_vmsr.obj: tool_vms.c
$(CCR) $(CFLAGS) /Fo"$@" tool_vms.c $(CCR) $(CFLAGS) /Fo"$@" tool_vms.c
xattrr.obj: xattr.c xattrr.obj: xattr.c
@ -426,8 +426,6 @@ hugehelpd.obj: hugehelp.c
$(CCD) $(CFLAGS) /Zm200 /Fo"$@" hugehelp.c $(CCD) $(CFLAGS) /Zm200 /Fo"$@" hugehelp.c
writeoutd.obj: writeout.c writeoutd.obj: writeout.c
$(CCD) $(CFLAGS) /Fo"$@" writeout.c $(CCD) $(CFLAGS) /Fo"$@" writeout.c
urlglobd.obj: urlglob.c
$(CCD) $(CFLAGS) /Fo"$@" urlglob.c
getpassd.obj: getpass.c getpassd.obj: getpass.c
$(CCD) $(CFLAGS) /Fo"$@" getpass.c $(CCD) $(CFLAGS) /Fo"$@" getpass.c
homedird.obj: homedir.c homedird.obj: homedir.c
@ -498,6 +496,8 @@ tool_setoptd.obj: tool_setopt.c
$(CCD) $(CFLAGS) /Fo"$@" tool_setopt.c $(CCD) $(CFLAGS) /Fo"$@" tool_setopt.c
tool_sleepd.obj: tool_sleep.c tool_sleepd.obj: tool_sleep.c
$(CCD) $(CFLAGS) /Fo"$@" tool_sleep.c $(CCD) $(CFLAGS) /Fo"$@" tool_sleep.c
tool_urlglobd.obj: tool_urlglob.c
$(CCD) $(CFLAGS) /Fo"$@" tool_urlglob.c
tool_vmsd.obj: tool_vms.c tool_vmsd.obj: tool_vms.c
$(CCD) $(CFLAGS) /Fo"$@" tool_vms.c $(CCD) $(CFLAGS) /Fo"$@" tool_vms.c
xattrd.obj: xattr.c xattrd.obj: xattr.c

View File

@ -49,7 +49,6 @@
#include "curlutil.h" #include "curlutil.h"
#include "homedir.h" #include "homedir.h"
#include "urlglob.h"
#include "writeout.h" #include "writeout.h"
#include "xattr.h" #include "xattr.h"
@ -79,6 +78,7 @@
#include "tool_parsecfg.h" #include "tool_parsecfg.h"
#include "tool_setopt.h" #include "tool_setopt.h"
#include "tool_sleep.h" #include "tool_sleep.h"
#include "tool_urlglob.h"
#include "memdebug.h" /* keep this as LAST include */ #include "memdebug.h" /* keep this as LAST include */

View File

@ -26,13 +26,14 @@
#define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */ #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
#include <curl/mprintf.h> #include <curl/mprintf.h>
#include "urlglob.h" #include "tool_urlglob.h"
#include "tool_vms.h" #include "tool_vms.h"
#include "memdebug.h" /* keep this as LAST include */ #include "memdebug.h" /* keep this as LAST include */
typedef enum { typedef enum {
GLOB_OK, GLOB_OK,
GLOB_NO_MEM,
GLOB_ERROR GLOB_ERROR
} GlobCode; } GlobCode;
@ -53,11 +54,12 @@ static GlobCode glob_set(URLGlob *glob, char *pattern,
/* processes a set expression with the point behind the opening '{' /* processes a set expression with the point behind the opening '{'
','-separated elements are collected until the next closing '}' ','-separated elements are collected until the next closing '}'
*/ */
URLPattern *pat;
GlobCode res;
bool done = FALSE; bool done = FALSE;
char* buf = glob->glob_buffer; char* buf = glob->glob_buffer;
URLPattern *pat;
pat = (URLPattern*)&glob->pattern[glob->size / 2]; pat = &glob->pattern[glob->size / 2];
/* patterns 0,1,2,... correspond to size=1,3,5,... */ /* patterns 0,1,2,... correspond to size=1,3,5,... */
pat->type = UPTSet; pat->type = UPTSet;
pat->content.Set.size = 0; pat->content.Set.size = 0;
@ -98,8 +100,8 @@ static GlobCode glob_set(URLGlob *glob, char *pattern,
else else
pat->content.Set.elements = malloc(sizeof(char*)); pat->content.Set.elements = malloc(sizeof(char*));
if(!pat->content.Set.elements) { if(!pat->content.Set.elements) {
snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory"); snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory\n");
return GLOB_ERROR; return GLOB_NO_MEM;
} }
pat->content.Set.elements[pat->content.Set.size] = pat->content.Set.elements[pat->content.Set.size] =
strdup(glob->glob_buffer); strdup(glob->glob_buffer);
@ -110,8 +112,8 @@ static GlobCode glob_set(URLGlob *glob, char *pattern,
Curl_safefree(pat->content.Set.elements); Curl_safefree(pat->content.Set.elements);
pat->content.Set.ptr_s = 0; pat->content.Set.ptr_s = 0;
pat->content.Set.size = 0; pat->content.Set.size = 0;
snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory"); snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory\n");
return GLOB_ERROR; return GLOB_NO_MEM;
} }
++pat->content.Set.size; ++pat->content.Set.size;
@ -120,8 +122,17 @@ static GlobCode glob_set(URLGlob *glob, char *pattern,
int wordamount; int wordamount;
/* always check for a literal (may be "") between patterns */ /* always check for a literal (may be "") between patterns */
if(GLOB_ERROR == glob_word(glob, ++pattern, ++pos, &wordamount)) res = glob_word(glob, ++pattern, ++pos, &wordamount);
return GLOB_ERROR; if(res) {
short elem;
for(elem = 0; elem < pat->content.Set.size; elem++)
Curl_safefree(pat->content.Set.elements[elem]);
Curl_safefree(pat->content.Set.elements);
pat->content.Set.ptr_s = 0;
pat->content.Set.size = 0;
return res;
}
*amount = pat->content.Set.size * wordamount; *amount = pat->content.Set.size * wordamount;
done = TRUE; done = TRUE;
@ -163,22 +174,26 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
*/ */
URLPattern *pat; URLPattern *pat;
char *c; char *c;
int wordamount=1;
char sep; char sep;
char sep2; char sep2;
int step; int step;
int rc; int rc;
GlobCode res;
int wordamount = 1;
pat = (URLPattern*)&glob->pattern[glob->size / 2]; pat = &glob->pattern[glob->size / 2];
/* patterns 0,1,2,... correspond to size=1,3,5,... */ /* patterns 0,1,2,... correspond to size=1,3,5,... */
++glob->size; ++glob->size;
if(ISALPHA(*pattern)) { /* character range detected */ if(ISALPHA(*pattern)) {
/* character range detected */
char min_c; char min_c;
char max_c; char max_c;
pat->type = UPTCharRange; pat->type = UPTCharRange;
rc = sscanf(pattern, "%c-%c%c%d%c", &min_c, &max_c, &sep, &step, &sep2); rc = sscanf(pattern, "%c-%c%c%d%c", &min_c, &max_c, &sep, &step, &sep2);
if((rc < 3) || (min_c >= max_c) || ((max_c - min_c) > ('z' - 'a'))) { if((rc < 3) || (min_c >= max_c) || ((max_c - min_c) > ('z' - 'a'))) {
/* the pattern is not well-formed */ /* the pattern is not well-formed */
snprintf(glob->errormsg, sizeof(glob->errormsg), snprintf(glob->errormsg, sizeof(glob->errormsg),
@ -196,12 +211,13 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
/* if there was a ":[num]" thing, use that as step or else use 1 */ /* if there was a ":[num]" thing, use that as step or else use 1 */
pat->content.CharRange.step = pat->content.CharRange.step =
((sep == ':') && (rc == 5) && (sep2 == ']'))?step:1; ((sep == ':') && (rc == 5) && (sep2 == ']')) ? step : 1;
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c; pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c;
pat->content.CharRange.max_c = max_c; pat->content.CharRange.max_c = max_c;
} }
else if(ISDIGIT(*pattern)) { /* numeric range detected */ else if(ISDIGIT(*pattern)) {
/* numeric range detected */
int min_n; int min_n;
int max_n; int max_n;
@ -216,14 +232,15 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
"error: bad range specification after pos %zu\n", pos); "error: bad range specification after pos %zu\n", pos);
return GLOB_ERROR; return GLOB_ERROR;
} }
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n = min_n; pat->content.NumRange.ptr_n = pat->content.NumRange.min_n = min_n;
pat->content.NumRange.max_n = max_n; pat->content.NumRange.max_n = max_n;
/* if there was a ":[num]" thing, use that as step or else use 1 */ /* if there was a ":[num]" thing, use that as step or else use 1 */
pat->content.NumRange.step = pat->content.NumRange.step =
((sep == ':') && (rc == 5) && (sep2 == ']'))?step:1; ((sep == ':') && (rc == 5) && (sep2 == ']')) ? step : 1;
if(*pattern == '0') { /* leading zero specified */ if(*pattern == '0') {
/* leading zero specified */
c = pattern; c = pattern;
while(ISDIGIT(*c)) { while(ISDIGIT(*c)) {
c++; c++;
@ -231,7 +248,6 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
instances of this pattern */ instances of this pattern */
} }
} }
} }
else { else {
snprintf(glob->errormsg, sizeof(glob->errormsg), snprintf(glob->errormsg, sizeof(glob->errormsg),
@ -249,18 +265,22 @@ static GlobCode glob_range(URLGlob *glob, char *pattern,
/* always check for a literal (may be "") between patterns */ /* always check for a literal (may be "") between patterns */
if(GLOB_ERROR == glob_word(glob, c, pos + (c - pattern), &wordamount)) res = glob_word(glob, c, pos + (c - pattern), &wordamount);
if(res == GLOB_ERROR) {
wordamount = 1; wordamount = 1;
res = GLOB_OK;
}
if(pat->type == UPTCharRange) if(!res) {
*amount = (pat->content.CharRange.max_c - if(pat->type == UPTCharRange)
pat->content.CharRange.min_c + 1) * *amount = wordamount * (pat->content.CharRange.max_c -
wordamount; pat->content.CharRange.min_c + 1);
else else
*amount = (pat->content.NumRange.max_n - *amount = wordamount * (pat->content.NumRange.max_n -
pat->content.NumRange.min_n + 1) * wordamount; pat->content.NumRange.min_n + 1);
}
return GLOB_OK; return res; /* GLOB_OK or GLOB_NO_MEM */
} }
static GlobCode glob_word(URLGlob *glob, char *pattern, static GlobCode glob_word(URLGlob *glob, char *pattern,
@ -291,20 +311,23 @@ static GlobCode glob_word(URLGlob *glob, char *pattern,
++pattern; ++pattern;
++pos; ++pos;
} }
*buf++ = *pattern++; /* copy character to literal */ *buf++ = *pattern++; /* copy character to literal */
++pos; ++pos;
} }
*buf = '\0'; *buf = '\0';
litindex = glob->size / 2; litindex = glob->size / 2;
/* literals 0,1,2,... correspond to size=0,2,4,... */ /* literals 0,1,2,... correspond to size=0,2,4,... */
glob->literal[litindex] = strdup(glob->glob_buffer); glob->literal[litindex] = strdup(glob->glob_buffer);
if(!glob->literal[litindex]) if(!glob->literal[litindex]) {
return GLOB_ERROR; snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory\n");
return GLOB_NO_MEM;
}
++glob->size; ++glob->size;
switch (*pattern) { switch (*pattern) {
case '\0': case '\0':
break; /* singular URL processed */ /* singular URL processed */
break;
case '{': case '{':
/* process set pattern */ /* process set pattern */
@ -313,15 +336,14 @@ static GlobCode glob_word(URLGlob *glob, char *pattern,
case '[': case '[':
/* process range pattern */ /* process range pattern */
res= glob_range(glob, ++pattern, ++pos, amount); res = glob_range(glob, ++pattern, ++pos, amount);
break; break;
} }
if(GLOB_OK != res) if(res)
/* free that strdup'ed string again */
Curl_safefree(glob->literal[litindex]); Curl_safefree(glob->literal[litindex]);
return res; /* something got wrong */ return res;
} }
int glob_url(URLGlob** glob, char* url, int *urlnum, FILE *error) int glob_url(URLGlob** glob, char* url, int *urlnum, FILE *error)
@ -332,34 +354,40 @@ int glob_url(URLGlob** glob, char* url, int *urlnum, FILE *error)
*/ */
URLGlob *glob_expand; URLGlob *glob_expand;
int amount; int amount;
char *glob_buffer = malloc(strlen(url)+1); char *glob_buffer;
GlobCode res;
*glob = NULL; *glob = NULL;
if(NULL == glob_buffer)
glob_buffer = malloc(strlen(url) + 1);
if(!glob_buffer)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
glob_expand = calloc(1, sizeof(URLGlob)); glob_expand = calloc(1, sizeof(URLGlob));
if(NULL == glob_expand) { if(!glob_expand) {
Curl_safefree(glob_buffer); Curl_safefree(glob_buffer);
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
glob_expand->size = 0; glob_expand->size = 0;
glob_expand->urllen = strlen(url); glob_expand->urllen = strlen(url);
glob_expand->glob_buffer = glob_buffer; glob_expand->glob_buffer = glob_buffer;
glob_expand->beenhere=0; glob_expand->beenhere = 0;
if(GLOB_OK == glob_word(glob_expand, url, 1, &amount))
res = glob_word(glob_expand, url, 1, &amount);
if(!res)
*urlnum = amount; *urlnum = amount;
else { else {
if(error && glob_expand->errormsg[0]) { if(error && glob_expand->errormsg[0]) {
/* send error description to the error-stream */ /* send error description to the error-stream */
fprintf(error, "curl: (%d) [globbing] %s", fprintf(error, "curl: (%d) [globbing] %s",
CURLE_URL_MALFORMAT, glob_expand->errormsg); (res == GLOB_NO_MEM) ? CURLE_OUT_OF_MEMORY : CURLE_URL_MALFORMAT,
glob_expand->errormsg);
} }
/* it failed, we cleanup */ /* it failed, we cleanup */
Curl_safefree(glob_buffer); Curl_safefree(glob_buffer);
Curl_safefree(glob_expand); Curl_safefree(glob_expand);
*urlnum = 1; *urlnum = 1;
return CURLE_URL_MALFORMAT; return (res == GLOB_NO_MEM) ? CURLE_OUT_OF_MEMORY : CURLE_URL_MALFORMAT;
} }
*glob = glob_expand; *glob = glob_expand;
@ -381,8 +409,7 @@ void glob_cleanup(URLGlob* glob)
for(elem = glob->pattern[i/2].content.Set.size - 1; for(elem = glob->pattern[i/2].content.Set.size - 1;
elem >= 0; elem >= 0;
--elem) { --elem) {
if(glob->pattern[i/2].content.Set.elements[elem]) Curl_safefree(glob->pattern[i/2].content.Set.elements[elem]);
Curl_safefree(glob->pattern[i/2].content.Set.elements[elem]);
} }
Curl_safefree(glob->pattern[i/2].content.Set.elements); Curl_safefree(glob->pattern[i/2].content.Set.elements);
} }
@ -394,13 +421,13 @@ void glob_cleanup(URLGlob* glob)
char *glob_next_url(URLGlob *glob) char *glob_next_url(URLGlob *glob)
{ {
char *buf = glob->glob_buffer;
URLPattern *pat; URLPattern *pat;
char *lit; char *lit;
size_t i; size_t i;
size_t j; size_t j;
size_t buflen = glob->urllen+1;
size_t len; size_t len;
size_t buflen = glob->urllen + 1;
char *buf = glob->glob_buffer;
if(!glob->beenhere) if(!glob->beenhere)
glob->beenhere = 1; glob->beenhere = 1;
@ -409,7 +436,7 @@ char *glob_next_url(URLGlob *glob)
/* implement a counter over the index ranges of all patterns, /* implement a counter over the index ranges of all patterns,
starting with the rightmost pattern */ starting with the rightmost pattern */
for(i = glob->size / 2 - 1; carry && i < glob->size; --i) { for(i = glob->size / 2 - 1; carry && (i < glob->size); --i) {
carry = FALSE; carry = FALSE;
pat = &glob->pattern[i]; pat = &glob->pattern[i];
switch (pat->type) { switch (pat->type) {
@ -487,19 +514,19 @@ char *glob_match_url(char *filename, URLGlob *glob)
{ {
char *target; char *target;
size_t allocsize; size_t allocsize;
size_t stringlen=0;
char numbuf[18]; char numbuf[18];
char *appendthis = NULL; char *appendthis = NULL;
size_t appendlen = 0; size_t appendlen = 0;
size_t stringlen = 0;
/* We cannot use the glob_buffer for storage here since the filename may /* We cannot use the glob_buffer for storage here since the filename may
* be longer than the URL we use. We allocate a good start size, then * be longer than the URL we use. We allocate a good start size, then
* we need to realloc in case of need. * we need to realloc in case of need.
*/ */
allocsize=strlen(filename)+1; /* make it at least one byte to store the allocsize = strlen(filename) + 1; /* make it at least one byte to store the
trailing zero */ trailing zero */
target = malloc(allocsize); target = malloc(allocsize);
if(NULL == target) if(!target)
return NULL; /* major failure */ return NULL; /* major failure */
while(*filename) { while(*filename) {
@ -507,7 +534,7 @@ char *glob_match_url(char *filename, URLGlob *glob)
unsigned long i; unsigned long i;
char *ptr = filename; char *ptr = filename;
unsigned long num = strtoul(&filename[1], &filename, 10); unsigned long num = strtoul(&filename[1], &filename, 10);
i = num-1; i = num - 1UL;
if(num && (i <= glob->size / 2)) { if(num && (i <= glob->size / 2)) {
URLPattern pat = glob->pattern[i]; URLPattern pat = glob->pattern[i];
@ -520,10 +547,10 @@ char *glob_match_url(char *filename, URLGlob *glob)
} }
break; break;
case UPTCharRange: case UPTCharRange:
numbuf[0]=pat.content.CharRange.ptr_c; numbuf[0] = pat.content.CharRange.ptr_c;
numbuf[1]=0; numbuf[1] = 0;
appendthis=numbuf; appendthis = numbuf;
appendlen=1; appendlen = 1;
break; break;
case UPTNumRange: case UPTNumRange:
snprintf(numbuf, sizeof(numbuf), "%0*d", snprintf(numbuf, sizeof(numbuf), "%0*d",
@ -542,25 +569,25 @@ char *glob_match_url(char *filename, URLGlob *glob)
else { else {
/* #[num] out of range, use the #[num] in the output */ /* #[num] out of range, use the #[num] in the output */
filename = ptr; filename = ptr;
appendthis=filename++; appendthis = filename++;
appendlen=1; appendlen = 1;
} }
} }
else { else {
appendthis=filename++; appendthis = filename++;
appendlen=1; appendlen = 1;
} }
if(appendlen + stringlen >= allocsize) { if(appendlen + stringlen >= allocsize) {
char *newstr; char *newstr;
/* we append a single byte to allow for the trailing byte to be appended /* we append a single byte to allow for the trailing byte to be appended
at the end of this function outside the while() loop */ at the end of this function outside the while() loop */
allocsize = (appendlen + stringlen)*2; allocsize = (appendlen + stringlen) * 2;
newstr=realloc(target, allocsize + 1); newstr = realloc(target, allocsize + 1);
if(NULL ==newstr) { if(!newstr) {
Curl_safefree(target); Curl_safefree(target);
return NULL; return NULL;
} }
target=newstr; target = newstr;
} }
memcpy(&target[stringlen], appendthis, appendlen); memcpy(&target[stringlen], appendthis, appendlen);
stringlen += appendlen; stringlen += appendlen;

View File

@ -1,5 +1,5 @@
#ifndef HEADER_CURL_URLGLOB_H #ifndef HEADER_CURL_TOOL_URLGLOB_H
#define HEADER_CURL_URLGLOB_H #define HEADER_CURL_TOOL_URLGLOB_H
/*************************************************************************** /***************************************************************************
* _ _ ____ _ * _ _ ____ _
* Project ___| | | | _ \| | * Project ___| | | | _ \| |
@ -24,7 +24,7 @@
#include "setup.h" #include "setup.h"
typedef enum { typedef enum {
UPTSet=1, UPTSet = 1,
UPTCharRange, UPTCharRange,
UPTNumRange UPTNumRange
} URLPatternType; } URLPatternType;
@ -38,12 +38,14 @@ typedef struct {
short ptr_s; short ptr_s;
} Set; } Set;
struct { struct {
char min_c, max_c; char min_c;
char max_c;
char ptr_c; char ptr_c;
int step; int step;
} CharRange; } CharRange;
struct { struct {
int min_n, max_n; int min_n;
int max_n;
short padlength; short padlength;
int ptr_n; int ptr_n;
int step; int step;
@ -52,7 +54,7 @@ typedef struct {
} URLPattern; } URLPattern;
typedef struct { typedef struct {
char* literal[10]; char *literal[10];
URLPattern pattern[9]; URLPattern pattern[9];
size_t size; size_t size;
size_t urllen; size_t urllen;
@ -66,4 +68,5 @@ char* glob_next_url(URLGlob*);
char* glob_match_url(char*, URLGlob *); char* glob_match_url(char*, URLGlob *);
void glob_cleanup(URLGlob* glob); void glob_cleanup(URLGlob* glob);
#endif /* HEADER_CURL_URLGLOB_H */ #endif /* HEADER_CURL_TOOL_URLGLOB_H */

View File

@ -283,11 +283,11 @@ SOURCE=.\tool_sleep.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\tool_vms.c SOURCE=.\tool_urlglob.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\urlglob.c SOURCE=.\tool_vms.c
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -463,11 +463,11 @@ SOURCE=.\tool_sleep.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\tool_vms.h SOURCE=.\tool_urlglob.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\urlglob.h SOURCE=.\tool_vms.h
# End Source File # End Source File
# Begin Source File # Begin Source File