9 |
use strict; |
use strict; |
10 |
|
|
11 |
use XML::Parser; |
use XML::Parser; |
|
use common; |
|
12 |
use Carp; |
use Carp; |
13 |
|
use Text::Iconv; |
14 |
|
|
15 |
$|=1; |
$|=1; |
16 |
|
|
108 |
# for unnumbered questions |
# for unnumbered questions |
109 |
my $u_db_col = "u"; |
my $u_db_col = "u"; |
110 |
|
|
111 |
|
# output encoding for files, probably defined in header.html also |
112 |
|
my $html_encoding="ISO-8859-2"; |
113 |
|
|
114 |
|
Text::Iconv->raise_error(1); # Conversion errors raise exceptions |
115 |
|
my $iconv; |
116 |
|
|
117 |
|
# convert UTF8 (as from XML file) to 8-bit encoding |
118 |
|
sub x { |
119 |
|
if (! $iconv) { |
120 |
|
$iconv = Text::Iconv->new('UTF8', $html_encoding); |
121 |
|
print "output encoding is $html_encoding\n"; |
122 |
|
} |
123 |
|
return $iconv->convert($_[0]); |
124 |
|
} |
125 |
|
|
126 |
|
1; |
127 |
|
|
128 |
#------------------------------------------------------------------ |
#------------------------------------------------------------------ |
129 |
|
|
130 |
sub suck_file { |
sub suck_file { |
131 |
my $file = shift || croak "suck_file called without argument"; |
my $file = shift || croak "suck_file called without argument"; |
132 |
open(H,$file) || die "can't open '$file': $!"; |
if (! -f $file) { |
133 |
|
my $template_file = $file; |
134 |
|
$template_file =~ s,^.*?/*([^/]+)$,$1,; |
135 |
|
if (-f $template_file) { |
136 |
|
print "WARNING: can't find '$file', copy template '$template_file' ? [Y/n]: "; |
137 |
|
my $a = <STDIN>; |
138 |
|
chomp $a; |
139 |
|
if ($a =~ m/^y/i || $a eq "") { |
140 |
|
open(I,$template_file) || die "FATAL: can't open template file '$template_file': $!"; |
141 |
|
open(O,"> $file") || die "FATAL: can't create '$file' from template: $!"; |
142 |
|
while(<I>) { |
143 |
|
print O $_; |
144 |
|
} |
145 |
|
close(I); |
146 |
|
close(O); |
147 |
|
print "File '$file' created from template '$template_file'\n"; |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
} |
152 |
|
|
153 |
|
if (! -f $file) { |
154 |
|
print STDERR "FATAL: please create file $file and then re-run this script!\n"; |
155 |
|
exit 1; |
156 |
|
} |
157 |
|
|
158 |
|
open(H,$file) || die "FATAL: can't open '$file': $!"; |
159 |
my $content; |
my $content; |
160 |
while (<H>) { $content .= $_; } ; |
while (<H>) { $content .= $_; } ; |
161 |
close(H); |
close(H); |
953 |
|
|
954 |
$$ncref = sub { |
$$ncref = sub { |
955 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
956 |
|
# encoding should be checked first since it also |
957 |
|
# initialize iconv for conversion from XML's UTF-8 |
958 |
|
$html_encoding=$attref->{html_encoding} if ($attref->{html_encoding}); |
959 |
$db_user=x($attref->{db_user}); |
$db_user=x($attref->{db_user}); |
960 |
$prefix=x($attref->{prefix}); |
$prefix=x($attref->{prefix}); |
961 |
$without_invitation=x($attref->{without_invitation}) && |
$without_invitation=x($attref->{without_invitation}) && |
974 |
$q_db_col=x($attref->{q_db_col}) || 'q'; |
$q_db_col=x($attref->{q_db_col}) || 'q'; |
975 |
$u_db_col=x($attref->{u_db_col}) || 'u'; |
$u_db_col=x($attref->{u_db_col}) || 'u'; |
976 |
|
|
977 |
|
|
978 |
} |
} |
979 |
} |
} |
980 |
|
|