[Po4a-commits] "po4a/lib/Locale/Po4a Xml.pm,1.56,1.57"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Sun Jan 13 00:03:44 UTC 2008


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory alioth:/tmp/cvs-serv3450/lib/Locale/Po4a

Modified Files:
	Xml.pm 
Log Message:
New option "cpp" to support C preprocessor directives (this avoids
re-wrapping lines with preprocessor directives).


Index: Xml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Xml.pm,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- Xml.pm	16 Aug 2007 17:21:28 -0000	1.56
+++ Xml.pm	13 Jan 2008 00:03:41 -0000	1.57
@@ -284,6 +284,18 @@
 Space separated list of tags that the module should not try to set by
 default in the "tags" or "inline" category.
 
+=item cpp
+
+Support C preprocessor directives.
+When this option is set, po4a will consider preprocessor directives as
+paragraph separators.
+This is important if the XML file must be preprocessed because otherwise
+the directives may be inserted in the middle of lines if po4a consider it
+belong to the current paragraph, and they won't be recognized by the
+preprocessor.
+Note: the preprocessor directives must only appear between tags
+(they must not break a tag).
+
 =back
 
 =cut
@@ -312,6 +324,7 @@
 	$self->{options}{'nodefault'}='';
 	$self->{options}{'includeexternal'}=0;
 	$self->{options}{'ontagerror'}="fail";
+	$self->{options}{'cpp'}=0;
 
 	$self->{options}{'verbose'}='';
 	$self->{options}{'debug'}='';
@@ -1305,6 +1318,29 @@
 	$self->pushline("<!--".$comments."-->\n") if defined $comments;
 	@comments = ();
 
+	if ($self->{options}{'cpp'}) {
+		my @tmp = @paragraph;
+		@paragraph = ();
+		while (@tmp) {
+			my ($t,$l) = (shift @tmp, shift @tmp);
+			# #include can be followed by a filename between
+			# <> brackets. In that case, the argument won't be
+			# handled in the same call to translate_paragraph.
+			# Thus do not try to match "include ".
+			if ($t =~ m/^#[ \t]*(if |endif|undef |include|else|ifdef |ifndef |define )/si) {
+				if (@paragraph) {
+					$self->translate_paragraph($translate,
+					                           @paragraph);
+					@paragraph = ();
+					$self->pushline("\n");
+				}
+				$self->pushline($t);
+			} else {
+				push @paragraph, ($t,$l);
+			}
+		}
+	}
+
 	if ( length($self->join_lines(@paragraph)) > 0 ) {
 		my $struc = $self->get_path;
 		my $options = $self->tag_in_list($struc,@{$self->{tags}});




More information about the Po4a-commits mailing list