1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "gks.h"
#include "gkscore.h"
static char *path = NULL;
static int wstype = GKS_K_WSTYPE_DEFAULT;
static int orientation = 0;
static double factor = 1.0;
static void usage(int help)
{
fprintf(stderr, "\
Usage: gksm [-Oorientation] [-factor f] [-h] [-t wstype] [file]\n\
-Oorientation Select the orientation (landscape, portrait).\n\
-factor f Specifies the magnification factor.\n\
-h Prints this information.\n\
-t wstype Use GKS workstation type wstype.\n");
if (help)
fprintf(stderr, "\n\
The present workstation types recognized by gksm are:\n\
61: PostScript (b/w) 2: GKS Metafile\n\
62: Color PostScript\n\
63: PostScript (b/w, landscape)\n\
64: Color PostScript (landscape)\n\
101: Portable Document Format (PDF)\n\
102: Portable Document Format (PDF, compressed)\n\
214: X display w\\ Sun rle rasterfile dump\n\
215: X display w\\ Compuserve GIF dump\n\
320: Windows Bitmap File (BMP)\n\
321: JPEG File\n\
322: Portable Network Graphics (PNG)\n\
323: Tagged Image File (TIFF)\n\
382: Scalable Vector Graphics (SVG)\n\
390: Windows Metafile (WMF)\n\
400: Quartz 2D Graphics (Mac OS X)\n");
exit(1);
}
static void parse(int argc, char **argv)
{
char *option;
int ret;
argv++;
while ((option = *argv++) != NULL)
{
if (!strcmp(option, "-Olandscape"))
{
orientation = 1;
}
else if (!strcmp(option, "-Oportrait"))
{
orientation = 2;
}
else if (!strcmp(option, "-factor"))
{
if (*argv)
factor = atof(*argv++);
else
usage(0);
}
else if (!strcmp(option, "-h"))
{
usage(1);
}
else if (!strcmp(option, "-t"))
{
if (*argv)
wstype = atoi(*argv++);
else
usage(0);
}
else if (*option == '-')
{
fprintf(stderr, "Invalid option: '%s'\n", option);
usage(0);
}
else
path = option;
}
if (path != NULL)
{
ret = access(path, R_OK);
if (ret)
{
perror("open");
exit(-1);
}
}
else
{
usage(0);
exit(1);
}
}
int main(int argc, char *argv[])
{
int i, asf[13];
int type, lenodr, maxodr = 100;
char *item;
parse(argc, argv);
for (i = 0; i < 13; i++) asf[i] = GKS_K_ASF_INDIVIDUAL;
gks_open_gks(6);
gks_set_asf(asf);
gks_open_ws(1, path, GKS_K_WSTYPE_MI);
gks_activate_ws(1);
gks_open_ws(2, GKS_K_CONID_DEFAULT, wstype);
gks_activate_ws(2);
switch (orientation)
{
case 1:
gks_set_ws_viewport(2, 0.0, 0.297, 0.0, 0.21);
gks_set_ws_window(2, 0.0, 1.0, 0.0, 0.21 / 0.297);
break;
case 2:
gks_set_ws_viewport(2, 0.0, 0.21, 0.0, 0.297);
gks_set_ws_window(2, 0.0, 0.21 / 0.297, 0.0, 1.0);
break;
}
if (factor != 1.0)
{
double transx = 0, transy = 0, mat[3][2];
if (factor < 1)
{
if (factor > 0)
{
transx = 0.5 * (factor - 1);
transy = -transx;
}
else
factor = -factor;
}
gks_create_seg(1);
gks_eval_xform_matrix(0.5, 0.5, transx, transy, 0, factor, factor, GKS_K_COORDINATES_NDC, mat);
gks_set_seg_xform(1, mat);
}
item = gks_malloc(maxodr * 80);
gks_get_item(1, &type, &lenodr);
while (type)
{
if (lenodr > maxodr)
{
while (lenodr > maxodr) maxodr *= 2;
item = gks_realloc(item, maxodr * 80);
}
gks_read_item(1, lenodr, maxodr, item);
gks_interpret_item(type, lenodr, maxodr, item);
gks_get_item(1, &type, &lenodr);
}
gks_update_ws(2, GKS_K_POSTPONE_FLAG);
if (wstype == GKS_K_WSTYPE_DEFAULT)
{
printf("Press RETURN to continue ...");
fflush(stdout);
getchar();
}
gks_emergency_close();
return 0;
}
|