2. Main loop

<<main_loop>>=
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parg.h"

<<global_variables>>
<<enums>>
<<sorg_data>>
<<function_declarations>>
<<functions>>
<<parsing_top>>
<<getline>>

int main(int argc, char *argv[])
{
    FILE *in;
    FILE *out;
    char *line;
    size_t read;
    size_t n;
    sorg_d sorg;
    char *filename;
<<local_variables>>

    filename = NULL;
    in = stdin;

<<parse_command_flags>>

    if(filename != NULL) {
        in = fopen(filename, "r");
    }

    out = stdout;

    line = NULL;
    n = 0;

    sorg_init(&sorg);

    while((read = sorg_getline(&line, &n, in)) != -1) {
        parse(&sorg, out, line, read);
    }

    if(sorg.pmode == MODE_TEXT) fprintf(out, "</p>");
    if(mktoc && sorg.depth >= 0) fprintf(out, "</ul>");
    if(in != stdin) fclose(in);
    if(line != NULL) free(line);
    return 0;
}



prev | home | next