#!/usr/bin/perl # max: A front end to Maxima that provides command history # and command line editing in the GNU Readline style. # Copyright (c) 2002, Mark A. Lawrence # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl # itself. use Term::ReadLine; use Expect; my $term = Term::ReadLine->new("Maxima Front End"); $pregex = qr/\(C\d+\) (?!.)/s; # input prompt regex; the # negative lookahead at the # end ensures that we will # not stop at an intermediate # (Cn) line $maxima = Expect->spawn("maxima") or die "Can't start maxima: $!\n"; $maxima->log_stdout(0); # we'll control all the output $maxima->stty(qw(raw -echo)); # prevent echoed input print "Max: Readline-aware front end for Maxima\nType 'qqq' to exit\n"; # loop controlled by Maxima's input prompt while ($maxima->expect(120, '-re', $pregex)) { # 2 minute timeout print $maxima->before(); # output previous results $input = $term->readline($maxima->match()); # get a line of input exit if $input eq 'qqq'; # cheap exit strategy until ($input =~ /;$/) { # tack on more lines $input .= $term->readline(); # until we hit a semicolon } $maxima->send("$input\n"); # give collected lines to Maxima }