-static gboolean
-document_load(PSDocument * gs, const gchar * fname)
-{
- g_return_val_if_fail(gs != NULL, FALSE);
- g_return_val_if_fail(PS_IS_DOCUMENT(gs), FALSE);
-
- LOG ("Load the document");
-
- /* clean up previous document */
- ps_document_cleanup(gs);
-
- if(fname == NULL) {
- gs->gs_status = "";
- return FALSE;
- }
-
- /* prepare this document */
- gs->structured_doc = FALSE;
- gs->send_filename_to_gs = TRUE;
- gs->current_page = 0;
- gs->loaded = FALSE;
- if(*fname == '/') {
- /* an absolute path */
- gs->gs_filename = g_strdup(fname);
- }
- else {
- /* path relative to our cwd: make it absolute */
- gchar *cwd = g_get_current_dir();
- gs->gs_filename = g_strconcat(cwd, "/", fname, NULL);
- g_free(cwd);
- }
-
- if((gs->reading_from_pipe = (strcmp(fname, "-") == 0))) {
- gs->send_filename_to_gs = FALSE;
- }
- else {
- /*
- * We need to make sure that the file is loadable/exists!
- * otherwise we want to exit without loading new stuff...
- */
- gchar *filename = NULL;
-
- if(!file_readable(fname)) {
- gchar buf[1024];
- g_snprintf(buf, 1024, _("Cannot open file %s.\n"), fname);
- interpreter_failed (gs, buf);
- gs->gs_status = _("File is not readable.");
- }
- else {
- filename = check_filecompressed(gs);
- }
-
- if(!filename || (gs->gs_psfile = fopen(filename, "r")) == NULL) {
- interpreter_failed (gs, NULL);
- ps_document_cleanup(gs);
- return FALSE;
- }
-
- /* we grab the vital statistics!!! */
- gs->doc = psscan(gs->gs_psfile, TRUE, filename);
-
- g_object_notify (G_OBJECT (gs), "title");
-
- if(gs->doc == NULL) {
- /* File does not seem to be a Postscript one */
- gchar buf[1024];
- g_snprintf(buf, 1024, _("Error while scanning file %s\n"), fname);
- interpreter_failed (gs, buf);
- ps_document_cleanup(gs);
- gs->gs_status = _("The file is not a PostScript document.");
- return FALSE;
- }
-
- if((!gs->doc->epsf && gs->doc->numpages > 0) ||
- (gs->doc->epsf && gs->doc->numpages > 1)) {
- gs->structured_doc = TRUE;
- gs->send_filename_to_gs = FALSE;
- }
- }
- gs->loaded = TRUE;
- compute_dimensions (gs, gs->current_page);
-
- gs->gs_status = _("Document loaded.");
-
- return gs->loaded;
-}