#!/usr/bin/env perl

#---------------------------------------------------------------------
#                          file information
#---------------------------------------------------------------------

# File:     fixtermcap-screen
# Purpose:  Removes "screen" entries from "/etc/termcap"
# License:  BSD
# Revision: 070205

#---------------------------------------------------------------------
#                            module setup
#---------------------------------------------------------------------

require 5.6.1;
use strict;
use Carp;
use warnings;
                                # Trap warnings
$SIG {__WARN__} = sub { die @_; };

#---------------------------------------------------------------------
#                           basic constants
#---------------------------------------------------------------------

use constant ZERO  => 0;        # Zero
use constant ONE   => 1;        # One

use constant FALSE => 0;        # Boolean FALSE
use constant TRUE  => 1;        # Boolean TRUE

#---------------------------------------------------------------------
#                         program parameters
#---------------------------------------------------------------------

                                # Data-file pathname (may be relative)
my $DFNAME = '/etc/termcap';

#---------------------------------------------------------------------
#                            main routine
#---------------------------------------------------------------------

sub Main
{
    my $data;                   # Data buffer

#ifdef NOTDEF
#   my $str = $ENV {'LACSYSTREE'};
#   die unless defined ($str) && length ($str);
#   $DFNAME = "$str$DFNAME";
#endif

    open (IFD, "<$DFNAME") ||
        die "Error: Can't open file for reading: $!\n$DFNAME\n";
    binmode IFD;
    undef $/;
    $data = <IFD>;
    $data = "" if !defined $data;
    close IFD;

    $data =~ y/\001//d;
    $data =~ s@\015+\012@\n@g;
    while ($data =~ s@\n\S+?\|screen-?\w*\|.*?:\s*\n@\n@gs) {}

                                # Consistency check
    die "fixtermcap-screen: Internal error\n" if $data =~ m@\001@;

    open (OFD, ">$DFNAME") ||
        die "Error: Can't open file for writing: $!\n$DFNAME\n";
    binmode OFD;
    print OFD $data;
    close OFD;
    undef;
}

#---------------------------------------------------------------------
#                            main program
#---------------------------------------------------------------------

&Main();                        # Call the main routine
exit ZERO;                      # Normal exit
