[3365] | 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 | #define _XOPEN_SOURCE_EXTENDED 1
|
---|
| 24 |
|
---|
| 25 | /* getopt is in posix.2, so cygwin should have it in unistd, but doesn't */
|
---|
| 26 | #if defined (__WIN32__) || defined (__CYGWIN__)
|
---|
| 27 | # include "getopt_old.h"
|
---|
| 28 | #else
|
---|
| 29 | # include <unistd.h>
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #include "UCArray.h"
|
---|
| 33 | #include "sysfuncs.h"
|
---|
| 34 | #include "TextGet.h"
|
---|
| 35 | #include "messages.h"
|
---|
| 36 | #include "mg_files.h"
|
---|
| 37 |
|
---|
| 38 | int main (int argc, char **argv) {
|
---|
| 39 | int ch;
|
---|
| 40 | char *filename = "";
|
---|
| 41 | char *basePath = "";
|
---|
| 42 | UCArray level;
|
---|
[8692] | 43 | SetCStr (level, "Document", 8);
|
---|
[3365] | 44 |
|
---|
| 45 | opterr = 0;
|
---|
| 46 | msg_prefix = argv[0];
|
---|
| 47 |
|
---|
| 48 | // process the command line arguments
|
---|
| 49 | while ((ch = getopt (argc, argv, "f:d:K:h")) != -1) {
|
---|
| 50 | switch (ch) {
|
---|
| 51 | case 'f': /* input file */
|
---|
| 52 | filename = optarg;
|
---|
| 53 | break;
|
---|
| 54 | case 'd':
|
---|
| 55 | basePath = optarg;
|
---|
| 56 | set_basepath (optarg);
|
---|
| 57 | break;
|
---|
| 58 | case 'K':
|
---|
[8692] | 59 | SetCStr (level, optarg, strlen(optarg));
|
---|
[3365] | 60 | break;
|
---|
| 61 | case 'h':
|
---|
| 62 | case '?':
|
---|
| 63 | fprintf (stderr, "usage: %s [-h] [-K level] [-d directory] -f name\n",
|
---|
| 64 | argv[0]);
|
---|
| 65 | exit (1);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | // load up the text information
|
---|
| 70 | TextData td;
|
---|
| 71 | if (!td.LoadData (basePath, filename)) {
|
---|
| 72 | FatalError (1, "Couldn't load text information for \"%s\"", filename);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | // output each document in the level
|
---|
| 76 | // cout << td.levels << "\n";
|
---|
| 77 |
|
---|
| 78 | TextLevelInfo levelInfo = td.levels.levelInfo[level];
|
---|
| 79 | unsigned long docNum = 1;
|
---|
| 80 | UCArray docText;
|
---|
| 81 | while (docNum <= levelInfo.numEntries) {
|
---|
| 82 | // TextIdx docIdx;
|
---|
| 83 | // if (GetDocIdx (td, level, docNum, docIdx)) {
|
---|
| 84 | // cout << "doc: " << docNum << "\n";
|
---|
| 85 | // cout << docIdx;
|
---|
| 86 | // }
|
---|
| 87 |
|
---|
| 88 | if (!GetDocText (td, level, docNum, docText)) {
|
---|
| 89 | FatalError (1, "Error while trying to get document %u", docNum);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | cout << docText << "\n";
|
---|
| 93 |
|
---|
[8692] | 94 | ++docNum;
|
---|
[3365] | 95 | }
|
---|
| 96 |
|
---|
| 97 | return 0;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|