| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#include <ctype.h> |
|---|
| 23 |
#include <sys/param.h> |
|---|
| 24 |
#include <stdio.h> |
|---|
| 25 |
#include <stdlib.h> |
|---|
| 26 |
#include <stdarg.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <locale.h> |
|---|
| 29 |
#include <err.h> |
|---|
| 30 |
#include <getopt.h> |
|---|
| 31 |
|
|---|
| 32 |
#include "libswish3.h" |
|---|
| 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 |
} |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
int |
|---|
| 56 |
main(int argc, char **argv) |
|---|
| 57 |
{ |
|---|
| 58 |
#ifdef LIBXML_READER_ENABLED |
|---|
| 59 |
int i, ch; |
|---|
| 60 |
int option_index; |
|---|
| 61 |
extern char *optarg; |
|---|
| 62 |
extern int optind; |
|---|
| 63 |
swish_Config *config; |
|---|
| 64 |
|
|---|
| 65 |
option_index = 0; |
|---|
| 66 |
|
|---|
| 67 |
swish_init(); |
|---|
| 68 |
|
|---|
| 69 |
while ((ch = getopt_long(argc, argv, "d:h", longopts, &option_index)) != -1) |
|---|
| 70 |
{ |
|---|
| 71 |
switch (ch) |
|---|
| 72 |
{ |
|---|
| 73 |
case 0: |
|---|
| 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 = swish_string_to_int(optarg); |
|---|
| 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++) { |
|---|
| 103 |
printf("config file %s\n", argv[i]); |
|---|
| 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 |
} |
|---|
| 119 |
swish_free_config(config); |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
xmlMemoryDump(); |
|---|
| 127 |
return 0; |
|---|
| 128 |
#else |
|---|
| 129 |
|
|---|
| 130 |
SWISH_CROAK("Your version of libxml2 is too old"); |
|---|
| 131 |
return 1; |
|---|
| 132 |
#endif |
|---|
| 133 |
|
|---|
| 134 |
} |
|---|