2019-02-05 02:44:07 +02:00
|
|
|
[Configuration::] Configuration.
|
|
|
|
|
|
|
|
Instructions of indoc to different output types.
|
|
|
|
|
2019-02-11 12:08:27 +02:00
|
|
|
@h Known instruction files.
|
|
|
|
Most configuration is done not from the command line, but by instructions
|
|
|
|
files, and we store a list of those here:
|
|
|
|
|
|
|
|
=
|
|
|
|
linked_list *instructions_files = NULL; /* of |filename| */
|
|
|
|
|
|
|
|
void Configuration::add_instructions_file(filename *F) {
|
|
|
|
if (instructions_files == NULL) instructions_files = NEW_LINKED_LIST(filename);
|
|
|
|
ADD_TO_LINKED_LIST(F, filename, instructions_files);
|
|
|
|
}
|
|
|
|
|
2019-02-17 16:08:19 +02:00
|
|
|
void Configuration::read_instructions(text_stream *target, settings_block *settings) {
|
2019-02-16 19:29:02 +02:00
|
|
|
Instructions::read_instructions(target, instructions_files, settings);
|
2019-02-11 12:08:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@h Command line switches.
|
2019-02-05 02:44:07 +02:00
|
|
|
|
|
|
|
=
|
2019-02-16 19:29:02 +02:00
|
|
|
typedef struct cl_state {
|
|
|
|
struct text_stream *target_chosen;
|
2019-02-17 16:08:19 +02:00
|
|
|
struct settings_block *settings;
|
2019-02-16 19:29:02 +02:00
|
|
|
} cl_state;
|
|
|
|
|
2019-02-17 16:08:19 +02:00
|
|
|
void Configuration::read_command_line(int argc, char **argv, settings_block *settings) {
|
2019-02-16 19:29:02 +02:00
|
|
|
cl_state state;
|
|
|
|
state.target_chosen = Str::new();
|
|
|
|
state.settings = settings;
|
2019-02-05 02:44:07 +02:00
|
|
|
@<Read the command line@>;
|
2019-02-17 16:08:19 +02:00
|
|
|
Configuration::add_instructions_file(
|
|
|
|
Filenames::in_folder(path_to_indoc_materials, I"basic-instructions.txt"));
|
2019-02-05 02:44:07 +02:00
|
|
|
Configuration::add_instructions_file(
|
2019-02-16 19:29:02 +02:00
|
|
|
Filenames::in_folder(settings->book_folder, I"indoc-instructions.txt"));
|
|
|
|
Configuration::read_instructions(state.target_chosen, settings);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@
|
|
|
|
|
|
|
|
@e VERBOSE_CLSW
|
|
|
|
@e TEST_INDEX_CLSW
|
|
|
|
@e REWRITE_CLSW
|
|
|
|
@e FROM_CLSW
|
|
|
|
@e TO_CLSW
|
|
|
|
@e INSTRUCTIONS_CLSW
|
|
|
|
|
|
|
|
@<Read the command line@> =
|
|
|
|
CommandLine::declare_heading(
|
|
|
|
L"indoc: a tool for rendering Inform documentation\n\n"
|
|
|
|
L"Usage: indoc [OPTIONS] TARGET\n"
|
|
|
|
L"where TARGET must be one of those set up in the instructions.\n");
|
|
|
|
|
|
|
|
CommandLine::declare_boolean_switch(VERBOSE_CLSW, L"verbose", 1,
|
|
|
|
L"explain what indoc is doing");
|
|
|
|
CommandLine::declare_boolean_switch(TEST_INDEX_CLSW, L"test-index", 1,
|
|
|
|
L"test indexing");
|
|
|
|
CommandLine::declare_switch(REWRITE_CLSW, L"rewrite-standard-rules", 2,
|
|
|
|
L"amend source of Standard Rules to include documentation references");
|
|
|
|
CommandLine::declare_switch(FROM_CLSW, L"from", 2,
|
|
|
|
L"use documentation in directory X (instead of 'Documentation' in cwd)");
|
|
|
|
CommandLine::declare_switch(TO_CLSW, L"to", 2,
|
|
|
|
L"redirect output to folder X (which must already exist)");
|
|
|
|
CommandLine::declare_switch(INSTRUCTIONS_CLSW, L"instructions", 2,
|
|
|
|
L"read further instructions from file X");
|
|
|
|
|
2019-02-16 19:29:02 +02:00
|
|
|
if (CommandLine::read(argc, argv, &state, &Configuration::switch, &Configuration::bareword)
|
2019-02-05 02:44:07 +02:00
|
|
|
== FALSE) exit(0);
|
|
|
|
|
|
|
|
@ =
|
2019-02-16 19:29:02 +02:00
|
|
|
void Configuration::switch(int id, int val, text_stream *arg, void *v_cl_state) {
|
2019-02-17 16:08:19 +02:00
|
|
|
settings_block *settings = ((cl_state *) v_cl_state)->settings;
|
2019-02-05 02:44:07 +02:00
|
|
|
switch (id) {
|
2019-02-16 19:29:02 +02:00
|
|
|
case VERBOSE_CLSW: settings->verbose_mode = val; break;
|
|
|
|
case TEST_INDEX_CLSW: settings->test_index_mode = val; break;
|
|
|
|
case REWRITE_CLSW: settings->standard_rules_filename = Filenames::from_text(arg); break;
|
|
|
|
case FROM_CLSW: settings->book_folder = Pathnames::from_text(arg); break;
|
|
|
|
case TO_CLSW: settings->destination = Pathnames::from_text(arg);
|
|
|
|
settings->destination_modifiable = FALSE; break;
|
2019-02-05 02:44:07 +02:00
|
|
|
case INSTRUCTIONS_CLSW: Configuration::add_instructions_file(Filenames::from_text(arg)); break;
|
|
|
|
default: internal_error("unimplemented switch");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 19:29:02 +02:00
|
|
|
void Configuration::bareword(int id, text_stream *opt, void *v_cl_state) {
|
|
|
|
cl_state *state = (cl_state *) v_cl_state;
|
|
|
|
Str::copy(state->target_chosen, opt);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|