fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / l10ntools / source / idxdict / idxdict.cxx
blobe35bceaa0aea3aacc2c4708e77e6f704f5e176a9
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 <cerrno>
11 #include <iostream>
12 #include <fstream>
13 #include <string>
14 #include <map>
15 #include <stdlib.h>
16 #include <string.h>
18 static const int MAXLINE = 1024*64;
20 using namespace std;
22 int main(int argc, char *argv[])
24 if (argc != 3 || strcmp(argv[1],"-o"))
26 cout << "Usage: idxdict -o outputfile < input\n";
27 ::exit(99);
29 // This call improves performance by approx 5x
30 std::ios_base::sync_with_stdio(false);
32 const char * outputFile(argv[2]);
33 char inputBuffer[MAXLINE];
34 multimap<string, size_t> entries;
35 multimap<string,size_t>::iterator ret(entries.begin());
37 int line(1);
38 cin.getline(inputBuffer, MAXLINE);
39 const string encoding(inputBuffer);
40 size_t currentOffset(encoding.size()+1);
41 while (true)
43 // Extract the next word, but not the entry count
44 cin.getline(inputBuffer, MAXLINE, '|');
46 if (cin.eof()) break;
48 string word(inputBuffer);
49 ret = entries.insert(ret, pair<string, size_t>(word, currentOffset));
50 currentOffset += word.size() + 1;
51 // Next is the entry count
52 cin.getline(inputBuffer, MAXLINE);
53 if (!cin.good())
55 cerr << "Unable to read entry - insufficient buffer?.\n";
56 exit(99);
58 currentOffset += strlen(inputBuffer)+1;
59 char * endptr;
60 errno = 0;
61 int entryCount(strtol(inputBuffer, &endptr, 10));
62 if (errno != 0 || endptr == inputBuffer || *endptr != '\0')
64 cerr
65 << "Unable to read count from \"" << inputBuffer
66 << "\" input.\n";
67 exit(99);
69 for (int i(0); i < entryCount; ++i)
71 cin.getline(inputBuffer, MAXLINE);
72 currentOffset += strlen(inputBuffer)+1;
73 ++line;
77 // Use binary mode to prevent any translation of LF to CRLF on Windows
78 ofstream outputStream(outputFile, ios_base::binary| ios_base::trunc|ios_base::out);
79 if (!outputStream.is_open())
81 cerr << "Unable to open output file " << outputFile << endl;
82 ::exit(99);
85 outputStream << encoding << '\n' << entries.size() << '\n';
87 for (multimap<string, size_t>::const_iterator ii(entries.begin());
88 ii != entries.end();
89 ++ii
92 outputStream << ii->first << '|' << ii->second << '\n';
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */