📄 gvcdisp.c
字号:
} return tpsfile;}voidrotate_last_files(int count){int i;char buf[MAXSTR]; strncpy(buf, last_files[count], MAXSTR-1); for (i=count; i>0; i--) strncpy(last_files[i], last_files[i-1], MAXSTR-1); strncpy(last_files[0], buf, MAXSTR-1);}voidupdate_last_files(char *filename){int i; for (i=0; i<last_files_count; i++) { if (strcmp(filename, last_files[i]) == 0) break; } if (i < last_files_count) { /* already in list */ rotate_last_files(i); return; } if (last_files_count < 4) last_files_count++; rotate_last_files(last_files_count-1); strncpy(last_files[0], filename, MAXSTR-1);}/* get filename then open new file for printing or extract */void gsview_select(){char buf[MAXSTR]; strncpy(buf, psfile.name, MAXSTR-1); if (get_filename(buf, FALSE, FILTER_PSALL, 0, IDS_TOPICOPEN)) gsview_selectfile(buf);}/* open new file for printing or extract */voidgsview_selectfile(char *filename){ while (*filename && *filename==' ') filename++; update_last_files(filename); if (gsdll.open && (gsdll.state!=GS_UNINIT)) { /* remember name for later */ strncpy(selectname, filename, sizeof(selectname)); /* close file and wait for notification */ post_img_message(WM_COMMAND, IDM_CLOSE); } else { /* open it ourselves */ PSFILE *tpsfile = gsview_openfile(filename); if (tpsfile) { psfile_free(&psfile); psfile = *tpsfile; post_img_message(WM_GSTITLE, 0); free(tpsfile); /* Do NOT free doc and page_list.select */ } } info_wait(IDS_NOWAIT);}/* get filename then open a new document and display it */void gsview_display(){char buf[MAXSTR]; strncpy(buf, psfile.name, MAXSTR-1); if (get_filename(buf, FALSE, FILTER_PSALL, 0, IDS_TOPICOPEN)) gsview_displayfile(buf);}/* open a new document and display it */voidgsview_displayfile(char *filename){PSFILE *tpsfile; tpsfile = gsview_openfile(filename); if (!tpsfile) return; update_last_files(filename); if (pending.psfile) { message_box_a("pending.psfile is already set", 0); e_free_psfile(tpsfile); return; } pending.psfile = tpsfile; if ( gsdll.hmodule && (psfile.dsc==(CDSC *)NULL) && (gsdll.state != GS_IDLE) ) /* don't know where we are so close and reopen */ pending.abort = TRUE; pending.now = TRUE; history_add(1);}/* Create and open a scratch file with a given name prefix. *//* Write the actual file name at fname. */FILE *gp_open_scratch_file(const char *prefix, char *fname, const char *mode){ char *temp;#if defined(UNIX) || defined(OS2) int fd;#endif if ( (temp = getenv("TEMP")) == NULL )#ifdef UNIX strcpy(fname, "/tmp");#else gs_getcwd(fname, MAXSTR-1);#endif else strncpy(fname, temp, MAXSTR-1); /* Prevent X's in path from being converted by mktemp. */ for ( temp = fname; *temp; temp++ ) { *temp = (char)tolower(*temp);#if defined(_Windows) || defined(OS2) if (*temp == '/') *temp = '\\';#endif } if ( strlen(fname) && (fname[strlen(fname)-1] != PATHSEP[0]) ) strcat(fname, PATHSEP); strncat(fname, prefix, MAXSTR-1-strlen(fname)); strncat(fname, "XXXXXX", MAXSTR-1-strlen(fname));#ifdef __IBMC__ { char *p; _tempnam(NULL, fname); strncpy(fname, p, MAXSTR-1); free(p); } return fopen(fname, mode);#else#if defined(UNIX) || defined(OS2) fd = mkstemp(fname); return fdopen(fd, mode);#else mktemp(fname); return fopen(fname, mode);#endif#endif}/* This is triggered by WM_ACTIVATE. * If the file has changed when we are activated, and Auto * redisplay is set, cause the file to be reloaded and * redisplayed. * returns 0 is no change, -1 if file deleted, * 1 if changed and should redisplay. */intdfchanged(){char *filename;GFile *gf;BOOL changed = FALSE;int code = 0; request_mutex(); if (psfile.locked) { release_mutex(); /* someone else has it */ return 0; } psfile.locked = TRUE; /* stop others using it */ release_mutex(); filename = psfile_name(&psfile); if (filename[0] != '\0') { if ((gf = gfile_open(filename, gfile_modeRead)) != NULL) { changed = gfile_changed(gf, psfile.length, psfile.filetimel, psfile.filetimeh); gfile_close(gf); } else code = -1; } else code = 0; psfile.locked = FALSE; if (code < 0) return code; if (changed && option.redisplay) return 1; return 0;}/* reopen psfile *//* psfile will then be locked until closed *//* return 0 if OK *//* if psfile time/date or length has changed, return 1 *//* return -1 if file can not be opened */intdfreopen(void){char *filename; if (debug & DEBUG_GENERAL) gs_addmess("dfreopen:\n"); request_mutex(); if (psfile.locked) { release_mutex(); /* someone else has it */ delayed_message_box(IDS_DEBUG_DFISLOCKED, 0); return -1; } psfile.locked = TRUE; /* stop others using it */ release_mutex(); filename = psfile_name(&psfile); if (psfile.file != NULL) { /* should never happen */ delayed_message_box(IDS_DEBUG_DFISOPEN, 0); } if (filename[0] == '\0') { psfile.locked = FALSE; delayed_message_box(IDS_NOTOPEN, 0); return -1; } if ((psfile.file = gfile_open(filename, gfile_modeRead)) == (GFile *)NULL) { if (debug) delayed_message_box(IDS_DEBUG_DFISMISSING, 0); filename[0] = '\0'; psfile.locked = FALSE; return -1; } if (gfile_changed(psfile.file, psfile.length, psfile.filetimel, psfile.filetimeh)) { /* doesn't cope with pdf file changing */ dfclose(); if (debug) delayed_message_box(IDS_DEBUG_DFCHANGED, 0); return 1; } if (psfile.ispdf) { /* We needed to open the PDF file to check for changes */ /* but we don't need it open for displaying. */ dfclose(); } return 0;}voiddfclose(){ if (debug & DEBUG_GENERAL) gs_addmess("dfclose:\n"); if (debug) { if ((psfile.file==NULL) && !psfile.ispdf) delayed_message_box(IDS_DEBUG_DFISCLOSED, 0); } if (psfile.file) gfile_close(psfile.file); psfile.file = NULL; psfile.locked = FALSE;}#ifndef VIEWONLY/* gunzip to temporary file */BOOLdsc_gunzip(PSFILE *psf){FILE *outfile;gzFile infile;char *buffer;int count; if (!load_zlib()) return FALSE; /* create buffer for file copy */ buffer = (char *)malloc(COPY_BUF_SIZE); if (buffer == (char *)NULL) { play_sound(SOUND_ERROR); unload_zlib(); return FALSE; } if ((infile = gzopen(psf->name, "rb")) == (gzFile)NULL) { play_sound(SOUND_ERROR); unload_zlib(); free(buffer); return FALSE; } if ( (outfile = gp_open_scratch_file(szScratch, psf->tname, "wb")) == (FILE *)NULL) { gserror(IDS_NOTEMP, NULL, MB_ICONEXCLAMATION, SOUND_ERROR); gzclose(infile); unload_zlib(); free(buffer); return FALSE; } gs_addmess("Uncompressing "); gs_addmess(psf->name); gs_addmess(" to "); gs_addmess(psf->tname); gs_addmess("\n"); while ( (count = gzread(infile, buffer, COPY_BUF_SIZE)) > 0 ) { fwrite(buffer, 1, count, outfile); } free(buffer); gzclose(infile); fclose(outfile); /* unload_zlib(); */ if (count < 0) return FALSE; return TRUE;}#if defined(_Windows) || defined(UNIX)/* Uncompress bzip2 to temporary file */BOOLdsc_bunzip2(PSFILE *psf){FILE *outfile;bzFile infile;char *buffer;int count; if (!load_bzip2()) return FALSE; /* create buffer for file copy */ buffer = (char *)malloc(COPY_BUF_SIZE); if (buffer == (char *)NULL) { play_sound(SOUND_ERROR); unload_bzip2(); return FALSE; } if ((infile = bzopen(psf->name, "rb")) == (bzFile)NULL) { play_sound(SOUND_ERROR); unload_bzip2(); free(buffer); return FALSE; } if ( (outfile = gp_open_scratch_file(szScratch, psf->tname, "wb")) == (FILE *)NULL) { gserror(IDS_NOTEMP, NULL, MB_ICONEXCLAMATION, SOUND_ERROR); bzclose(infile); unload_bzip2(); free(buffer); return FALSE; } gs_addmess("Uncompressing "); gs_addmess(psf->name); gs_addmess(" to "); gs_addmess(psf->tname); gs_addmess("\n"); while ( (count = bzread(infile, buffer, COPY_BUF_SIZE)) > 0 ) { fwrite(buffer, 1, count, outfile); } free(buffer); bzclose(infile); fclose(outfile); /* unload_bzip2(); */ if (count < 0) return FALSE; return TRUE;}#endif#endif /* !VIEWONLY *//* Debug for DSC comments */voiddsc_dump(PSFILE *psf){char buf[MAXSTR]; sprintf(buf, "DSC dump for %.200s\n", psf->name); gs_addmess(buf); dsc_display(psf->dsc, dsc_addmess); sprintf(buf, "End of DSC dump\n"); gs_addmess(buf);}int show_dsc_error(void *caller_data, CDSC *dsc, unsigned int explanation, const char *line, unsigned int line_len){ int response = CDSC_RESPONSE_CANCEL; int severity; char buf[MAXSTR]; int len; char title[MAXSTR]; char linefmt[MAXSTR]; int i; char *p; int count; if (explanation > dsc->max_error) return CDSC_RESPONSE_OK; severity = dsc->severity[explanation]; /* If debug function provided, copy messages there */ if (dsc->debug_print_fn) { switch (severity) { case CDSC_ERROR_INFORM: dsc_debug_print(dsc, "\nDSC Information"); break; case CDSC_ERROR_WARN: dsc_debug_print(dsc, "\nDSC Warning"); break; case CDSC_ERROR_ERROR: dsc_debug_print(dsc, "\nDSC Error"); } dsc_debug_print(dsc, "\n"); if (explanation <= dsc->max_error) { if (line && line_len) { int length = min(line_len, sizeof(buf)-1); sprintf(buf, "At line %d:\n", dsc->line_count); dsc_debug_print(dsc, buf); strncpy(buf, line, length); buf[length]='\0'; dsc_debug_print(dsc, " "); dsc_debug_print(dsc, buf); } dsc_debug_print(dsc, dsc_message[explanation]); } } /* Here you could prompt user for OK, Cancel, Ignore ALL DSC */ if (option.dsc_warn == IDM_DSC_OFF) return response; else if ((option.dsc_warn == IDM_DSC_ERROR) && (severity < CDSC_ERROR_ERROR)) return response; else if ((option.dsc_warn == IDM_DSC_WARN) && (severity < CDSC_ERROR_WARN)) return response; switch (severity) { case CDSC_ERROR_INFORM: i = IDS_DSC_INFO; break; case CDSC_ERROR_WARN: i = IDS_DSC_WARN; break; case CDSC_ERROR_ERROR: i = IDS_DSC_ERROR; break; default: i = -1; } if (i != -1) load_string_a(i, title, sizeof(title)); else title[0] = '\0'; /* build up string */#define MSGBUFLEN 4096 p = (char *)malloc(MSGBUFLEN); if (p == (char *)NULL) return response;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -