| 676 | } |
| 677 | |
| 678 | int main(int argc, char *argv[]) |
| 679 | { |
| 680 | extern char *optarg; |
| 681 | extern int opterr; |
| 682 | extern int optind; |
| 683 | int option; |
| 684 | char const *opt_str = "1dhm:o:svw"; |
| 685 | char usage_str[80]; |
| 686 | |
| 687 | char token[MAX_TOKEN+1]; |
| 688 | const char *type; |
| 689 | unsigned line; |
| 690 | unsigned col; |
| 691 | |
| 692 | char *outfile = 0; |
| 693 | enum { PLAIN, CSV, JSON, JSONL, XML, RAW } mode = PLAIN; |
| 694 | int first_time = 1; |
| 695 | |
| 696 | sprintf(usage_str, "usage: %%s [ -%s ] [ FILES ]\n", opt_str); |
| 697 | |
| 698 | /* Process arguments: */ |
| 699 | while ((option = getopt(argc, argv, opt_str)) != EOF) { |
| 700 | switch (option) { |
| 701 | |
| 702 | case '1': |
| 703 | continuous_files = 1; |
| 704 | break; |
| 705 | |
| 706 | case 'd': |
| 707 | debug = verbose = 1; |
| 708 | break; |
| 709 | |
| 710 | case 'h': |
| 711 | fputs( |
| 712 | "A tokenizer for JavaScript source code with output in 6 formats.\n" |
| 713 | "Recognizes the following token classes: keyword, identifier, integer,\n" |
| 714 | "floating, string, regex, and operator.\n\n", stderr); |
| 715 | fprintf(stderr, usage_str, basename(argv[0])); |
| 716 | fputs( |
| 717 | "\nCommand line options are:\n" |
| 718 | "-d : print debug info to stderr; implies -v.\n" |
| 719 | "-h : print just this text to stderr and stop.\n" |
| 720 | "-m<mode> : output mode either plain (default), csv, json, jsonl, xml, or raw.\n" |
| 721 | "-o<file> : name for output file (instead of stdout).\n" |
| 722 | "-s : enable a special start token specifying the filename.\n" |
| 723 | "-1 : treat all filename arguments as a continuous single input.\n" |
| 724 | "-v : print action summary to stderr.\n" |
| 725 | "-w : suppress all warning messages.\n", |
| 726 | stderr); |
| 727 | return 0; |
| 728 | |
| 729 | case 'm': |
| 730 | if (!strcmp(optarg, "plain")) |
| 731 | mode = PLAIN; |
| 732 | else if (!strcmp(optarg, "csv")) |
| 733 | mode = CSV; |
| 734 | else if (!strcmp(optarg, "json")) |
| 735 | mode = JSON; |
nothing calls this directly
no test coverage detected