#!/usr/bin/perl -w # genrpbindings -- generate ratpoison bindings for various languages # # Copyright (C) 2003, 2004 Ryan Yeske, Doug Kearns, Shawn Betts # # currently generates bindings for: # * Perl (Ratpoison.pm) Ryan Yeske # * Emacs Lisp (ratpoison-cmd.el) Ryan Yeske # * Ruby (ratpoison.rb) Doug Kearns # * Common Lisp (ratpoison.lisp) Shawn Betts # add more languages! # # Bindings are just very thin wrappers, no argument checking is done. # All of the functions return a string. # # Example: ratpoison --command='echo hello world' # # #!perl # use Ratpoison; # Ratpoison::echo ("hello world") # # ;;; elisp # (require 'ratpoison-cmd) # (ratpoison-echo "hello world") # # #!ruby # require "ratpoison" # Ratpoison.echo ("hello world") # # ;;; Common Lisp # (load "ratpoison.lisp") # (ratpoison:rp-echo "hello world") $\="\n"; # set this to your rp binary $RATPOISON=$ENV{RATPOISON} || "ratpoison"; # open source file $ACTIONS_C="../src/actions.c"; open ACTIONS_C or die "Can't open $ACTIONS_C"; # open target files $PERL_FILE="./Ratpoison.pm"; $ELISP_FILE="./ratpoison-cmd.el"; $RUBY_FILE="./ratpoison.rb"; $COMMONLISP_FILE="./ratpoison.lisp"; open PERL, ">$PERL_FILE" or die "Can't create $PERL_FILE"; open ELISP, ">$ELISP_FILE" or die "Can't create $ELISP_FILE"; open RUBY, ">$RUBY_FILE" or die "Can't create $RUBY_FILE"; open COMMONLISP, ">$COMMONLISP_FILE" or die "Can't create $COMMONLISP_FILE"; # PERL preamble print PERL 'package Ratpoison;'; print PERL '$RATPOISON="',$RATPOISON,'";'; print PERL 'sub command { return `$RATPOISON -c "@_"`; }'; # ELISP preamble print ELISP '(defvar ratpoison-program "',$RATPOISON,'")'; print ELISP < (point-max) 1) (- (point-max) 1) (point-max))))) PREAMBLE # RUBY preamble print RUBY <) { if (m!/\*\@begin !) { while () { last if (m!/\*\@end !); if (/\s*add_command\s*\(\"([^\"]+)\",\s*[^\"]+,\s*([0-9]+),\s*[0-9]+,\s*([0-9]+)/) { my $name = $1; my $numargs = $2; my $optargs = $3; # Skip the arguments for (my $i=0; $i<$numargs; $i++) { ; } $nbindings++; print PERL "sub $name { return command (\"$name\", \@_); }"; print ELISP "(defun-ratpoison $name)"; print COMMONLISP "(defun-ratpoison $name)"; print RUBY " def $name (*args)"; print RUBY " return command (\"$name\", args)"; print RUBY " end"; print RUBY " module_function :$name\n"; } } } } print "$nbindings bindings."; # PERL postamble # nothing # ELISP postamble print ELISP '(provide \'ratpoison-cmd)'; # RUBY postamble print RUBY "end"; close PERL; print "Created $PERL_FILE"; close ELISP; print "Created $ELISP_FILE"; close RUBY; print "Created $RUBY_FILE"; close COMMONLISP; print "Created $COMMONLISP_FILE";