3. Top Level Function

<<functions>>=
<<helper_functions>>
static int mkpage (wmp_core *core, sqlite3 *wiki, int prog)
{
    int rc;
    unsigned int id;
    unsigned int next;
    unsigned int last;
    wwstring str;
    int err;
    unsigned int prev_header_id;
    int page_id;
    int single_page;

    err = 0;
    wwstring_init(&str);
    prev_header_id = 0;
    page_id = 0;
    next = 0;
    single_page = 0;
<<page_generation>>
    cleanup:
    wwstring_free(&str);

    return err;
}

int p_weewiki(int argc, char *argv[])
{
    sqlite3 *wiki;
    wmp_core core;
    int err;
    int prog;
    int rc;

    err = 0;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s program [db]\n", argv[0]);
        return 1;
    }

    rc = wmp_core_open(&core, wmp_filename_get());
    if (!rc) return 0;

<<open_the_db>>
<<clear_and_reset>>

    if (!strncmp(argv[1], "all", 3)) {
        sqlite3_stmt *stmt;
        int run;

        run = 1;
        printf("rendering all pages\n");
        sqlite3_prepare_v2(wiki,
                           "SELECT DISTINCT(program) FROM resources;",
                           -1, &stmt, NULL);
        while (run) {
            rc = sqlite3_step(stmt);

            switch (rc) {
                case SQLITE_ROW:
                    prog = sqlite3_column_int(stmt, 0);
                    printf("generating program %d\n", prog);
                    err = mkpage(&core, wiki, prog);
                    if (err) run = 0;
                    break;
                case SQLITE_DONE:
                    run = 0;
                    break;
                default:
                    fprintf(stderr, "Error: %s\n", sqlite3_errmsg(wiki));
                    break;
            }
        }

        sqlite3_finalize(stmt);
    } else {
        prog = atoi(argv[1]);
        err = mkpage(&core, wiki, prog);
    }

<<close_the_db>>

    wmp_core_close(&core);
    return err;
}



prev | home | next