#!/usr/local/bin/perl 
#
# Copyright (C) 1992 by Gustaf Neumann, Stefan Nusser
#
#      Wirtschaftsuniversitaet Wien,
#      Abteilung fuer Wirtschaftsinformatik
#      Augasse 2-6,
#      A-1090 Vienna, Austria
#      neumann@wu-wien.ac.at, nusser@wu-wien.ac.at
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appears in all copies and that both that
# copyright notice and this permission notice appear in all supporting
# documentation.  This software is provided "as is" without expressed or
# implied warranty.
#
# Date: Mon, Apr 13 1992
# Author: Gustaf Neumann
# Version: 0.9
#

$options = "u:";
$WafeLib = $ENV{'WAFELIB'} || "/usr/lib/X11/wafe";
require "$WafeLib/perl/wafe.pl";

$sharefile = '/mount/dec4/usr/tmp/common';
$lockfile = "$sharefile.LOCK";

chop($host = `/bin/hostname`);
$head =  '\n *****  Projiziert von '.$ENV{'USER'}.' auf '.$host.' *****\n';


&UI( <<"End of Wafe");
   Form basis topLevel defaultDistance 3

      Label title basis width 600 label {X-Projektor} $infoColors

      Viewport vport basis \\
	    width 600 height 300 allowVert true allowHoriz true fromVert title

      Text ausgabe vport \\
	    type file string $sharefile \\
	    scrollHorizontal whenNeeded scrollVertical whenNeeded \\
	    $textFont $roColors displayCaret false

      Command quit basis \\ 
            label Quit callback {echo %w} $buttonAtts \\
            fromVert vport 

      Command projekt basis \\
           label Projektion  callback {echo %w} $buttonAtts \\
           fromVert vport fromHoriz quit

    realize; deleteWindowProtocol quit

proc print {string fname} { \\
    set f [open \$fname w]; \\
    puts \$f \$string; \\
    close \$f;}
End of Wafe


#        ($odev,$oino,$omode,$onlink,$ouid,$ogid,$ordev,$osize,
#         $oatime,$omtime,$octime,$oblksize,$oblks) = stat($sharefile);
$octime = 0;


while (1) {
    $_ = &wafe'readTimeout($opt_u);

    if (/^projekt/) {
	  while (stat($lockfile)) { select(undef, undef, undef, 1); }

	  open(LOCKFILE,">$lockfile");
	  print LOCKFILE "\n";
	  close LOCKFILE;

	  open(SHAREFILE,">$sharefile");
	  print SHAREFILE $header;
	  close(SHAREFILE);

          &Xui("getSelectionValue {print  \"$head\$PRIMARY\" {$sharefile}; echo unlink}");
#	  system "/usr/bin/X11/xselection PRIMARY >> $sharefile";

	  unlink $lockfile;
      }

     if (/^unlink/) {
	  unlink $lockfile;
     } 

     if (/^quit/) {
         unlink $lockfile;  #save is save
         last;
     }

     next if stat($lockfile);
     ($ndev,$nino,$nmode,$nnlink,$nuid,$ngid,$nrdev,$nsize,
     $natime,$nmtime,$nctime,$nblksize,$nblks) = stat($sharefile);

     if ($nctime > $octime) {
	 &Xui("sV ausgabe string $sharefile");
	 $octime = $nctime;
     }

}
&Xui("quit");



