Lazy-load and reuse default tags set options, and fix no value not being accepted as CLI tags list option values
This commit is contained in:
parent
c7911c47c9
commit
1df4fab239
|
@ -125,6 +125,10 @@ int main(int argc, char **argv) {
|
|||
int config_buffer = 0;
|
||||
hbs_options_t config_stream = hbs_options_create();
|
||||
|
||||
int nondefault_ex_collapse_whitespace = 0;
|
||||
int nondefault_ex_destroy_whole_whitespace = 0;
|
||||
int nondefault_ex_trim_whitespace = 0;
|
||||
|
||||
// Parse arguments
|
||||
while (1) {
|
||||
struct option long_options[] = {
|
||||
|
@ -135,9 +139,9 @@ int main(int argc, char **argv) {
|
|||
{"output", required_argument, NULL, 'o'},
|
||||
{"suppress", required_argument, NULL, 's'},
|
||||
|
||||
{"MXcollapseWhitespace", required_argument, NULL, 1},
|
||||
{"MXdestroyWholeWhitespace", required_argument, NULL, 2},
|
||||
{"MXtrimWhitespace", required_argument, NULL, 3},
|
||||
{"MXcollapseWhitespace", optional_argument, NULL, 1},
|
||||
{"MXdestroyWholeWhitespace", optional_argument, NULL, 2},
|
||||
{"MXtrimWhitespace", optional_argument, NULL, 3},
|
||||
|
||||
{"MXtrimClassAttr", no_argument, &(config_stream->trim_class_attr), 0},
|
||||
{"MXdecEnt", no_argument, &(config_stream->decode_entities), 0},
|
||||
|
@ -186,19 +190,26 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
|
||||
case 1:
|
||||
nondefault_ex_collapse_whitespace = 1;
|
||||
config_stream->ex_collapse_whitespace = _parse_list_of_tags(optarg);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
nondefault_ex_destroy_whole_whitespace = 1;
|
||||
config_stream->ex_destroy_whole_whitespace = _parse_list_of_tags(optarg);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
nondefault_ex_trim_whitespace = 1;
|
||||
config_stream->ex_trim_whitespace = _parse_list_of_tags(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!nondefault_ex_collapse_whitespace) config_stream->ex_collapse_whitespace = hbs_options_default_ex_collapse_whitespace();
|
||||
if (!nondefault_ex_destroy_whole_whitespace) config_stream->ex_destroy_whole_whitespace = hbs_options_default_ex_destroy_whole_whitespace();
|
||||
if (!nondefault_ex_trim_whitespace) config_stream->ex_trim_whitespace = hbs_options_default_ex_trim_whitespace();
|
||||
|
||||
hbe_info_kv_string("Input", input_path);
|
||||
hbe_info_kv_string("Output", output_path);
|
||||
hbe_info_kv_boolean("Buffer output until success", config_buffer);
|
||||
|
|
|
@ -21,33 +21,45 @@ typedef struct hbs_options_s {
|
|||
int remove_tag_whitespace;
|
||||
} *hbs_options_t;
|
||||
|
||||
static nh_set_str_t _hbs_options_default_ex_collapse_whitespace(void) {
|
||||
nh_set_str_t set = nh_set_str_create();
|
||||
hbr_wsstags_add_elems(set);
|
||||
return set;
|
||||
static nh_set_str_t _hbs_options_default_ex_collapse_whitespace = NULL;
|
||||
|
||||
nh_set_str_t hbs_options_default_ex_collapse_whitespace(void) {
|
||||
if (_hbs_options_default_ex_collapse_whitespace == NULL) {
|
||||
_hbs_options_default_ex_collapse_whitespace = nh_set_str_create();
|
||||
hbr_wsstags_add_elems(_hbs_options_default_ex_collapse_whitespace);
|
||||
}
|
||||
return _hbs_options_default_ex_collapse_whitespace;
|
||||
}
|
||||
|
||||
static nh_set_str_t _hbs_options_default_ex_destroy_whole_whitespace(void) {
|
||||
nh_set_str_t set = nh_set_str_create();
|
||||
hbr_wsstags_add_elems(set);
|
||||
hbr_contenttags_add_elems(set);
|
||||
hbr_formattingtags_add_elems(set);
|
||||
return set;
|
||||
static nh_set_str_t _hbs_options_default_ex_destroy_whole_whitespace = NULL;
|
||||
|
||||
nh_set_str_t hbs_options_default_ex_destroy_whole_whitespace(void) {
|
||||
if (_hbs_options_default_ex_destroy_whole_whitespace == NULL) {
|
||||
_hbs_options_default_ex_destroy_whole_whitespace = nh_set_str_create();
|
||||
hbr_wsstags_add_elems(_hbs_options_default_ex_destroy_whole_whitespace);
|
||||
hbr_contenttags_add_elems(_hbs_options_default_ex_destroy_whole_whitespace);
|
||||
hbr_formattingtags_add_elems(_hbs_options_default_ex_destroy_whole_whitespace);
|
||||
}
|
||||
return _hbs_options_default_ex_destroy_whole_whitespace;
|
||||
}
|
||||
|
||||
static nh_set_str_t _hbs_options_default_ex_trim_whitespace(void) {
|
||||
nh_set_str_t set = nh_set_str_create();
|
||||
hbr_wsstags_add_elems(set);
|
||||
hbr_formattingtags_add_elems(set);
|
||||
return set;
|
||||
static nh_set_str_t _hbs_options_default_ex_trim_whitespace = NULL;
|
||||
|
||||
nh_set_str_t hbs_options_default_ex_trim_whitespace(void) {
|
||||
if (_hbs_options_default_ex_trim_whitespace == NULL) {
|
||||
_hbs_options_default_ex_trim_whitespace = nh_set_str_create();
|
||||
hbr_wsstags_add_elems(_hbs_options_default_ex_trim_whitespace);
|
||||
hbr_formattingtags_add_elems(_hbs_options_default_ex_trim_whitespace);
|
||||
}
|
||||
return _hbs_options_default_ex_trim_whitespace;
|
||||
}
|
||||
|
||||
// WARNING: Rules must be initialised before calling this function
|
||||
hbs_options_t hbs_options_create(void) {
|
||||
hbs_options_t opt = hbu_mem_malloc(sizeof(struct hbs_options_s));
|
||||
opt->ex_collapse_whitespace = _hbs_options_default_ex_collapse_whitespace();
|
||||
opt->ex_destroy_whole_whitespace = _hbs_options_default_ex_destroy_whole_whitespace();
|
||||
opt->ex_trim_whitespace = _hbs_options_default_ex_trim_whitespace();
|
||||
opt->ex_collapse_whitespace = NULL;
|
||||
opt->ex_destroy_whole_whitespace = NULL;
|
||||
opt->ex_trim_whitespace = NULL;
|
||||
opt->suppressed_errors = nh_set_int32_create();
|
||||
opt->trim_class_attr = 1;
|
||||
opt->decode_entities = 1;
|
||||
|
|
Loading…
Reference in New Issue