bump product version to 4.1.6.2
[LibreOffice.git] / l10ntools / source / idxdict / idxdict.cxx
blob67811c08ff5a86fa652ca19a5ca539091046621e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <iostream>
11 #include <fstream>
12 #include <string>
13 #include <map>
14 #include <stdlib.h>
15 #include <string.h>
17 static const int MAXLINE = 1024*64;
19 using namespace std;
21 int main(int argc, char *argv[])
23 if (argc != 3 || strcmp(argv[1],"-o"))
25 cout << "Usage: idxdict -o outputfile < input\n";
26 ::exit(99);
28 // This call improves performance by approx 5x
29 cin.sync_with_stdio(false);
31 const char * outputFile(argv[2]);
32 char inputBuffer[MAXLINE];
33 multimap<string, size_t> entries;
34 multimap<string,size_t>::iterator ret(entries.begin());
36 int line(1);
37 cin.getline(inputBuffer, MAXLINE);
38 const string encoding(inputBuffer);
39 size_t currentOffset(encoding.size()+1);
40 while (true)
42 // Extract the next word, but not the entry count
43 cin.getline(inputBuffer, MAXLINE, '|');
45 if (cin.eof()) break;
47 string word(inputBuffer);
48 ret = entries.insert(ret, pair<string, size_t>(word, currentOffset));
49 currentOffset += word.size() + 1;
50 // Next is the entry count
51 cin.getline(inputBuffer, MAXLINE);
52 if (!cin.good())
54 cerr << "Unable to read entry - insufficient buffer?.\n";
55 exit(99);
57 currentOffset += strlen(inputBuffer)+1;
58 int entryCount(strtol(inputBuffer, NULL, 10));
59 for (int i(0); i < entryCount; ++i)
61 cin.getline(inputBuffer, MAXLINE);
62 currentOffset += strlen(inputBuffer)+1;
63 ++line;
67 // Use binary mode to prevent any translation of LF to CRLF on Windows
68 ofstream outputStream(outputFile, ios_base::binary| ios_base::trunc|ios_base::out);
69 if (!outputStream.is_open())
71 cerr << "Unable to open output file " << outputFile << endl;
72 ::exit(99);
75 outputStream << encoding << '\n' << entries.size() << '\n';
77 for (multimap<string, size_t>::const_iterator ii(entries.begin());
78 ii != entries.end();
79 ++ii
82 outputStream << ii->first << '|' << ii->second << '\n';
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */