summaryrefslogtreecommitdiffstats
path: root/lib/Locale/Po4a/KernelHelp.pm
blob: 96cd21f0425c2553471366252e5710d2acd04f30 (plain)
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
# Locale::Po4a::KernelHelp -- Convert kernel configuration help from/to PO files
#
# This program is free software; you may redistribute it and/or modify it
# under the terms of GPL v2.0 or later (see COPYING).
#
# See gettext documentation for more info about PO files.

############################################################################
# Modules and declarations
############################################################################

use Pod::Parser;
use Locale::Po4a::TransTractor qw(process new);
use Locale::Po4a::Common;

package Locale::Po4a::KernelHelp;

use 5.16.0;
use strict;
use warnings;

require Exporter;

use vars qw(@ISA @EXPORT $AUTOLOAD);
@ISA    = qw(Locale::Po4a::TransTractor);
@EXPORT = qw();                             # new process write read writepo readpo);

my $debug = 0;

sub initialize { }

sub parse {
    my $self = shift;
    my ( $line, $ref );
    my $paragraph = "";                     # Buffer where we put the paragraph while building
    my ($status)  = 0;                      # Syntax of KH is:
                                            #   description<nl>variable<nl>help text<nl><nl>
                                            # Status will be:
                                            #   0             1            2        3   0

    my ( $desc, $variable );

  LINE:
    ( $line, $ref ) = $self->shiftline();

    while ( defined($line) ) {
        chomp($line);
        print STDERR "status=$status;Seen >>$line<<:" if $debug;

        if ( $line =~ /^\#/ ) {
            print STDERR "comment.\n" if $debug;
            $self->pushline("$line\n");
        } elsif ( $status == 0 ) {
            if ( $line =~ /\S/ ) {
                print STDERR "short desc.\n" if $debug;
                $desc = $line;
                $status++;
            } else {
                print STDERR "empty line.\n" if $debug;
                $self->pushline("$line\n");
            }
        } elsif ( $status == 1 ) {
            print STDERR "var name.\n" if $debug;
            $variable = $line;
            $status++;

            $self->pushline( $self->translate( $desc, $ref, "desc_$variable" ) . "\n$variable\n" );

        } elsif ( $status == 2 ) {
            $line =~ s/^  //;
            if ( $line =~ /\S/ ) {
                print STDERR "paragraph line.\n" if $debug;
                $paragraph .= $line . "\n";
            } else {
                print STDERR "end of paragraph.\n" if $debug;
                $status++;
                $paragraph = $self->translate( $paragraph, $ref, "helptxt_$variable" );
                $paragraph =~ s/^/  /gm;
                $self->pushline("$paragraph\n");
                $paragraph = "";
            }
        } elsif ( $status == 3 ) {
            if ( $line =~ s/^  // ) {
                if ( $line =~ /\S/ ) {
                    print "begin of paragraph.\n" if $debug;
                    $paragraph = $line . "\n";
                    $status--;
                } else {
                    print "end of config option.\n" if $debug;
                    $status = 0;
                    $self->pushline("\n");
                }
            } else {
                $self->unshiftline( $line, $ref );
                $status = 0;
            }
        } else {
            die wrap_ref_mod( $ref, "po4a::kernelhelp", gettext("Syntax error") );
        }

        # Reinit the loop
        ( $line, $ref ) = $self->shiftline();
    }
}

sub docheader {
    return <<EOT;
#
#        *****************************************************
#        *           GENERATED FILE, DO NOT EDIT             *
#        * THIS IS NO SOURCE FILE, BUT RESULT OF COMPILATION *
#        *****************************************************
#
# This file was generated by po4a(7). Do not store it (in VCS, for example),
# but store the PO file used as source file by pod-translate.
#
# In fact, consider this as a binary, and the PO file as a regular .c file:
# If the PO get lost, keeping this translation up-to-date will be harder.
#
EOT
}
1;

##############################################################################
# Module return value and documentation
##############################################################################

1;
__END__

=encoding UTF-8

=head1 NAME

Locale::Po4a::KernelHelp - convert kernel configuration help from/to PO files

=head1 DESCRIPTION

Locale::Po4a::KernelHelp is a module to help the translation of
documentation for the Linux kernel configuration options into other [human]
languages.

=head1 STATUS OF THIS MODULE

This module is just written, and needs more tests. Most of the needed work
will concern the tools used to parse this file (and configure the kernel),
so that they accept to read the documentation from another (translated)
file.

=head1 SEE ALSO

L<Pod::Parser>,
L<Locale::Po4a::Man(3pm)>,
L<Locale::Po4a::Pod(3pm)>,
L<Locale::Po4a::TransTractor(3pm)>,
L<po4a(7)|po4a.7>

=head1 AUTHORS

 Denis Barbier <barbier@linuxfr.org>
 Martin Quinson (mquinson#debian.org)

=head1 COPYRIGHT AND LICENSE

Copyright © 2002 SPI, Inc.

This program is free software; you may redistribute it and/or modify it
under the terms of GPL v2.0 or later (see the COPYING file).

=cut