| | 33 | |
|---|
| | 34 | extern int SWISH_DEBUG; |
|---|
| | 35 | |
|---|
| | 36 | static struct option longopts[] = |
|---|
| | 37 | { |
|---|
| | 38 | {"debug", required_argument, 0, 'd'}, |
|---|
| | 39 | {"help", no_argument, 0, 'h'}, |
|---|
| | 40 | {0, 0, 0, 0} |
|---|
| | 41 | }; |
|---|
| | 42 | |
|---|
| | 43 | int |
|---|
| | 44 | usage() |
|---|
| | 45 | { |
|---|
| | 46 | |
|---|
| | 47 | char * descr = "swish_header reads and writes swish3 header/config files\n"; |
|---|
| | 48 | printf("swish_header [opts] file\n"); |
|---|
| | 49 | printf("opts:\n --debug [lvl]\n --help\n"); |
|---|
| | 50 | printf("\n%s\n", descr); |
|---|
| | 51 | exit(0); |
|---|
| | 52 | } |
|---|
| 42 | | for (i=1; i < argc; i++) { |
|---|
| | 69 | while ((ch = getopt_long(argc, argv, "d:h", longopts, &option_index)) != -1) |
|---|
| | 70 | { |
|---|
| | 71 | switch (ch) |
|---|
| | 72 | { |
|---|
| | 73 | case 0: /* If this option set a flag, do nothing else now. */ |
|---|
| | 74 | if (longopts[option_index].flag != 0) |
|---|
| | 75 | break; |
|---|
| | 76 | printf("option %s", longopts[option_index].name); |
|---|
| | 77 | if (optarg) |
|---|
| | 78 | printf(" with arg %s", optarg); |
|---|
| | 79 | printf("\n"); |
|---|
| | 80 | break; |
|---|
| | 81 | |
|---|
| | 82 | case 'd': |
|---|
| | 83 | printf("turning on debug mode: %s\n", optarg); |
|---|
| | 84 | |
|---|
| | 85 | if (!isdigit(optarg[0])) |
|---|
| | 86 | err(1, "-d option requires a positive integer as argument\n"); |
|---|
| | 87 | |
|---|
| | 88 | SWISH_DEBUG = (int) strtol(optarg, (char **) NULL, 10); |
|---|
| | 89 | break; |
|---|
| | 90 | |
|---|
| | 91 | case '?': |
|---|
| | 92 | case 'h': |
|---|
| | 93 | default: |
|---|
| | 94 | usage(); |
|---|
| | 95 | |
|---|
| | 96 | } |
|---|
| | 97 | |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | i = optind; |
|---|
| | 101 | |
|---|
| | 102 | for (; i < argc; i++) { |
|---|
| 44 | | config = swish_read_header( (char*)argv[i] ); |
|---|
| 45 | | swish_debug_config(config); |
|---|
| | 104 | config = swish_init_config(); |
|---|
| | 105 | if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { |
|---|
| | 106 | SWISH_DEBUG_MSG("init_config"); |
|---|
| | 107 | } |
|---|
| | 108 | swish_config_set_default(config); |
|---|
| | 109 | if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { |
|---|
| | 110 | SWISH_DEBUG_MSG("set default"); |
|---|
| | 111 | } |
|---|
| | 112 | if (!swish_merge_config_with_header( (char*)argv[i], config )) { |
|---|
| | 113 | SWISH_CROAK("failed to merge header %s with defaulf config", argv[i]); |
|---|
| | 114 | } |
|---|
| | 115 | swish_write_header("swish_header.xml", config); |
|---|
| | 116 | if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { |
|---|
| | 117 | SWISH_DEBUG_MSG("header written"); |
|---|
| | 118 | } |
|---|