From 6f402e2d2f052972886712f60d592684c8671982 Mon Sep 17 00:00:00 2001 From: epoch Date: Sat, 20 Apr 2019 05:32:27 -0500 Subject: rebased on an old copy of this repo. renamed everything. rewrote the uri parser. added uricmp. wew. --- uricut.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 uricut.c (limited to 'uricut.c') diff --git a/uricut.c b/uricut.c new file mode 100644 index 0000000..5fe8764 --- /dev/null +++ b/uricut.c @@ -0,0 +1,158 @@ +#include "uri.h" + +#include +#include +#include +#include +#include +#include +#include + +/* + schemes are case sensitive but cononicals are lower case. + domain is case insensitive. return it lowercased? + port is optional and in decimal + path + scheme://username:password@domain:port/path?query_string#fragment_id + mailto:username@domain + + optional stuff: + scheme, username, password, port, path, query_string, fragment_id +*/ + +#define AorB(a,b) ((a)?(a):(b)) + +#define F_SCHEME 1<<0 +#define F_USERNAME 1<<1 +#define F_PASSWORD 1<<2 +#define F_DOMAIN 1<<3 +#define F_PORT 1<<4 +#define F_PATH 1<<5 +#define F_QUERY_STRING 1<<6 +#define F_FRAGMENT_ID 1<<7 +#define F_WHOLE_URI 1<<8 + +char *long_opts[]={"scheme","username","password","domain","port","path","query_string","fragment_id","URI",0}; +char *short_opts[]={"s","u","k","d","P","p","q","f","U"}; + +int main(int argc,char *argv[]) { + char *uri; + char *line=0; + short args[256];//this needs to be a short to make room for the F_WHOLE_URI + int i,j,c=0; + int size=1024; + char fixme=0; + char using_stdin=1; + char malloced=0; + struct uri u; + if(argc > 1) { + if(!strcmp(argv[1],"--help") || !strcmp(argv[1],"-h")) { + printf("usage: echo uris | uricut [options]\n"); + printf("usage: uricut [options] uri [options] [uri]\n\n"); + printf("options: \n"); + for(i=0;long_opts[i];i++) { + printf(" -%s|--%s\n",short_opts[i],long_opts[i]); + } + printf("To set default values use environment variables like: CUTURI_[OPTION]\n"); + return 2; + } + } + argv++; + argc--; + while(1) { + u.scheme=0; + u.username=0; + u.password=0; + u.domain=0; + u.port=0; + u.path=0; + u.query_string=0; + u.fragment_id=0; + if(!using_stdin) c=0; + if(argc >= 1) { + for(;argc>0;argc--,argv++) { + for(i=0;long_opts[i];i++) { + if(!strncmp(*argv,"--",2)) { + if(!strcmp(*argv+2,long_opts[i])) { + args[c]=1<