mmds
view release on metacpan or search on metacpan
# Don't care about the result. Take its length.
$ruler_margin = length ($`);
# Initialize margin stack and associated variables.
@margin_stack = ($tent_margin = $ruler_margin);
$guess_margin = 0;
}
# Handle data line.
&data_line ($current_line);
}
last if $test && $. > 100;
}
&flush_line;
close (FILE);
}
# Finally...
&wrap_up;
exit ($error_count != 0);
################ Subroutines ################
sub init {
$error_count = 0; # none
$pending_text = ""; # nothing
$pending_tag = ""; # none
$pending_style = -1; # unknown
$lines_to_skip = 0; # none
$delete_vertical_space = 0; # no
$ruler_margin = 6; # initial
@margin_stack = ($tent_margin = $ruler_margin); # initial
$guess_margin = 1; # try to find out
$inited = 0; # the generators are not inited yet
$try_headers = 1; # try to find headers
$enriched_mode = 0; # enriched mode
$tabbing = $tabular = $literal = 0; # not yet
# Set header stuff
set_language($language);
phase_msg ("This is $my_package" .
" [" . nls($::TXT_LANGUAGE) . "]" ) if $opt_ident;
# Styles and leaders.
&::enum
($::STANDARD=1, $::ENUM1, $::ENUM2, $::HEADER1, $::HEADER2,
$::HEADER3, $::CAPTION1, $::CAPTION2);
&::enum
($::LEADER_NONE=0, $::LEADER_DEFAULT, $::LEADER_ALPH, $::LEADER_NUM,
$::LEADER_BULLET, $::LEADER_DASH, $::LEADER_EMPTY);
&::enum
($::TBCTL_INIT=0, $::TBCTL_ROW, $::TBCTL_COL, $::TBCTL_END,
$::TBCTL_HEAD);
# Provide defaults
local (@pw) = getpwuid ($<);
($::headers[$::HDR_MHID] = $ENV{"MMDS_ID"}
|| $cfg->gps("general.id", $pw[0])) =~ tr/[a-z]/[A-Z]/;
$::headers[$::HDR_AUTHOR] = $::headers[$::HDR_FROM] =
$ENV{"MMDS_FULLNAME"} || $ENV{"FULLNAME"}
|| $cfg->gps("general.author", $pw[6]);
$::headers[$::HDR_CITY] = $cfg->gps("general.city", "Doolin");
$::headers[$::HDR_VERSION] = "X0.0";
$::headers[$::HDR_COMPANY] = $cfg->gps("general.company",
"Free Software Foundation");
$::headers[$::HDR_DEPT] = $ENV{"MMDS_DEPT"} || $ENV{"MMDS_DEPARTMENT"}
|| $cfg->gps("general.department",
"League of Programming Freedom");
$::headers[$::HDR_DEPT] = $::headers[$::HDR_COMPANY]
unless vec ($::hdr_set, $::HDR_DEPT, 1) =
defined $::headers[$::HDR_DEPT] && ($::headers[$::HDR_DEPT] ne "");
$::headers[$::HDR_CMPY] = $cfg->gps("general.cmpy", "FSF");
$::headers[$::HDR_CLOSING] = &nls ($::TXT_CLOSING)
unless defined $::headers[$::HDR_CLOSING];
$::headers[$::HDR_CLOSING] .= "\n" . $::headers[$::HDR_COMPANY];
# Set document properties, if known.
&set_document_type ($document_type) if $document_type;
# Open feedback file.
if ( $feedback ) {
$feedback = open (FEEDBACK, ">$feedback");
err("Cannot create $feedback: [$!]") unless $feedback;
}
}
sub wrap_up {
if ( $inited ) {
flush_line(); # flush pending output
$outdrv->wrapup($error_count);
close(FEEDBACK) if $feedback;
}
else {
print STDERR ("Empty document?\n");
}
if ( $error_count ) {
phase_msg("Errors detected = $error_count");
}
else {
phase_msg("Conversion completed") if $verbose;
}
}
sub warn {
my (@msg) = @_;
# Common trick: call error handler and decrement error counter.
err("Warning: ", @msg);
$error_count--;
}
sub err {
my (@text) = @_;
print STDERR ("\"$file\", line ", $., ": ", @text, "\n",
$current_line, "\n");
$error_count++;
}
$outdrv->emit_header($depth, $line, $tag);
}
$pending_style = $::STANDARD; # revert to standard style
}
sub tabcontrol {
my $result = $outdrv->emit_tab_control;
return 1 unless $result;
err("Table error: ", $result);
}
sub deblank {
my ($line) = @_;
# Discard leading and trailing white-space.
# Compress multiple white-space to single blanks.
$line = $' if $line =~ /^\s+/; # leading...
$line = $` if $line =~ /\s+$/; # ...trailing...
$line =~ s/\s+/ /g; # ...internal...
$line; # return
}
sub detab {
my ($line) = @_;
my (@l) = split (/\t/, $line);
# Replace tabs with blanks, retaining layout
$line = shift (@l);
$line .= " " x (8-length($line)%8) . shift(@l) while $#l >= 0;
$line;
}
sub decode_enriched {
local ($_) = @_;
s|<bold><italic>|\252bi\252|g;
s|</italic></bold>|\252~bi\252|g;
s|<italic>|\252i\252|g;
s|</italic>|\252~i\252|g;
s|<bold>|\252b\252|g;
s|</bold>|\252~b\252|g;
s|<underline>|\252u\252|g;
s|</underline>|\252~u\252|g;
s|<fixed>|\252t\252|g;
s|</fixed>|\252~t\252|g;
s|<<|<|g;
$_;
}
sub pathexpand {
my ($path, $mustexist) = @_;
local($[) = 0;
if ( $path =~ m|^~/| ) {
setpwent;
if ( defined ($home = $ENV{'HOME'} || $ENV{'LOGDIR'}
|| (getpwuid($>))[7]) ) {
$path = $home . '/' . $';
}
}
elsif ( $path =~ m|^~([^/]+)/| ) {
setpwent;
if ( defined ($home = (getpwnam($1))[7]) ) {
$path = $home . '/' . $';
}
}
if ($path !~ /^\//) {
chop ($wd = `pwd`);
$path = "$wd/$path";
}
for (;;) {
my $changes = 0;
my @components = split (/\//,$path);
prefix:
for (my $i = 1; $i <= $#components; $i++) {
if ($components[$i] eq ".") {
splice(@components, $i, 1);
}
elsif ($components[$i] eq "..") {
splice(@components, $i-1, 2);
}
elsif (-l ($prefix = join('/', @components[0 .. $i]))) {
($components[$i] = readlink $prefix) ||
die("Couldn't read $prefix ($!)\n");
if ($components[$i] =~ /^\//) {
splice(@components, 0, $i);
}
}
elsif ($mustexist && ! -e $prefix) {
return "";
}
else {
next prefix;
}
$changes = 1;
last prefix;
}
$path = join('/', @components);
if (!$changes) {
return $path;
}
}
}
( run in 1.661 second using v1.01-cache-2.11-cpan-ceb78f64989 )