17. Parse

The parse command will parse an org file via orgparse and write the HTML output. This is primarily useful for debugging scripts.

<<argparse_entries>>=
{"parse", 5, p_parse, NULL},
<<static_funcdefs>>=
static int p_parse(int argc, char *argv[]);
<<functions>>=
static int p_parse(int argc, char *argv[])
{
    weewiki_d ww;
    FILE *fp;
    unsigned char *txt;
    size_t sz;
    weewiki_export_d ex;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s file.org\n", argv[0]);
        return 1;
    } else {
        fp = fopen(argv[1], "r");
        if (fp == NULL) {
            fprintf(stderr,
                    "Could not open '%s' for reading.\n",
                    argv[1]);
            return 1;
        }
    }

    weewiki_init(&ww);
    weewiki_open(&ww, weewiki_dbname_get());

    weewiki_set(&ww);

    weewiki_orgparse_setup(&ex.op);
    ex.env = weewiki_janet_setup();

    weewiki_janet_loadconfig(ex.env);

    ex.fp = stdout;
    ww.fp = ex.fp;
    ww.ud = &ex;

    fseek(fp, 0, SEEK_END);
    sz = ftell(fp);
    txt = calloc(1, sz + 1);
    fseek(fp, 0, SEEK_SET);
    fread(txt, 1, sz, fp);
    fclose(fp);

    write_file(&ex, txt, sz);

    weewiki_janet_cleanup();

    weewiki_close(&ww);
    weewiki_clean(&ww);

    return 0;
}



prev | home | next