/* * text2word by Dom Lachowicz */ #include #include int main(int argc, char *argv[]) { FILE *in, *out; wvExporter *wv; char line[BUFSIZ]; if(argc != 3) { fprintf(stderr, "Usage: text2word in_txtfile out_docfile\n"); exit(1); } /* open file for reading */ in = fopen(argv[1], "r"); if(in == NULL) { fprintf(stderr, "Error opening %s for reading\n", argv[1]); exit(1); } /* open a new word document */ wv = wvExporter_create(argv[2]); if(wv == NULL) { fprintf(stderr, "Error opening %s for export\n", argv[2]); exit(1); } /* TODO: dump some information into * the summary stream */ /* wvExporter_summaryPut(wv, , ); */ /********************************************* * be a dummie and assume that everything is * really one section and one paragraph. we are * dealing with a text document here so there's * really only 1 section and all of the paragraphs * and all of the characters really have the same * style so we can get away with this ********************************************/ wvExporter_sectionBegin(wv); wvExporter_paraBegin(wv); while(fgets(in, line, BUFSIZ) != NULL) { int nlen = strlen(line); /* detect hard-line break */ if(line[nlen-1] == '\n') { line[nlen-1] = 0; wvExporter_textRun(wv, line); wvExporter_hardBreak(wv); } else wvExporter_textRun(wv, line); } /* end the paragraph */ wvExporter_paraEnd(wv); /* end the section */ wvExporter_sectionEnd(wv); /* close the input and output streams */ fclose(in); wvExporter_close(wv); return 0; }