Fix uninitialized warnings.
[wine] / tools / winedump / emf.c
1 /*
2  *  Dump an Enhanced Meta File
3  *
4  *  Copyright 2005 Mike McCormack
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdio.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
30 #endif
31 #include <fcntl.h>
32 #include <stdarg.h>
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37
38 static unsigned int read_int(unsigned char *buffer)
39 {
40     return buffer[0]
41      + (buffer[1]<<8)
42      + (buffer[2]<<16)
43      + (buffer[3]<<24);
44 }
45
46 #define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break
47
48 static int dump_emfrecord(int fd)
49 {
50     unsigned char buffer[8];
51     int r;
52     unsigned int type, length, i;
53
54     r = read(fd, buffer, 8);
55     if(r!=8)
56         return -1;
57
58     type = read_int(buffer);
59     length = read_int(buffer+4);
60
61     switch(type)
62     {
63     EMRCASE(EMR_HEADER);
64     EMRCASE(EMR_POLYGON);
65     EMRCASE(EMR_POLYLINE);
66     EMRCASE(EMR_SETWINDOWEXTEX);
67     EMRCASE(EMR_SETWINDOWORGEX);
68     EMRCASE(EMR_SETVIEWPORTEXTEX);
69     EMRCASE(EMR_EOF);
70     EMRCASE(EMR_SETMAPMODE);
71     EMRCASE(EMR_SETPOLYFILLMODE);
72     EMRCASE(EMR_SETROP2);
73     EMRCASE(EMR_SCALEWINDOWEXTEX);
74     EMRCASE(EMR_SAVEDC);
75     EMRCASE(EMR_SELECTOBJECT);
76     EMRCASE(EMR_CREATEPEN);
77     EMRCASE(EMR_CREATEBRUSHINDIRECT);
78     EMRCASE(EMR_DELETEOBJECT);
79     EMRCASE(EMR_RECTANGLE);
80     EMRCASE(EMR_SELECTPALETTE);
81     EMRCASE(EMR_GDICOMMENT);
82     EMRCASE(EMR_EXTSELECTCLIPRGN);
83     EMRCASE(EMR_EXTCREATEFONTINDIRECTW);
84     EMRCASE(EMR_EXTTEXTOUTW);
85     EMRCASE(EMR_POLYGON16);
86     EMRCASE(EMR_POLYLINE16);
87
88     default:
89         printf("%08x %08x\n",type,length);
90         break;
91     }
92
93     if ( (length < 8) || (length % 4) )
94         return -1;
95
96     length -= 8;
97
98     for(i=0; i<length; i+=4)
99     {
100          if (i%16 == 0)
101              printf("   ");
102          memset(buffer,0,sizeof buffer);
103          r = read(fd,buffer,4);
104          if(r!=4)
105              return -1;
106          printf("%08x ", read_int(buffer));
107          if ( (i%16 == 12) || ((i+4)==length) )
108              printf("\n");
109     }
110
111     return 0;
112 }
113
114 static int dump_emf_records(int fd)
115 {
116     while(!dump_emfrecord(fd))
117         ;
118     return 0;
119 }
120
121 int dump_emf(const char *emf)
122 {
123     int fd;
124
125     fd = open(emf,O_RDONLY);
126     if (fd<0) return -1;
127     dump_emf_records(fd);
128     close(fd);
129     return 0;
130 }