The top level, which is little more than a demarcation between subcommands.

§1. Every program using foundation must define this:

define PROGRAM_NAME "inweb"

§2. Almost all of the literate programming functionality which powers Inweb is now library-ized into foundation, but it is very slightly modified when used inside Inweb itself, and those modifications come into effect when the following is defined:

define THIS_IS_INWEB

§3. As we will see, reading the command line is not an entirely simple business, but otherwise we do as little as possible here, and delegate everything to the subcommands.

int main(int argc, char **argv) {
    Initialise inweb3.1;
    inweb_instructions args = Configuration::read(argc, argv);
    Make some global settings3.2;
    if (no_inweb_errors == 0) {
        switch (args.subcommand) {
            case NO_CLSUB:
                if (argc <= 1)
                    PRINT("inweb: a tool for literate programming. See 'inweb help' for more.\n");
                break;
            case ADVANCE_BUILD_CLSUB:  InwebAdvanceBuild::run(&args); break;
            case INSPECT_CLSUB:        InwebInspect::run(&args); break;
            case MAP_CLSUB:            InwebMap::run(&args); break;
            case MAKE_README_CLSUB:    InwebMake::run(&args); break;
            case MAKE_GITIGNORE_CLSUB: InwebMake::run(&args); break;
            case MAKE_MAKEFILE_CLSUB:  InwebMake::run(&args); break;
            case TEST_LANGUAGE_CLSUB:  InwebTestLanguage::run(&args); break;
            case WEAVE_CLSUB:          InwebWeave::run(&args); break;
            case TANGLING_CLSUB:       InwebTangle::run(&args); break;
        }
    }
    Shut inweb down3.3;
}

§3.1. Initialise inweb3.1 =

    Foundation::start(argc, argv);
    LiterateModule::start();
    WeavingFormats::create_weave_formats();

§4. We keep global settings to a minimum. Note that the installation path can only be set after the command-line switches are read, since they can change it.

pathname *path_to_inweb = NULL;  where we are installed
int no_inweb_errors = 0;
int verbose_mode = FALSE;
int old_inweb_compatibility_mode = TRUE;

§3.2. Make some global settings3.2 =

    verbose_mode = args.verbose_switch;
    old_inweb_compatibility_mode = TRUE;
    path_to_inweb = Pathnames::installation_path("INWEB_PATH", I"inweb");
    if (verbose_mode) {
        PRINT("Installation path is %p\n", path_to_inweb);
        Locales::write_locales(STDOUT);
    }
    pathname *M = Pathnames::path_to_inweb_materials();
    Pathnames::set_path_to_LP_resources(M);
    if (args.import_setting)
        WebModules::set_default_search_path(
            WebModules::make_search_path(args.import_setting));

§3.3. Shut inweb down3.3 =

    Foundation::end();
    return (no_inweb_errors == 0)?0:1;