-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpd
executable file
·127 lines (115 loc) · 2.89 KB
/
pd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /bin/bash
#
# pd --- user script to send data to pdplot daemon
#
usage="usage: pd [-k][-n][-p][-d N] [-w window_name] [file...]"
gopts='c:knp:rd:f:w:g:h:s:a:'
#
# -n don't clear the existing data
# -k kill the pdplot daemon, remove the pipe
# -a <file> dump plot to <file>.ap
# -h <file> dump plot to <file>.hpgl
# -g <file> dump plot to <file>.png
# -p <file> dump the plot to <file>.ps
# -f <file> dump the plot to <file>.dxf
# -s <file> dump the plot to <file>.svg
# -c <file> dump the plot to <file>.d (piglet cell)
# -r refresh the window
# -d N debug level N (default 0)
# -w name specify the name of the window
wd=`pwd`
clear="clear"
kill=0
cmd=""
debug=""
given_name=""
set -f
set -- `getopt "$gopts" "$@"`; ret=$?
set +f
if [ $ret != 0 ] ; then
echo "$usage" 1>&2; exit 2
fi
while [ $# -gt 0 ] ; do
case $1 in
-n ) clear=""; shift ;;
-r ) cmd="plot"; shift ;;
-k ) kill=1; shift ;;
-d ) debug="-d $2"; shift 2 ;;
-a ) cmd="autoplot $wd/$2"; shift 2 ;;
-c ) cmd="pig $wd/$2"; shift 2 ;;
-p ) cmd="post $wd/$2"; shift 2 ;;
-f ) cmd="dxf $wd/$2"; shift 2 ;;
-s ) cmd="svg $wd/$2"; shift 2 ;;
-g ) cmd="graph $wd/$2"; shift 2 ;;
-h ) cmd="hpgl $wd/$2"; shift 2 ;;
-w ) given_name=$2; shift 2 ;;
-- ) shift; break ;;
#### These cases should never be executed:
-* ) echo "$0: script error: option '$1' not handled" 1>&2; exit 2;;
* ) echo "$0: getopts error parsing option '$1'" 1>&2; exit 2;;
esac
done
# echo $cmd
# Now only filenames are left:
files=$*
pdplot=pdplot
if [ -z "$given_name" ] ; then given_name=$(basename $0) ; fi
displayhost=${DISPLAY%%[.:]*}
if [ "$displayhost" = `hostname` ] ; then
window="$given_name"
else
window="`hostname`.$given_name"
fi
pipedir=/var/spool/sockets/pdplot
pipe=$pipedir/$window.$DISPLAY
function psgrep
{
ps -ef | sed '/grep/d' | grep "$pdplot *$displayarg"
}
if [ "$DISPLAY" = "" ] ; then
echo 'pd: $DISPLAY is not set' 1>&2
exit 2
elif [ "$DISPLAY" = `hostname`:0.0 ] ; then
displayarg=""
else
displayarg="-D $DISPLAY"
fi
if [ ! -d $pipedir ] ; then
echo "pd: creating $pipedir" 1>&2
mkdir $pipedir
chmod 777 $pipedir
fi
if [ $kill = 1 ] ; then
if [ ! -p $pipe ] ; then
rm -f $pipe
fi
psgrep | awk '{print "kill " $2}' | sh
ps=`psgrep`
if [ "$ps" != "" ] ; then
echo "Process still alive:\n$ps"
fi
exit 0
fi
if [ ! -p $pipe ] ; then
echo "pd: creating $pipe" 1>&2
\rm -f $pipe
/usr/bin/mkfifo -m 666 $pipe 2>/dev/null
fi
if psgrep >/dev/null ; then
true # already running
else
echo "pd: starting pd daemon" 1>&2
#$pdplot $displayarg -X $window $debug <$pipe &
#$pdplot <$pipe &
$pdplot $displayarg <$pipe &
fi
if [ "$cmd" != "" ] ; then
echo "$cmd" >$pipe
else
{
echo "$clear"
cat $files
echo "" # the file might not have a newline...
echo "plot"
} >$pipe
fi