1#!/usr/bin/env python3
2
3#   Copyright (C) 2011, 2012  Povilas Kanapickas <povilas@radix.lt>
4#
5#   This file is part of cppreference-doc
6#
7#   This program is free software: you can redistribute it and/or modify
8#   it under the terms of the GNU General Public License as published by
9#   the Free Software Foundation, either version 3 of the License, or
10#   (at your option) any later version.
11#
12#   This program is distributed in the hope that it will be useful,
13#   but WITHOUT ANY WARRANTY; without even the implied warranty of
14#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#   GNU General Public License for more details.
16#
17#   You should have received a copy of the GNU General Public License
18#   along with this program.  If not, see http://www.gnu.org/licenses/.
19
20import fnmatch
21import re
22import os
23import sys
24import shutil
25import urllib.parse
26
27# copy the source tree
28os.system('rm -rf output/reference')
29os.system('mkdir -p output/reference')
30os.system('cp -r reference/* output/reference ')
31
32# find files that need to be preprocessed
33html_files = []
34for root, dirnames, filenames in os.walk('output/reference/'):
35    for filename in fnmatch.filter(filenames, '*.html'):
36        html_files.append(os.path.join(root, filename))
37
38# clean the html files
39for fn in html_files:
40    f = open(fn, "r")
41    text = f.read()
42    f.close()
43
44    f = open(fn, "w")
45    f.write(text)
46    f.close()
47
48    tmpfile = fn + '.tmp';
49    ret = os.system('xsltproc --novalid --html --encoding UTF-8 preprocess.xsl "' + fn + '" > "' + tmpfile + '"')
50    if ret != 0:
51        print("FAIL: " + fn)
52        continue
53    os.system('mv "' + tmpfile + '" "' + fn + '"')
54
55
56