home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / xap / gchess / xboard-3.0 / xboard-3 / xboard-3.0.pl9 / cmail < prev    next >
Text File  |  1993-09-05  |  40KB  |  1,011 lines

  1. #!/usr/local/bin/perl
  2. ## (Change the top line to reflect the location of perl on your system)
  3. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  4. ## cmail 1.0: a tool to aid playing chess by email
  5. ## Copyright (C) 1993  Free Software Foundation, Inc.
  6. ##
  7. ## cmail is free software; you can redistribute it and/or modify
  8. ## it under the terms of the GNU General Public License as published by
  9. ## the Free Software Foundation; either version 2 of the License, or
  10. ## (at your option) any later version.
  11. ##
  12. ## cmail is distributed in the hope that it will be useful,
  13. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ## GNU General Public License for more details.
  16. ##
  17. ## You should have received a copy of the GNU General Public License
  18. ## along with cmail; if not, write to the Free Software
  19. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ##
  21. ## Modified:  $Date: 1993/09/05 11:25:01 $
  22. ## Revision:  $Revision: 1.27 $
  23. ## Email:     welsh@epcc.ed.ac.uk
  24. ## Snailmail: Evan Welsh
  25. ##            Edinburgh Parallel Computing Centre
  26. ##            JCMB, Kings Buildings
  27. ##            The University of Edinburgh
  28. ##            Edinburgh EH9 3JZ
  29. ##            Scotland
  30. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  31.  
  32.  
  33. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  34. ## Print verbose diagnostics for debugging
  35. sub debug {
  36.     if ($DEBUG) {
  37.     $old = select ;        ## Remember the selected output 
  38.     select(logfile) ;    ## Diagnostics go to logfile
  39.     $| = 1 ;        ## Keep it flushed
  40.     for ($i = 0 ; $i <= $#_ ; $i ++) {
  41.         printf($_[$i]) ;    ## Print one or more diagnostic messages
  42.     }
  43.     select($old) ;        ## Re-select the old output
  44.     }
  45. }
  46. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  47.  
  48.  
  49. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  50. ## Create a directory for storing games in if it doesn't already exist
  51. sub need_chess_dir {
  52.     ## ################################################################# ##
  53.     ## Check for existence of the named chess directory
  54.     ## ################################################################# ##
  55.  
  56.     if (! (-d "$CHESSDIR")) {
  57.  
  58.     ## ############################################################# ##
  59.     ## Ask user for confirmation if attached to tty
  60.     ## ############################################################# ##
  61.  
  62.     if (-t) {
  63.         $old = select ;    ## Remember selected output
  64.         select(stdout) ;    ## Write to standard output
  65.         $| = 1 ;        ## Keep it flushed
  66.         printf("Chess directory <$CHESSDIR> does not exist.") ;
  67.         printf(" Create it? [y/q]: ");
  68.  
  69.         $_ = <tty> ;    ## Read response from tty
  70.         if (/^[qQ].*/) {
  71.         die "Bye!\n" ;    ## Quit if q selected
  72.         }
  73.  
  74.         select($old) ;    ## Re-select the old output
  75.     }
  76.  
  77.     ## ############################################################# ##
  78.     ## Create a chess directory or die
  79.     ## ############################################################# ##
  80.  
  81.     die "Can't create directory: $CHESSDIR\n"
  82.         unless mkdir("$CHESSDIR", 511) ;
  83.     printf("Created chess directory <$CHESSDIR>.\n") ;
  84.     printf("You can move it but remember to set the CMAIL_DIR") ;
  85.     printf(" environment variable.\n") ;
  86.     }
  87.  
  88.     ## ################################################################# ##
  89.     ## Change to the $CHESSDIR directory whether newly created or not
  90.     ## ################################################################# ##
  91.  
  92.     chdir "$CHESSDIR" ;
  93. }
  94. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  95.  
  96.  
  97. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  98. ## Parse command-line arguments
  99. sub parse_flags {
  100.     ## ################################################################# ##
  101.     ## Set up defaults from the environment or from hard-wired constants
  102.     ## ################################################################# ##
  103.  
  104.     $SHOWC       = 0 ;
  105.     $SHOWW       = 0 ;
  106.     $LOGFILE     = "&STDERR" ;
  107.     $CHESSDIR     = $ENV{'CMAIL_DIR'} ;
  108.     $CHESSDIR     = $ENV{'CHESSDIR'}     if ("" eq "$CHESSDIR") ;
  109.     $CHESSDIR     = "$ENV{'HOME'}/Chess" if ("" eq "$CHESSDIR") ;
  110.     $CHESSDIR     = "~/Chess"            if ("" eq "$CHESSDIR") ;
  111.     $ALIAS_FILE     = $ENV{'CMAIL_ALIASES'} ;
  112.     $ALIAS_FILE     = ".cmailaliases" if("" eq $ALIAS_FILE) ;
  113.     $GAMES_FILE     = $ENV{'CMAIL_GAMES'} ;
  114.     $GAMES_FILE     = ".cmailgames" if("" eq $GAMES_FILE) ;
  115.     $TIME_DELAY     = $ENV{'CMAIL_TIME_DELAY'} ;
  116.     $TIME_DELAY     = 0 if("" eq $TIME_DELAY) ;
  117.     $ME         = $ENV{'CMAIL_ADDRESS'} ;
  118.     $ME         = $ENV{'LOGNAME'} if("" eq $ME) ;
  119.     $SEND_MAIL   = 1 ;
  120.     $LOAD_XBOARD = 1 ;
  121.  
  122.     ## ################################################################# ##
  123.     ## Define the usage string
  124.     ## ################################################################# ##
  125.  
  126.     $USAGE = "cmail [-c] [-w] [-v] [-[no]mail] [-[no]xboard] [-remail]"
  127.     . " [-game name] [-me name] [-opp name] [-oppaddr address]"
  128.         . " [-dir directory] [-gamesfile file] [-aliasesfile file]"
  129.         . " [-logfile file] [-td delay]" ;
  130.  
  131.     ## ################################################################# ##
  132.     ## Overwrite defaults if specified on the command-line
  133.     ## ################################################################# ##
  134.  
  135.     while ($ARGV = shift) {
  136.     if    ("$ARGV" eq "-c")          {$SHOWC       = 1     ;}
  137.     elsif ("$ARGV" eq "-w")          {$SHOWW       = 1     ;}
  138.     elsif ("$ARGV" eq "-v")          {$DEBUG       = 1     ;}
  139.     elsif ("$ARGV" eq "-mail")      {$SEND_MAIL   = 1     ;}
  140.     elsif ("$ARGV" eq "-nomail")      {$SEND_MAIL   = 0     ;}
  141.     elsif ("$ARGV" eq "-xboard")      {$LOAD_XBOARD = 1     ;}
  142.     elsif ("$ARGV" eq "-noxboard")      {$LOAD_XBOARD = 0     ;}
  143.     elsif ("$ARGV" eq "-remail")      {$LOAD_XBOARD = 0     ;
  144.                        $SEND_MAIL   = 1     ;}
  145.     elsif ("$ARGV" eq "-game")      {$GAME_NAME   = shift ;}
  146.     elsif ("$ARGV" eq "-me")      {$ME          = shift ;}
  147.     elsif ("$ARGV" eq "-opp")      {$OPP_NAME    = shift ;}
  148.     elsif ("$ARGV" eq "-oppaddr")      {$OPP_ADDRESS = shift ;}
  149.     elsif ("$ARGV" eq "-dir")      {$CHESSDIR    = shift ;}
  150.     elsif ("$ARGV" eq "-gamesfile")   {$GAMES_FILE  = shift ;}
  151.     elsif ("$ARGV" eq "-aliasesfile") {$ALIAS_FILE  = shift ;}
  152.     elsif ("$ARGV" eq "-logfile")     {$LOGFILE     = shift ;}
  153.     elsif ("$ARGV" eq "-td")          {$TIME_DELAY  = shift ;}
  154.     else {
  155.         die("Unrecognised flag <$ARGV>\nUsage: $USAGE\n");
  156.     }
  157.     }
  158. }
  159. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  160.  
  161.  
  162. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  163. ## Initialisation of variables and environment
  164. sub showGPL {
  165.     ## ################################################################# ##
  166.     ## Show copyright notice
  167.     ## ################################################################# ##
  168.  
  169.     while(<DATA>) {
  170.     last if(/^{END OF GPL COPYRIGHT}$/) ;
  171.     $_ =~ s/\$Revision[:] (.*) \$/$1/ ;
  172.     print ;
  173.     }
  174.     
  175.     ## ################################################################# ##
  176.     ## Show conditions if requested
  177.     ## ################################################################# ##
  178.  
  179.     while(<DATA>) {
  180.     last if(/^{END OF GPL CONDITIONS}$/) ;
  181.     if($SHOWW) {
  182.         print ;
  183.     }
  184.     }
  185.  
  186.     ## ################################################################# ##
  187.     ## Show warranty if requested
  188.     ## ################################################################# ##
  189.  
  190.     if ($SHOWC) {
  191.     if($SHOWW) {
  192.         printf("\n") ;
  193.     }
  194.     while(<DATA>) {
  195.         print ;
  196.     }
  197.     }
  198.  
  199.     if ($SHOWC || $SHOWW) {
  200.     exit ;            ## Abort if showed conditions or warranty
  201.     }
  202. }
  203. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  204.  
  205.  
  206. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  207. ## Initialisation of variables and environment
  208. sub initialise {
  209.     $FLIP = "false" ;        ## The board is not flipped by default
  210.     
  211.     &parse_flags(@ARGV) ;    ## Parse command-line arguments
  212.  
  213.     &showGPL ;
  214.  
  215.     open(tty, "< /dev/tty") ;    ## Open tty for reading
  216.  
  217.     &need_chess_dir() ;        ## Check for the existence of CHESSDIR
  218.  
  219.     if ($DEBUG) {
  220.     open (logfile, ">$LOGFILE") ; ## Default is STDERR
  221.     }
  222.  
  223.     &debug("Called <initialise>\n") ;
  224. }
  225. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  226.  
  227.  
  228. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  229. ## Prompt for a game name, if <cr> use a default
  230. sub prompt_for_game_name {
  231.     &debug("Called <prompt_for_game_name>\n") ;
  232.     $old = select ;        ## Remember the selected output
  233.     select(stdout);        ## Diagnostics go to logfile
  234.     $| = 1 ;            ## Keep it flushed
  235.  
  236.     printf("Game name [<cr> to use default]: ") ;
  237.     die "cmail: tty not open\n" unless (-t) ;
  238.     <tty> =~ /(.*)/ ;        ## Read line from tty
  239.     $GAME_NAME = "$1" ;        ## Assign to game name
  240.  
  241.     select($old) ;        ## Re-select the old output
  242. }
  243. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  244.  
  245.  
  246. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  247. ## Get opponent's address
  248. sub find_opp_address_in_game_file {
  249.     &debug("Called <find_opp_address_in_game_file> game name",
  250.        " <$GAME_NAME>\n") ;
  251.     if (! ("" eq "$GAME_NAME")) { ## Can't find it without the game name
  252.  
  253.     ## ############################################################# ##
  254.     ## Open the game file and read all the entries
  255.     ## ############################################################# ##
  256.  
  257.     if (open(GAMES_IN, "< $GAMES_FILE")) {
  258.  
  259.         while(<GAMES_IN>) {
  260.         if ($_ =~ /^<$GAME_NAME>\s*(.*)\s*$/) {    ## Match!
  261.             $OPP_ADDRESS = $1 ;    ## Found opponent's address
  262.         }
  263.         }
  264.  
  265.         if ("" eq $OPP_ADDRESS) { 
  266.         $SAVE_ADDRESS = 1 ; ## Save the address when it is found
  267.         }
  268.  
  269.     } else {        ## Game file doesn't exist yet
  270.         $SAVE_ADDRESS = 1 ;    ## Save the address when it is found
  271.     }
  272.     }
  273. }
  274. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  275.  
  276.  
  277. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  278. ## Get opponent's address
  279. sub find_game_in_game_file {
  280.     &debug("Called <find_game_in_game_file> opp address",
  281.        " <$OPP_ADDRESS>\n") ;
  282.     if ("" ne "$OPP_ADDRESS") { ## Can't find it without the opp address
  283.  
  284.     ## ############################################################# ##
  285.     ## Open the game file and read all the entries
  286.     ## ############################################################# ##
  287.  
  288.     if (open(GAMES_IN, "< $GAMES_FILE")) {
  289.         while(<GAMES_IN>) {
  290.         if ($_ =~ /^<(.*)>\s*$OPP_ADDRESS\s*$/) {
  291.             $GAME_NAME = $1 ; ## Match!
  292.         }
  293.         }
  294.     } else {
  295.         $SAVE_ADDRESS = 1 ; ## Save the address when it is found
  296.         $GAME_NAME    = "$ME-VS-$OPP_NAME" ; ## Construct default name
  297.     }
  298.     }
  299.     ## ################################################################# ##
  300.     ## Failed to find the game name so construct a default from players
  301.     ## ################################################################# ##
  302.  
  303.     if ("" eq $GAME_NAME) {
  304.     $SAVE_ADDRESS = 1 ;    ## Save the address when it is found
  305.     $GAME_NAME    = "$ME-VS-$OPP_NAME" ; ## Construct default name
  306.     }
  307. }
  308. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  309.  
  310.  
  311. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  312. ## Prompt for opponent's address
  313. sub prompt_for_opp_address {
  314.     &debug("Called <prompt_for_opp_address>\n") ;
  315.  
  316.     ## ################################################################# ##
  317.     ## Prompt for opponent's email address
  318.     ## ################################################################# ##
  319.  
  320.     printf("Opponent's email address: ") ;
  321.     die "cmail: tty not open\n" unless (-t) ;
  322.     <tty> =~ /(.*)/ ;
  323.     $OPP_ADDRESS = $1 ;
  324.  
  325.     ## ################################################################# ##
  326.     ## Use name as default if still blank
  327.     ## ################################################################# ##
  328.  
  329.     if ("" eq $OPP_ADDRESS) {
  330.     $OPP_ADDRESS = $OPP_NAME ;
  331.     }
  332.  
  333.     ## ################################################################# ##
  334.     ## Add the alias to the alias file
  335.     ## ################################################################# ##
  336.  
  337.     if ($ADD_ALIAS == 1) {
  338.     printf("Adding alias <$OPP_NAME = $OPP_ADDRESS>.\n") ;
  339.     die "Can't open file: $ALIAS_FILE\n"
  340.         unless open(ALIASES_OUT, ">> $ALIAS_FILE") ;
  341.     select(ALIASES_OUT) ;
  342.     printf("$OPP_NAME\t=\t$OPP_ADDRESS\n") ;
  343.     close(ALIASES_OUT) ;
  344.     select(stdout) ;
  345.     }
  346. }
  347. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  348.  
  349.  
  350. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  351. ## Prompt for opponent's name
  352. sub prompt_for_opp_name {
  353.     &debug("Called <prompt_for_opp_name>\n") ;
  354.     $old = select ;        ## Remember the selected output 
  355.     select(stdout) ;        ## Write to stdout
  356.     $| = 1 ;            ## Keep it flushed
  357.     printf("Opponent's name: ") ;
  358.  
  359.     die "cmail: tty not open\n" unless (-t) ; ## Check tty is open
  360.     <tty> =~ /(.*)/ ;        ## Read line from tty
  361.     $OPP_NAME = $1 ;        ## Match!
  362.     die "I can't proceed without the opponent's name.\n"
  363.     if ("" eq $OPP_NAME) ;
  364.  
  365.     select($old) ;        ## Re-select the old output
  366. }
  367. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  368.  
  369.  
  370. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  371. ## Search for opponent's name in alias file if it exists
  372. sub find_opp_address_in_alias_file {
  373.     &debug("Called <find_opp_address_in_alias_file> opp name <$OPP_NAME>\n") ;
  374.  
  375.     ## ################################################################# ##
  376.     ## Check the alias file exists
  377.     ## ################################################################# ##
  378.  
  379.     if (-f "$ALIAS_FILE") {
  380.     ## ############################################################# ##
  381.     ## Open alias file and read all the entries
  382.     ## ############################################################# ##
  383.  
  384.     die "Can't open file: $ALIAS_FILE\n"
  385.         unless open(ALIASES_IN, "< $ALIAS_FILE") ;
  386.     while (<ALIASES_IN>) {
  387.         if (/$OPP_NAME\s*=\s*(.*)/) {
  388.         $OPP_ADDRESS = $1 ; ## Match!
  389.         }
  390.     }
  391.  
  392.     ## ############################################################# ##
  393.     ## Check if we should save the new address in the alias file
  394.     ## ############################################################# ##
  395.  
  396.     if ("" eq $OPP_ADDRESS) {
  397.         $ADD_ALIAS = 1 ;    ## Remember to add new alias to alias file
  398.     }
  399.  
  400.     close(ALIASES_IN) ;    ## Close alias in file
  401.     } else {
  402.     $ADD_ALIAS = 1 ;    ## Remember to add new alias to alias file
  403.     }
  404. }
  405. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  406.  
  407.  
  408. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  409. ## Add this game to the list of games in the game file
  410. sub add_game_to_game_file {
  411.     &debug("Called <add_game_to_game_file>\n") ;
  412.  
  413.     ## ################################################################# ##
  414.     ## Append address to game file
  415.     ## ################################################################# ##
  416.  
  417.     if ($SAVE_ADDRESS) {
  418.     die "Can't open file: $GAMES_FILE\n" ## Open the file or die
  419.         unless open(GAMES_OUT, ">> $GAMES_FILE") ;
  420.     select(GAMES_OUT) ;    ## Write to games file
  421.     printf("<$GAME_NAME> $OPP_ADDRESS\n") ;    ## Make the entry
  422.     close(GAMES_OUT) ;    ## Close games file
  423.     }
  424.  
  425.     select(STDOUT) ;        ## Re-select STDOUT
  426. }
  427. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  428.  
  429.  
  430. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  431. ## Load the game
  432. sub play_game {
  433.     &debug("Called <play_game>\n") ;
  434.     $| = 1 ;            ## Start flushing output buffer
  435.  
  436.     ## ################################################################# ##
  437.     ## Load xboard unless inhibited by command-line arguments
  438.     ## ################################################################# ##
  439.  
  440.     if ($LOAD_XBOARD) {
  441.     ## ############################################################# ##
  442.     ## Remove output files from orevious run
  443.     ## ############################################################# ##
  444.  
  445.     system("rm -f $GAME_NAME.pos.out $GAME_NAME.game.out") ;
  446.     printf("Loading xboard for game <$GAME_NAME>...") ;
  447.  
  448.     ## ############################################################# ##
  449.     ## Invoke xboard with loads of flags
  450.     ## ############################################################# ##
  451.  
  452.       system(  "xboard"
  453.            . " -cmail"
  454.            . " -flipView $FLIP"
  455.            . " -ncp"
  456.            . " -td $TIME_DELAY"
  457.            . " -lgf $GAME_NAME.game.in"
  458.            . " -sgf $GAME_NAME.game.out"
  459.            . " -spf $GAME_NAME.pos.out") ;
  460.  
  461.     ## ############################################################# ##
  462.     ## The flags for older versions of xboard are commented out below 
  463.     ## ############################################################# ##
  464.  
  465. #       system(  "xboard"
  466. #             . " -cmail true"
  467. #             . " -flip $FLIP"
  468. #             . " -ncp    true"
  469. #             . " -td $TIME_DELAY"
  470. #             . " -lgf $GAME_NAME.game.in"
  471. #             . " -sgf $GAME_NAME.game.out"
  472. #             . " -spf $GAME_NAME.pos.out") ;
  473.  
  474.     printf("done.\n") ;
  475.     } else {
  476.     printf("Bypassing xboard (as requested).\n") ; ## On command-line
  477.     }
  478. }
  479. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  480.  
  481.  
  482. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  483. ## Find the game the user wants by any means possible
  484. sub find_game {
  485.     &debug("Called <find_game>\n") ;
  486.  
  487.     ## ################################################################# ##
  488.     ## Ask user for a game name if not already known
  489.     ## ################################################################# ##
  490.  
  491.     if ("" eq "$GAME_NAME") {
  492.     &prompt_for_game_name() ;
  493.     }
  494.  
  495.     ## ################################################################# ##
  496.     ## Find out opponent's details
  497.     ## ################################################################# ##
  498.  
  499.     if ("" eq "$GAME_NAME") {
  500.     if ("" eq "$OPP_NAME") {
  501.         &prompt_for_opp_name() ; ## Ask user for opponent's name
  502.     }
  503.     &find_opp_address_in_alias_file() ; ## Find opp address in aliases
  504.     &find_game_in_game_file() ; ## Find game name in game file
  505.     } else {
  506.     &find_opp_address_in_game_file() ; ## Find opp address in game file
  507.     if ("" eq "$OPP_ADDRESS") {
  508.         $OPP_ADDRESS = $RETURN_ADDRESS ; ## Use return address instead
  509.     }
  510.     if ("" eq "$OPP_ADDRESS") {
  511.         &prompt_for_opp_name() ; ## Ask user for opponent's name
  512.     }
  513.     }
  514.  
  515.     ## ################################################################# ##
  516.     ## Finally ask user for missing details as a last resort
  517.     ## ################################################################# ##
  518.  
  519.     if ("" eq "$OPP_ADDRESS") {
  520.     &find_opp_address_in_alias_file() ; ## Find opp address in aliases
  521.     if ("" eq "$OPP_ADDRESS") {
  522.         &prompt_for_opp_address() ;    ## Ask user for opponent's address
  523.     }
  524.     }
  525.  
  526.     ## ################################################################# ##
  527.     ## If no $GAME_NAME.game.in file, assume we're starting a new game
  528.     ## ################################################################# ##
  529.  
  530.     if (! (-f "$GAME_NAME.game.in")) {
  531.     &start_new_game() ;
  532.     }
  533.  
  534.     ## ################################################################# ##
  535.     ## Give up if we haven't got anywhere to send a move to
  536.     ## ################################################################# ##
  537.  
  538.     if ("" eq "$OPP_ADDRESS") {
  539.     die "Can't proceed without opponent's email address.\n" ;
  540.     }
  541. }
  542. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  543.  
  544.  
  545. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  546. ## Start a new game
  547. sub start_new_game {
  548.     printf("Starting a new game.\n") ;
  549.     $TO_PLAY = "white" ;
  550.     $MOVENUM = 0 ;
  551.  
  552.     ## ################################################################# ##
  553.     ## Create an empty game file
  554.     ## ################################################################# ##
  555.  
  556.     open(GAMEFILE, ">> $GAME_NAME.game.in") ;
  557.     select(GAMEFILE) ;
  558.     printf("# xboard game file\n\n        algebraic\n") ;
  559.     close(GAMEFILE) ;
  560. }
  561. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  562.  
  563.  
  564. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  565. ## Analyse the email message
  566. sub analyse_email_message {
  567.     printf("Extracting game from email message...") ;
  568.     &debug("Extracting game from email message...\n") ;
  569.  
  570.     ## ################################################################# ##
  571.     ## Parse the mail message
  572.     ## ################################################################# ##
  573.  
  574.     while(<stdin>) {
  575.     if (/^From.*[ <]+([^<\s]+@[^>\s]+)[>]*$/) {
  576.         $RETURN_ADDRESS = $1 ; ## Default for opponent's email address
  577.         &debug("Found opponent's email address <$RETURN_ADDRESS>\n") ;
  578.     } elsif(/^Subject: cmail[ ]*(\d+)[.].*$/) {
  579.         if ($1 eq 1) {
  580.         $SAVE_ADDRESS = 1 ; ## Save address if on first move
  581.         }
  582.         &debug("Move is $1 according to subject line\n") ;
  583.     } elsif(/^cmail game <(.*)>$/) {
  584.         $GAME_NAME = $1 ;
  585.         &debug("Found game name <$GAME_NAME>\n") ;
  586.     } elsif(/xboard position file/) {
  587.         &debug("Found xboard position file\n") ; ## Don't need to read
  588.     } elsif(/(\S+) to play/) {
  589.         $TO_PLAY = $1 ;    ## Who's move is it (colour)?
  590.         if ($TO_PLAY eq "black") {
  591.         $FLIP = "true" ; ## Flip xboard board if black to play
  592.         }
  593.         &debug("Found to play <$TO_PLAY>, flip is <$FLIP>\n") ;
  594.     } elsif(/xboard game file/) {
  595.         ## ######################################################### ##
  596.         ## Open game file for copying the rest of the mail message into
  597.         ## ######################################################### ##
  598.         
  599.         $IN_FILE = 1 ;
  600.         open(GAMEFILE, "> $GAME_NAME.game.in") ;
  601.         select(GAMEFILE) ;
  602.         &debug("Found xboard game file\n") ;
  603.     }
  604.     if($IN_FILE) {
  605.         print ;        ## Copy end of mail message into game file
  606.     }
  607.     }
  608.     select(STDOUT) ;
  609.     printf("done.\n") ;
  610.     &debug("done.\n") ;
  611.     close(GAMEFILE) ;
  612.     close(POSFILE) ;
  613.     
  614.     ## ################################################################# ##
  615.     ## Check that we have enough info about the players to continue
  616.     ## ################################################################# ##
  617.  
  618.     &find_game() ;
  619. }
  620. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  621.  
  622.  
  623. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  624. ## Analyse output files and send the move
  625. sub send_move {
  626.     ## ################################################################# ##
  627.     ## Check that the game.out and pos.out files exist
  628.     ## ################################################################# ##
  629.  
  630.     if (-f "$GAME_NAME.pos.out") {
  631.     $YES_POS_FILE = 1 ;
  632.     } else {
  633.     $YES_POS_FILE = 0 ;
  634.     }
  635.     if (-f "$GAME_NAME.game.out") {
  636.     $YES_GAME_FILE = 1 ;
  637.     } else {
  638.     $YES_GAME_FILE = 0 ;
  639.     }
  640.  
  641.     ## ################################################################# ##
  642.     ## Process the game.out and pos.out files
  643.     ## ################################################################# ##
  644.  
  645.     if ($YES_POS_FILE) {
  646.     if ($YES_GAME_FILE) {
  647.         ## ######################################################### ##
  648.         ## Open the .out file to be mailed for writing
  649.         ## ######################################################### ##
  650.  
  651.         die "Can't create file: $GAME_NAME.out\n"
  652.         unless open(out, "> $GAME_NAME.out") ;
  653.         select(out) ;
  654.  
  655.         ## ######################################################### ##
  656.         ## Cat the pos file into the .out file 
  657.         ## ######################################################### ##
  658.  
  659.         die "Can't open file: $GAME_NAME.pos.out\n"
  660.         unless open(pos, "< $GAME_NAME.pos.out") ;
  661.         printf("cmail game <$GAME_NAME>\n") ;
  662.         while(<pos>) {
  663.         &debug("$_") ;
  664.  
  665.         ## ##################################################### ##
  666.         ## We probably don't know who it is to play if we bypassed
  667.         ## loading xboard (for remail) so derive it from the
  668.         ## "to play" line in the pos.out file
  669.         ## ##################################################### ##
  670.  
  671.         if (/(\S+) to play/) {
  672.             if (! $LOAD_XBOARD) {
  673.             if ($1 eq "black") {
  674.                 $TO_PLAY = "white" ; ## Change black to white
  675.             } else {
  676.                 $TO_PLAY = "black" ; ## Change white to black
  677.             }
  678.             &debug("Found <$1> to play in",
  679.                    " <$GAME_NAME.pos.out>,",
  680.                    " reversed for remailing <$TO_PLAY>\n") ;
  681.             }
  682.         }
  683.         
  684.         print ;        ## Write the line to the .out file
  685.         }
  686.         close(pos) ;    ## Close the pos.out file
  687.  
  688.         ## ######################################################### ##
  689.         ## Look at $GAME_NAME.game.out
  690.         ## ######################################################### ##
  691.  
  692.         die "Can't open file: $GAME_NAME.game.out\n"
  693.         unless open(game, "< $GAME_NAME.game.out") ;
  694.  
  695.         ## ######################################################### ##
  696.         ## Cat the .game.out file into the .out file, remembering
  697.         ## the move number of the last line
  698.         ## ######################################################### ##
  699.  
  700.         while(<game>) {
  701.         &debug("$_") ;
  702.         if ($_ =~ /^(\d+).\s*\S*\s+(\S+)[ ]*$/) {
  703.             $MOVENUM = $1 ;
  704.             $MOVE = $2 ;
  705.         }
  706.         print ;
  707.         }
  708.         close(game) ;    ## Close the game.out file
  709.         close(out) ;    ## Close the .out file
  710.         select(STDOUT) ;    ## Write to the standard output
  711.  
  712.         ## ######################################################### ##
  713.         ## If it's black to play the subject line of the outgoing
  714.         ## mail message contains dots where the white move would 
  715.         ## normally be
  716.         ## ######################################################### ##
  717.  
  718.         if ($TO_PLAY eq "black") {
  719.         $DOTS = " ...." ;
  720.         } else {
  721.         $DOTS = "" ;
  722.         }
  723.  
  724.         ## ######################################################### ##
  725.         ## Send the mail message to opponent's address unless bypassed
  726.         ## ######################################################### ##
  727.  
  728.         if ($SEND_MAIL) {
  729.         system(  "/usr/ucb/mail -s"
  730.                . " \"cmail $MOVENUM.$DOTS $MOVE <$GAME_NAME>\""
  731.                . " $OPP_ADDRESS < $GAME_NAME.out") ;
  732.         printf("Emailed move to <$OPP_ADDRESS>: $MOVENUM.$DOTS") ;
  733.         printf(" $MOVE <$GAME_NAME>\n") ;
  734.         } else {
  735.         printf("Email not sent (as requested).\n") ;
  736.         printf("Would have emailed move to <$OPP_ADDRESS>:") ;
  737.         printf(" $MOVENUM.$DOTS $MOVE <$GAME_NAME>\n") ;
  738.         }
  739.     } else {
  740.         printf("I can't find the game file.") ;
  741.         printf(" Did you save the game?\n") ;
  742.         printf("Email not sent\n") ;
  743.     }
  744.     } else {
  745.     if ($YES_GAME_FILE) {
  746.         printf("I can't find the position file.") ;
  747.         printf("Did you save the position?\n") ;
  748.         printf("Email not sent\n") ;
  749.     } else {
  750.         printf("I can't find the position file or the game file.") ;
  751.         printf(" Did you save them?\n") ;
  752.         printf("Email not sent\n") ;
  753.     }
  754.     }
  755. }
  756. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  757.  
  758.  
  759. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  760. ## Main body
  761.  
  762. &initialise() ;            ## Initialise variables etc.
  763.  
  764. if (-t) { ## No input directed (invoked from a shell rather than a mailer)
  765.     &debug("Interactive!\n") ;
  766.     &find_game() ;        ## Get the necessary info about the game
  767. } else {
  768.     &debug("Piping!\n") ;
  769.     &analyse_email_message() ;    ## Analyse the mail message
  770. }
  771.  
  772. &add_game_to_game_file() ;    ## Create an entry in user's list of games
  773.  
  774. &play_game() ;                  ## Load the game
  775.  
  776. &send_move() ;                  ## Analyse output files and send the move
  777.  
  778. close(tty) ;            ## Tidy up
  779. if ($DEBUG) {
  780.     close (logfile) ;        ## Tidy up
  781. }
  782. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  783. __END__
  784. cmail $Revision: 1.27 $, Copyright (C) 1993 Free Software Foundation, Inc.
  785. cmail comes with ABSOLUTELY NO WARRANTY; for details type `cmail -w'.
  786. cmail is free software, and you are welcome to redistribute it
  787. under certain conditions; type `cmail -c' for details.
  788.  
  789. {END OF GPL COPYRIGHT}
  790.             GNU GENERAL PUBLIC LICENSE
  791.    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  792.  
  793.   0. This License applies to any program or other work which contains
  794. a notice placed by the copyright holder saying it may be distributed
  795. under the terms of this General Public License.  The "Program", below,
  796. refers to any such program or work, and a "work based on the Program"
  797. means either the Program or any derivative work under copyright law:
  798. that is to say, a work containing the Program or a portion of it,
  799. either verbatim or with modifications and/or translated into another
  800. language.  (Hereinafter, translation is included without limitation in
  801. the term "modification".)  Each licensee is addressed as "you".
  802.  
  803. Activities other than copying, distribution and modification are not
  804. covered by this License; they are outside its scope.  The act of
  805. running the Program is not restricted, and the output from the Program
  806. is covered only if its contents constitute a work based on the
  807. Program (independent of having been made by running the Program).
  808. Whether that is true depends on what the Program does.
  809.  
  810.   1. You may copy and distribute verbatim copies of the Program's
  811. source code as you receive it, in any medium, provided that you
  812. conspicuously and appropriately publish on each copy an appropriate
  813. copyright notice and disclaimer of warranty; keep intact all the
  814. notices that refer to this License and to the absence of any warranty;
  815. and give any other recipients of the Program a copy of this License
  816. along with the Program.
  817.  
  818. You may charge a fee for the physical act of transferring a copy, and
  819. you may at your option offer warranty protection in exchange for a fee.
  820.  
  821.   2. You may modify your copy or copies of the Program or any portion
  822. of it, thus forming a work based on the Program, and copy and
  823. distribute such modifications or work under the terms of Section 1
  824. above, provided that you also meet all of these conditions:
  825.  
  826.     a) You must cause the modified files to carry prominent notices
  827.     stating that you changed the files and the date of any change.
  828.  
  829.     b) You must cause any work that you distribute or publish, that in
  830.     whole or in part contains or is derived from the Program or any
  831.     part thereof, to be licensed as a whole at no charge to all third
  832.     parties under the terms of this License.
  833.  
  834.     c) If the modified program normally reads commands interactively
  835.     when run, you must cause it, when started running for such
  836.     interactive use in the most ordinary way, to print or display an
  837.     announcement including an appropriate copyright notice and a
  838.     notice that there is no warranty (or else, saying that you provide
  839.     a warranty) and that users may redistribute the program under
  840.     these conditions, and telling the user how to view a copy of this
  841.     License.  (Exception: if the Program itself is interactive but
  842.     does not normally print such an announcement, your work based on
  843.     the Program is not required to print an announcement.)
  844.  
  845. These requirements apply to the modified work as a whole.  If
  846. identifiable sections of that work are not derived from the Program,
  847. and can be reasonably considered independent and separate works in
  848. themselves, then this License, and its terms, do not apply to those
  849. sections when you distribute them as separate works.  But when you
  850. distribute the same sections as part of a whole which is a work based
  851. on the Program, the distribution of the whole must be on the terms of
  852. this License, whose permissions for other licensees extend to the
  853. entire whole, and thus to each and every part regardless of who wrote it.
  854.  
  855. Thus, it is not the intent of this section to claim rights or contest
  856. your rights to work written entirely by you; rather, the intent is to
  857. exercise the right to control the distribution of derivative or
  858. collective works based on the Program.
  859.  
  860. In addition, mere aggregation of another work not based on the Program
  861. with the Program (or with a work based on the Program) on a volume of
  862. a storage or distribution medium does not bring the other work under
  863. the scope of this License.
  864.  
  865.   3. You may copy and distribute the Program (or a work based on it,
  866. under Section 2) in object code or executable form under the terms of
  867. Sections 1 and 2 above provided that you also do one of the following:
  868.  
  869.     a) Accompany it with the complete corresponding machine-readable
  870.     source code, which must be distributed under the terms of Sections
  871.     1 and 2 above on a medium customarily used for software interchange; or,
  872.  
  873.     b) Accompany it with a written offer, valid for at least three
  874.     years, to give any third party, for a charge no more than your
  875.     cost of physically performing source distribution, a complete
  876.     machine-readable copy of the corresponding source code, to be
  877.     distributed under the terms of Sections 1 and 2 above on a medium
  878.     customarily used for software interchange; or,
  879.  
  880.     c) Accompany it with the information you received as to the offer
  881.     to distribute corresponding source code.  (This alternative is
  882.     allowed only for noncommercial distribution and only if you
  883.     received the program in object code or executable form with such
  884.     an offer, in accord with Subsection b above.)
  885.  
  886. The source code for a work means the preferred form of the work for
  887. making modifications to it.  For an executable work, complete source
  888. code means all the source code for all modules it contains, plus any
  889. associated interface definition files, plus the scripts used to
  890. control compilation and installation of the executable.  However, as a
  891. special exception, the source code distributed need not include
  892. anything that is normally distributed (in either source or binary
  893. form) with the major components (compiler, kernel, and so on) of the
  894. operating system on which the executable runs, unless that component
  895. itself accompanies the executable.
  896.  
  897. If distribution of executable or object code is made by offering
  898. access to copy from a designated place, then offering equivalent
  899. access to copy the source code from the same place counts as
  900. distribution of the source code, even though third parties are not
  901. compelled to copy the source along with the object code.
  902.  
  903.   4. You may not copy, modify, sublicense, or distribute the Program
  904. except as expressly provided under this License.  Any attempt
  905. otherwise to copy, modify, sublicense or distribute the Program is
  906. void, and will automatically terminate your rights under this License.
  907. However, parties who have received copies, or rights, from you under
  908. this License will not have their licenses terminated so long as such
  909. parties remain in full compliance.
  910.  
  911.   5. You are not required to accept this License, since you have not
  912. signed it.  However, nothing else grants you permission to modify or
  913. distribute the Program or its derivative works.  These actions are
  914. prohibited by law if you do not accept this License.  Therefore, by
  915. modifying or distributing the Program (or any work based on the
  916. Program), you indicate your acceptance of this License to do so, and
  917. all its terms and conditions for copying, distributing or modifying
  918. the Program or works based on it.
  919.  
  920.   6. Each time you redistribute the Program (or any work based on the
  921. Program), the recipient automatically receives a license from the
  922. original licensor to copy, distribute or modify the Program subject to
  923. these terms and conditions.  You may not impose any further
  924. restrictions on the recipients' exercise of the rights granted herein.
  925. You are not responsible for enforcing compliance by third parties to
  926. this License.
  927.  
  928.   7. If, as a consequence of a court judgment or allegation of patent
  929. infringement or for any other reason (not limited to patent issues),
  930. conditions are imposed on you (whether by court order, agreement or
  931. otherwise) that contradict the conditions of this License, they do not
  932. excuse you from the conditions of this License.  If you cannot
  933. distribute so as to satisfy simultaneously your obligations under this
  934. License and any other pertinent obligations, then as a consequence you
  935. may not distribute the Program at all.  For example, if a patent
  936. license would not permit royalty-free redistribution of the Program by
  937. all those who receive copies directly or indirectly through you, then
  938. the only way you could satisfy both it and this License would be to
  939. refrain entirely from distribution of the Program.
  940.  
  941. If any portion of this section is held invalid or unenforceable under
  942. any particular circumstance, the balance of the section is intended to
  943. apply and the section as a whole is intended to apply in other
  944. circumstances.
  945.  
  946. It is not the purpose of this section to induce you to infringe any
  947. patents or other property right claims or to contest validity of any
  948. such claims; this section has the sole purpose of protecting the
  949. integrity of the free software distribution system, which is
  950. implemented by public license practices.  Many people have made
  951. generous contributions to the wide range of software distributed
  952. through that system in reliance on consistent application of that
  953. system; it is up to the author/donor to decide if he or she is willing
  954. to distribute software through any other system and a licensee cannot
  955. impose that choice.
  956.  
  957. This section is intended to make thoroughly clear what is believed to
  958. be a consequence of the rest of this License.
  959.  
  960.   8. If the distribution and/or use of the Program is restricted in
  961. certain countries either by patents or by copyrighted interfaces, the
  962. original copyright holder who places the Program under this License
  963. may add an explicit geographical distribution limitation excluding
  964. those countries, so that distribution is permitted only in or among
  965. countries not thus excluded.  In such case, this License incorporates
  966. the limitation as if written in the body of this License.
  967.  
  968.   9. The Free Software Foundation may publish revised and/or new versions
  969. of the General Public License from time to time.  Such new versions will
  970. be similar in spirit to the present version, but may differ in detail to
  971. address new problems or concerns.
  972.  
  973. Each version is given a distinguishing version number.  If the Program
  974. specifies a version number of this License which applies to it and "any
  975. later version", you have the option of following the terms and conditions
  976. either of that version or of any later version published by the Free
  977. Software Foundation.  If the Program does not specify a version number of
  978. this License, you may choose any version ever published by the Free Software
  979. Foundation.
  980.  
  981.   10. If you wish to incorporate parts of the Program into other free
  982. programs whose distribution conditions are different, write to the author
  983. to ask for permission.  For software which is copyrighted by the Free
  984. Software Foundation, write to the Free Software Foundation; we sometimes
  985. make exceptions for this.  Our decision will be guided by the two goals
  986. of preserving the free status of all derivatives of our free software and
  987. of promoting the sharing and reuse of software generally.
  988. {END OF GPL CONDITIONS}
  989.             GNU GENERAL PUBLIC LICENSE
  990.                 NO WARRANTY
  991.  
  992.   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  993. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  994. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  995. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  996. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  997. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  998. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  999. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  1000. REPAIR OR CORRECTION.
  1001.  
  1002.   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  1003. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  1004. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  1005. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  1006. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  1007. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  1008. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  1009. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  1010. POSSIBILITY OF SUCH DAMAGES.
  1011.