dtinfo: remove register keyword
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / cgm / testcgm.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: testcgm.c /main/6 1996/06/11 16:10:02 cde-hal $ */
24 /* test module to try the CGM =->pixmap library */
25 #include <X11/Xlib.h>
26 #include <X11/Intrinsic.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stddef.h>
30 #include "spec.h"
31 #include "GraphicsP.h"
32
33 main(int argc, char **argv)
34 {
35   XGCValues myStruct;
36   unsigned long mask;
37   Display *display;
38   int scr_num;
39   Window win;
40   XWindowAttributes wa;
41   Dimension ret_width = 0, ret_height = 0;
42   Pixel *ret_colors;
43   int ret_number, pageNo;
44   GC myGC;
45   Pixmap myPixmap = NULL;
46   char *fileName;
47   int i;
48   _DtGrStream stream ;
49   int status ;
50   _DtGrContext gr_context ;
51
52   if (!(display = XOpenDisplay(NULL))) {
53     fprintf(stderr, "couldn't open X display\n");
54     exit(1);
55   }
56   scr_num = DefaultScreen(display);
57   win = XCreateSimpleWindow(display, RootWindow(display, scr_num), 0, 0,
58                             512, 512, 2,
59                             BlackPixel(display, scr_num),
60                             WhitePixel(display, scr_num));
61   XSetStandardProperties(display, win, "VCGM", "VCGM", NULL, NULL, 0,
62                          NULL);
63   XMapWindow(display, win);
64   /* find out what we actually got */
65   XGetWindowAttributes(display, win, &wa);
66   XFlush(display);
67   /* make a reasonable GC */
68   mask = GCForeground | GCBackground;
69   myStruct.foreground = BlackPixel(display, scr_num);
70   myStruct.background = WhitePixel(display, scr_num);
71   myGC = XCreateGC(display, win, mask, &myStruct);
72   /* check on the filename */
73   fileName = (argc > 1) ? argv[1] : "test.cgm";
74   /* and pagenumber */
75   if ((argc < 3) || !sscanf(argv[2], " %d", &pageNo)) pageNo = 1;
76
77   /* first register our converter */
78   _DtGrRegisterConverter("CGM",  processCGM, NULL, NULL, NULL);
79
80
81   /* set up our stream */
82   stream.type = _DtGrFILE ;
83   stream.source.file.filename = fileName ;
84   stream.source.file.fileptr = fopen(stream.source.file.filename, "r") ;
85
86   gr_context.image_type = NULL;
87   gr_context.context = NULL;
88
89   /* get the pixmap we want */
90   status = _DtGrLoad (&stream, NULL,
91                       ScreenOfDisplay(display, scr_num),
92                       wa.depth,
93                       wa.colormap,
94                       wa.visual,
95                       BlackPixelOfScreen(ScreenOfDisplay(display, scr_num)),
96                       WhitePixelOfScreen(ScreenOfDisplay(display, scr_num)),
97                       myGC,
98                       _DtGrCOLOR, True,
99                       &ret_width,
100                       &ret_height,
101                       100,
102                       &myPixmap, NULL,
103                       &ret_colors,
104                       &ret_number, 
105                       &gr_context);
106
107   /* exit if didn't get a Pixmap */
108   if ((status != _DtGrSUCCESS) || !myPixmap) {
109     fprintf(stderr, "no Pixmap returned!\n");
110     exit(2);
111   } else {
112     fprintf(stderr, "got Pixmap, width = %d, height = %d\n", ret_width,
113             ret_height);
114   }
115
116   /* wait for some tty input before we copy the pixmap  */
117   fprintf(stderr, "hit return to see Pixmap!");
118   scanf("%*c");
119   /* display the Pixmap */
120   XCopyArea(display, myPixmap, win, myGC, 0, 0, ret_width, ret_height,
121             0, 0);
122   XFlush(display);
123   /* wait for some tty input before we terminate */
124   fprintf(stderr, "hit return to terminate!");
125   scanf("%*c");
126 }
127
128