📄 gvcmisc.c
字号:
if (option.save_dir) {
char workdir[MAXSTR];
gs_getcwd(workdir, sizeof(workdir)); /* save current in case chdir fails */
profile_read_string(prf, section, "LastDir", "", profile, sizeof(profile));
if (gs_chdir(profile))
gs_chdir(workdir);
}
profile_read_string(prf, section, "DrawMethod", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1) {
switch (i) {
case (IDM_DRAWGPI-IDM_DRAWMENU):
option.drawmethod = IDM_DRAWGPI;
break;
case (IDM_DRAWWIN-IDM_DRAWMENU):
option.drawmethod = IDM_DRAWWIN;
break;
default:
case (IDM_DRAWDEF-IDM_DRAWMENU):
option.drawmethod = IDM_DRAWDEF;
break;
}
}
profile_read_string(prf, section, "ProgressiveUpdate", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1) {
option.update = i;
}
profile_read_string(prf, section, "PrinterDevice", "", profile, sizeof(profile));
if (strlen(profile)!=0)
strncpy(option.printer_device, profile, sizeof(option.printer_device)-1);
profile_read_string(prf, section, "PrinterResolution", "", profile, sizeof(profile));
if (strlen(profile)!=0)
strncpy(option.printer_resolution, profile, sizeof(option.printer_resolution)-1);
profile_read_string(prf, section, "PrintFixedMedia", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.print_fixed_media = i;
profile_read_string(prf, section, "ConvertDevice", "", profile, sizeof(profile));
if (strlen(profile)!=0)
strncpy(option.convert_device, profile, sizeof(option.convert_device)-1);
profile_read_string(prf, section, "ConvertResolution", "", profile, sizeof(profile));
if (strlen(profile)!=0)
strncpy(option.convert_resolution, profile, sizeof(option.convert_resolution)-1);
profile_read_string(prf, section, "ConvertFixedMedia", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.convert_fixed_media = i;
profile_read_string(prf, section, "PrintGDIDepth", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.print_gdi_depth = i+IDC_MONO;
profile_read_string(prf, section, "PrintGDIFixedMedia", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.print_gdi_fixed_media = i;
profile_read_string(prf, section, "PrinterPort", "", profile, sizeof(option.printer_port)-1);
if (profile[0] != '\0')
strncpy(option.printer_port, profile, sizeof(option.printer_port)-1);
profile_read_string(prf, section, "PrinterQueue", "", profile, sizeof(option.printer_queue)-1);
if (profile[0] != '\0')
strncpy(option.printer_queue, profile, sizeof(option.printer_queue)-1);
profile_read_string(prf, section, "PrintToFile", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.print_to_file = i;
profile_read_string(prf, section, "PrintMethod", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.print_method = i;
profile_read_string(prf, section, "PrintReverse", "", profile, sizeof(profile));
if (sscanf(profile,"%d", &i) == 1)
option.print_reverse = i;
for (i=0; i<NUMSOUND; i++) {
char buf[MAXSTR];
convert_widechar(buf, sound[i].file, sizeof(buf)-1);
profile_read_string(prf, section, sound[i].entry, buf,
profile, sizeof(profile));
convert_multibyte(sound[i].file, profile,
sizeof(sound[i].file)/sizeof(TCHAR)-1);
}
profile_read_string(prf, section, "LastFile1", "", profile,sizeof(profile));
if (profile[0])
strncpy(last_files[0], profile, sizeof(last_files[0])-1);
profile_read_string(prf, section, "LastFile2", "", profile,sizeof(profile));
if (profile[0])
strncpy(last_files[1], profile, sizeof(last_files[1])-1);
profile_read_string(prf, section, "LastFile3", "", profile,sizeof(profile));
if (profile[0])
strncpy(last_files[2], profile, sizeof(last_files[2])-1);
profile_read_string(prf, section, "LastFile4", "", profile,sizeof(profile));
if (profile[0])
strncpy(last_files[3], profile, sizeof(last_files[3])-1);
for (last_files_count=0; last_files_count<4; last_files_count++)
if (strlen(last_files[last_files_count])==0)
break;
#ifndef VIEWONLY
read_measure_profile(prf);
#endif
read_usermedia_profile(prf);
profile_close(prf);
}
/* write settings to INI file */
void
write_profile(void)
{
char profile[MAXSTR];
const char *section = INISECTION;
int i;
PROFILE *prf;
char secver[MAXSTR];
if (debug & DEBUG_GENERAL)
gs_addmessf("Writing profile \042%s\042\n", szIniFile);
prf = profile_open(szIniFile);
if (prf == (PROFILE *)NULL) {
message_box_a("profile_open() failed, no memory\n", 0);
return;
}
/* GSview-N.N */
sprintf(secver, "GSview-%s", GSVIEW_DOT_VERSION);
profile_write_string(prf, secver, "Version", GSVIEW_DOT_VERSION);
sprintf(profile, "%d", (int)option.gsversion);
profile_write_string(prf, secver, "GSversion", profile);
sprintf(profile, "%d", (int)option.configured);
profile_write_string(prf, secver, "Configured", profile);
profile_write_string(prf, secver, "GhostscriptDLL", option.gsdll);
profile_write_string(prf, secver, "GhostscriptEXE", option.gsexe);
profile_write_string(prf, secver, "GhostscriptInclude", option.gsinclude);
profile_write_string(prf, secver, "GhostscriptOther", option.gsother);
sprintf(profile, "%d %d", (int)option.img_origin.x, (int)option.img_origin.y);
/* Options */
profile_write_string(prf, section, "Language",
language_twocc(option.language));
profile_write_string(prf, section, "HelpCmd", option.helpcmd);
profile_write_string(prf, section, "Origin", profile);
sprintf(profile, "%d %d", (int)option.img_size.x, (int)option.img_size.y);
profile_write_string(prf, section, "Size", profile);
sprintf(profile, "%d", (int)option.img_max);
profile_write_string(prf, section, "Maximized", profile);
sprintf(profile, "%d", (int)option.settings);
profile_write_string(prf, section, "SaveSettings", profile);
sprintf(profile, "%d", (int)option.button_show);
profile_write_string(prf, section, "ButtonBar", profile);
sprintf(profile, "%d", (int)option.fit_page);
profile_write_string(prf, section, "FitWindowToPage", profile);
sprintf(profile, "%g %g", option.xdpi, option.ydpi);
profile_write_string(prf, section, "Resolution", profile);
sprintf(profile, "%g %g", option.zoom_xdpi, option.zoom_ydpi);
profile_write_string(prf, section, "ZoomResolution", profile);
sprintf(profile, "%d", option.depth);
profile_write_string(prf, section, "Depth", profile);
sprintf(profile, "%d", option.alpha_text);
profile_write_string(prf, section, "TextAlphaBits", profile);
sprintf(profile, "%d", option.alpha_graphics);
profile_write_string(prf, section, "GraphicsAlphaBits", profile);
if (option.media == IDM_USERSIZE)
strcpy(profile, MEDIA_USERDEFINED);
else
strcpy(profile, option.medianame);
profile_write_string(prf, section, "Media", profile);
sprintf(profile, "%d", (int)option.media_rotate);
profile_write_string(prf, section, "MediaRotate", profile);
sprintf(profile, "%u %u", option.user_width, option.user_height);
profile_write_string(prf, section, "UserSize", profile);
sprintf(profile, "%d", (int)option.epsf_clip);
profile_write_string(prf, section, "EpsfClip", profile);
sprintf(profile, "%d", (int)option.epsf_warn);
profile_write_string(prf, section, "EpsfWarn", profile);
sprintf(profile, "%d", (int)option.ignore_dsc);
profile_write_string(prf, section, "IgnoreDSC", profile);
sprintf(profile, "%d", (int)option.dsc_warn - IDM_DSC_OFF);
profile_write_string(prf, section, "DSCWarn", profile);
sprintf(profile, "%d", (int)option.show_bbox);
profile_write_string(prf, section, "ShowBBox", profile);
sprintf(profile, "%d", (int)option.auto_orientation);
profile_write_string(prf, section, "AutoOrientation", profile);
sprintf(profile, "%d", option.orientation - IDM_PORTRAIT);
profile_write_string(prf, section, "Orientation", profile);
sprintf(profile, "%d", (int)option.swap_landscape);
profile_write_string(prf, section, "SwapLandscape", profile);
sprintf(profile, "%d", option.unit - IDM_UNITPT);
profile_write_string(prf, section, "Unit", profile);
sprintf(profile, "%d", (int)option.unitfine);
profile_write_string(prf, section, "UnitFine", profile);
sprintf(profile, "%d", (int)option.pstotext);
profile_write_string(prf, section, "PStoText", profile);
sprintf(profile, "%d", (int)option.safer);
profile_write_string(prf, section, "Safer", profile);
sprintf(profile, "%d", (int)option.redisplay);
profile_write_string(prf, section, "AutoRedisplay", profile);
sprintf(profile, "%d", (int)option.auto_bbox);
profile_write_string(prf, section, "AutoBoundingBox", profile);
sprintf(profile, "%d", (int)option.save_dir);
profile_write_string(prf, section, "SaveLastDir", profile);
if (option.save_dir) {
gs_getcwd(profile, sizeof(profile));
profile_write_string(prf, section, "LastDir", profile);
}
sprintf(profile, "%d", (option.drawmethod - IDM_DRAWMENU));
profile_write_string(prf, section, "DrawMethod", profile);
sprintf(profile, "%d", option.update);
profile_write_string(prf, section, "ProgressiveUpdate", profile);
profile_write_string(prf, section, "PrinterPort", option.printer_port);
profile_write_string(prf, section, "PrinterQueue",
option.printer_queue);
if (option.printer_device[0] != '\0')
profile_write_string(prf, section, "PrinterDevice",
option.printer_device);
if (option.printer_resolution[0] != '\0')
profile_write_string(prf, section, "PrinterResolution",
option.printer_resolution);
sprintf(profile, "%d", (int)option.print_fixed_media);
profile_write_string(prf, section, "PrintFixedMedia", profile);
if (option.convert_device[0] != '\0')
profile_write_string(prf, section, "ConvertDevice",
option.convert_device);
if (option.convert_resolution[0] != '\0')
profile_write_string(prf, section, "ConvertResolution",
option.convert_resolution);
sprintf(profile, "%d", (int)option.convert_fixed_media);
profile_write_string(prf, section, "ConvertFixedMedia", profile);
sprintf(profile, "%d", (int)(option.print_gdi_depth-IDC_MONO));
profile_write_string(prf, section, "PrintGDIDepth", profile);
sprintf(profile, "%d", (int)option.print_gdi_fixed_media);
profile_write_string(prf, section, "PrintGDIFixedMedia", profile);
sprintf(profile, "%d", (int)option.print_to_file);
profile_write_string(prf, section, "PrintToFile", profile);
sprintf(profile, "%d", (int)option.print_method);
profile_write_string(prf, section, "PrintMethod", profile);
sprintf(profile, "%d", (int)option.print_reverse);
profile_write_string(prf, section, "PrintReverse", profile);
for (i=0; i<NUMSOUND; i++) {
char buf[MAXSTR];
convert_widechar(buf, sound[i].file, sizeof(buf)-1);
profile_write_string(prf, section, sound[i].entry, buf);
}
profile_write_string(prf, section, "LastFile1", last_files[0]);
profile_write_string(prf, section, "LastFile2", last_files[1]);
profile_write_string(prf, section, "LastFile3", last_files[2]);
profile_write_string(prf, section, "LastFile4", last_files[3]);
#ifndef VIEWONLY
write_measure_profile(prf);
#endif
profile_close(prf);
}
void
write_profile_last_files(void)
{
const char *section = INISECTION;
PROFILE *prf;
prf = profile_open(szIniFile);
profile_write_string(prf, section, "LastFile1", last_files[0]);
profile_write_string(prf, section, "LastFile2", last_files[1]);
profile_write_string(prf, section, "LastFile3", last_files[2]);
profile_write_string(prf, section, "LastFile4", last_files[3]);
profile_close(prf);
}
#ifdef DEBUG_MALLOC
FILE *malloc_file;
#define MALLOC_FILE "c:\\gsview.txt"
#endif
#undef malloc
#undef calloc
#undef realloc
#undef free
long allocated_memory = 0;
void * debug_malloc(size_t size)
{
if (debug & DEBUG_MEM) {
char buf[MAXSTR];
void *p = malloc(size+sizeof(long));
long *pl = (long *)p;
if (pl) {
*pl = size;
allocated_memory += size;
pl++;
}
if (size == 4096)
gs_addmess("\r\nstop here\r\n");
#ifdef NOTUSED
#endif
sprintf(buf, "malloc(%ld) 0x%x, allocated = %ld\r\n",
(long)size, (int)pl, allocated_memory);
gs_addmess(buf);
#ifdef DEBUG_MALLOC
if (malloc_file == (FILE *)NULL)
malloc_file = fopen(MALLOC_FILE, "wb");
if (malloc_file != (FILE *)NULL) {
fputs(buf, malloc_file);
fflush(malloc_file);
}
#endif
return (void *)pl;
}
return malloc(size);
}
void * debug_realloc(void *block, size_t size)
{
if (debug & DEBUG_MEM) {
char buf[MAXSTR];
long *pl = (long *)block;
long oldsize = 0;
if (pl) {
pl--;
oldsize = *pl;
allocated_memory -= oldsize;
pl = (long *)realloc((void *)pl, size+sizeof(long));
if (pl) {
*pl = size;
allocated_memory += size;
pl++;
}
}
sprintf(buf, "realloc old %ld 0x%x, new %ld 0x%x, allocated = %ld\r\n",
oldsize, (int)block, (long)size, (int)pl, allocated_memory);
gs_addmess(buf);
#ifdef DEBUG_MALLOC
if (malloc_file == (FILE *)NULL)
malloc_file = fopen(MALLOC_FILE, "wb");
if (malloc_file != (FILE *)NULL) {
fputs(buf, malloc_file);
fflush(malloc_file);
}
#endif
return (void *)pl;
}
return realloc(block, size);
}
void debug_free(void *block)
{
if (debug & DEBUG_MEM) {
char buf[MAXSTR];
long *pl = (long *)block;
long oldsize = 0;
if (pl) {
pl--;
oldsize = *pl;
allocated_memory -= oldsize;
free((void *)pl);
}
sprintf(buf, "free %ld 0x%x, allocated = %ld\r\n",
oldsize, (int)block, allocated_memory);
gs_addmess(buf);
#ifdef DEBUG_MALLOC
if (malloc_file == (FILE *)NULL)
malloc_file = fopen(MALLOC_FILE, "wb");
if (malloc_file != (FILE *)NULL) {
fputs(buf, malloc_file);
fflush(malloc_file);
}
#endif
return;
}
free(block);
return;
}
void debug_memory_report(void)
{
if (debug & DEBUG_MEM) {
char buf[256];
sprintf(buf, "Allocated memory = %ld bytes", allocated_memory);
message_box_a(buf, 0);
#ifdef DEBUG_MALLOC
fclose(malloc_file);
#endif
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -