[3365] | 1 | /**************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * text.h -- Header file for compression related stuff
|
---|
| 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 | // UCArray currently contains all the basic reading and writing functions
|
---|
| 23 | #include "UCArray.h"
|
---|
| 24 | #include "text.h"
|
---|
| 25 |
|
---|
| 26 | compressed_text_header::compressed_text_header () {
|
---|
| 27 | Clear();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void compressed_text_header::Clear () {
|
---|
| 31 | num_of_docs = 0;
|
---|
| 32 | num_of_words = 0;
|
---|
| 33 | num_of_bytes = 0.0;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | bool compressed_text_header::Read (FILE *f) {
|
---|
| 38 | return (ReadUL (f, num_of_docs) &&
|
---|
| 39 | ReadUL (f, num_of_words) &&
|
---|
| 40 | ReadD (f, num_of_bytes));
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | bool compressed_text_header::Write (FILE *f) const {
|
---|
| 44 | return (WriteUL (f, num_of_docs) &&
|
---|
| 45 | WriteUL (f, num_of_words) &&
|
---|
| 46 | WriteD (f, num_of_bytes));
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | auxiliary_dict::auxiliary_dict () {
|
---|
| 51 | word_data[0] = NULL;
|
---|
| 52 | word_data[1] = NULL;
|
---|
| 53 | words[0] = NULL;
|
---|
| 54 | words[1] = NULL;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | auxiliary_dict::~auxiliary_dict () {
|
---|
| 58 | Clear ();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | void auxiliary_dict::Clear () {
|
---|
| 62 | if (word_data[0] != NULL) {
|
---|
[12320] | 63 | delete []word_data[0];
|
---|
[3365] | 64 | word_data[0] = NULL;
|
---|
| 65 | }
|
---|
| 66 | if (word_data[1] != NULL) {
|
---|
[12320] | 67 | delete []word_data[1];
|
---|
[3365] | 68 | word_data[1] = NULL;
|
---|
| 69 | }
|
---|
| 70 | if (words[0] != NULL) {
|
---|
[12320] | 71 | delete []words[0];
|
---|
[3365] | 72 | words[0] = NULL;
|
---|
| 73 | }
|
---|
| 74 | if (words[1] != NULL) {
|
---|
[12320] | 75 | delete []words[1];
|
---|
[3365] | 76 | words[1] = NULL;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | compression_dict::compression_dict () {
|
---|
| 82 | int which;
|
---|
[9613] | 83 | for (which = 0; which < 2; ++which) {
|
---|
[3365] | 84 | cfh[which] = NULL;
|
---|
| 85 | values[which] = NULL;
|
---|
| 86 | escape[which] = NULL;
|
---|
| 87 | chars_huff[which] = NULL;
|
---|
| 88 | chars_vals[which] = NULL;
|
---|
| 89 | lens_huff[which] = NULL;
|
---|
| 90 | lens_vals[which] = NULL;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | MemForCompDict = 0;
|
---|
| 94 | ad = NULL;
|
---|
| 95 | fast_loaded = 0;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | compression_dict::~compression_dict () {
|
---|
| 99 | Clear ();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void compression_dict::Clear () {
|
---|
| 103 | int which;
|
---|
[9613] | 104 | for (which = 0; which < 2; ++which) {
|
---|
[3365] | 105 | if (cfh[which] != NULL) {
|
---|
| 106 | delete cfh[which];
|
---|
| 107 | cfh[which] = NULL;
|
---|
| 108 | }
|
---|
| 109 | if (values[which] != NULL) {
|
---|
[12320] | 110 | delete []values[which][0][0];
|
---|
| 111 | delete []values[which][0];
|
---|
| 112 | delete []values[which];
|
---|
[3365] | 113 | values[which] = NULL;
|
---|
| 114 | }
|
---|
| 115 | if (escape[which] != NULL) { // don't know if needed
|
---|
| 116 | //delete escape[which]; // this was causing a seg fault
|
---|
| 117 | escape[which] = NULL;
|
---|
| 118 | }
|
---|
| 119 | if (chars_huff[which] != NULL) {
|
---|
| 120 | delete chars_huff[which];
|
---|
| 121 | chars_huff[which] = NULL;
|
---|
| 122 | }
|
---|
| 123 | if (chars_vals[which] != NULL) {
|
---|
[12320] | 124 | delete []chars_vals[which][0];
|
---|
| 125 | delete []chars_vals[which];
|
---|
[3365] | 126 | chars_vals[which] = NULL;
|
---|
| 127 | }
|
---|
| 128 | if (lens_huff[which] != NULL) {
|
---|
| 129 | delete lens_huff[which];
|
---|
| 130 | lens_huff[which] = NULL;
|
---|
| 131 | }
|
---|
| 132 | if (lens_vals[which] != NULL) {
|
---|
[12320] | 133 | delete []lens_vals[which][0];
|
---|
| 134 | delete []lens_vals[which];
|
---|
[3365] | 135 | lens_vals[which] = NULL;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | if (ad != NULL) {
|
---|
| 140 | delete ad;
|
---|
| 141 | ad = NULL;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | MemForCompDict = 0;
|
---|
| 145 | fast_loaded = 0;
|
---|
| 146 | }
|
---|