1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * mgpp_decompress_text.cpp --
|
---|
4 | * Copyright (C) 1999 Rodger McNab
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | **************************************************************************/
|
---|
21 |
|
---|
22 | #define _XOPEN_SOURCE 1
|
---|
23 | // This was added for Solaris, but it makes things worse on Solaris for me...
|
---|
24 | // #define _XOPEN_SOURCE_EXTENDED 1
|
---|
25 |
|
---|
26 | /* getopt is in posix.2, so cygwin should have it in unistd, but doesn't */
|
---|
27 | #if defined (__WIN32__) || defined (__CYGWIN__)
|
---|
28 | # include "getopt_old.h"
|
---|
29 | #else
|
---|
30 | # include <unistd.h>
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include "UCArray.h"
|
---|
34 | #include "sysfuncs.h"
|
---|
35 | #include "TextGet.h"
|
---|
36 | #include "messages.h"
|
---|
37 | #include "mg_files.h"
|
---|
38 |
|
---|
39 | int main (int argc, char **argv) {
|
---|
40 | int ch;
|
---|
41 | char *filename = (char*)"";
|
---|
42 | char *basePath = (char*)"";
|
---|
43 | UCArray level;
|
---|
44 | SetCStr (level, "Document", 8);
|
---|
45 |
|
---|
46 | opterr = 0;
|
---|
47 | msg_prefix = argv[0];
|
---|
48 |
|
---|
49 | // process the command line arguments
|
---|
50 | while ((ch = getopt (argc, argv, "f:d:K:h")) != -1) {
|
---|
51 | switch (ch) {
|
---|
52 | case 'f': /* input file */
|
---|
53 | filename = optarg;
|
---|
54 | break;
|
---|
55 | case 'd':
|
---|
56 | basePath = optarg;
|
---|
57 | set_basepath (optarg);
|
---|
58 | break;
|
---|
59 | case 'K':
|
---|
60 | SetCStr (level, optarg, strlen(optarg));
|
---|
61 | break;
|
---|
62 | case 'h':
|
---|
63 | case '?':
|
---|
64 | fprintf (stderr, "usage: %s [-h] [-K level] [-d directory] -f name\n",
|
---|
65 | argv[0]);
|
---|
66 | exit (1);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | // load up the text information
|
---|
71 | TextData td;
|
---|
72 | if (!td.LoadData (basePath, filename)) {
|
---|
73 | FatalError (1, "Couldn't load text information for \"%s\"", filename);
|
---|
74 | }
|
---|
75 |
|
---|
76 | // output each document in the level
|
---|
77 | // cout << td.levels << "\n";
|
---|
78 |
|
---|
79 | TextLevelInfo levelInfo = td.levels.levelInfo[level];
|
---|
80 | mg_u_long docNum = 1;
|
---|
81 | UCArray docText;
|
---|
82 | while (docNum <= levelInfo.numEntries) {
|
---|
83 | // TextIdx docIdx;
|
---|
84 | // if (GetDocIdx (td, level, docNum, docIdx)) {
|
---|
85 | // cout << "doc: " << docNum << "\n";
|
---|
86 | // cout << docIdx;
|
---|
87 | // }
|
---|
88 |
|
---|
89 | if (!GetDocText (td, level, docNum, docText)) {
|
---|
90 | FatalError (1, "Error while trying to get document %u", docNum);
|
---|
91 | }
|
---|
92 |
|
---|
93 | cout << docText << "\n";
|
---|
94 |
|
---|
95 | ++docNum;
|
---|
96 | }
|
---|
97 |
|
---|
98 | return 0;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|