Exemple #1
0
void faup_options_enable_tld_above_one(faup_options_t *opts)
{
	opts->tld_greater_extraction = 1;
	opts->tld_tree = faup_tld_tree_new();
}
Exemple #2
0
int main(int argc, char **argv)
{
	faup_handler_t *fh;
	char *strbuf=NULL;

	char *tld_file=NULL;

	faup_options_t faup_opts;
	int opt;

	int tld_pos;

	faup_options_defaults(&faup_opts);

	fh = faup_init();


//	tld_tree = faup_tld_tree_new();
//	tld_pos = get_tld_pos(tld_tree, argv[1]);
//	printf("TLD Pos:%d\n", tld_pos);

	while ((opt = getopt(argc, argv, "pld:vo:ut")) != -1) {
	  switch(opt) {
	  case 'p':
	    faup_opts.print_header = 1;
	    break;
	  case 'l':
	    faup_opts.print_line = 1;
	    break;
	  case 'd':
	    faup_opts.sep_char = optarg[0];
	    break;
	  case 'o':
	  	if (!strcmp("csv", optarg)) {
	  		faup_opts.output = FAUP_OUTPUT_CSV;
	  	} else if (!strcmp("json", optarg)) {
	  		faup_opts.output = FAUP_OUTPUT_JSON;
	  	} else {
	  		fprintf(stderr, "invalid output option '%s'!\n", optarg);
	  		exit(1);
	  	}
	  	break;
	  case 't':
	  	faup_opts.tld_tree = faup_tld_tree_new();
	  	faup_opts.tld_greater_extraction = 1;
	  	break;
	  case 'u':
	  	faup_tld_update();
	  	exit(0);
	  	break;
	  case 'v':
	    printf("faup v%s\n", faup_get_version());
	    exit(0);
	    break;
	  default:
	    print_help(argv);
	    exit(1);
	  }
	}

	if (isatty(fileno(stdin))) {
		if (argc < 2) {
			print_help(argv);
			exit(1);
		}
		if (faup_opts.print_header) {
		        print_header(faup_opts.print_header, faup_opts.sep_char);
		}

		if (!argv[optind]) {
		  exit(1);
		}

		faup_decode(fh, argv[optind], strlen(argv[optind]), &faup_opts);

		switch(faup_opts.output) {
			case FAUP_OUTPUT_JSON:
				faup_output_json(fh, stdout);
				break;
			default:
				if (faup_opts.print_line) {
		 			printf("0%c", faup_opts.sep_char);
				}
				faup_output_csv(fh, faup_opts.sep_char, stdout);
				printf("\n");
				break;			
		}
	} else {       	/* We read from stdin */
		long line_nb = 1;
		if (faup_opts.print_header) {
		        print_header(faup_opts.print_line, faup_opts.sep_char);
		}
		while (!feof(stdin)) {
			strbuf = readline(stdin);
			if (!strbuf) {
				break;
			}
			if (strbuf[0] == '\0') {
				break;
			}

			faup_decode(fh, strbuf, strlen(strbuf), &faup_opts);		
			switch(faup_opts.output) {
				case FAUP_OUTPUT_JSON:
					faup_output_json(fh, stdout);
					break;
				default:
					if (faup_opts.print_line) {
				        printf("%ld%c", line_nb, faup_opts.sep_char);
					}
					faup_output_csv(fh, ',', stdout);
					printf("\n");
					break;
			}	

			free(strbuf);
			line_nb++;
		}
	}

	faup_terminate(fh);

	return 0;
}