commit 462a9a8013dec40e1ee710e23385a89e49bf1801 from: Sven M. Hallberg date: Sat Jul 01 16:13:47 2023 UTC move opening/closing of xfile into main commit - 470927252fcd4952bfd15f13f01cf614f98012c9 commit + 462a9a8013dec40e1ee710e23385a89e49bf1801 blob - e145a182c8e3e56b544d5b9b8d005296aab94fb3 blob + bad0993416cbe5289eddec11426c1f0761fd56ad --- pdf.c +++ pdf.c @@ -2171,27 +2171,18 @@ basename(const char *fn) assert(*p != '\0'); /* not the empty string */ return p; } - -#include /* for text_extract */ /* * This utility extracts the text stream from the global environment * and writes it out to a file. */ void -text_extract(struct Env *aux, const char *outfn) +text_extract(struct Env *aux, FILE *stream) { - FILE *stream; struct textnode *cur; - /* open the file for writing */ - if ((stream = fopen(outfn, "w")) == NULL) - err(2, "%s", outfn); - for (cur = aux->txthead; cur != NULL; cur = cur->next) fwrite(cur->tstr->text, 1, cur->tstr->nchars, stream); - - fclose(stream); } @@ -5157,8 +5148,16 @@ main(int argc, char *argv[]) /* extract text if requested */ if (xfile != NULL) { + FILE *f; + + /* open the output file */ + if ((f = fopen(xfile, "w")) == NULL) + err(2, "%s", xfile); + process_page_content(&aux); - text_extract(&aux, xfile); + text_extract(&aux, f); + + fclose(f); } #ifdef LEAKCHECK