home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / pt.shar / pt / Configure next >
Encoding:
Text File  |  1993-05-26  |  4.2 KB  |  187 lines

  1.  
  2. $STD_PERL = '/usr/bin/perl';
  3.  
  4. select(STDERR);
  5.  
  6. print "Configuring pt...\n\n";
  7.  
  8. sub findpath {
  9.     local($path);
  10.     local($arg) = shift;
  11.     for $dir (split(/:/,$ENV{'PATH'})) {
  12.     if (-x "$dir/$arg" && -f _) {
  13.         $path = "$dir/$arg";
  14.         last;
  15.     } 
  16.     } 
  17.     $path;
  18. }
  19.  
  20. &getperl();
  21.  
  22. if ($path = &findpath('ps')) {
  23.     $PS = $path;
  24.     print "Your ps lives in $path.\n";
  25. } else {
  26.     die "You don't have a ps on this system, bailing out";
  27.  
  28. $DEATH_STAR = 0;
  29. $FLAG_WIDTH = 0;
  30.  
  31. $_ = `$PS l1 2>/dev/null`;
  32. if ($?) {
  33.     # maybe system V
  34.     $_ = `$PS -ef -p 1 2>/dev/null`;
  35.     if ($? == 0) {
  36.     $DEATH_STAR = 1;
  37.     print "You have a SysV-style ps; this may be boring.\n";
  38.     } else {
  39.     print "Your ps doesn't like either BSD or SysV syntax!\n";
  40.     } 
  41. } else {
  42.     print "Congratulations, your ps groks BSD syntax.\n";
  43.  
  44.     if (/^\s*F/) {
  45.     if (!/\n(\s*[a-f\d]+)/) {
  46.         print "No flag width -- assuming 7\n";
  47.         $FLAG_WIDTH = 7;
  48.     } else {
  49.         $FLAG_WIDTH = length($1);
  50.         print "Your ps flags width appears to be $FLAG_WIDTH.\n";
  51.         if (/F\s+S\s+UID/) {
  52.         print "Your ps interposes STAT between FLAGS and UID\n";
  53.         $early_stat++;
  54.         } 
  55.     }
  56.     } else {
  57.     # bsd 4.4?
  58.     print <<EOF;
  59. But you have no ps flags; don't worry, you're 
  60. proabably better off that way.
  61. EOF
  62.     } 
  63.  
  64. $FIRST_SPLIT = $DEATH_STAR   # cursed be
  65.         ? '^\s*([\da-fA-F]+)\s+\S+\s+([\-\d]+)\s+(\d+)\s+(\d+)'
  66.         : $FLAG_WIDTH 
  67.             ? $early_stat
  68.             ? '^(\s*[\da-fA-F]+)\s*\w+\s*([\-\d]+)\s+(\d+)\s+(\d+)'
  69.             : '^(\s*[\da-fA-F]+)\s*([\-\d]+)\s+(\d+)\s+(\d+)'
  70.             : '^(\s*)([\da-fA-F]+)\s*([\-\d]+)\s+(\d+)\s+(\d+)';
  71.  
  72. print "\n";
  73.  
  74. $PROG = 'getwin.c';
  75.  
  76. open(PROG, ">$PROG") || die "can't creat $PROG: $!";
  77. print PROG <<'EOF';
  78. #include <sys/ioctl.h>
  79. main() { printf("0x%08x\n", TIOCGWINSZ); } 
  80. EOF
  81. close(PROG) || die "can't close $PROG: $!";
  82.  
  83. unless ($CC_PATH = &findpath('cc')) {
  84.     print "No C compiler found, trying gcc\n";
  85.     if ($CC_PATH = &getpath('gcc'))  {
  86.     print "What luck -- you have a gcc\n";
  87.     } else {
  88.     print "SNAFU: No C compiler -- guessing TIOCGWINSZ is 0x40087468\n";
  89.     $TIOCGWINSZ = 0x40087468;
  90.     if (ioctl(STDERR, $TIOCGWINSZ, $winsize)) {
  91.         ($rows, $cols) = unpack('S4', $winsize);
  92.         if ($cols > 20 && $cols < 200) { 
  93.         print "Ok, TIOCGWINSZ seems ok as 0x40087468\n";
  94.         $TIOCGWINSZ = '0x40087468';
  95.         } else {
  96.     print "TIOCGWINSZ doesn't seem to work, will grope environment\n";
  97.         } 
  98.     } 
  99.     } 
  100. } else {
  101.     print "Your C compiler lives in $CC_PATH.\n";
  102.  
  103.     print "Testing for window-size awareness...";
  104.     if (system("$CC_PATH getwin.c >/dev/null 2>&1") == 0) {
  105.     print "done.\n";
  106.     chop($TIOCGWINSZ = `./a.out`);
  107.     print "Great -- your TIOCGWINSZ is $TIOCGWINSZ.\n";;
  108.     } else {
  109.     print "oops!\n";
  110.     print "Bummer -- you have no TIOCGWINSZ!\n";
  111.     $TIOCGWINSZ = 0;
  112.     } 
  113.  
  114.     unlink('a.out', $PROG);
  115. }
  116.  
  117. select(STDOUT);
  118.  
  119. while (<>) {
  120.     if (s/#\$\$#\s*//) {
  121.     s/TIOCGWINSZ\s*=[^;]*/TIOCGWINSZ = $TIOCGWINSZ/o 
  122.         ||
  123.     s/PS\s*=\s*\"[^"]*"/PS = "$PS"/o
  124.         ||
  125.     s/DEATH_STAR\s*=[^;]*/DEATH_STAR = $DEATH_STAR/o 
  126.         ||
  127.     s/FLAG_WIDTH\s*=[^;]*/FLAG_WIDTH = $FLAG_WIDTH/o 
  128.         ||
  129.     s/FIRST_SPLIT\s*=[^;]*/FIRST_SPLIT = '$FIRST_SPLIT'/o 
  130.         ;
  131.     }
  132.     print;
  133. close(STDOUT) || die "can't close STDOUT: $!";
  134.  
  135.  
  136.  
  137.  
  138. print STDERR "\nDone with Configure.\n\n";
  139. exit;
  140.  
  141. sub getperl {
  142.     if (-e $STD_PERL && -f _ && -x _) { # stat, !lstat
  143.     print <<EOF;
  144. Good, I see that perl lives in the standard place ($STD_PERL)
  145. EOF
  146.     print "How 'bout I use that one, ok? [y] ";
  147.     open(TTY, "</dev/tty") || die "can't open /dev/tty: $!";
  148.     if (<TTY> !~ /^\s*n/i)  {
  149.         print STDOUT "#!$STD_PERL\n";
  150.         print "\n";
  151.         return;
  152.     } 
  153.     print "Ok, fine, let's grope about your system then...\n";
  154.     } else {
  155.     $whine++;
  156.     } 
  157.  
  158.     if ($path = &findpath('perl')) {
  159.     print "Your perl lives in $path.\n";
  160.     print STDOUT "#!$path\n";
  161.     $whine && print <<EOF;
  162.  
  163. You know, life would be easier if you just made $STD_PERL 
  164. a symlink to where it where it really lives.
  165. EOF
  166.     } else {
  167.     print <<EOF;
  168.  
  169. What, no perl on your system?  Then just who is running this script?  
  170. Ok, we'll configure up your script so it tries to find whatever perl is
  171. in the user's path, something you don't seem to have.
  172.  
  173. EOF
  174.     print STDOUT <<'EOF';
  175. #!/bin/sh -- # wish we had a perl
  176. eval "exec perl -S $0 $*"
  177.     if $running_under_some_shell;
  178.  
  179. EOF
  180.     }
  181.     print "\n";
  182. }
  183.  
  184.