-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_generator.c
2361 lines (2094 loc) · 68.4 KB
/
html_generator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****h* ROBODoc/HTML_Generator
* FUNCTION
* The generator for HTML output.
*
* The generator supports sections upto 7 levels deep. It supports
* a Table of Contents based on all headers. A masterindex for
* all headertypes and seperate masterindexes for each headertype.
*
* MODIFICATION HISTORY
* 2003-02-03 Frans Slothouber Refactoring
* ????-??-?? Frans Slothouber V1.0
*******
* $Id: html_generator.c,v 1.90 2007/06/14 15:13:02 thuffir Exp $
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "html_generator.h"
#include "util.h"
#include "globals.h"
#include "robodoc.h"
#include "links.h"
#include "headers.h"
#include "headertypes.h"
#include "generator.h"
#include "items.h"
#include "string.h"
#include "document.h"
#include "directory.h"
#include "path.h"
#include "part.h"
#include "roboconfig.h"
#ifdef DMALLOC
#include <dmalloc.h>
#endif
static char *css_name = NULL;
static int in_linecomment = 0; // are we in a line comment?
static void RB_HTML_Generate_String(
FILE *dest_doc,
const char *a_string );
/* TODO Documentation */
static void HTML_Generate_Div(
FILE *dest_doc,
char *id )
{
fprintf( dest_doc, "<div id=\"%s\">\n", id );
}
/* TODO Documentation */
static void HTML_Generate_Div_End(
FILE *dest_doc,
char *id )
{
fprintf( dest_doc, "</div> <!-- %s -->\n", id );
}
/* TODO Documentation */
char *HTML_TOC_Index_Filename(
struct RB_Document *document )
{
char *toc_index_path = NULL;
char *toc_index_name = "toc_index.html";
assert( document->docroot->name );
toc_index_path =
calloc( strlen( toc_index_name ) + 2 +
strlen( document->docroot->name ), 1 );
strcpy( toc_index_path, document->docroot->name );
strcat( toc_index_path, toc_index_name );
return toc_index_path;
}
/* TODO Documentation */
static void RB_HTML_Generate_Source_Tree_Entry(
FILE *dest_doc,
char *dest_name,
struct RB_Path *parent_path,
struct RB_Directory *srctree,
struct RB_Document *document )
{
struct RB_Path *cur_path;
struct RB_Filename *cur_filename;
fprintf( dest_doc, "<ul>\n" );
for ( cur_filename = srctree->first;
cur_filename; cur_filename = cur_filename->next )
{
if ( cur_filename->path == parent_path )
{
char *r = 0;
if ( cur_filename->link )
{
if ( document->actions.do_one_file_per_header )
{
fprintf( dest_doc, "<li><tt>\n" );
RB_HTML_Generate_String( dest_doc, cur_filename->name );
fprintf( dest_doc, "</tt></li>\n" );
}
else
{
r = RB_HTML_RelativeAddress( dest_name,
cur_filename->link->
file_name );
fprintf( dest_doc, "<li>\n" );
fprintf( dest_doc, "<a href=\"%s#%s\"><tt>\n", r,
cur_filename->link->label_name );
RB_HTML_Generate_String( dest_doc, cur_filename->name );
fprintf( dest_doc, "</tt></a></li>\n" );
}
}
}
}
for ( cur_path = srctree->first_path;
cur_path; cur_path = cur_path->next )
{
if ( cur_path->parent == parent_path )
{
fprintf( dest_doc, "<li>\n" );
RB_HTML_Generate_String( dest_doc, cur_path->name );
RB_HTML_Generate_Source_Tree_Entry( dest_doc, dest_name, cur_path,
srctree, document );
fprintf( dest_doc, "</li>\n" );
}
}
fprintf( dest_doc, "</ul>\n" );
}
/* TODO Documentation */
void RB_HTML_Generate_Source_Tree(
FILE *dest_doc,
char *dest_name,
struct RB_Document *document )
{
struct RB_Directory *srctree;
srctree = document->srctree;
RB_HTML_Generate_Source_Tree_Entry( dest_doc, dest_name, NULL, srctree,
document );
}
/****if* HTML_Generator/RB_HTML_Generate_String
* FUNCTION
* Write a string to the destination document, escaping
* characters where necessary.
* SYNOPSIS
*/
static void RB_HTML_Generate_String(
FILE *dest_doc,
const char *a_string )
/*
* INPUTS
* o dest_doc -- the file the characters are written too
* o a_string -- a nul terminated string.
* SEE ALSO
* RB_HTML_Generate_Char()
* SOURCE
*/
{
int i;
int l = strlen( a_string );
unsigned char c;
for ( i = 0; i < l; ++i )
{
c = a_string[i];
RB_HTML_Generate_Char( dest_doc, c );
}
}
/*******/
/****if* HTML_Generator/RB_HTML_Generate_False_Link
* FUNCTION
* Create a representation for a link that links an word in
* a header to the header itself.
* SYNOPSIS
*/
void RB_HTML_Generate_False_Link(
FILE *dest_doc,
char *name )
/*
* INPUTS
* * dest_doc -- the file the representation is written to.
* * name -- the word.
* SOURCE
*/
{
fprintf( dest_doc, "<strong>" );
RB_HTML_Generate_String( dest_doc, name );
fprintf( dest_doc, "</strong>" );
}
/*******/
/****f* HTML_Generator/RB_HTML_Color_String
* FUNCTION
* Generates various colored strings
* SOURCE
*/
static void RB_HTML_Color_String(
FILE *dest_doc,
int open,
const char *class,
const char *string )
{
switch ( open )
{
// string, closing
case 0:
RB_HTML_Generate_String( dest_doc, string );
fprintf( dest_doc, "</span>" );
break;
// opening, string
case 1:
fprintf( dest_doc, "<span class=\"%s\">", class );
RB_HTML_Generate_String( dest_doc, string );
break;
// opening, string, closing
case 2:
fprintf( dest_doc, "<span class=\"%s\">", class );
RB_HTML_Generate_String( dest_doc, string );
fprintf( dest_doc, "</span>" );
break;
// opening, char, closing
case 3:
fprintf( dest_doc, "<span class=\"%s\">", class );
RB_HTML_Generate_Char( dest_doc, *string );
fprintf( dest_doc, "</span>" );
break;
// Bug
default:
assert( 0 );
}
}
/*******/
/****f* HTML_Generator/RB_HTML_Generate_Line_Comment_End
* FUNCTION
* Check if a line comment is active and generate ending sequence for it.
* Should be called at the end of each SOURCE line.
* SYNOPSIS
*/
void RB_HTML_Generate_Line_Comment_End(
FILE *dest_doc )
{
// Check if we are in a line comment
if ( in_linecomment )
{
// and end the line comment
in_linecomment = 0;
RB_HTML_Color_String( dest_doc, in_linecomment, COMMENT_CLASS, "" );
}
}
/*******/
/****f* HTML_Generator/RB_HTML_Generate_Extra
* FUNCTION
* Do some additional processing to detect HTML extra's like
* file references and other kind of links for the documentation
* body of an item.
* SYNOPSIS
*/
int RB_HTML_Generate_Extra(
FILE *dest_doc,
enum ItemType item_type,
char *cur_char,
char prev_char )
/*
* INPUTS
* o dest_doc -- the file to write to.
* o item_type -- the kind of item the body belongs to.
* o cur_char -- pointer to a substring of the item's body
* o prev_char -- the character just before cur char (zero if none)
* RESULTS
* Number of characters produced.
* SOURCE
*/
{
char link[1024], *str;
int res = -1;
unsigned int i;
static int incomment = 0; /* are we in comment? */
static int quote = 0; /* double quote */
static int squote = 0; /* single quote */
// Reset comment and quote state machine if not source item
if ( !Works_Like_SourceItem( item_type ) )
{
quote = 0;
squote = 0;
incomment = 0;
in_linecomment = 0;
}
// else check for quotations and string literals
else if ( !( incomment || in_linecomment ) )
{
switch ( *cur_char )
{
// Check for quoted string literals ("string")
case '\"':
if ( !squote && course_of_action.do_quotes )
{
if ( prev_char != '\\' )
{
quote = !quote;
RB_HTML_Color_String( dest_doc, quote,
QUOTE_CLASS, "\"" );
return 0;
}
else if ( quote && *( ( char * ) ( cur_char - 2 ) ) == '\\' )
{
quote = !quote; /* case "... \\" */
RB_HTML_Color_String( dest_doc, quote,
QUOTE_CLASS, "\"" );
return 0;
}
}
break;
// Check for single quoted string literals ('string')
case '\'':
if ( !quote && course_of_action.do_squotes )
{
if ( prev_char != '\\' )
{
squote = !squote;
RB_HTML_Color_String( dest_doc, squote,
SQUOTE_CLASS, "\'" );
return 0;
}
else if ( squote && *( ( char * ) ( cur_char - 2 ) ) == '\\' )
{
squote = !squote; /* case '\\' */
RB_HTML_Color_String( dest_doc, squote,
SQUOTE_CLASS, "\'" );
return 0;
}
}
break;
default:
break;
}
}
// Recognise line comments
if ( Works_Like_SourceItem( item_type ) && !incomment && !quote
&& !squote && course_of_action.do_line_comments )
{
// check for line comment start
if ( !in_linecomment )
{
str =
Find_Parameter_Partial( &
( configuration.
source_line_comments ), cur_char );
if ( str )
{
in_linecomment = 1;
RB_HTML_Color_String( dest_doc, in_linecomment,
COMMENT_CLASS, str );
// We found it, so exit
return strlen( str ) - 1;
}
}
// The end of line comments are generated in
// RB_HTML_Generate_Line_Comment_End()
}
// Recognise block comments
if ( Works_Like_SourceItem( item_type ) && !in_linecomment && !quote
&& !squote && course_of_action.do_block_comments )
{
// Check for block comment start
if ( !incomment )
{
str =
Find_Parameter_Partial( &
( configuration.
remark_begin_markers ), cur_char );
if ( str )
{
incomment = 1;
RB_HTML_Color_String( dest_doc, incomment,
COMMENT_CLASS, str );
// We found it, so exit
return strlen( str ) - 1;
}
}
// Check for block comment end
else
{
str =
Find_Parameter_Partial( &( configuration.remark_end_markers ),
cur_char );
if ( str )
{
incomment = 0;
RB_HTML_Color_String( dest_doc, incomment,
COMMENT_CLASS, str );
// We found it, so exit
return strlen( str ) - 1;
}
}
}
// Do further source formating
if ( Works_Like_SourceItem( item_type ) &&
!in_linecomment && !incomment && !quote && !squote )
{
// Check for keywords
if ( configuration.keywords.number && course_of_action.do_keywords )
{
char *keyword;
// Check if we are at the beginning of a word
if ( !utf8_isalnum( prev_char ) && ( prev_char != '_' ) )
{
// Count word length
for ( i = 1; // A word should have at least one character...
utf8_isalnum( cur_char[i] ) || ( cur_char[i] == '_' );
i++ );
// Check if it is a keyword
if ( ( keyword = Find_Keyword( cur_char, i ) ) )
{
RB_HTML_Color_String( dest_doc, 2, KEYWORD_CLASS,
keyword );
// Exit function
return i - 1;
}
}
}
// Do some fancy coloration for non-alphanumeric chars
if ( !utf8_isalnum( *cur_char ) && *cur_char != '_'
&& *cur_char != ' ' && course_of_action.do_non_alpha )
{
RB_HTML_Color_String( dest_doc, 3, SIGN_CLASS, cur_char );
return 0;
}
}
// Check for links, etc...
if ( incomment || in_linecomment || !Works_Like_SourceItem( item_type ) )
{
if ( strncmp( "http://", cur_char, 7 ) == 0 )
{
sscanf( cur_char, "%s", link );
RB_Say( "found link %s\n", SAY_DEBUG, link );
res = ( strlen( link ) - 1 );
/* [ 697247 ] http://body. does not skip the '.' */
if ( link[( strlen( link ) - 1 )] == '.' )
{
link[( strlen( link ) - 1 )] = '\0';
fprintf( dest_doc, "<a href=\"%s\">%s</a>.", link, link );
}
else
{
fprintf( dest_doc, "<a href=\"%s\">%s</a>", link, link );
}
}
else if ( strncmp( "href:", cur_char, 5 ) == 0 )
{
/*
* handy in relative hyperlink paths, e.g.
* href:../../modulex/
*/
sscanf( ( cur_char + 5 ), "%s", link );
RB_Say( "found link %s\n", SAY_DEBUG, link );
res = ( strlen( link ) + 4 );
fprintf( dest_doc, "<a href=\"%s\">%s</a>", link, link );
}
else if ( strncmp( "file:/", cur_char, strlen( "file:/" ) ) == 0 )
{
sscanf( cur_char, "%s", link );
RB_Say( "found link %s\n", SAY_DEBUG, link );
res = ( strlen( link ) - 1 );
fprintf( dest_doc, "<a href=\"%s\">%s</a>", link, link );
}
else if ( strncmp( "mailto:", cur_char, 7 ) == 0 )
{
sscanf( ( cur_char + 7 ), "%s", link );
RB_Say( "found mail to %s\n", SAY_DEBUG, link );
res = ( strlen( link ) + 6 );
fprintf( dest_doc, "<a href=\"mailto:%s\">%s</a>", link, link );
}
else if ( strncmp( "image:", cur_char, 6 ) == 0 )
{
sscanf( ( cur_char + 6 ), "%s", link );
RB_Say( "found image %s\n", SAY_DEBUG, link );
res = ( strlen( link ) + 5 );
fprintf( dest_doc, "<img src=\"%s\">", link );
}
}
return res;
}
/******/
void RB_HTML_Generate_Item_Name(
FILE *dest_doc,
char *name )
{
fprintf( dest_doc, "<p class=\"item_name\">" );
RB_HTML_Generate_String( dest_doc, name );
fprintf( dest_doc, "</p>\n" );
}
void RB_HTML_Generate_Item_Begin(
FILE *dest_doc,
char *name )
{
USE( dest_doc );
USE( name );
/* empty */
}
void RB_HTML_Generate_Item_End(
FILE *dest_doc,
char *name )
{
USE( dest_doc );
USE( name );
/* empty */
}
int sectiontoc_counters[MAX_SECTION_DEPTH];
/****f* HTML_Generator/RB_HTML_Generate_TOC_Section
* FUNCTION
* Create a table of contents based on the hierarchy of
* the headers starting for a particular point in this
* hierarchy (the parent).
* SYNOPSIS
*/
void RB_HTML_Generate_TOC_Section(
FILE *dest_doc,
char *dest_name,
struct RB_header *parent,
struct RB_header **headers,
int count,
int depth )
/*
* INPUTS
* o dest_doc -- the file to write to.
* o dest_name -- the name of this file.
* o parent -- the parent of the headers for which the the
* current level(depth) of TOC is created.
* o headers -- an array of headers for which the TOC is created
* o count -- the number of headers in this array
* o depth -- the current depth of the TOC
* NOTES
* This is a recursive function and tricky stuff.
* SOURCE
*/
{
struct RB_header *header;
int i, n, once = 0;
++sectiontoc_counters[depth];
for ( i = depth + 1; i < MAX_SECTION_DEPTH; ++i )
{
sectiontoc_counters[i] = 0;
}
// List item start
fprintf( dest_doc, "<li>" );
// Do not generate section numbers if sectionnameonly
if ( !( course_of_action.do_sectionnameonly ) )
{
for ( i = 1; i <= depth; ++i )
{
fprintf( dest_doc, "%d.", sectiontoc_counters[i] );
}
fprintf( dest_doc, " " );
}
// Generate Link to first reference name
RB_HTML_Generate_Link( dest_doc, dest_name, parent->file_name,
parent->unique_name,
// only generate function name if sectionnameonly
( course_of_action.do_sectionnameonly ) ?
parent->function_name : parent->name, 0 );
// Generate links to further reference names
for ( n = 1; n < parent->no_names; n++ )
{
RB_HTML_Generate_String( dest_doc, ", " );
RB_HTML_Generate_Link( dest_doc, dest_name, parent->file_name,
parent->unique_name, parent->names[n], 0 );
}
// List item end
fprintf( dest_doc, "</li>\n" );
for ( i = 0; i < count; ++i )
{
header = headers[i];
if ( header->parent == parent )
{
// Generate better TOC level hiearchy (Thuffir)
// We only generate <ul> once for a level
if ( !once )
{
once = 1;
fprintf( dest_doc, "<ul>\n" );
}
RB_HTML_Generate_TOC_Section( dest_doc, dest_name, header,
headers, count, depth + 1 );
}
else
{
/* Empty */
}
}
// If we have generated an <ul> before, generate the closing one too.
if ( once )
fprintf( dest_doc, "</ul>\n" );
}
/*******/
void RB_HTML_Generate_TOC_2(
FILE *dest_doc,
struct RB_header **headers,
int count,
struct RB_Part *owner,
char *dest_name )
{
struct RB_header *header;
int i, j;
int depth = 1;
for ( i = 0; i < MAX_SECTION_DEPTH; ++i )
{
sectiontoc_counters[i] = 0;
}
fprintf( dest_doc, "<h3>TABLE OF CONTENTS</h3>\n" );
if ( course_of_action.do_sections )
{
/* --sections was specified, create a TOC based on the
* hierarchy of the headers.
*/
fprintf( dest_doc, "<ul>\n" );
for ( i = 0; i < count; ++i )
{
header = headers[i];
if ( owner == NULL )
{
if ( header->parent )
{
/* Will be done in the subfunction */
}
else
{
RB_HTML_Generate_TOC_Section( dest_doc, dest_name, header,
headers, count, depth );
}
}
else
{
/* This is the TOC for a specific RB_Part (MultiDoc
* documentation). We only include the headers that
* are part of the subtree. That is, headers that are
* parth the RB_Part, or that are childern of the
* headers in the RB_Part.
*/
if ( header->owner == owner )
{
/* BUG 721690 */
/* Any of the parents of this header should not
* have the same owner as this header, otherwise
* this header will be part of the TOC multiple times.
*/
int no_bad_parent = TRUE;
struct RB_header *parent = header->parent;
for ( ; parent; parent = parent->parent )
{
if ( parent->owner == owner )
{
no_bad_parent = FALSE;
break;
}
}
if ( no_bad_parent )
{
RB_HTML_Generate_TOC_Section( dest_doc, dest_name,
header, headers, count,
depth );
}
}
}
}
fprintf( dest_doc, "</ul>\n" );
}
else
{
/* No --section option, generate a plain, one-level
* TOC
*/
fprintf( dest_doc, "<ul>\n" );
for ( i = 0; i < count; ++i )
{
header = headers[i];
if ( header->name && header->function_name &&
( ( owner == NULL ) || ( header->owner == owner ) ) )
{
for ( j = 0; j < header->no_names; j++ )
{
fprintf( dest_doc, "<li>" );
RB_HTML_Generate_Link( dest_doc, dest_name,
header->file_name,
header->unique_name,
header->names[j], 0 );
fprintf( dest_doc, "</li>\n" );
}
}
}
fprintf( dest_doc, "</ul>\n" );
}
}
/****f* HTML_Generator/RB_HTML_Generate_Label
* FUNCTION
* Generate a label (name) that can be refered too.
* A label should consist of only alphanumeric characters so
* all 'odd' characters are replaced with their ASCII code in
* hex format.
* SYNOPSIS
*/
void RB_HTML_Generate_Label(
FILE *dest_doc,
char *name )
/*
* INPUTS
* o dest_doc -- the file to write it to.
* o name -- the name of the label.
* SOURCE
*/
{
int i;
int l = strlen( name );
unsigned char c;
fprintf( dest_doc, "<a name=\"" );
for ( i = 0; i < l; ++i )
{
c = name[i];
if ( utf8_isalnum( c ) )
{
RB_HTML_Generate_Char( dest_doc, c );
}
else
{
char buf[4];
sprintf( buf, "%02x", c );
RB_HTML_Generate_Char( dest_doc, buf[0] );
RB_HTML_Generate_Char( dest_doc, buf[1] );
}
}
fprintf( dest_doc, "\"></a>\n" );
}
/********/
static int section_counters[MAX_SECTION_DEPTH];
/* TODO Documentation */
void RB_HTML_Generate_BeginSection(
FILE *dest_doc,
int depth,
char *name,
struct RB_header *header )
{
int i;
++section_counters[depth];
for ( i = depth + 1; i < MAX_SECTION_DEPTH; ++i )
{
section_counters[i] = 0;
}
switch ( depth )
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
fprintf( dest_doc, "<h%d>", depth );
// Only generate section numbers if no sectionnameonly
if ( !( course_of_action.do_sectionnameonly ) )
{
for ( i = 1; i <= depth; ++i )
{
fprintf( dest_doc, "%d.", section_counters[i] );
}
fprintf( dest_doc, " " );
}
// Print Header "first" name
RB_HTML_Generate_String( dest_doc, name );
// Print further names
for ( i = 1; i < header->no_names; i++ )
{
fprintf( dest_doc, ( i % header_breaks ) ? ", " : ",<br />" );
RB_HTML_Generate_String( dest_doc, header->names[i] );
}
// Include module name if not sectionnameonly
if ( !( course_of_action.do_sectionnameonly ) )
{
fprintf( dest_doc, " [ " );
RB_HTML_Generate_String( dest_doc, header->htype->indexName );
fprintf( dest_doc, " ]" );
}
fprintf( dest_doc, " </h%d>\n", depth );
break;
default:
/* too deep, don't do anything. */
assert( 0 );
}
}
void RB_HTML_Generate_EndSection(
FILE *dest_doc,
int depth,
char *name )
{
USE( dest_doc );
USE( name );
USE( depth );
/* Empty */
}
char *RB_HTML_Get_Default_Extension(
void )
{
return ( ".html" );
}
/****f* HTML_Generator/RB_HTML_Generate_Doc_Start
* NAME
* RB_HTML_Generate_Doc_Start --
* FUNCTION
* Generate the first part of a HTML document.
* As far as ROBODoc is concerned a HTML document
* consists of three parts:
* * The start of a document
* * The body of a document
* * The end of a document
* SYNOPSIS
*/
void RB_HTML_Generate_Doc_Start(
FILE *dest_doc,
char *src_name,
char *name,
char *dest_name,
char *charset )
/*
* INPUTS
* o dest_doc -- the output file.
* o src_name -- The file or directoryname from which
* this document is generated.
* o name -- The title for this document
* o dest_name -- the name of the output file.
* o charset -- the charset to be used for the file.
* SOURCE
*/
{
if ( course_of_action.do_headless )
{
/* The user wants a headless document, so we skip everything
* upto and until <BODY>
*/
}
else
{
/* Append document type and title */
fprintf( dest_doc, "<?xml version=\"1.0\" encoding=\"%s\"?>\n",
charset ? charset : DEFAULT_CHARSET );
fprintf( dest_doc,
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" );
fprintf( dest_doc,
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" );
fprintf( dest_doc,
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n" );
fprintf( dest_doc, "<head>\n" );
fprintf( dest_doc,
"<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />\n" );
/* TODO is charset still needed?? */
fprintf( dest_doc,
"<meta http-equiv=\"Content-type\" content=\"text/html; charset=%s\" />\n",
charset ? charset : DEFAULT_CHARSET );
RB_InsertCSS( dest_doc, dest_name );
fprintf( dest_doc, "<title>%s</title>\n", name );
/* append SGML-comment with document- and copyright-info. This code
* ensures that every line has an own comment to avoid problems with
* buggy browsers */
fprintf( dest_doc, "<!-- Source: %s -->\n", src_name );
if ( course_of_action.do_nogenwith )
{
}
else
{
static const char copyright_text[]
= COMMENT_ROBODOC /* COMMENT_COPYRIGHT */ ;
size_t i = 0;
char previous_char = '\n';
char current_char = copyright_text[i];
while ( current_char )
{
if ( previous_char == '\n' )
{
fprintf( dest_doc, "<!-- " );
}
if ( current_char == '\n' )
{
fprintf( dest_doc, " -->" );
}
else if ( ( current_char == '-' )
&& ( previous_char == '-' ) )
{
/* avoid "--" inside SGML-comment, and use "-_" instead; this
* looks a bit strange, but one should still be able to figure
* out what is meant when reading the output */
current_char = '_';
}
fputc( current_char, dest_doc );
i += 1;
previous_char = current_char;
current_char = copyright_text[i];
}
}
/* append heading and start list of links to functions */
fprintf( dest_doc, "</head>\n" );
fprintf( dest_doc, "<body>\n" );
}