Skip to content

Commit

Permalink
Wrap diff removing diffutils
Browse files Browse the repository at this point in the history
Issue: #78
  • Loading branch information
dspinellis committed Aug 20, 2017
1 parent c3eb066 commit 01691ba
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 27 deletions.
5 changes: 0 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
url = https://github.com/mfragkoulis/coreutils
branch = master
ignore=dirty
[submodule "unix-tools/diffutils"]
path = unix-tools/diffutils
url = https://github.com/mfragkoulis/diffutils
branch = master
ignore=dirty
[submodule "unix-tools/grep"]
path = unix-tools/grep
url = https://github.com/mfragkoulis/grep
Expand Down
Empty file added simple-shell/diff0.success
Empty file.
4 changes: 4 additions & 0 deletions simple-shell/diff1-stdin.success
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1c1
< 0
---
> 1
2 changes: 2 additions & 0 deletions simple-shell/diff1.success
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0a1
> 0
4 changes: 4 additions & 0 deletions simple-shell/diff2.success
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1c1
< 0
---
> 1
8 changes: 8 additions & 0 deletions simple-shell/diff4.success
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1d0
< 0
1d0
< 1
1d0
< 2
1d0
< 3
2 changes: 1 addition & 1 deletion unix-tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bin/*
cat
coreutils/*
diffutils/*
diff
etc/*
gawk/*
gnulib/*
Expand Down
29 changes: 10 additions & 19 deletions unix-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pr pathchk od numfmt nohup unexpand uname tty tsort truncate true \
tr touch timeout test tee tail tac sync sum stat split sleep shuf \
shred yes whoami wc vdir unlink uniq

FID=http://www.bmrb.wisc.edu/ftp/pub/bmrb/timedomain/bmr6443/timedomain_data/c13-hsqc/june11-se-6426-CA.fid/fid
FID=http://www.bmrb.wisc.edu/ftp/pub/bmrb/timedomain/bmr6443/timedomain_data/c13-hsqc/june11-se-6426-CA.fid/fid

PREFIX?=/usr/local/dgsh
DGSHPATH=$(PREFIX)/libexec/dgsh
Expand Down Expand Up @@ -62,7 +62,6 @@ get-submodules:
cd .. && git submodule update --init --recursive --depth=5000 \
$(TD)/bash \
$(TD)/coreutils \
$(TD)/diffutils \
$(TD)/grep

configure:
Expand All @@ -79,13 +78,6 @@ configure:
--mandir=$(MANDUMPDIR) \
--infodir=$(MANDUMPDIR) \
--localedir=$(MANDUMPDIR)
cd diffutils && ./bootstrap && ./configure --prefix=$(PREFIX) \
--bindir=$(DGSHPATH) \
--docdir=$(MANDUMPDIR) \
--mandir=$(MANDUMPDIR) \
--infodir=$(MANDUMPDIR) \
--localedir=$(MANDUMPDIR) \
SHELL=`which bash`
cd grep && ./bootstrap && ./configure --prefix=$(PREFIX) \
--bindir=$(DGSHPATH) \
--docdir=$(MANDUMPDIR) \
Expand All @@ -96,10 +88,9 @@ configure:
make:
$(MAKE) -C bash CFLAGS="$(CFLAGS)"
$(MAKE) -C coreutils
$(MAKE) -C diffutils
$(MAKE) -C grep

build-install: cat tee make
build-install: cat diff tee make
mkdir -p ../build/libexec/dgsh ../build/bin
cp bash/bash ../build/libexec/dgsh/
rm -f ../build/bin/dgsh
Expand All @@ -109,33 +100,34 @@ build-install: cat tee make
cp coreutils/src/join ../build/libexec/dgsh/
cp coreutils/src/paste ../build/libexec/dgsh/
cp coreutils/src/sort ../build/libexec/dgsh/
cp diffutils/src/diff ../build/libexec/dgsh/
cp grep/src/grep ../build/libexec/dgsh/
cp grep/src/egrep ../build/libexec/dgsh/
cp grep/src/fgrep ../build/libexec/dgsh/
chmod 755 tee cat
cp -p cat tee ../build/libexec/dgsh/
chmod 755 cat diff tee
cp -p cat diff tee ../build/libexec/dgsh/
./install-wrapped.sh $$(cd .. ; pwd)/build

install: cat tee make
install: cat 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 diffutils install
$(MAKE) -C grep install
# Install last to overwrite standard tools of coreutils
install cat $(DESTDIR)$(DGSHPATH)
install diff $(DESTDIR)$(DGSHPATH)
install tee $(DESTDIR)$(DGSHPATH)
./install-wrapped.sh
rm -rf $(DESTDIR)$(MANDUMPDIR)

cat: cat.sh
install $? $@

tee: tee.sh
diff: diff.sh
install $? $@

tee: tee.sh
install $? $@

test: test-bash test-compat

Expand All @@ -158,7 +150,7 @@ test-bash: ../simple-shell/fid
printf "$B\nBash tests:${EC}\n"

./run_all_simple_tests.sh $(PSDIR)

printf " $BPaper examples under ../example:${EC}\n"

# No diff, just check execution exit status
Expand Down Expand Up @@ -193,5 +185,4 @@ test-bash: ../simple-shell/fid
clean:
$(MAKE) -C bash clean
$(MAKE) -C coreutils clean
$(MAKE) -C diffutils clean
$(MAKE) -C grep clean
2 changes: 1 addition & 1 deletion unix-tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ make install # install in ./bin
make -s test # run tests
```

The current collection of Unix tools include *coreutils, diffutils, gawk, grep, parallel, sed, and tar*.
The current collection of Unix tools include *coreutils, gawk, grep, parallel, sed, and tar*.
Of those currently *comm*, *join*, *paste*, and *sort* have been adapted for use with dgsh.

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


# 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=":qscC:uU:enyW:pF:tTlrNx:X:S:iEZbwBIaD:dv-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
from-file)
from_file="${!OPTIND}"
OPTIND=$(($OPTIND + 1))
;;
from-file=*)
from_file=${OPTARG#*=}
;;
to-file)
to_file="${!OPTIND}"
OPTIND=$(($OPTIND + 1))
;;
to-file=*)
to_file=${OPTARG#*=}
;;
esac
;;
esac
done

# Examine the number of remaining (non-option) arguments
case $(($# - $OPTIND + 1)) in
0)
if [[ -n "$from_file" ]] || [[ -n "$to_file" ]] ; then
# An arbitrary number of inputs can be handled
exec dgsh-wrap -i a /usr/bin/diff "$@"
else
# Exactly two inputs are required
exec dgsh-wrap /usr/bin/diff "$@" '<|' '<|'
fi
;;
1)
if [[ -n "$from_file" ]] || [[ -n "$to_file" ]] ; then
# No input is required
exec dgsh-wrap -i 0 /usr/bin/diff "$@"
elif [[ "${!OPTIND}" == '-' ]] ; then
# One (non-stdin) input is required
exec dgsh-wrap -I /usr/bin/diff "$@" '<|'
else
# One (stdin) input is required
exec dgsh-wrap /usr/bin/diff "$@" -
fi
;;
*)
# No input is required
exec dgsh-wrap -i 0 /usr/bin/diff "$@"
;;
esac
1 change: 0 additions & 1 deletion unix-tools/diffutils
Submodule diffutils deleted from b9c7e0
6 changes: 6 additions & 0 deletions unix-tools/run_all_simple_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ there" |
}} |
cat"

# Wrapped diff
./run_simple_test.sh $PSDIR diff4 '! dgsh-enumerate 4 | diff -w --to-file=/dev/null'
./run_simple_test.sh $PSDIR diff2 '! dgsh-enumerate 2 | diff -w'
./run_simple_test.sh $PSDIR diff1 '! dgsh-enumerate 1 | diff -w /dev/null'
./run_simple_test.sh $PSDIR diff1-stdin '! dgsh-enumerate 2 | diff -'
./run_simple_test.sh $PSDIR diff0 'diff -w /dev/null /dev/null'

0 comments on commit 01691ba

Please sign in to comment.