2 // This file is part of hhpcomp, a free HTML Help Project (*.hhp) compiler.
3 // Copyright (C) 2015 Benedikt Freisen
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "hhp_reader.h"
37 #include "chmc/chmc.h"
41 extern "C" struct chmcTreeNode
*chmc_add_file(struct chmcFile
*chm
, const char *filename
,
42 UInt16 prefixlen
, int sect_id
, UChar
*buf
,
48 int main(int argc
, char** argv
)
52 cerr
<< "Usage: hhpcomp <input.hhp>" << endl
;
56 string absolute_name
= replace_backslashes(real_path(argv
[1]));
57 int prefixlen
= absolute_name
.find_last_of('/');
58 clog
<< prefixlen
<< endl
;
59 chdir(absolute_name
.substr(0, prefixlen
).c_str()); // change to the project file's directory
60 hhp_reader
project_file(absolute_name
);
63 struct chmcConfig chm_config
;
65 memset(&chm
, 0, sizeof(struct chmcFile
));
66 memset(&chm_config
, 0, sizeof(struct chmcConfig
));
67 chm_config
.title
= project_file
.get_title_string().c_str();
68 chm_config
.hhc
= project_file
.get_contents_file_string().c_str();
69 chm_config
.hhk
= project_file
.get_index_file_string().c_str();
70 chm_config
.deftopic
= project_file
.get_default_topic_string().c_str();
71 chm_config
.language
= project_file
.get_language_code();
72 chm_config
.tmpdir
= ".";
75 err
= chmc_init(&chm
, replace_backslashes(project_file
.get_compiled_file_string()).c_str(), &chm_config
);
78 cerr
<< "could not initialize chmc" << endl
;
82 for (set
<string
>::iterator it
= project_file
.get_file_pathes_iterator_begin();
83 it
!= project_file
.get_file_pathes_iterator_end(); ++it
)
85 clog
<< "File: " << *it
<< endl
;
87 stat(it
->c_str(), &buf
);
88 if ((chmc_add_file(&chm
, it
->c_str(), prefixlen
, 1, NULL
, buf
.st_size
)) ? chmcerr_code() : CHMC_NOERR
)
90 cerr
<< "could not add file: " << *it
<< endl
;