main.cc 6.04 KB
Newer Older
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
1
#include <iostream>
2
3
4
#include <string>
#include <string>
#include <cstdlib>
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
5
6
7
8
9
#include "xml_transform.hh"

int main(int argc, char **argv)
{

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
10
  std::string man;
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
11
12
  man = "xml_transform\n"
    "OPTIONS:\n\n"
13

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
14
    "HTML output:\n"
15
16
17
18
19
20
21
22
    "\t\033[01m--html\033[00m\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.html\033[00m"
    "\t\t\tCreates HTML file, images are embedded inside in base 64 format.\n"
    "\t\033[01m--html-base64\033[00m \033[04minput.xml\033[00m \033[04moutput.html\033[00m"
    "\t\t\tSame as --html but input is a XML file with images encoded in base 64 inside.\n"

    "\t\033[01m--html-full\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput_dir\033[00m"
    "\t\t\tCreates HTML file without converting images in base 64. Images + HTML file are placed in output_dir.\n\n"

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
23
    "PDF output:\n"
24
25
26
27
28
29
30
31
32
33
    "\t\033[01m--pdf\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.pdf\033[00m"
    "\t\t\tCreates PDF file, images are embedded inside in base 64 format.\n"
    "\t\033[01m--pdf-base64\033[00m \033[04minput.xml\033[00m \033[04moutput.pdf\033[00m"
    "\t\t\tSame as --pdf but input is a XML file with images encoded in base 64 inside.\n\n"

    "SVG output (experimental, may not work with all files):\n"
    "\t\033[01m--svg\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.svg\033[00m"
    "\t\t\tCreates SVG file, images are embedded inside in base 64 format.\n"
    "\t\033[01m--svg-base64\033[00m \033[04minput.xml\033[00m \033[04moutput.svg\033[00m"
    "\t\t\tSame as --svg but input is a XML file with images encoded in base 64 inside.\n\n"
34
35

    "OpenDocument output:\n"
36
    "\t\033[01m--oo-doc\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.odt\033[00m"
37
38
    "\t\t\tCreates Open Document Writer (odt) file.\n"
    "\tThis is experimental, Open Office will warn you and ask you to repair the file which is corrupted, click on repair.\n\n"
39

40
    "Base 64 operations:\n"
41
    "\t\033[01m--to-base64\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.xmlc\033[00m"
42
43
    "\t\t\tCreates a container XML file. It will contain regions which are cropped and converted in base 64.\n"

44
    "\t\033[01m--to-base64-no-crop\033[00m \033[04minput.xml\033[00m \033[04mimage\033[00m \033[04moutput.xmlc\033[00m"
45
46
47
48
49
    "\t\tSame as --to-base64 but only the full picture will be converted, regions are not cropped\n"

    "\t\033[01m--from-base64\033[00m \033[04minput.xml\033[00m \033[04moutput_dir\033[00m"
    "\t\t\tDecodes a XML file which has been encoded in base 64, regions will be converted into png files and saved in output_dir.\n\n"

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
50
51
52
    "Requirements:\n"
    "PDF : fop >= 0.95\n"
    "HTML : xsltproc\n"
53
    "SVG : trunk version of fop\n"
54
55
    "OpenDocument : ooconvert (included) and OpenOffice >= 3.xx";

Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
56
57
58
  if (argc > 4)
    {
      std::string html = "--html";
59
60
      std::string html_full = "--html-full";
      std::string open = "--oo-doc";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
61
      std::string pdf = "--pdf";
62
      std::string svg = "--svg";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
63
64
      std::string to_base64 = "--to-base64";
      std::string to_base64nocrop = "--to-base64-no-crop";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
65

66
      if (html_full.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
67
68
69
	{
	  XmlTransform xmlt(argv[2], argv[3], argv[4]);
	  xmlt.createHTML(false);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

	  QString cmd = "sh templates/xml_transform.sh html " + xmlt.out() + "output.xml " +  xmlt.out() + "output.html";
	  return system (cmd.toAscii().constData());
	}
      else if (html.compare(argv[1]) == 0)
	{
	  QTemporaryFile tmp;
	  tmp.open();
	  tmp.fileName();

	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), tmp.fileName());
	  xmlt.toBase64(false);

	  QString cmd = "sh templates/xml_transform.sh html-base64 " + tmp.fileName() + " " + argv[4];
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
85
	}
86
      else if (pdf.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
87
	{
88
89
90
91
92
93
94
95
96
	  QTemporaryFile tmp;
	  tmp.open();
	  tmp.fileName();

	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), tmp.fileName());
	  xmlt.toBase64(false);

	  QString cmd = "sh templates/xml_transform.sh pdf " + tmp.fileName() + " " + argv[4];
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
97
	}
98
      else if (svg.compare(argv[1]) == 0)
99
	{
100
101
102
103
104
105
106
107
108
	  QTemporaryFile tmp;
	  tmp.open();
	  tmp.fileName();

	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), tmp.fileName());
	  xmlt.toBase64(false);

	  QString cmd = "sh templates/xml_transform.sh svg " + tmp.fileName() + " " + argv[4];
	  return system (cmd.toAscii().constData());
109
	}
110
      else if (open.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
111
	{
112
113
114
115
116
117
	  QString dir = QDir::tempPath() + "/xml_transform." + argv[4];
	  XmlTransform xmlt(argv[2], argv[3], dir);
	  xmlt.createOpen();

	  QString cmd = "sh templates/xml_transform.sh oo-doc " + dir + " " + argv[4];
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	}
      else if (to_base64.compare(argv[1]) == 0)
	{
	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
	  xmlt.toBase64(false);
	}
      else if (to_base64nocrop.compare(argv[1]) == 0)
	{
	  XmlTransform xmlt(argv[2], argv[3], QString::Null(), argv[4]);
	  xmlt.toBase64(true);
	}
      else
	std::cout << man << std::endl;
    }
  else if (argc > 3)
    {
134
135
136
      std::string pdf_base64 = "--pdf-base64";
      std::string svg_base64 = "--svg-base64";
      std::string html_base64 = "--html-base64";
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
137
138
      std::string from_base64 = "--from-base64";

139
      if (svg_base64.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
140
	{
141
142
	  QString cmd = "sh templates/xml_transform.sh svg " + QString(argv[2]) + " " + QString(argv[3]);
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
143
	}
144
      else if (pdf_base64.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
145
	{
146
147
	  QString cmd = "sh templates/xml_transform.sh pdf " + QString(argv[2]) + " " + QString(argv[3]);
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
148
	}
149
      else if (html_base64.compare(argv[1]) == 0)
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
150
	{
151
152
	  QString cmd = "sh templates/xml_transform.sh html-base64 " + QString(argv[2]) + " " + QString(argv[3]);
	  return system (cmd.toAscii().constData());
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
153
154
155
156
157
158
	}
      else if (from_base64.compare(argv[1]) == 0)
	{
	  XmlTransform xmlt(argv[2], QString::Null(), argv[3]);
	  xmlt.fromBase64();
	}
Arthur Crepin-Leblond's avatar
Arthur Crepin-Leblond committed
159
160
161
162
163
164
165
166
      else
	std::cout << man << std::endl;
    }
  else
    std::cout << man << std::endl;

  return 0;
}