2
2
# #
3
3
# W HelpBookHandler.g GAPDoc Frank Lübeck
4
4
# #
5
- # H @(#)$Id: HelpBookHandler.g,v 1.4 2001-06-07 20:30:34 gap Exp $
5
+ # H @(#)$Id: HelpBookHandler.g,v 1.5 2001-06-11 08:04:28 gap Exp $
6
6
# #
7
7
# Y Copyright (C) 2000, Frank Lübeck, Lehrstuhl D für Mathematik,
8
8
# Y RWTH Aachen
@@ -46,7 +46,7 @@ HELP_BOOK_HANDLER.GapDocGAP.ReadSix := function(stream)
46
46
47
47
# in position 6 of each entry we put the corresponding search string
48
48
for a in res.entries do
49
- a[ 6 ] := STRING_LOWER (StripEscapeSequences(a[ 1 ] ));
49
+ a[ 6 ] := SIMPLE_STRING (StripEscapeSequences(a[ 1 ] ));
50
50
NormalizeWhitespace(a[ 6 ] );
51
51
od ;
52
52
@@ -126,12 +126,17 @@ HELP_BOOK_HANDLER.GapDocGAP.HelpData := function(book, entrynr, type)
126
126
return a;
127
127
fi ;
128
128
129
+ a := info.entries[ entrynr] ;
130
+
131
+ # section number info
132
+ if type = " secnr" then
133
+ return a{[ 3 ,2 ]} ;
134
+ fi ;
135
+
129
136
if not type in info.types then
130
137
return fail ;
131
138
fi ;
132
139
133
- a := info.entries[ entrynr] ;
134
-
135
140
if type = " text" then
136
141
str := StringFile(Filename(info.directory, Concatenation(" chap" ,
137
142
String(a[ 3 ][ 1 ] ), " .txt" )));
@@ -162,20 +167,35 @@ HELP_BOOK_HANDLER.GapDocGAP.HelpData := function(book, entrynr, type)
162
167
return rec (file := info.pdffile, page := a[ 5 ] );
163
168
fi ;
164
169
165
- if type = " secnr" then
166
- return a{[ 3 ,2 ]} ;
167
- fi ;
168
-
169
170
return fail ;
170
171
end ;
171
172
173
+ # # cache list of chapter numbers, but only if we need them
174
+ HELP_BOOK_HANDLER.GapDocGAP.ChapNumbers := function (info )
175
+ local l, sp;
176
+ if not IsBound (info.ChapNumbers) then
177
+ l := Set(List(info.entries,a-> a[ 3 ][ 1 ] ));
178
+ sp := IntersectionSet(l, [ " Bib" , " Ind" ] );
179
+ l := Difference(l, sp);
180
+ Append(l, sp);
181
+ info.ChapNumbers := l;
182
+ fi ;
183
+ end ;
184
+
172
185
# # for ?<<, ?>>, ?< and ?>
173
- HELP_BOOK_HANDLER.GapDocGAP.MatchBeginChap := function (book, entrynr )
174
- local info, ent, cnr, nr;
186
+ HELP_BOOK_HANDLER.GapDocGAP.MatchPrevChap := function (book, entrynr )
187
+ local info, chnums, ent, cnr, new, nr;
175
188
info := HELP_BOOK_INFO(book);
189
+ HELP_BOOK_HANDLER.GapDocGAP.ChapNumbers(info);
190
+ chnums := info.ChapNumbers;
176
191
ent := info.entries;
177
- cnr := [ ent[ entrynr][ 3 ] , 0 , 0 ] ;
178
- nr := First([ 1 .. Length(ent)] , i-> ent[ i][ 3 ] = cnr);
192
+ cnr := ent[ entrynr][ 3 ] ;
193
+ if cnr[ 2 ] <> 0 or cnr[ 3 ] <> 0 or cnr[ 1 ] = chnums[ 1 ] then
194
+ new := [ cnr[ 1 ] , 0 , 0 ] ;
195
+ else
196
+ new := [ chnums[ Position(chnums, cnr[ 1 ] )- 1 ] , 0 , 0 ] ;
197
+ fi ;
198
+ nr := First([ 1 .. Length(ent)] , i-> ent[ i][ 3 ] = new);
179
199
if nr = fail then
180
200
# return current
181
201
nr := entrynr;
@@ -184,20 +204,38 @@ HELP_BOOK_HANDLER.GapDocGAP.MatchBeginChap := function(book, entrynr)
184
204
end ;
185
205
186
206
HELP_BOOK_HANDLER.GapDocGAP.MatchNextChap := function (book, entrynr )
187
- local info, ent, old, chnrs, pos, cnr, nr;
207
+ # # local info, ent, old, chnrs, pos, cnr, nr;
208
+ # # info := HELP_BOOK_INFO(book);
209
+ # # HELP_BOOK_HANDLER.GapDocGAP.ChapNumbers(info);
210
+ # # ent := info.entries;
211
+ # # old := ent[entrynr][3];
212
+ # # # this handles appendices as chapters
213
+ # # chnrs := Set(Difference(List(ent, a-> a[1]), ["Bib", "Ind"]));
214
+ # # pos := Position(chnrs, old[1]);
215
+ # # if pos < Length(chnrs) then
216
+ # # cnr := [chnrs[pos+1], 0, 0];
217
+ # # else
218
+ # # # no next chapter, return the last
219
+ # # cnr := [old[1], 0, 0];
220
+ # # fi;
221
+ # # nr := First([1..Length(ent)], i-> ent[i][3]=cnr);
222
+ # # if nr = fail then
223
+ # # # return current
224
+ # # nr := entrynr;
225
+ # # fi;
226
+ # # return [info, nr];
227
+ local info, chnums, ent, cnr, new, nr;
188
228
info := HELP_BOOK_INFO(book);
229
+ HELP_BOOK_HANDLER.GapDocGAP.ChapNumbers(info);
230
+ chnums := info.ChapNumbers;
189
231
ent := info.entries;
190
- old := ent[ entrynr][ 3 ] ;
191
- # this handles appendices as chapters
192
- chnrs := Set(Difference(List(ent, a-> a[ 1 ] ), [ " Bib" , " Ind" ] ));
193
- pos := Position(chnrs, old[ 1 ] );
194
- if pos < Length(chnrs) then
195
- cnr := [ chnrs[ pos+ 1 ] , 0 , 0 ] ;
232
+ cnr := ent[ entrynr][ 3 ] ;
233
+ if cnr[ 1 ] = chnums[ Length(chnums)] then
234
+ new := [ cnr[ 1 ] , 0 , 0 ] ;
196
235
else
197
- # no next chapter, return the last
198
- cnr := [ old[ 1 ] , 0 , 0 ] ;
236
+ new := [ chnums[ Position(chnums, cnr[ 1 ] )+ 1 ] , 0 , 0 ] ;
199
237
fi ;
200
- nr := First([ 1 .. Length(ent)] , i-> ent[ i][ 3 ] = cnr );
238
+ nr := First([ 1 .. Length(ent)] , i-> ent[ i][ 3 ] = new );
201
239
if nr = fail then
202
240
# return current
203
241
nr := entrynr;
0 commit comments