Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8335 maxcodehac 1
 
2
   GNU UnRTF, a command-line program to convert RTF documents to other formats.
3
   Copyright (C) 2000,2001 Zachary Thayer Smith
4
5
 
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 2 of the License, or
8
   (at your option) any later version.
9
10
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
 
16
   along with this program; if not, write to the Free Software
17
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
 
20
=============================================================================*/
21
22
 
23
 
24
 * Module name:    word
25
 * Author name:    Zach Smith
26
 * Create date:    01 Sep 00
27
 * Purpose:        Management of Word objects, which contain strings
28
 *                 as well as other Words.
29
 *----------------------------------------------------------------------
30
 * Changes:
31
 * 14 Oct 00, tuorfa@yahoo.com: fixed \fs bug (# is 2X the point size).
32
 * 14 Oct 00, tuorfa@yahoo.com: fixed table data printing.
33
 * 14 Oct 00, tuorfa@yahoo.com: protection against null entries in \info
34
 * 14 Oct 00, tuorfa@yahoo.com: fixed printing of  again
35
 * 14 Oct 00, tuorfa@yahoo.com: fixed closure of tables
36
 * 15 Oct 00, tuorfa@yahoo.com: fixed font attributes preceding 
37
 * 15 Oct 00, tuorfa@yahoo.com: attributes now continue if >1 \cell in group
38
 * 15 Oct 00, tuorfa@yahoo.com: fixed font-size bug, lack of 
39
 *  7 Nov 00, tuorfa@yahoo.com: fixed \'## translatin bug
40
 *  8 Apr 01, tuorfa@yahoo.com: added check for out of memory after malloc
41
 * 21 Apr 01, tuorfa@yahoo.com: bug fixes regarding author, date
42
 * 21 Apr 01, tuorfa@yahoo.com: added paragraph alignment
43
 * 21 Apr 01, tuorfa@yahoo.com: fix for words getting lost after \par
44
 * 24 Jul 01, tuorfa@yahoo.com: moved conversion code to convert.c
45
 * 22 Sep 01, tuorfa@yahoo.com: moved word_dump to here from parse.c
46
 * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks
47
 *--------------------------------------------------------------------*/
48
49
 
50
 
51
#include 
52
#include 
53
#include 
54
55
 
56
#include "parse.h"
57
#include "malloc.h"
58
#include "main.h"
59
#include "error.h"
60
#include "word.h"
61
#include "hash.h"
62
63
 
64
 
65
 
66
static int indent_level=0;
67
68
 
69
 
70
 
71
 
72
 * Name:	word_string
73
 * Purpose:	Obtains the string of a Word object. This involves accessing
74
 *		the Word hash.
75
 * Args:	Word*.
76
 * Returns:	String.
77
 *=======================================================================*/
78
79
 
80
word_string (Word *w) {
81
	char *str;
82
	CHECK_PARAM_NOT_NULL(w);
83
	if (w->hash_index) str = hash_get_string (w->hash_index);
84
	else str = NULL;
85
	return str;
86
}
87
88
 
89
 
90
 
91
 * Name:	word_new
92
 * Purpose:	Instantiates a new Word object.
93
 * Args:	String.
94
 * Returns:	Word*.
95
 *=======================================================================*/
96
97
 
98
word_new (char *str) {
99
	Word * w;
100
101
 
102
	if (!w)
103
		error_handler ("out of memory");
104
	memset ((void*) w, 0, sizeof(Word));
105
	if (!w) error_handler ("cannot allocate a Word");
106
107
 
108
	else w->hash_index = 0;
109
110
 
111
}
112
113
 
114
 
115
 
116
 
117
 * Name:	word_free
118
 * Purpose:	Deallocates a Word object.
119
 * Args:	Word.
120
 * Returns:	None.
121
 *=======================================================================*/
122
123
 
124
	Word *prev;
125
	Word *w2;
126
127
 
128
129
 
130
		w2 = w->child;
131
		if (w2)
132
			word_free(w2);
133
134
 
135
		w = w->next;
136
		my_free ((char*) prev);
137
	}
138
}
139
140
 
141
 
142
 
143
 
144
 
145
 * Name:	print_indentation
146
 * Purpose:	Prints padding for the word_dump routine.
147
 * Args:	Identation level.
148
 * Returns:	None.
149
 *=======================================================================*/
150
151
 
152
print_indentation (int level)
153
{
154
	int i;
155
156
 
157
		for (i=0;i
158
			printf (". ");
159
	} else {
160
		printf ("\n-----------------------------------------------------------------------\n\n");
161
	}
162
}
163
164
 
165
 
166
 
167
 
168
 * Name:	word_dump
169
 * Purpose:	Recursive diagnostic routine to print out a tree of words.
170
 * Args:	Word tree.
171
 * Returns:	None.
172
 *=======================================================================*/
173
174
 
175
word_dump (Word *w)
176
{
177
	char *s;
178
179
 
180
181
 
182
	indent_level += 2;
183
	print_indentation (indent_level);
184
185
 
186
		s = word_string (w);
187
		if (s) {
188
			printf ("\"%s\" ", s);
189
		} else {
190
			if (w->child) {
191
				word_dump (w->child);
192
				printf ("\n");
193
				print_indentation (indent_level);
194
			}
195
			else
196
				warning_handler ("Word object has no string and no children");
197
		}
198
		w = w->next;
199
	}
200
201
 
202
}
203
>
204