📄 gvcinit.c
字号:
/* Copyright (C) 1993-2002, Ghostgum Software Pty Ltd. All rights reserved.
This file is part of GSview.
This program is distributed with NO WARRANTY OF ANY KIND. No author
or distributor accepts any responsibility for the consequences of using it,
or for whether it serves any particular purpose or works at all, unless he
or she says so in writing. Refer to the GSview Licence (the "Licence")
for full details.
Every copy of GSview must include a copy of the Licence, normally in a
plain ASCII text file named LICENCE. The Licence grants you the right
to copy, modify and redistribute GSview, but only under certain conditions
described in the Licence. Among other things, the Licence requires that
the copyright notice and this notice be preserved on all copies.
*/
/* gvcinit.c */
/* Initialisation routines for PM and Windows GSview */
#include "gvc.h"
/* Parse the command line.
* Return 0 on success.
* If argument unknown, return argc of that argument
*/
int parse_argv(GSVIEW_ARGS *args, int argc, char *argv[])
{
int i;
int j;
char *s;
char *p;
int len;
for (i=1; i < argc; i++) {
s = argv[i];
#ifdef UNIX
if (*s == '-')
#else
if ((*s == '-') || (*s == '/'))
#endif
{
p = s+2;
switch (s[1]) {
case 'd':
if (*p) {
args->debug = atoi(p);
}
else
args->debug = !args->debug;
break;
case 't':
if (*p) {
args->multithread = atoi(p);
}
else
args->multithread = !args->multithread;
break;
case 'p':
args->print = 1;
if (*p) {
if (strlen(p) < sizeof(args->queue) - 1)
strncpy(args->queue, p, sizeof(args->queue));
}
break;
case 'f':
args->convert = 1;
if (*p) {
if (strlen(p) < sizeof(args->device) - 1)
strncpy(args->device, p, sizeof(args->device));
}
break;
case 's':
args->spool = 1;
if (*p) {
if (strlen(p) < sizeof(args->queue) - 1)
strncpy(args->queue, p, sizeof(args->queue));
}
break;
case 'e':
args->existing = i; /* send all after this */
break;
case 'x':
args->exit_existing = 1;
break;
case 'h':
args->help = 1;
break;
case 'v':
args->version = 1;
break;
case 'g':
if (*p == 'e') {
/* -geometry */
p = argv[++i];
if (p == NULL)
return --i;
args->geometry = sscanf(argv[i], "%dx%d%d%d",
&args->geometry_width, &args->geometry_height,
&args->geometry_xoffset, &args->geometry_yoffset);
switch (args->geometry) {
case 2:
args->geometry_xoffset = args->geometry_yoffset
= CW_USEDEFAULT;
/* drop thru */
case 4:
break; /* OK */
default:
return --i;
}
}
else {
return i;
}
break;
case 'm':
if (strlen(p) == 0)
p = argv[++i];
if (p == NULL)
return --i;
/* compare against known media */
for (j=0; dsc_known_media[j].name != (char *)NULL; j++) {
if (!stricmp(dsc_known_media[j].name, p)) {
strncpy(args->media, p, sizeof(args->media)-1);
break;
}
}
if (args->media[0] == '\0')
return i;
break;
case 'o':
args->orient = 0;
if (strlen(p) == 0)
p = argv[++i];
if (p == NULL)
return --i;
if (stricmp(p, "auto")==0)
args->orient = IDM_AUTOORIENT;
else if (stricmp(p, "portrait")==0)
args->orient = IDM_PORTRAIT;
else if (stricmp(p, "landscape")==0)
args->orient = IDM_LANDSCAPE;
else if (stricmp(p, "upsidedown")==0)
args->orient = IDM_UPSIDEDOWN;
else if (stricmp(p, "seascape")==0)
args->orient = IDM_SEASCAPE;
if (args->orient == 0)
return i;
break;
case 'r':
args->xdpi = args->ydpi = 0.0;
if (strlen(p) == 0)
p = argv[++i];
if (p == NULL)
return --i;
j = sscanf(p, "%fx%f", &args->xdpi, &args->ydpi);
if (j == 1)
args->ydpi = args->xdpi;
if ((args->xdpi < 1.0) || (args->ydpi < 1.0))
return i;
break;
default:
return i;
}
}
else {
/* filename */
len = strlen(s);
if (*s == '\042') {
/* Don't copy quotes */
s++;
len -= 2; /* ignore leading and trailing quotes */
if (len <= 0)
return i;
}
if (len < (int)sizeof(args->filename) - 1)
strncpy(args->filename, s, len+1);
}
}
return 0;
}
/* Platform independent processing of arguments, before window creation */
void
use_args(GSVIEW_ARGS *args)
{
/* override those from the command line */
if (args->media[0])
strncpy(option.medianame, args->media, sizeof(option.medianame));
if (args->orient == IDM_AUTOORIENT)
option.auto_orientation = TRUE;
else if (args->orient) {
option.auto_orientation = FALSE;
option.orientation = args->orient;
}
if ((args->xdpi > 1.0) && (args->ydpi > 1.0)) {
if (args->print) {
sprintf(option.printer_resolution, "%fx%f",
(double)args->xdpi, (double)args->ydpi);
}
else if (args->convert) {
sprintf(option.convert_resolution, "%fx%f",
(double)args->xdpi, (double)args->ydpi);
}
else {
option.xdpi = args->xdpi;
option.ydpi = args->ydpi;
}
}
if (args->geometry) {
if (args->geometry == 4) {
option.img_origin.x = args->geometry_xoffset;
option.img_origin.y = args->geometry_yoffset;
}
if (args->geometry >= 2) {
option.img_size.x = args->geometry_width;
option.img_size.y = args->geometry_height;
}
}
}
/* copy printer profiles */
int
gsview_printer_profiles(void)
{
char buf[MAXSTR];
FILE *pf;
char section[MAXSTR];
char *key;
const char *value;
PROFILE *prf;
/* open an INI file and copy everything to user ini file
* overwriting anything the user already had
*/
#ifdef UNIX
strncpy(buf, szEtcPath, sizeof(buf)-1);
#else
convert_widechar(buf, szExePath, sizeof(buf)-1);
#endif
strncat(buf, "printer.ini", sizeof(buf)-1-strlen(buf));
if (debug & DEBUG_GENERAL)
gs_addmessf("Reading printer profiles from \042%s\042\n", buf);
pf = fopen(buf, "r");
if (!pf) {
strcpy(buf, "printer.ini");
if (debug & DEBUG_GENERAL)
gs_addmessf("Reading printer profiles from \042%s\042\n", buf);
pf = fopen(buf, "r");
if (!pf) {
gserror(IDS_NOPRINTERINI, NULL, 0, SOUND_ERROR);
return 1;
}
}
prf = profile_open(szIniFile);
if (!prf) {
gserror(IDS_NOINI, NULL, 0, SOUND_ERROR);
return 1;
}
while (fgets(buf, sizeof(buf)-1, pf)) {
if (buf[0] == '[') {
/* new section */
strcpy(section, buf+1);
strtok(section, "[]");
/* delete old section */
profile_write_string(prf, section, NULL, NULL);
}
else if ((buf[0] != '\n') && (buf[0] != ';')) {
key = strtok(buf, "=");
value = strtok(NULL, "\n");
if (value == (char *)NULL)
value = "";
/* don't copy devices from wrong OS */
#ifdef _Windows
if ((strcmp(section, "Devices")==0) &&
(strcmp(key, "os2prn") == 0))
key = NULL;
#else
if ((strcmp(section, "Devices")==0) &&
(strncmp(key, "mswinpr", 7) == 0))
key = NULL;
#endif
if (key)
profile_write_string(prf, section, key, value);
}
}
profile_close(prf);
fclose(pf);
return 0;
}
void
init_options(void)
{
option.language = IDM_LANGEN;
option.gsversion = GS_REVISION;
default_gsdll(option.gsdll);
default_gsexe(option.gsexe);
default_gsinclude(option.gsinclude);
option.gsother[0] = '\0';
#ifdef X11
strcpy(option.helpcmd, "gsview-help");
#else
option.helpcmd[0] = '\0';
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -