#include "uri.h" #include #include #include #include #define LINE_LENGTH 1024 #define MATCH_UNEXIST 0 #define MATCH_PATTERN 1 #define MATCH_REVERSE -1 // return 1 if the match and rule should have the main function print this URL. int match(char rule,char *part,char *arg) { switch(rule) { case MATCH_UNEXIST: if(part == 0) return 1; break; case MATCH_REVERSE: if(part) { if(!fnmatch(arg,part,FNM_NOESCAPE)) return 0; else return 1; } break; case MATCH_PATTERN: if(part) if(!fnmatch(arg,part,FNM_NOESCAPE)) return 1; break; default: fprintf(stderr,"oh god. what the hell happened to get here?\n"); break; } return 0; } int main(int argc,char *argv[]) { int i,j;; int ret=1; struct uri u; char rule=MATCH_PATTERN; char *line=malloc(LINE_LENGTH); char copy[LINE_LENGTH]; if(argc < 2) { printf("usage: urimatch [-][n][r][s|u|k|d|P|p|q|f] [string]\n"); printf("scheme://username:password@domain:port/path?query_string#fragment_id\n"); printf("s://u:k@d:P/p?q#f\n"); printf("This allows matching of subdomains, like `echo epoch.ano | urimatch -D ano` would match.\n"); printf("the 'n' flag can be put before any of the other flags to check for a missing.\n"); return 1; } while(fgets(line,LINE_LENGTH-1,stdin)) { if(strchr(line,'\r')) *strchr(line,'\r')=0; if(strchr(line,'\n')) *strchr(line,'\n')=0; strcpy(copy,line); memset(&u,0,sizeof(u)); urifromline(&u,line); //use the character in argv[1] to match stdin against argv[2]. if match print whole line. for(i=1;i