CVS update by ben xemacs-builds/ben ...
xemacs-cvs at xemacs.org
xemacs-cvs at xemacs.org
Mon Dec 25 04:09:28 EST 2006
User: ben
Date: 06/12/25 10:09:28
Modified: xemacs-builds/ben bash-functions perl-rename
Added: xemacs-builds/ben cvs-shell-functions psgrep
xemacs-shell-functions
Log:
Major restructuring of bash-functions; split part of code into new files cvs-shell-functions and xemacs-shell-functions; rewrite code to handle lists of bad files like *~ and *.obj; using this, get recursive diff working without need for extra file diff.xcl
Revision Changes Path
1.5 +169 -456 XEmacs/xemacs-builds/ben/bash-functions
Index: bash-functions
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs-builds/ben/bash-functions,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -p -r1.4 -r1.5
--- bash-functions 2006/09/29 06:48:32 1.4
+++ bash-functions 2006/12/25 09:09:25 1.5
@@ -1,17 +1,18 @@
##### bash-functions -*- Shell-script -*-
-##### This sets up functions and aliases for use with the XEmacs build/code
-##### scripts written by Ben Wing.
+##### This sets up functions and aliases.
-##### Mostly tested under CygWin. Requires bash or zsh.
+##### Mostly tested under Cygwin. Requires bash or zsh.
-##### Copyright (C) 2000-2004 Ben Wing.
+##### Copyright (C) 2000-2006 Ben Wing.
-##### I would suggest that you source this file into your own Shell .rc
+##### I would suggest that you source this file into your own shell .rc
##### file. See also sample.bashrc.
-##### General path-finding functions
+##################### Initialization
+# Determine our own full path; then set up alias to load and edit it.
+
if echo $0 | grep '^/' > /dev/null ; then
fullpath=$0
else
@@ -20,6 +21,11 @@ else
fi
# echo "Fullpath is $fullpath"
+alias sbf=". $fullpath"
+alias vbf="vi $fullpath"
+
+##################### General path-finding functions
+
# Find all files matching $1 (a shell-type wildcard) in the subdirectory
# tree under the current directory (.). Case is ignored. Errors on stderr
# are ignored. If $1 empty, just find all files under current directly
@@ -51,7 +57,7 @@ function fin0()
# Uses `fin0' for proper handling of spaces.
function fin-copy()
{
- fin0 "$1" | xargs -0 cp -t "$2"
+ fin0 "$1" | xargs -0 cp -at "$2"
}
# Like `fin' but only find directories
@@ -124,6 +130,34 @@ function cdwhich()
fi
}
+# now there is a real which, plus a `type' which does which plus
+# gives info about built-in commands/aliases/etc.
+## function which()
+## {
+## local doall
+## if [ "$1" = "--all" ] ; then
+## shift
+## doall=t
+## fi
+##
+## (IFS=':'
+## for x in $PATH ; do
+## if [ -f $x/$1 ] ; then
+## echo $x/$1
+## if [ -z "$doall" ] ; then break ; fi
+## elif [ -f $x/$1.exe ] ; then
+## echo $x/$1.exe
+## if [ -z "$doall" ] ; then break ; fi
+## elif [ -f $x/$1.com ] ; then
+## echo $x/$1.com
+## if [ -z "$doall" ] ; then break ; fi
+## elif [ -f $x/$1.bat ] ; then
+## echo $x/$1.bat
+## if [ -z "$doall" ] ; then break ; fi
+## fi
+## done) | sort | uniq
+## }
+
function dorec()
{
find . | xargs "$@"
@@ -139,8 +173,87 @@ function make-dir-alias()
# better (also handles pd/pop, etc.)
[ -n "$ZSH_NAME" ] || eval "alias $1='cd \"\$$1\"'"
}
+
+# First, accumulate an array of templates for files that we don't
+# want to match when grepping or diffing.
+badfiles=(
+'temacs.bsc'
+'*~'
+'*.orig'
+'*.elc'
+'*.exe'
+'*.obj'
+'*.class'
+'*.pyc'
+'*.pdb'
+'TAGS'
+'*.a'
+'*.o'
+'*.dll'
+'*.ncb'
+'*.mo'
+'image.0*'
+'.\#*'
+)
+
+# Now, generate the actual command-line strings to exclude those files.
+# The following code was wicked hard to get right, and needs to be
+# different between zsh and bash. Note:
+#
+# 1. set -f and set +f are needed at least for bash, to prevent it from doing
+# filename expansion during the crap below. zsh seems less prone to
+# do random expansion when you don't want it to.
+# 2. Expressions like ${badfiles[@]} expand an array into a string with
+# spaces between it. Note that bash won't do that if you just say
+# $badfiles; instead, you just get the first element of the array.
+# zsh does what we expect, and gives you all the elements. If you
+# put an expression like this in quotes, you get multiple words, as
+# desired.
+# 3. Expressions like ${foo/BAR/BAZ} substitute BAR with BAZ; with an
+# array reference like ${badfiles[@]/BAR/BAZ}, all elements get
+# substituted, and the result is a string unless enclosed in parens,
+# in which case it's still an array.
+# 4. In an expression like just cited, if BAR is #, it substitutes the
+# beginning of the string; similarly % for the end. BUT: substitution
+# with % DOES NOT WORK in current zsh, despite the docs. (It does work
+# in bash.) So we have to do a different trick, where an expression
+# like (YY${^badfiles}ZZ) replaces each word 'foo' with 'YYfooZZ';
+# the ^ triggers this and it's called "rc quotes" mode since the old
+# shell 'rc' did this.
+# 5. zsh doesn't automatically do whitespace breaking, so we need to force
+# it by using ($=findargs).
+# 6. Due to bash's aggressive filename expansion, the ONLY way to get
+# things to work below in rg() and friends is to keep things in an array,
+# with all frobbing done with globbing disabled (set -f), then use
+# "${findargs[@]}" to get whitespace breaking but no globbing (NO OTHER
+# WAY to get one but not the other!).
+# 7. The trick with YY and ZZ is needed because there's no simple way
+# to add to the beginning and end of a string at the same time, and
+# doing it the more obvious way results in something like
+#
+# -name -o '*.obj' -o -name -o '*.dll' -o ...
+#
+# due to over-aggressive whitespace breaking.
+# 8. Conclusion: Shell quoting is HORRIBLE.
+#
+#
+set -f
+diffargs=(${badfiles[@]/#/-x })
+if [ -n "$ZSH_NAME" ]; then
+ diffargs=($=diffargs)
+ findargs=(YY${^badfiles}ZZ)
+ findargs=(${findargs[@]/YY/-name })
+ findargs=(${findargs[@]/ZZ/ -o})
+ findargs=($=findargs)
+else
+ findargs=(${badfiles[@]/#/YY})
+ findargs=(${findargs[@]/%/ZZ})
+ findargs=(${findargs[@]/YY/-name })
+ findargs=(${findargs[@]/ZZ/ -o})
+fi
+set +f
-##### Grepping
+##################### Grepping
# see if grep -P is supported
if echo foo | grep -P foo > /dev/null 2>&1 ; then
@@ -153,64 +266,67 @@ fi
function runfind()
{
find . \
- -name "*~" -o \
- -name "*.orig" -prune -o \
-name CVS -prune -o \
- -name "temacs.bsc" -o \
- -name "*.elc" -o \
- -name "*.exe" -o \
- -name "*.obj" -o \
- -name "*.o" -o \
- -name "*.class" -o \
- -name "*.pyc" -o \
- -name "TAGS" -o \
- -name "*.pdb" -o \
- -name "*.a" -o \
- -name "*.dll" -o \
- -name "*.ncb" -o \
- -name "*.mo" -o \
- -name "image.0*" -o \
- -name "*.xpm" -o \
- -name "*.sbr" -o \
- -name "*.o" -o \
- -name "*.jpg" -o \
- -name "*.png" -o \
- -name "*.gif" -o \
- -name "*.au" -o \
- -name "*.ico" -o \
- -name "*.bmp" -o \
- -name ".\#*" -o \
- "$@"
+ "${findargs[@]}" \
+ -type f -print0 | xargs -0 grep $grepopt "$@" | more
}
-# Recursive grep, excluding annoying files (binary, etc).
-function rg()
-{
- runfind -type f -print0 | xargs -0 grep $grepopt "$@" | more
-}
-
# Like recursive grep, but look only in the current directory.
function nrg()
{
- runfind -type d -prune -o -type f -print0 | xargs -0 grep $grepopt "$@" | more
+ find . -name . -o -type d -prune -o \
+ -name CVS -prune -o \
+ "${findargs[@]}" \
+ -type f -print0 | xargs -0 grep $grepopt "$@" | more
}
# Print out non-binary files
function printtext()
{
- runfind -name "*.gz" -o \
+ find . \
+ -name CVS -prune -o \
+ "${findargs[@]}" \
+ -name "*.sbr" -o \
+ -name "*.jpg" -o \
+ -name "*.png" -o \
+ -name "*.gif" -o \
+ -name "*.gz" -o \
+ -name "*.xpm" -o \
+ -name "*.xbm" -o \
-name "*.Z" -o \
-name "*.bz2" -o \
-name "*.tgz" -o \
+ -name "*.au" -o \
+ -name "*.ico" -o \
+ -name "*.bmp" -o \
-type f -print
}
-# For use in XEmacs src directory. Grep all important files. For me
-# (under Cygwin), this is much faster than `rg'.
-function gx()
-{
- grep $grepopt "$@" *.[chCH] s/*.[hH] m/*.[hH] *.in.in *.h.in | more
-}
+# NOTE NOTE NOTE: We don't use the following anymore, but I'm not
+# deleting it yet in case this technique comes in handy later.
+# This generates text that can be pasted to easily generate functions
+# such as rg(), above.
+#function makefind()
+#{
+# sed "s/^\(.*\)\$/ -name \"\1\" -o \\\\/" <<'EOF'
+#temacs.bsc
+#*~
+#*.orig
+#*.elc
+#*.exe
+#*.obj
+#*.class
+#*.pyc
+#TAGS
+#temacs.pdb
+#*.a
+#*.dll
+#*.mo
+#image.0*
+#*.xpm
+#.\#*
+#EOF
+#}
# Grep .c and .h files in the current directory.
function gc()
@@ -223,21 +339,8 @@ function gh()
{
grep $grepopt "$@" *.[hH] | more
}
-
-##### Global Search/Replace
-
-# `grx FIND-EXPR REPLACE-EXPR [FILES ...]'. For use in XEmacs src directory.
-# Do a global search and replace over the source files in the XEmacs source
-# directory, including all useful files. Include also the files in
-# FILES. For me (under Cygwin), this is much faster than using `find'.
-function grx()
-{
- f1="$1"; f2="$2"
- shift 2
- gr "$f1" "$f2" *.[chCH] s/*.[hH] m/*.[hH] *.in.in *.h.in ${1+"$@"}
-}
-##### Diffing
+##################### Diffing
alias diff='diff -u'
@@ -246,140 +349,13 @@ function dm()
diff "$@" | more
}
-function diff-between-workspaces()
-{
- file=$1 ; shift
- while [ ! -z "$1" ] ; do
- if [ -d $1 -a -f $1/$file ]; then
- mdiff $1/$file $2/$file
- break
- fi
- shift 2
- done
-}
-
-#do diff between two versions of a file in two different workspaces.
-function difwms()
-{
- diff-between-workspaces $1 $xw $xms $xwl $xmsl $xws $xmss
-}
-
function rdiff()
-{
- diff -r -X /src/diff.xcl "$@"
-}
-
-function rdiffx()
-{
- diff -r -x '*.info' -x '*.info-*' -x DOC -X /src/diff.xcl "$@"
-}
-
-
-##### CVS
-
-# alias cvs='cvs -d :pserver:xemacs at cvs.xemacs.org:/usr/CVSroot'
-alias ccom='cvs-commit'
-alias cup='cvs-update'
-alias cdin='cvs-diff'
-alias lcvs='cvs -d /usr/local/cvsroot'
-
-function cmdi()
-{
- cvs-merge-diff "$@" | more
-}
-
-alias cvsfc='cvs-fix-chlogs'
-
-# `cthis FILE ...' or `cs FILE ...': when merging: what change did I make
-# that led to the merge?
-
-# A merge happens happens when you make a change to a file while meanwhile
-# someone else makes a change to the same file. The second one who checks
-# in has to merge the other one's changes into his version. CVS tries to
-# automate the merge, but merge conflicts can arise, esp. when you and the
-# other guy are both modifying the same part of the code. In this case,
-# your working version is the (broken) merged file, and your file in its
-# state before merging is difficult to locate. `cthis' tells you what
-# changes you had made at the point you checked the file in and begun to
-# merge. `cthat' similarly tells you the changes the other guy made. The
-# merge is the process of combining these two. Take a look at the comments
-# in `cvs-merge-diff' for full info about the merging process and what
-# exactly is going on.
-
-# when merging: what change did I make that led to the merge?
-function cthis()
{
- cvs-merge-diff -from a -to b "$@" | more
+ diff -x CVS "${diffargs[@]}" "$@" | more
}
-alias cs=cthis
+##################### Tar functions
-# `cthat FILE ...' or `ct FILE ...': when merging: what change did the
-# other guy make that led to the merge?
-
-# See comments near `cthis' for more info.
-function cthat()
-{
- cvs-merge-diff -from a -to c "$@" | more
-}
-
-alias ct=cthat
-
-# `cdi FILE ...': front-end onto `cvs diff' that does lots of nice things.
-
-function cdi()
-{
- cvs-diff "$@" | more
-}
-
-# `clog FILE ...': front-end onto `cvs log' that does lots of nice things.
-#
-# At this point, this just means piping through `more'.
-
-function clog()
-{
- cvs log "$@" | more
-}
-
-# `cfix FILE ...': nuke the file and retrieve from cvs again.
-# BE VERY CAREFUL DOING THIS!!!!!
-
-function cfix()
-{
- rm "$@"
- cvs update "$@"
-}
-
-# `cldiff [NUM] FILE ...':Diff most-recently checked in version and its
-# parent or ancestor.
-
-# Do a diff between the most-recently checked in version of a file and its
-# parent, telling you what changes were put in by the most-recently checked
-# in version. With a number, diff with the n'th most recent parent.
-function cldiff()
-{
- val=1
- case "$1" in
- [0-9]* ) val=$1 ; shift ;;
- esac
- cvs-merge-diff -from $val -to c "$@" | more
-}
-
-# `cdicom ARGS': Do a commit of a directory tree using cvs-commit, with the
-# ARGS collected together as the log message. Before committing, do a
-# `cvs-diff' to get the changes you made, and send them to a temp file,
-# whose name is printed at the end of the commit output.
-
-function cdicom()
-{
- tmp=$x/$$.txt
- cvs-diff > $tmp
- ccom -m "$*"
- echo "output is $tmp"
-}
-
-##### Tar functions
-
function bzuntar()
{
if [ -z "$1" ] ; then
@@ -433,13 +409,8 @@ function tarls()
tar tf $1
fi
}
-
-##### Misc
-alias patch='patch --verbose'
-alias nmk='nmake -f xemacs.mak'
-alias nmkun='nmake -f xemacs.mak unicode-encapsulate'
-alias rm-msvc-temp='rm xemacs.ncb xemacs.opt xemacs.plg'
+##################### Development-Related Functions
function teemake()
{
@@ -448,20 +419,6 @@ function teemake()
make "$@" | tee "$file" 2>&1
}
-alias xxemacs='DISPLAY=localhost:0 xemacs'
-
-function dotags2()
-{
- PATH=lib-src:$PATH
- cd nt; nmake -f xemacs.mak tags
-}
-
-function dodepend()
-{
- PATH=lib-src:$PATH
- cd nt; nmake -f xemacs.mak depend
-}
-
function nmgrep()
{
for x in * ; do
@@ -469,247 +426,3 @@ function nmgrep()
nm $x | grep $grepopt "$@"
done
}
-
-# now where is a real which, plus a `type' which does which plus
-# gives info about built-in commands/aliases/etc.
-## function which()
-## {
-## local doall
-## if [ "$1" = "--all" ] ; then
-## shift
-## doall=t
-## fi
-##
-## (IFS=':'
-## for x in $PATH ; do
-## if [ -f $x/$1 ] ; then
-## echo $x/$1
-## if [ -z "$doall" ] ; then break ; fi
-## elif [ -f $x/$1.exe ] ; then
-## echo $x/$1.exe
-## if [ -z "$doall" ] ; then break ; fi
-## elif [ -f $x/$1.com ] ; then
-## echo $x/$1.com
-## if [ -z "$doall" ] ; then break ; fi
-## elif [ -f $x/$1.bat ] ; then
-## echo $x/$1.bat
-## if [ -z "$doall" ] ; then break ; fi
-## fi
-## done) | sort | uniq
-## }
-
-if [ -z "$NONLOCAL" ] ; then
-
-####################################################
-##### Getting to various commonly-used paths ######
-####################################################
-
-. $xbin/config-inc
-
-x="$conf_wstop"
-alias x="cd $x"
-
-xc="$conf_outtop"
-
-# look under $xc for a directory matching $1 and cd to it. words separated
-# by dashes can be abbreviated, e.g. `w-m-c' for `working-mule-cpp'.
-
-function xc()
-{
- if [ -z "$1" ] ; then
- cd $xc
- else
- cd $(find $xc -type d -name "$(echo $1 | sed 's/-/*-/g')*")
- fi
-}
-
-# same as xc() but go to the src/ directory underneath the (first)
-# found directory.
-
-function xcs()
-{
- if [ -z "$1" ] ; then
- cd $xc
- else
- cd $(echo $(find $xc -type d -name "$(echo $1 | sed 's/-/*-/g')*") | sed 's/ .*//')/src
- fi
-}
-
-if [ -n "$ZSH_NAME" ] ; then
- # zsh does not automatically split var references on whitespace,
- # so tell it to do so.
- conf_all_config_names=($=conf_all_config_names)
-fi
-
-for y in $conf_all_config_names ; do
- eval "dir$y=`config_options $y | sed 's/ /-/'g`"
-done
-
-function make-ws-aliases()
-{
- make-dir-alias x$1 "$x/$2"
- make-dir-alias x${1}s "\$x$1/src"
- make-dir-alias x${1}ss "\$x$1/src/s"
- make-dir-alias x${1}sm "\$x$1/src/m"
- make-dir-alias x${1}l "\$x$1/lisp"
- make-dir-alias x${1}lm "\$x$1/lisp/mule"
- make-dir-alias x${1}n "\$x$1/nt"
- make-dir-alias x${1}e "\$x$1/etc"
- make-dir-alias x${1}ls "\$x$1/lib-src"
- make-dir-alias x${1}m "\$x$1/man"
-
- make-dir-alias x${1}c "$x/cygbuild/$2-$dir0"
- make-dir-alias x${1}cs "\$x${1}c/src"
-
- for y in $conf_all_config_names ; do
- make-dir-alias x${1}c$y "$x/cygbuild/$2-\$dir$y"
- make-dir-alias x${1}c${y}s "\$x${1}c${y}/src"
- done
-
- eval "alias x${1}cr='rebu $2'"
- eval "alias x${1}cb='bu $2'"
-}
-
-function make-emacs-aliases()
-{
- make-dir-alias $1 "$2"
- make-dir-alias ${1}s "\$$1/src"
- make-dir-alias ${1}ss "\$$1/src/s"
- make-dir-alias ${1}sm "\$$1/src/m"
- make-dir-alias ${1}l "\$$1/lisp"
- make-dir-alias ${1}e "\$$1/etc"
- make-dir-alias ${1}ls "\$$1/lib-src"
- make-dir-alias ${1}m "\$$1/man"
-}
-
-make-dir-alias xbin "$xbin"
-
-function xps()
-{
- if [ -z "$1" ] ; then
- cd $xps
- else
- # local -a declares an array, and the line
- # after it accesses the first element.
- # the //-/*- replaces - with *- within the
- # parameter, so you can use `e-u' to mean
- # `edit-utils'.
- if [ -z "$ZSH_NAME" ] ; then
- local -a arg=($xps/xemacs-packages/${1//-/*-}*)
- else
- # zsh naturally does it differently. For one, the `local' command
- # doesn't allow initialization. For another, the order of filename
- # expansion vs. parameter expansion is different in such a way that
- # we need to insert the extra ~ below to get the meaning we want.
- local -a arg
- arg=($xps/xemacs-packages/${~1//-/*-}*)
- fi
- # at this point arg has an array of all matches. Pick the first one.
- cd ${arg[0]}
- fi
-}
-
-function xps2()
-{
- if [ -z "$1" ] ; then
- cd $xps2
- else
- # local -a declares an array, and the line
- # after it accesses the first element.
- # the //-/*- replaces - with *- within the
- # parameter, so you can use `e-u' to mean
- # `edit-utils'.
- if [ -z "$ZSH_NAME" ] ; then
- local -a arg=($xps2/xemacs-packages/${1//-/*-}*)
- else
- # zsh naturally does it differently. For one, the `local' command
- # doesn't allow initialization. For another, the order of filename
- # expansion vs. parameter expansion is different in such a way that
- # we need to insert the extra ~ below to get the meaning we want.
- local -a arg
- arg=($xps2/xemacs-packages/${~1//-/*-}*)
- fi
- # at this point arg has an array of all matches. Pick the first one.
- cd ${arg[0]}
- fi
-}
-
-
-# basic function to build a package workspace from scratch. arguments are
-# workspace name.
-function bup()
-{
- ws="$1"
- shift
- build --packages --keep-going $ws scratch "$@"
-}
-
-# basic function to rebuild an existing package workspace. arguments are
-# workspace name and configuration(s).
-function rebup()
-{
- ws="$1"
- shift
- build --packages --keep-going $ws rebuild "$@"
-}
-
-# Basic function to build a workspace from scratch. Arguments are
-# workspace name and configuration(s).
-function bu()
-{
- ws="$1"
- shift
- build --keep-going $ws scratch "$@"
-}
-
-# Basic function to build a workspace from scratch. No filtering of output.
-# Arguments are workspace name and configuration(s).
-function bunf()
-{
- ws="$1"
- shift
- build --keep-going --no-filter $ws scratch "$@"
-}
-
-# Basic function to rebuild an existing workspace. Arguments are
-# workspace name and configuration(s).
-function rebu()
-{
- ws="$1"
- shift
- build --keep-going $ws rebuild "$@"
-}
-
-# Basic function to rebuild an existing workspace. No filtering of output.
-# Arguments are workspace name and configuration(s).
-function rebunf()
-{
- ws="$1"
- shift
- build --keep-going --no-filter $ws rebuild "$@"
-}
-
-# basic function to build a workspace from scratch for workspaces
-# where the Mule support doesn't work under Windows. arguments are
-# workspace name and configuration(s).
-function bunm()
-{
- ws="$1"
- shift
- build --no-mule-on-win --keep-going $ws scratch "$@"
-}
-
-# basic function to rebuild an existing workspace for workspaces where
-# the Mule support doesn't work under Windows. arguments are
-# workspace name and configuration(s).
-function rebunm()
-{
- ws="$1"
- shift
- build --no-mule-on-win --keep-going $ws rebuild "$@"
-}
-
-alias sbf=". $fullpath"
-alias vbf="vi $fullpath"
-
-fi
1.2 +176 -6 XEmacs/xemacs-builds/ben/perl-rename
Index: perl-rename
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs-builds/ben/perl-rename,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -p -r1.1 -r1.2
--- perl-rename 2004/11/13 23:01:10 1.1
+++ perl-rename 2006/12/25 09:09:25 1.2
@@ -1,5 +1,6 @@
#!/usr/bin/perl -w
+############## OLD ##############
# Usage is something like
# perl-rename 's/\.c$/-old.c/' *.c
# or optionally using find:
@@ -9,12 +10,181 @@
# where EXPR is evaluated (with $_ set to the file) and should change it
# to a new name.
-my $code = shift;
+# my $code = shift;
-# #### WARNING: Currently untested
+# # #### WARNING: Currently untested
-while ($_ = shift) {
- my $old = $_;
- eval $code;
- rename $old, $_ unless $old eq $_;
+# while ($_ = shift) {
+# my $old = $_;
+# eval $code;
+# rename $old, $_ unless $old eq $_;
+# }
+
+use strict;
+use Getopt::Long;
+
+(my $myName = $0) =~ s at .*/@@; my $usage="
+Usage: $myName [-v] [--full] [--help] [-n|--dry-run] [-f|--force] (--dotund | EXPR) [file ...]
+
+Rename files according to EXPR. This allows multiple files to be renamed
+using a common specification. Possible calling sequence is
+
+ $myName 's/\$/-old/' *.c
+
+to rename all *.c files to *-old.c.
+
+NOTE: Under normal operation, $myName strips off any extensions (up to two
+extensions per file) before evaluating the expression and later puts them on
+again; this makes it easier to make changes to the base (main) part of a
+filename without modifying the extension. To suppress this, use --full, in
+which case full names are supplied to the EXPR.
+
+Note that EXPR is a standard Perl expression. Normally it should be of the
+form s///, but any command that modifies $_ will do; so (e.g.) tr/// could
+be used to convert all uppercase to lowercase or remove excess spaces or
+whatever.
+
+A quick review of Perl substitution commands: In a command s/FROM/TO/FLAGS,
+FROM is a Perl-compatible regex, TO is the replacement text, FLAGS are
+possible modification flags, and /// are delimiters. Most useful flags
+here are 'i' (case-insensitive matching in FROM), 'g' (apply substitution
+as many times as possible; otherwise, at most one substitution is made),
+'e' (evaluate replacement text as a perl expression). Delimiters can be
+replaced by any printable, non-alphanumeric chars; if you use parens,
+brackets, braces or angle brackets as delimiters, the beginning and ending
+delimiter must form a matched pair, four delimiters occur instead of three,
+and matched- delimiter counting happens inside of the delimited text, e.g.
+
+ s[foo/([a-z]+)bar](foo=(($1))())i
+
+means FROM=foo/([a-z]+)bar, TO=foo=(($1))(), FLAGS=i, DELIMITERS=[]().
+
+As shown, parens for grouping (likewise | for alternations) do not require
+a preceding backslash, unlike in basic grep or in Emacs, and $1, $2,
+etc. are used in the replacement text instead of \1, \2, etc. In general,
+any non-alphanumeric character that is backslashed represents that
+character itself. Also, numerous Perl-specific features exist, e.g.
+non-capturing groups, specified with (?:......), and non-greedy matching, e.g.
+.*? (match as little as possible).
+
+Argument -n or --dry-run means \"don't actually do any renames; just print
+commands indicating what renames would be done.\"
+
+Argument --dotund means that names with dots or underscores in place of spaces
+will be renamed to use spaces. The heuristics for how to do this are somewhat
+complicated and not expressible in a simple s/// expression. When --dotund
+is used, EXPR must be omitted.
+
+Argument -v prints out extra information about extracted bases and extensions
+and munging used to avoid collisions.
+
+Normally, $myName will not rename a file onto an existing file (although that
+ can be changed using -f or --force). Instead, it will add a number onto a
+file (e.g. foo-1.c or foo-2.c), starting at 1 and looping until a unique
+number is found.
+
+Note: $myName will stop processing a file if the computed name to rename to
+is the same as the original name. During the loop above to find a
+non-existing numbered file name, processing will stop if the numbered file
+at any stage of the loop becomes the same as the original. For example,
+attempting to rename foo-1.c to foo.c when foo.c already exists leaves
+foo-1.c as is rather than renaming it to foo-2.c. This makes it easy to
+compress all numbered files to their minimal forms using something like
+
+ $myName 's/-[0-9]\$//' *
+
+(This only applies to files with a single digit after the dash for safety,
+so that files named something like 'myfile-10-9-98.txt' aren't affected.)
+
+An alternative way for running $myName is to use 'find', like this:
+
+ find . -name '*.c' -print0 | xargs -0 $myName 's/\$/-old/'
+
+
+";
+
+my %op;
+
+IMPLEMENT ME;
+
+&GetOptions (\%op, "help", "n|dry-run", "", "v", "no-recurse");
+
+die $usage if $op{"help"};
+
+my $printinput = 0;
+my $printinput_divided = 1;
+my $printnew = 1;
+my $rename = 0;
+my $rename_dry_run = 1;
+
+# FIXME:
+# TODO:
+# 1) Make a log of all renamings so we can go find original name if we
+# end up not liking the new name.
+# 2) Count how many dots and underlines each name has, and make a note of
+# cases with lots (e.g. 4 or more of each) but not translated; also,
+# count places with few dots and/or underlines and note places where we
+# did translate them
+# 3) Extend this to a general rename system, where I can say
+#
+# perlrename 's/expr1/expr2/' where I give an expression to be run,
+# and the new name may be munged as below to make sure it doesn't already
+# exist. Use this to create scripts to do many of the renames currently
+# done by hand; note that we may need to run these multiple times as
+# other transformations put more files into formats to be affected by
+# previous transformations
+#
+# General rename system should stop, as always, if planning on renaming
+# a file to an existing name. (?) This relates especially to trying to
+# rename a foo-1.bar file to foo.bar; if at any point in the checking
+# to see if name doesn't already exist and adding a number if so,
+# we get to a name identical to the original name, stop. Otherwise,
+# trying to rename foo-1.bar to foo.bar when foo.bar exists, we end up
+# renaming to foo-2.bar when really we want it left at foo-1.bar.
+#
+# 4) Look for names where we have an extra -1 or whatever and try to get rid
+# of it. Given the caveat at the end of (3), might be enough to just
+# rename (.*)-[0-9]+\.(EXT) to $1.$2, which will give it the lowest
+# possible -# extension, or none if not necessary. Before this, handle
+# extensions of (#) by renaming to -#.
+#
+# 5) Use foo(5).c instead of foo-5.c when doing numbers, to reduce likelihood
+# of conflicts with numbering for other uses.
+
+while (<>) {
+ chomp;
+ my $origname = "$_";
+ print "input: $_\n" if $printinput;
+ my ($base, $ext) = /^(.*?)((\.[a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_]?[a-zA-Z0-9_]?)?(\.[a-zA-Z0-9_][a-zA-Z0-9_]?[a-zA-Z0-9_]?[a-zA-Z0-9_]?[a-zA-Z0-9_]?[a-zA-Z0-9_]?[a-zA-Z0-9_]?[a-zA-Z0-9_]?[a-zA-Z0-9_]?)?)$/;
+ print "base=$base, ext=$ext\n" if $printinput_divided;
+ if (!$base || !$ext) {
+ $base = $_;
+ $ext = "";
+ }
+ $_ = $base;
+ my $hasnospace = !/ /;
+ my $hasdot = /([-]|[A-Za-z][^ .][^ .]+)\.+([-]|[A-Za-z][^ .][^ .]+)\.+([-]|[A-Za-z][^ .][^ .]+)/;
+ if (/_/) {
+ s/__/ - /g;
+ s/_/ /g;
+ }
+ if ($hasnospace || $hasdot) {
+ s/\./ /g;
+ }
+ $base = $_;
+ if ($origname eq "$base$ext") { next; }
+ print "$base$ext before munging\n" if $printnew;
+ if (-e "$base$ext") {
+ my $origbase = $base;
+ for (my $count = 1;; $count++) {
+ $base = "$origbase-$count";
+ if (! -e "$base$ext") {
+ print "$base$ext after munging\n" if $printnew;
+ last;
+ }
+ }
+ }
+ print "mv '$origname' to '$base$ext'\n" if $rename_dry_run;
+ rename($origname, "$base$ext") if $rename;
}
+
1.1 XEmacs/xemacs-builds/ben/cvs-shell-functions
Index: cvs-shell-functions
===================================================================
##### cvs-bash-functions -*- Shell-script -*-
##################### CVS
alias ccom='cvs-commit'
alias cup='cvs-update'
alias cdin='cvs-diff'
alias lcvs='cvs -d /usr/local/cvsroot'
function cmdi()
{
cvs-merge-diff "$@" | more
}
alias cvsfc='cvs-fix-chlogs'
# `cthis FILE ...' or `cs FILE ...': when merging: what change did I make
# that led to the merge?
# A merge happens happens when you make a change to a file while meanwhile
# someone else makes a change to the same file. The second one who checks
# in has to merge the other one's changes into his version. CVS tries to
# automate the merge, but merge conflicts can arise, esp. when you and the
# other guy are both modifying the same part of the code. In this case,
# your working version is the (broken) merged file, and your file in its
# state before merging is difficult to locate. `cthis' tells you what
# changes you had made at the point you checked the file in and begun to
# merge. `cthat' similarly tells you the changes the other guy made. The
# merge is the process of combining these two. Take a look at the comments
# in `cvs-merge-diff' for full info about the merging process and what
# exactly is going on.
# when merging: what change did I make that led to the merge?
function cthis()
{
cvs-merge-diff -from a -to b "$@" | more
}
alias cs=cthis
# `cthat FILE ...' or `ct FILE ...': when merging: what change did the
# other guy make that led to the merge?
# See comments near `cthis' for more info.
function cthat()
{
cvs-merge-diff -from a -to c "$@" | more
}
alias ct=cthat
# `cdi FILE ...': front-end onto `cvs diff' that does lots of nice things.
function cdi()
{
cvs-diff "$@" | more
}
# `clog FILE ...': front-end onto `cvs log' that does lots of nice things.
#
# At this point, this just means piping through `more'.
function clog()
{
cvs log "$@" | more
}
# `cfix FILE ...': nuke the file and retrieve from cvs again.
# BE VERY CAREFUL DOING THIS!!!!!
function cfix()
{
rm "$@"
cvs update "$@"
}
# `cldiff [NUM] FILE ...':Diff most-recently checked in version and its
# parent or ancestor.
# Do a diff between the most-recently checked in version of a file and its
# parent, telling you what changes were put in by the most-recently checked
# in version. With a number, diff with the n'th most recent parent.
function cldiff()
{
val=1
case "$1" in
[0-9]* ) val=$1 ; shift ;;
esac
cvs-merge-diff -from $val -to c "$@" | more
}
# `cdicom ARGS': Do a commit of a directory tree using cvs-commit, with the
# ARGS collected together as the log message. Before committing, do a
# `cvs-diff' to get the changes you made, and send them to a temp file,
# whose name is printed at the end of the commit output.
function cdicom()
{
tmp=$x/$$.txt
cvs-diff > $tmp
ccom -m "$*"
echo "output is $tmp"
}
1.1 XEmacs/xemacs-builds/ben/psgrep
Index: psgrep
===================================================================
#!/bin/sh
ps auxww | grep ${1+"$@"} | grep -v 'psgrep ' | grep -v ' grep '
1.1 XEmacs/xemacs-builds/ben/xemacs-shell-functions
Index: xemacs-shell-functions
===================================================================
##### xemacs-bash-functions -*- Shell-script -*-
#####################
##### for use with the XEmacs build/code scripts written by Ben Wing.
#####################
##################### Various XEmacs-related functions
# alias cvs='cvs -d :pserver:xemacs at cvs.xemacs.org:/usr/CVSroot'
# For use in XEmacs src directory. Grep all important files. For me
# (under Cygwin), this is much faster than `rg'.
function gx()
{
grep $grepopt "$@" *.[chCH] s/*.[hH] m/*.[hH] *.in.in *.h.in | more
}
# `grx FIND-EXPR REPLACE-EXPR [FILES ...]'. For use in XEmacs src directory.
# Do a global search and replace over the source files in the XEmacs source
# directory, including all useful files. Include also the files in
# FILES. For me (under Cygwin), this is much faster than using `find'.
function grx()
{
f1="$1"; f2="$2"
shift 2
gr "$f1" "$f2" *.[chCH] s/*.[hH] m/*.[hH] *.in.in *.h.in ${1+"$@"}
}
function diff-between-workspaces()
{
file=$1 ; shift
while [ ! -z "$1" ] ; do
if [ -d $1 -a -f $1/$file ]; then
mdiff $1/$file $2/$file
break
fi
shift 2
done
}
#do diff between two versions of a file in two different workspaces.
function difwms()
{
diff-between-workspaces $1 $xw $xms $xwl $xmsl $xws $xmss
}
function rdiffx()
{
diff -r -x '*.info' -x '*.info-*' -x DOC -X /src/diff.xcl "$@"
}
alias nmk='nmake -f xemacs.mak'
alias nmkun='nmake -f xemacs.mak unicode-encapsulate'
alias rm-msvc-temp='rm xemacs.ncb xemacs.opt xemacs.plg'
alias xxemacs='DISPLAY=localhost:0 xemacs'
function dotags2()
{
PATH=lib-src:$PATH
cd nt; nmake -f xemacs.mak tags
}
function dodepend()
{
PATH=lib-src:$PATH
cd nt; nmake -f xemacs.mak depend
}
####################################################
##### Getting to various commonly-used paths ######
####################################################
. $xbin/config-inc
x="$conf_wstop"
alias x="cd $x"
xc="$conf_outtop"
# look under $xc for a directory matching $1 and cd to it. words separated
# by dashes can be abbreviated, e.g. `w-m-c' for `working-mule-cpp'.
function xc()
{
if [ -z "$1" ] ; then
cd $xc
else
cd $(find $xc -type d -name "$(echo $1 | sed 's/-/*-/g')*")
fi
}
# same as xc() but go to the src/ directory underneath the (first)
# found directory.
function xcs()
{
if [ -z "$1" ] ; then
cd $xc
else
cd $(echo $(find $xc -type d -name "$(echo $1 | sed 's/-/*-/g')*") | sed 's/ .*//')/src
fi
}
if [ -n "$ZSH_NAME" ] ; then
# zsh does not automatically split var references on whitespace,
# so tell it to do so.
conf_all_config_names=($=conf_all_config_names)
fi
for y in $conf_all_config_names ; do
eval "dir$y=`config_options $y | sed 's/ /-/'g`"
done
function make-ws-aliases()
{
make-dir-alias x$1 "$x/$2"
make-dir-alias x${1}s "\$x$1/src"
make-dir-alias x${1}ss "\$x$1/src/s"
make-dir-alias x${1}sm "\$x$1/src/m"
make-dir-alias x${1}l "\$x$1/lisp"
make-dir-alias x${1}lm "\$x$1/lisp/mule"
make-dir-alias x${1}n "\$x$1/nt"
make-dir-alias x${1}e "\$x$1/etc"
make-dir-alias x${1}ls "\$x$1/lib-src"
make-dir-alias x${1}m "\$x$1/man"
make-dir-alias x${1}c "$x/cygbuild/$2-$dir0"
make-dir-alias x${1}cs "\$x${1}c/src"
for y in $conf_all_config_names ; do
make-dir-alias x${1}c$y "$x/cygbuild/$2-\$dir$y"
make-dir-alias x${1}c${y}s "\$x${1}c${y}/src"
done
eval "alias x${1}cr='rebu $2'"
eval "alias x${1}cb='bu $2'"
}
function make-emacs-aliases()
{
make-dir-alias $1 "$2"
make-dir-alias ${1}s "\$$1/src"
make-dir-alias ${1}ss "\$$1/src/s"
make-dir-alias ${1}sm "\$$1/src/m"
make-dir-alias ${1}l "\$$1/lisp"
make-dir-alias ${1}e "\$$1/etc"
make-dir-alias ${1}ls "\$$1/lib-src"
make-dir-alias ${1}m "\$$1/man"
}
make-dir-alias xbin "$xbin"
function xps()
{
if [ -z "$1" ] ; then
cd $xps
else
# local -a declares an array, and the line
# after it accesses the first element.
# the //-/*- replaces - with *- within the
# parameter, so you can use `e-u' to mean
# `edit-utils'.
if [ -z "$ZSH_NAME" ] ; then
local -a arg=($xps/xemacs-packages/${1//-/*-}*)
else
# zsh naturally does it differently. For one, the `local' command
# doesn't allow initialization. For another, the order of filename
# expansion vs. parameter expansion is different in such a way that
# we need to insert the extra ~ below to get the meaning we want.
local -a arg
arg=($xps/xemacs-packages/${~1//-/*-}*)
fi
# at this point arg has an array of all matches. Pick the first one.
cd ${arg[0]}
fi
}
function xps2()
{
if [ -z "$1" ] ; then
cd $xps2
else
# local -a declares an array, and the line
# after it accesses the first element.
# the //-/*- replaces - with *- within the
# parameter, so you can use `e-u' to mean
# `edit-utils'.
if [ -z "$ZSH_NAME" ] ; then
local -a arg=($xps2/xemacs-packages/${1//-/*-}*)
else
# zsh naturally does it differently. For one, the `local' command
# doesn't allow initialization. For another, the order of filename
# expansion vs. parameter expansion is different in such a way that
# we need to insert the extra ~ below to get the meaning we want.
local -a arg
arg=($xps2/xemacs-packages/${~1//-/*-}*)
fi
# at this point arg has an array of all matches. Pick the first one.
cd ${arg[0]}
fi
}
# basic function to build a package workspace from scratch. arguments are
# workspace name.
function bup()
{
ws="$1"
shift
build --packages --keep-going $ws scratch "$@"
}
# basic function to rebuild an existing package workspace. arguments are
# workspace name and configuration(s).
function rebup()
{
ws="$1"
shift
build --packages --keep-going $ws rebuild "$@"
}
# Basic function to build a workspace from scratch. Arguments are
# workspace name and configuration(s).
function bu()
{
ws="$1"
shift
build --keep-going $ws scratch "$@"
}
# Basic function to build a workspace from scratch. No filtering of output.
# Arguments are workspace name and configuration(s).
function bunf()
{
ws="$1"
shift
build --keep-going --no-filter $ws scratch "$@"
}
# Basic function to rebuild an existing workspace. Arguments are
# workspace name and configuration(s).
function rebu()
{
ws="$1"
shift
build --keep-going $ws rebuild "$@"
}
# Basic function to rebuild an existing workspace. No filtering of output.
# Arguments are workspace name and configuration(s).
function rebunf()
{
ws="$1"
shift
build --keep-going --no-filter $ws rebuild "$@"
}
# basic function to build a workspace from scratch for workspaces
# where the Mule support doesn't work under Windows. arguments are
# workspace name and configuration(s).
function bunm()
{
ws="$1"
shift
build --no-mule-on-win --keep-going $ws scratch "$@"
}
# basic function to rebuild an existing workspace for workspaces where
# the Mule support doesn't work under Windows. arguments are
# workspace name and configuration(s).
function rebunm()
{
ws="$1"
shift
build --no-mule-on-win --keep-going $ws rebuild "$@"
}
More information about the XEmacs-CVS
mailing list