Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccFromXml.cpp
Go to the documentation of this file.
1// IccToXml.cpp : Defines the entry point for the console application.
2//
3
4#include <stdio.h>
5#include "IccTagXmlFactory.h"
6#include "IccMpeXmlFactory.h"
7#include "IccProfileXml.h"
8#include "IccIO.h"
9#include "IccUtil.h"
10#include "IccProfLibVer.h"
11#include "IccLibXMLVer.h"
12#include <cstring> /* C strings strcpy, memcpy ... */
13
14int main(int argc, char* argv[])
15{
16 if (argc<=2) {
17 printf("IccFromXml built with IccProfLib Version " ICCPROFLIBVER ", IccLibXML Version " ICCLIBXMLVER "\n\nUsage: IccFromXml xml_file saved_profile_file {-noid -v{=[relax_ng_schema_file - optional]}}\n");
18 return -1;
19 }
20
23
24 CIccProfileXml profile;
25 std::string reason;
26
27 std::string szRelaxNGDir;
28 bool bNoId = false;
29
30 const char* szRelaxNGFileName = "SampleIccRELAX.rng";
31 int i;
32 for (i=3; i<argc; i++) {
33 if (!stricmp(argv[i], "-noid")) {
34 bNoId = true;
35 }
36 else if (!strncmp(argv[i], "-v", 2) || !strncmp(argv[i], "-V", 2)) {// user specified schema validation
37 if (argv[i][2]=='=') {
38 szRelaxNGDir = argv[i]+3;
39 }
40 else {
41 std::string path = argv[0]; // current directory where program is called
42
43#ifdef WIN32
44 if (path != "IccFromXml.exe") { //current directory is not path where program is located
45 path = path.substr(0,path.find_last_of("\\"));
46 path += "\\";
47 }
48#else
49 if (path.substr(0,1) != "./"){
50 path = path.substr(0,path.find_last_of("//"));
51 path += "//";
52 }
53#endif
54
55 path += szRelaxNGFileName;
56
57 FILE *f = fopen(path.c_str(), "r");
58
59 if (f) {
60 fclose(f);
61
62 szRelaxNGDir = path;
63 }
64 }
65 }
66 }
67
68 if (!profile.LoadXml(argv[1], szRelaxNGDir.c_str(), &reason)) {
69 printf("%s", reason.c_str());
70#ifndef WIN32
71 printf("\n");
72#endif
73 printf("Unable to Parse '%s'\n", argv[1]);
74 return -1;
75 }
76
77 std::string valid_report;
78
79 if (profile.Validate(valid_report)<=icValidateWarning) {
80 int i;
81
82 for (i=0; i<16; i++) {
83 if (profile.m_Header.profileID.ID8[i])
84 break;
85 }
86 if (SaveIccProfile(argv[2], &profile, bNoId ? icNeverWriteID : (i<16 ? icAlwaysWriteID : icVersionBasedID))) {
87 printf("Profile parsed and saved correctly\n");
88 }
89 else {
90 printf("Unable to save profile as '%s'\n", argv[2]);
91 return -1;
92 }
93 }
94 else {
95 int i;
96
97 for (i=0; i<16; i++) {
98 if (profile.m_Header.profileID.ID8[i])
99 break;
100 }
101 if (SaveIccProfile(argv[2], &profile, bNoId ? icNeverWriteID : (i<16 ? icAlwaysWriteID : icVersionBasedID))) {
102 printf("Profile parsed. Profile is invalid, but saved correctly\n");
103 }
104 else {
105 printf("Unable to save profile - profile is invalid!\n");
106 return -1;
107 }
108 printf("%s", valid_report.c_str());
109 }
110
111 printf("\n");
112 return 0;
113}
114
@ icValidateWarning
Definition IccDefs.h:120
File: IccIO.h.
#define ICCLIBXMLVER
Definition IccLibXMLVer.h:2
File: IccMpeXmlFactory.h.
#define stricmp
#define ICCPROFLIBVER
bool SaveIccProfile(const icChar *szFilename, CIccProfile *pIcc, icProfileIDSaveMethod nWriteId)
Name: SaveIccProfile.
File: IccProfileXml.h.
File: IccTagXmlFactory.h.
File: IccUtil.h.
int main()
Core and external libraries necessary for the fuzzer functionality.
static void PushFactory(IIccMpeFactory *pFactory)
Function: PushFactory(pFactory) Add an IIccMpeFactory to the stack of element factories tracked by th...
Class: CIccMpeXmlFactory.
bool LoadXml(const char *szFilename, const char *szRelaxNGDir, std::string *parseStr=NULL)
static void PushFactory(IIccTagFactory *pFactory)
Function: PushFactory(pFactory) Add an IIccTagFactory to the stack of tag factories tracked by the sy...
Class: CIccTagXmlFactory.