Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Štvrtok, 18. apríl 2024

Súbor: [Platon] / scripts / ep / pwdhide / pwdhide.pl (stiahnutie)

Revízia 1.3, Wed Jun 26 13:35:59 2002 UTC (21 years, 9 months ago) by jombik9


Zmeny od 1.2: +39 -34 [lines]

pwdhide.pl reimplmentation; string (regexp) to hide is passed as first
  argument on command line
configuration files changed according to previous changes

#!/usr/bin/perl -w
use strict;

#############################################################################
#                                                                           #
#  pwdhide.pl                                                               #
#                                                                           #
#  Keyboard echo on terminal (TTY) screen switcher.                         #
#  Prepina medzi pisanim/nepisanim klavesnice na obrazovku terminalu.       #
#                                                                           #
#                                                     Wolcano [13/03/2002]  #
#                                                       Nepto [24/06/2002]  #
#                                                                           #
#############################################################################

#
# output (1 or 0)
#
my $OUTPUT = 0;

#
# verbose (1 or 0)
#
my $VERBOSE = 1;

#############################################################################

#
# program name
#
my $PRG = __FILE__;

#
# silenced flag
#
my $SIL = 0;

#
# parent process ID (PID)
#
my $PPID = getppid();

#
# parent terminal (TTY)
#
my $TTY = `ps --no-headers -otty '$PPID'`;
chomp $TTY;    # to remove ending newline

#
# command variables
#
my $CMD_BASE = "stty --file '/dev/$TTY'";

#
# do_stty() subroutine
#
sub do_stty
{
    my $cmd;
    my $onoff;

    if ($SIL) {
        $onoff = 'on';
        $cmd   = "$CMD_BASE echo";
    } else {
        $onoff = 'off';
        $cmd   = "$CMD_BASE -echo";
    }

    system($cmd);
    print STDERR "$PRG: turning $onoff echo ($cmd)\n" if $VERBOSE;

    $SIL = !$SIL;
}

#
# line variables
#
my $input_data;
my $raw_line;
my $line;

#
# command line parameters test (@ARGV doesn't contain program name)
#
if (scalar(@ARGV) < 1) {
    print("pwdhide.pl - written and copyrights by Nepto & Wolcano\n");
    print("Usage: $PRG <regexp-to-hide>\n");
    exit 1;
}

#
# string to hide
#
my $STR = $ARGV[0];

#
# System init
#
select(STDIN);  $| = 1;    # make unbuffered
select(STDERR); $| = 1;    # make unbuffered
select(STDOUT); $| = 1;    # make unbuffered

print STDERR "$PRG: starting...\n" if $VERBOSE;

#
# main loop
#
while ( $input_data = <STDIN> ) {
    foreach $raw_line ( split ( /\n/, $input_data ) ) {
        $line = $raw_line;
        $line =~ s/^\s*//g;
        $line =~ s/\s*$//g;
        next if !length($line);

        do_stty() if ($SIL != 0);
        do_stty() if ( $SIL == 0 && $line =~ /$STR/ );

        # print '*******************'.$_."%%\n" if $OUTPUT;
        print STDOUT $raw_line if $OUTPUT;
    }
}

# restore input echo if it is turned off
do_stty() if ($SIL != 0);

print STDERR "$PRG: terminating...\n" if $VERBOSE;


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok