A small amendment to pactester

25 views
Skip to first unread message

Phil Randal

unread,
May 20, 2008, 3:52:23 PM5/20/08
to pacparser
pactester.exe is not as useful as it could be when fed with a file of
urls.

Patch below fixes a memory allocation bug (OK, I'm a pedant, it'll
only show for very large url files), adds comment lines starting with
"#" to the urls file, and prints out the comments, urls, and results
when run in url file mode.

Enjoy,

Phil

D:\DISKS\pacparser\devel\pacparser-1.0.5>c:\cygwin\bin\diff -Naur
pactester.c pa
ctester.c.new
--- pactester.c 2008-05-10 09:35:10.000000000 -0100
+++ pactester.c.new 2008-05-20 18:45:58.203125000 -0100
@@ -162,10 +162,15 @@
return 1;
}
while (fgets(line, sizeof(line), fp)) {
- char *url = strdup(line);
+ char *url = &line[0];
// remove spaces from the beginning.
while (*url == ' ' || *url == '\t')
url++;
+ // skip comment lines
+ if (*url == '#') {
+ printf("%s", url);
+ continue;
+ }
char *urlend = url;
while (*urlend != '\r' && *urlend != '\n' && *urlend != '\0' &&
*urlend != ' ' && *urlend != '\t')
@@ -176,7 +181,7 @@
continue;
proxy = NULL;
proxy = pacparser_find_proxy(url, host);
- if(proxy) printf("%s\n", proxy);
+ if(proxy) printf("%s : %s\n", url, proxy);
}
}
pacparser_cleanup();


Phil Randal

unread,
May 20, 2008, 4:03:26 PM5/20/08
to pacparser
The last part of that patch should, of course, have been:

@@ -176,8 +181,9 @@
continue;
proxy = NULL;
proxy = pacparser_find_proxy(url, host);
- if(proxy) printf("%s\n", proxy);
+ if(proxy) printf("%s : %s\n", url, proxy);
}
+ fclose(fp);
}
pacparser_cleanup();
}

Always explicitly close open files :-)

Phil Randal

unread,
May 20, 2008, 4:16:38 PM5/20/08
to pacparser
oh yeah, there's also a

pacparser_cleanup();

missing after you fail to open the urls list.

Pedantic Phil :-)

Manu Garg

unread,
May 21, 2008, 7:48:33 AM5/21/08
to pacp...@googlegroups.com
On Wed, May 21, 2008 at 1:22 AM, Phil Randal <phil....@gmail.com> wrote:
>
> pactester.exe is not as useful as it could be when fed with a file of
> urls.
>
> Patch below fixes a memory allocation bug (OK, I'm a pedant, it'll
> only show for very large url files), adds comment lines starting with
> "#" to the urls file, and prints out the comments, urls, and results
> when run in url file mode.

Thanks a lot for the patch Phil. I have applied it to the repository:

http://code.google.com/p/pacparser/source/diff?r=91&format=side&path=/trunk/pactester.c#

Cheers,
Manu

Reply all
Reply to author
Forward
0 new messages