summaryrefslogtreecommitdiff
path: root/libspectre
diff options
context:
space:
mode:
authorRandy <randy408@protonmail.com>2020-02-18 21:33:37 +0000
committerAlbert Astals Cid <tsdgeos@yahoo.es>2020-02-18 21:33:37 +0000
commit7ae80bff9ee04793a1c0d59e538da7802f81a43d (patch)
tree7eb47fdef7361eebde800393ba0d37b5e1dc053e /libspectre
parentbdc1caaeb22832a0dc1f7420a497cd2382d5edd6 (diff)
Refactor code so that psscan() can accept a FILE*, this will enable parsing from fmemopen()'d buffers. I figured this should be merged separately before spectre_document_load_from_data() is added.
Diffstat (limited to 'libspectre')
-rw-r--r--libspectre/ps.c11
-rw-r--r--libspectre/ps.h1
-rw-r--r--libspectre/spectre-document.c14
3 files changed, 15 insertions, 11 deletions
diff --git a/libspectre/ps.c b/libspectre/ps.c
index 18c3c30..e6b508c 100644
--- a/libspectre/ps.c
+++ b/libspectre/ps.c
@@ -368,10 +368,9 @@ static Boolean scan_boundingbox(int *bb, const char *line)
/*###########################################################*/
struct document *
-psscan(const char *filename, int scanstyle)
+psscan(FILE *file, const char *filename, int scanstyle)
{
struct document *doc;
- FILE *file;
int bb_set = NONE;
int pages_set = NONE;
int page_order_set = NONE;
@@ -424,11 +423,6 @@ psscan(const char *filename, int scanstyle)
return(NULL);
}
- file = fopen (filename, "rb");
- if (!file) {
- return NULL;
- }
-
fd = ps_io_init(file);
/* rjl: check for DOS EPS files and almost DSC files that start with ^D */
@@ -437,7 +431,6 @@ psscan(const char *filename, int scanstyle)
fprintf(stderr, "Warning: empty file.\n");
ENDMESSAGE(psscan)
ps_io_exit(fd);
- fclose (file);
return(NULL);
}
@@ -451,7 +444,6 @@ psscan(const char *filename, int scanstyle)
fprintf(stderr, "psscan error: input files seems to be a PJL file.\n");
ENDMESSAGE(psscan)
ps_io_exit(fd);
- fclose (file);
return (NULL);
}
}
@@ -1234,7 +1226,6 @@ continuepage:
#endif
ENDMESSAGE(psscan)
ps_io_exit(fd);
- fclose (file);
return doc;
}
diff --git a/libspectre/ps.h b/libspectre/ps.h
index e063668..851c55c 100644
--- a/libspectre/ps.h
+++ b/libspectre/ps.h
@@ -153,6 +153,7 @@ struct page {
Document psscan (
#if NeedFunctionPrototypes
+ FILE *,
const char *,
int /* scanstyle */
#endif
diff --git a/libspectre/spectre-document.c b/libspectre/spectre-document.c
index 6dde48b..c08c3c2 100644
--- a/libspectre/spectre-document.c
+++ b/libspectre/spectre-document.c
@@ -54,6 +54,7 @@ void
spectre_document_load (SpectreDocument *document,
const char *filename)
{
+ FILE *file;
_spectre_return_if_fail (document != NULL);
_spectre_return_if_fail (filename != NULL);
@@ -66,10 +67,17 @@ spectre_document_load (SpectreDocument *document,
psdocdestroy (document->doc);
document->doc = NULL;
}
+
+ file = fopen (filename, "rb");
+ if (!file) {
+ document->status = SPECTRE_STATUS_LOAD_ERROR;
+ return;
+ }
- document->doc = psscan (filename, SCANSTYLE_NORMAL);
+ document->doc = psscan (file, filename, SCANSTYLE_NORMAL);
if (!document->doc) {
document->status = SPECTRE_STATUS_LOAD_ERROR;
+ fclose(file);
return;
}
@@ -77,6 +85,7 @@ spectre_document_load (SpectreDocument *document,
document->status = SPECTRE_STATUS_LOAD_ERROR;
psdocdestroy (document->doc);
document->doc = NULL;
+ fclose(file);
return;
} else if (document->doc->numpages == 0 && !document->doc->format) {
@@ -91,6 +100,7 @@ spectre_document_load (SpectreDocument *document,
document->status = SPECTRE_STATUS_LOAD_ERROR;
psdocdestroy (document->doc);
document->doc = NULL;
+ fclose(file);
return;
}
@@ -101,6 +111,8 @@ spectre_document_load (SpectreDocument *document,
if (document->status != SPECTRE_STATUS_SUCCESS)
document->status = SPECTRE_STATUS_SUCCESS;
+
+ fclose(file);
}
void