-
Notifications
You must be signed in to change notification settings - Fork 3
/
reademf.c
89 lines (70 loc) · 2.31 KB
/
reademf.c
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
/**
Example program demonstrating how to code a program to read an EMF file. This example just examines the contents
of one EMF file and prints the contents record by record, showing all fields (except for bitmaps).
Run like:
reademf filename.emf
Writes description of the EMF file to stdout.
Build with: gcc -Wall -o reademf reademf.c uemf.c uemf_print.c uemf_endian.c uemf_utf.c upmf.c upmf_print.c -lm
*/
/*
File: reademf.c
Version: 0.0.6
Date: 17-OCT-2013
Author: David Mathog, Biology Division, Caltech
email: [email protected]
Copyright: 2013 David Mathog and California Institute of Technology (Caltech)
*/
#include <stdlib.h>
#include <stdio.h>
#include "uemf.h"
#include "uemf_print.h"
/**
\fn myEnhMetaFileProc(char *contents, unsigned int length, PEMF_WORKING_DATA lpData)
\param contents binary contents of an EMF file
\param length length in bytes of contents
*/
int myEnhMetaFileProc(char *contents, size_t length)
{
size_t off=0;
size_t result;
int OK =1;
int recnum=0;
PU_ENHMETARECORD pEmr;
char *blimit;
blimit = contents + length;
while(OK){
if(off>=length){ //normally should exit from while after EMREOF sets OK to false, this is most likely a corrupt EMF
printf("WARNING: record claims to extend beyond the end of the EMF file\n");
return(0);
}
pEmr = (PU_ENHMETARECORD)(contents + off);
if(!recnum && (pEmr->iType != U_EMR_HEADER)){
printf("WARNING: EMF file does not begin with an EMR_HEADER record\n");
}
result = U_emf_onerec_print(contents, blimit, recnum, off);
if(result == (size_t) -1){
printf("ABORTING on invalid record - corrupt file?\n");
OK=0;
}
else if(!result){
OK=0;
}
else {
off += result;
recnum++;
}
} //end of while
return 1;
}
int main(int argc, char *argv[]){
(void) argc; /* quiet the unused parameter compiler warning */
size_t length;
char *contents=NULL;
if(emf_readdata(argv[1],&contents,&length)){
printf("reademf: fatal error: could not open or successfully read file:%s\n",argv[1]);
exit(EXIT_FAILURE);
}
(void) myEnhMetaFileProc(contents,length);
free(contents);
exit(EXIT_SUCCESS);
}