#!/usr/bin/perl ############################################################################### # # # Name : generate_aliases # # Author : Chris Koeritz # # Rights : Copyright (C) 1996-$now by Author # # # # Purpose: # # # # This script generates YETI alias files. Alias files contain a list of # # definitions for command aliases that are written in the specified shell # # dialect (such as bash or perl) and which are additionally tailored for the # # operating system to be used. # # # ############################################################################### # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the Free # # Software Foundation; either version 2 of the License or (at your option) # # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.txt" for a # # version of the License. Please send any updates to "fred@gruntose.com". # ############################################################################### require "importenv.pl"; # make sure we know where to store the files we're creating. if ( ! length("$GENERADIR") ) { print "\ The GENERADIR variable is not defined. This must point to the location where\n\ the generated scripts are stored. Perhaps you still need to run\n\ bootstrap_shells.sh and set up some environment variables. Please see\n\ http://yeticode.org for more details.\n"; exit 1; #really need to use better exit codes. } $GENERADIR =~ s/\\/\//g; $SHELLDIR =~ s/\\/\//g; $YETI_DIR =~ s/\\/\//g; # create our generated shells directory if it's not already. if (! -d $GENERADIR) { mkdir $GENERADIR; } system("bash \"$SHELLDIR\"/unter_alia.sh"); # generate the first set of alias files; these are the root files used # by the shell. each of them will be written to in turn invoke the # p_alias files which are made from the set of shells in SHELLDIR (see # below). #hmmm: how about any array here for these file names? # trash the old versions. unlink("$GENERADIR/4start.bat"); unlink("$GENERADIR/p_alias.bat"); unlink("$GENERADIR/p_alias.yao"); unlink("$GENERADIR/p_alias.sh"); unlink("$GENERADIR/p_alias.cmd"); printf "writing $GENERADIR/4start.bat...\n"; printf "writing $GENERADIR/p_alias.bat...\n"; printf "writing $GENERADIR/p_alias.yao...\n"; printf "writing $GENERADIR/p_alias.sh...\n"; printf "writing $GENERADIR/p_alias.cmd...\n"; # open the alias files to be created. open(fnt, ">> $GENERADIR/4start.bat"); open(dos, ">> $GENERADIR/p_alias.bat"); open(yao, ">> $GENERADIR/p_alias.yao"); open(she, ">> $GENERADIR/p_alias.sh"); open(cmd, ">> $GENERADIR/p_alias.cmd"); # special setup for 4start; need to include base set of variables and aliases. print fnt "\@echo off\r\n"; print fnt "\r\nrem variable inits below.\r\n"; # get the variables. open(vars, "< $SHELLDIR/variable.one"); while () { print fnt; } close(vars); #print "os is $OS\n"; if ($OS =~ /"Windows_9."/) { print "9x alias setup\n"; # setup for 9x aliases. open(alia, "< $GENERADIR/aliases.4ds"); while () { print fnt; } close(alia); } else { #print "nt alias setup\n"; # setup for nt aliases. open(alia, "< $GENERADIR/aliases.4nt"); while () { print fnt; } close(alia); } print fnt "\r\n\r\nrem Below are the generated aliases.\r\n"; sub make_bash_alias { local($aliasname) = shift(@_); local($source_dir) = shift(@_); #print "bash alias is $aliasname, dir is $source_dir\n"; print fnt "alias $aliasname=bash $source_dir/$aliasname.sh\"\r\n"; print dos "$aliasname=bash $source_dir/$aliasname.sh \$\*\r\n"; print yao "alias $aliasname=bash $source_dir/$aliasname.sh\r\n"; print she "alias $aliasname=\"bash $source_dir/$aliasname.sh\"\n"; print cmd "$aliasname=bash $source_dir/$aliasname.sh \$\*\r\n"; } sub make_perl_alias { local($aliasname) = shift(@_); local($source_dir) = shift(@_); #print "perl alias is $aliasname, dir is $source_dir\n"; print fnt "alias $aliasname=perl $source_dir/$aliasname.pl\"\r\n"; print dos "$aliasname=perl $source_dir/$aliasname.pl \$\*\r\n"; print yao "alias $aliasname=perl $source_dir/$aliasname.pl\r\n"; print she "alias $aliasname=\"perl $source_dir/$aliasname.pl\"\n"; print cmd "$aliasname=perl $source_dir/$aliasname.pl \$\*\r\n"; } # find the list of files in the shells directory. opendir(shells, "$SHELLDIR"); @shell_files = sort(readdir(shells)); #print "yeti shells: @shell_files\n"; # construct aliases for items in the shells directory. foreach $file (@shell_files) { if ($file =~ /\.[pP][lL]$/) { local($aliasname) = $file; $aliasname =~ s/\.[Pp][lL]$//; &make_perl_alias($aliasname, "$SHELLDIR"); } elsif ($file =~ /\.[sS][hH]$/) { local($aliasname) = $file; $aliasname =~ s/\.[Ss][Hh]$//; &make_bash_alias($aliasname, $SHELLDIR); } } # open the hoople binary directory to find shells in there. opendir(hooplebins, "$REPOSITORY_DIR/bin"); @hoople_files = sort(readdir(hooplebins)); #print "hoople bins: @hoople_files\n"; # construct aliases for items in the hoople bins directory. foreach $file (@hoople_files) { if ($file =~ /\.[pP][lL]$/) { local($aliasname) = $file; $aliasname =~ s/\.[Pp][lL]$//; &make_perl_alias($aliasname, "$REPOSITORY_DIR/bin"); } elsif ($file =~ /\.[sS][hH]$/) { local($aliasname) = $file; $aliasname =~ s/\.[Ss][Hh]$//; &make_bash_alias($aliasname, "$REPOSITORY_DIR/bin"); } } # final bit for 4nt is to call nechung. print fnt "\r\n\r\nrem Below is added call to nechung.\r\n"; print fnt "nechung\r\n"; print fnt ":exitatious\r\n"; close(fnt); close(dos); close(yao); close(she);