File: fix_example_docs.pl

package info (click to toggle)
libxlsxwriter 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,864 kB
  • sloc: ansic: 65,601; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (130 lines) | stat: -rw-r--r-- 6,512 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

#
# Simple program to arrange the example programs in a user defined order
# instead of a sorted order. Also add a caption.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2014-2025, John McNamara, jmcnamara@cpan.org.
#
use warnings;
use strict;

# The required example order and descriptions.
my @examples = (
    [ 'hello.c',                'A simple hello world example' ],
    [ 'anatomy.c',              'The anatomy of a libxlsxwriter program' ],
    [ 'demo.c',                 'Demo of some of the libxlsxwriter features' ],
    [ 'tutorial1.c',            'Tutorial 1 from the documentation' ],
    [ 'tutorial2.c',            'Tutorial 2 from the documentation' ],
    [ 'tutorial3.c',            'Tutorial 3 from the documentation' ],
    [ 'format_font.c',          'Example of writing data with font formatting' ],
    [ 'format_num_format.c',    'Example of writing data with number formatting' ],
    [ 'dates_and_times01.c',    'Writing dates and times with numbers' ],
    [ 'dates_and_times02.c',    'Writing dates and times with datetime' ],
    [ 'dates_and_times03.c',    'Writing dates and times with Unix datetimes' ],
    [ 'dates_and_times04.c',    'Dates and times with different formats' ],
    [ 'hyperlinks.c',           'A example of writing urls/hyperlinks' ],
    [ 'rich_strings.c',         'A example of writing "rich" multi-format strings' ],
    [ 'array_formula.c',        'A example of using array formulas' ],
    [ 'dynamic_arrays.c',       'A example of using Excel 365 dynamic array formulas' ],
    [ 'utf8.c',                 'A example of some UTF-8 text' ],
    [ 'constant_memory.c',      'Write a large file with constant memory usage' ],
    [ 'output_buffer.c',        'Write a file to a memory buffer' ],
    [ 'image_buffer.c',         'Example of inserting an image from a memory buffer.' ],
    [ 'embed_image_buffer.c',   'Example of embedding an image from a memory buffer.' ],
    [ 'merge_range.c',          'Create a merged range of cells' ],
    [ 'merge_rich_string.c',    'Create a merged range with a rich string' ],
    [ 'autofilter.c',           'An example of a worksheet autofilter' ],
    [ 'data_validate.c',        'Examples of worksheet data validation and dropdown lists' ],
    [ 'conditional_format1.c',  'A simple conditional formatting example' ],
    [ 'conditional_format2.c',  'An advanced conditional formatting example' ],
    [ 'tables.c',               'Example of table to a worksheet.' ],
    [ 'images.c',               'Example of inserting images in worksheet cells.' ],
    [ 'embed_images.c',         'Example of embedding images in worksheet cells.' ],
    [ 'headers_footers.c',      'Example of adding worksheet headers/footers' ],
    [ 'defined_name.c',         'Example of how to create defined names' ],
    [ 'outline.c',              'Example of grouping and outlines' ],
    [ 'outline_collapsed.c',    'Example of grouping and collapsed outlines' ],
    [ 'watermark.c',            'Example of how to set a watermark image for a worksheet' ],
    [ 'background.c',           'Example of how to set the background image for a worksheet' ],
    [ 'tab_colors.c',           'Example of how to set worksheet tab colors' ],
    [ 'diagonal_border.c',      'Example of how to set a worksheet cell diagonal border.' ],
    [ 'hide_sheet.c',           'Example of hiding a worksheet' ],
    [ 'doc_properties.c',       'Example of setting workbook doc properties' ],
    [ 'doc_custom_properties.c','Example of setting custom doc properties' ],
    [ 'worksheet_protection.c', 'Example of enabling worksheet protection' ],
    [ 'hide_row_col.c',         'Example of hiding worksheet rows and columns' ],
    [ 'comments1.c',            'Example of adding cell comments to a worksheet' ],
    [ 'comments2.c',            'Example of adding cell comments with options' ],
    [ 'macro.c',                'Example of adding a VBA macro to a workbook' ],
    [ 'panes.c',                'Example of how to create worksheet panes' ],
    [ 'ignore_errors.c',        'Example of ignoring worksheet errors/warnings' ],
    [ 'lambda.c',               'Example of using the EXCEL 365+ LAMBDA() function' ],
    [ 'chart.c',                'Example of a simple column chart' ],
    [ 'chart_area.c',           'Examples of area charts' ],
    [ 'chart_bar.c',            'Examples of bar charts' ],
    [ 'chart_column.c',         'Examples of column charts' ],
    [ 'chart_line.c',           'Example of a line chart' ],
    [ 'chart_scatter.c',        'Examples of scatter charts' ],
    [ 'chart_radar.c',          'Examples of radar charts' ],
    [ 'chart_pie.c',            'Examples of pie charts' ],
    [ 'chart_doughnut.c',       'Examples of doughnut charts' ],
    [ 'chart_clustered.c',      'Examples of clustered category chart' ],
    [ 'chart_data_table.c',     'Examples of charts with data tables' ],
    [ 'chart_data_tools.c',     'Examples of charts data tools' ],
    [ 'chart_data_labels.c',    'Examples of charts data labels' ],
    [ 'chart_fonts.c',          'Examples of using charts fonts' ],
    [ 'chart_pattern.c',        'Examples of using charts patterns' ],
    [ 'chart_styles.c',         'Examples of built-in charts styles' ],
    [ 'chartsheet.c',           'Example of a chartsheet chart' ],
);

# Convert the array refs to a hash for lookups.
my %examples;
for my $example (@examples) {
    $examples{$example->[0]} = 1;
}

my $in_list = 0;

while ( my $line = <> ) {

    # Print all lines not in the <ul> list.
    print $line if !$in_list;

    # Check for <ul> list.
    if ( $line =~ /<div class="textblock">/ ) {
        $in_list = 1;
    }

    # Capture the <li> items of the list.
    if ( $line =~ /<li><a class="el" href="[^"]+">([^<]+)/ ) {
        my $example = $1;

        # Warn if there are any new/unkown items.
        if ( !exists $examples{$example} ) {
            warn "$0 Unknown example: $example\n";
        }
        next;
    }

    # At the end of the <ul> list print out the <li> items in user defined order.
    if ( $line =~ m{^</ul>} ) {
        $in_list = 0;

        for my $aref ( @examples ) {
            my $example  = $aref->[0];
            my $filename = $aref->[0];
            my $desc     = $aref->[1];

            $example =~ s/\.c/_8c-example.html/;

            printf qq(<li><a class="el" href="%s">%s</a> %s</li>\n\n),
              $example, $filename, $desc;
        }
        print $line;
    }
}

__END__