"Fossies" - the Fresh Open Source Software Archive

Member "sendpage-1.001001/examples/configure-pc" (3 Jan 2008, 3700 Bytes) of package /linux/privat/old/sendpage-1.001001.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 use strict;
    3 use warnings;
    4 
    5 select STDOUT; $|=1;
    6 
    7 # TODO: make options
    8 
    9 my $PC="skytel";
   10 my $PAGER="osdl";
   11 my $CFG_REAL="/etc/sendpage.cf";
   12 my $CFG_TEST="/tmp/sendpage.cf"; # TODO: use real tmp file name
   13 
   14 my %cfg; # hash contained PC config under test
   15 
   16 # Uses globals $CFG_REAL, $CFG_TEST, and %cfg
   17 sub update_PC_config
   18 {
   19     print "Updating sendpage test configuration...\n";
   20 
   21     my %config = %cfg; # build a copy of the hash
   22     my $line;
   23 
   24     open(INPUT,"<$CFG_REAL") || die "$CFG_REAL: $!\n";
   25     open(OUTPUT,">$CFG_TEST") || die "$CFG_TEST: $!\n";
   26 
   27     # write everything until PC line
   28     while (($line=<INPUT>) !~ /^\[pc:$PC\]$/) {
   29         print OUTPUT $line;
   30     }
   31     print OUTPUT $line; # write PC line
   32 
   33     # process the parameters
   34     while (($line=<INPUT>) !~ /^\[/) {
   35         chomp($line);
   36         if ($line=~/^(\S+)\s*=\s*(.*)$/) {
   37             my ($name,$value)=($1,$2);
   38             
   39             # If the setting is different, set it
   40             if (defined($config{$name}) &&
   41                             $value ne $config{$name}) {
   42                 $line="$name = $config{$name}";
   43                 delete $config{$name};
   44             }
   45         }
   46         
   47         print OUTPUT $line,"\n";
   48     }   
   49     # Print remaining settings
   50     foreach my $name (sort keys %config) {
   51         print OUTPUT "$name = $config{$name}\n";
   52     }
   53 
   54     # print the next [] section
   55     print OUTPUT $line;
   56 
   57     # Write the rest of the file
   58     while ($line=<INPUT>) {
   59         print OUTPUT $line;
   60     }
   61 
   62     close(INPUT);
   63     close(OUTPUT);
   64 }
   65 
   66 sub stop_sendpage
   67 {
   68     system("sendpage -bs >/dev/null 2>&1");
   69 }
   70 
   71 sub restart_sendpage
   72 {
   73     stop_sendpage();
   74     system("sendpage -C $CFG_TEST -bd >/dev/null 2>&1");
   75 }
   76 
   77 sub send_test_page
   78 {
   79     my ($msg,$num)=@_;
   80     my $pretty="\t--- test page $num ---\n".$msg;
   81     $pretty=~s/\n/\n\t/g;
   82     $pretty.="\n\t--- end page $num ---";
   83 
   84     open(PAGE,"|snpp -n $PAGER") || die "snpp: $!\n";
   85     print PAGE $msg;
   86     close(PAGE);
   87 
   88     print "Sending page ...\n$pretty\n";
   89 }
   90 
   91 sub get_yes_no
   92 {
   93     print "[Y/n]: ";
   94     my $answer;
   95     
   96     while ($answer=<STDIN>) {
   97         chomp($answer);
   98         return 1 if ($answer=~/^([yY].*|$)/);
   99         return 0 if ($answer=~/^\s*[nN]/);
  100     }
  101     die "STDIN closed!\n";
  102 }
  103 
  104 sub Done
  105 {
  106     print "Your configuration adjustment should be:\n";
  107     foreach my $name (sort keys %cfg) {
  108         print "$name = $cfg{$name}\n";
  109     }
  110 
  111     stop_sendpage();
  112     exit(0);
  113 }
  114 
  115 my $msg;
  116 my $okay;
  117 
  118 ##############################
  119 update_PC_config();
  120 restart_sendpage();
  121 
  122 $msg="0:test page";
  123 send_test_page($msg,0);
  124 print "Did test page 0 get delivered and look correct?\n";
  125 $okay = get_yes_no();
  126 
  127 if ($okay) {
  128     print "Good.  You can send simple pages at least.  :)\n";
  129 }
  130 else {
  131     print "That's not good.  Better get sendpage configured correctly.\n";
  132     stop_sendpage();
  133     exit(1);
  134 }
  135 
  136 ##############################
  137 
  138 # Start by turning on esc'd characters via the 1.8 TAP spec
  139 $cfg{'esc'}="true";
  140 update_PC_config();
  141 restart_sendpage();
  142 
  143 $msg="1:This\nis a CR and this\tis a tab.";
  144 send_test_page($msg,1);
  145 print "Did test page 1 get delivered and look correct?\n";
  146 $okay = get_yes_no();
  147 
  148 if ($okay) {
  149     print "You're done!  Congratulations, you have a 1.8 TAP PC!\n";
  150     Done();
  151 }
  152 
  153 
  154 delete $cfg{'esc'};
  155 
  156 ##############################
  157 
  158 $cfg{'ctrl'}="true";
  159 update_PC_config();
  160 restart_sendpage();
  161 
  162 $msg="2:This\nis a CR and this\tis a tab.";
  163 send_test_page($msg,2);
  164 print "Did test page 2 get delivered with *both* the CR and tab shown correct?\n";
  165 $okay = get_yes_no();
  166 if ($okay) {
  167     print "You're done!  Your PC lets control characters through.\n";
  168     Done();
  169 }
  170 else {
  171     delete $cfg{'ctrl'};
  172 
  173     print "Did the CR show up correctly?\n";
  174     $okay = get_yes_no();
  175 
  176     if ($okay) {
  177         $cfg{'lfok'}='true';
  178         print "You're done!  You have an LF-okay PC!\n";
  179         Done();
  180     }
  181 }
  182 
  183 print "You're done!  Sorry, your PC doesn't allow control characters.  :(\n";
  184 Done();
  185 
  186 
  187 # TODO: Do length tests, but that tends to be pager-specific
  188 
  189