Skip to content

Commit

Permalink
Provide wrapped cmp command
Browse files Browse the repository at this point in the history
Issue: #78
  • Loading branch information
dspinellis committed Aug 20, 2017
1 parent 3eb7df4 commit 2f7e093
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 5 deletions.
Empty file added simple-shell/cmp0.success
Empty file.
Empty file added simple-shell/cmp1-same1.success
Empty file.
Empty file added simple-shell/cmp1-same2.success
Empty file.
Empty file added simple-shell/cmp2-diff.success
Empty file.
Empty file added simple-shell/cmp2-same.success
Empty file.
1 change: 1 addition & 0 deletions unix-tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin/*
cat
cmp
coreutils/*
diff
etc/*
Expand Down
12 changes: 8 additions & 4 deletions unix-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ make:
$(MAKE) -C coreutils
$(MAKE) -C grep

build-install: cat diff tee make
build-install: cat cmp diff tee make
mkdir -p ../build/libexec/dgsh ../build/bin
cp bash/bash ../build/libexec/dgsh/
rm -f ../build/bin/dgsh
Expand All @@ -103,18 +103,19 @@ build-install: cat diff tee make
cp grep/src/grep ../build/libexec/dgsh/
cp grep/src/egrep ../build/libexec/dgsh/
cp grep/src/fgrep ../build/libexec/dgsh/
chmod 755 cat diff tee
cp -p cat diff tee ../build/libexec/dgsh/
chmod 755 cat cmp diff tee
cp -p cat cmp diff tee ../build/libexec/dgsh/
./install-wrapped.sh $$(cd .. ; pwd)/build

install: cat diff tee make
install: cat cmp diff tee make
$(MAKE) -C bash install
rm -f $(DESTDIR)$(PREFIX)/bin/dgsh
ln $(DESTDIR)$(DGSHPATH)/bash $(DESTDIR)$(PREFIX)/bin/dgsh || install $(DESTDIR)$(DGSHPATH)/bash $(DESTDIR)$(PREFIX)/bin/dgsh
$(MAKE) -C coreutils install
$(MAKE) -C grep install
# Install last to overwrite standard tools of coreutils
install cat $(DESTDIR)$(DGSHPATH)
install cmp $(DESTDIR)$(DGSHPATH)
install diff $(DESTDIR)$(DGSHPATH)
install tee $(DESTDIR)$(DGSHPATH)
./install-wrapped.sh
Expand All @@ -123,6 +124,9 @@ install: cat diff tee make
cat: cat.sh
install $? $@

cmp: cmp.sh
install $? $@

diff: diff.sh
install $? $@

Expand Down
57 changes: 57 additions & 0 deletions unix-tools/cmp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
#!dgsh
#
# Dgsh-compatible wrapping of the GNU cmp command
# Depending on the arguments, the command can accept 0-2 inputs
#


oopt=''

# For the parsing of long options see
# https://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options/7680682#7680682
optspec=":bi:ln:sv-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
quiet)
oopt='-o 0'
;;
silent)
oopt='-o 0'
;;
esac
;;
s)
oopt='-o 0'
;;
esac
done

# Examine the number of remaining (non-option) arguments
case $(($# - $OPTIND + 1)) in
0)
# Exactly two inputs are required
exec dgsh-wrap $oopt /usr/bin/cmp "$@" '<|' '<|'
;;
1)
if [[ "${!OPTIND}" == '-' ]] ; then
# One (non-stdin) input is required
exec dgsh-wrap -I $oopt /usr/bin/cmp "$@" '<|'
else
# One (stdin) input is required
exec dgsh-wrap $oopt /usr/bin/cmp "$@" -
fi
;;
*)
ARG2=$((OPTIND + 1))
if [[ "${!OPTIND}" == '-' ]] || [[ "${!ARG2}" == '-' ]] ; then
# One (stdin) input is required
exec dgsh-wrap /usr/bin/cmp $oopt "$@"
else
# No input is required
exec dgsh-wrap -i 0 /usr/bin/cmp $oopt "$@"
fi
;;
esac
7 changes: 7 additions & 0 deletions unix-tools/run_all_simple_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,10 @@ there" |
./run_simple_test.sh $PSDIR diff0-stdin1 '! dgsh-enumerate 1 | diff -w - /dev/null'
./run_simple_test.sh $PSDIR diff0-stdin2 '! dgsh-enumerate 1 | diff -w /dev/null -'
./run_simple_test.sh $PSDIR diff0-noin '! dgsh-enumerate 1 | diff -w /dev/null /dev/null'

# Wrapped cmp
./run_simple_test.sh $PSDIR cmp2-same '{{ echo a ; echo a ; }} | cmp'
./run_simple_test.sh $PSDIR cmp2-diff '! {{ echo a ; echo b ; }} | cmp -s'
./run_simple_test.sh $PSDIR cmp1-same1 'echo -n | cmp - /dev/null'
./run_simple_test.sh $PSDIR cmp1-same2 'echo -n | cmp /dev/null -'
./run_simple_test.sh $PSDIR cmp0 'cmp /dev/null /dev/null'
2 changes: 1 addition & 1 deletion unix-tools/wrapped-commands-posix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dm chgrp
dm chmod
dm chown
D cksum
D cmp
c cmp
c comm
d command
f compress # TODO custom
Expand Down
6 changes: 6 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ <h2>Adapted tools</h2>
<td>0&mdash;M</td>
<td>No options are supported</td>
</tr>
<tr>
<td>cmp</td>
<td>0&mdash;2</td>
<td>0&mdash;1</td>
<td></td>
</tr>
<tr>
<td>comm</td>
<td>0&mdash;2</td>
Expand Down

0 comments on commit 2f7e093

Please sign in to comment.