-
Notifications
You must be signed in to change notification settings - Fork 44
/
setup.csh
158 lines (156 loc) · 4.92 KB
/
setup.csh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# mdsplus.csh - to be sourced during login from csh or derivative
#
# this script will search for the first environment variable definition file
# it can find looking in the following order:
# $setup_file
# ./envsyms
# $MDSPLUS_DIR/etc/envsyms
#
#
# The definition file should contain the following types of lines:
#
# 1) comment-line
# 2) variable-definition
# 3) include-statement
# 4) source-statement
# 5) dot-statement
#
# where:
#
# 1) comment-line:
#
# A comment line beginning with # in first character.
#
# 2) variable-definition:
#
# A environment variable definition of the following form:
#
# environment-variable-name environment-variable-value optional-delimiter-spec
#
# where:
#
# optional-delimiter-spec is the character ">" or "<" followed by a delimiter
#
# Examples:
#
# myvar foo (define environment variable myvar to have the value foo)
# mytree_path $HOME/mytree <; (define environment variable mytree_path to have the
# value $HOME/mytree. If mytree_path was previously
# defined, mytree_path will become $HOME/mytree followed
# by a semi-colon followed by the original value.)
# PATH $HOME/bin :> (Append $HOME/bin to the PATH environment variable.)
#
# 3) include-statement:
#
# Include another definition file.
#
# Example:
#
# include $HOME/.mdsplus
#
# 4) source-statement
#
# Source another file with shell commands
#
# Example:
#
# source $HOME/myscript.csh
#
# 5) dot-statement
#
# Noop in csh used when same definition file is invoked by mdsplus.sh
#
#
#
if ( $?MDSPLUS_DIR ) then
setenv MDSPLUS_DIR $MDSPLUS_DIR
else if ( -r /etc/.mdsplus_dir ) then
setenv MDSPLUS_DIR `cat /etc/.mdsplus_dir`
else
setenv MDSPLUS_DIR /usr/local/mdsplus
endif
if ( $?temp_sym_name ) then
set temp_sym_old_value=`printenv $temp_sym_name`
if ( $temp_sym_old_value == '' ) then
setenv $temp_sym_name $temp_sym_value
else
set found=false
foreach v (`echo ${temp_sym_old_value} | tr "${temp_delim}" "\n"`)
if ( $v == $temp_sym_value ) then
set found=true
endif
end
if ( $found == 'false' ) then
switch ($temp_direction)
case '>':
setenv $temp_sym_name ${temp_sym_old_value}${temp_delim}${temp_sym_value}
breaksw
case '<':
setenv $temp_sym_name ${temp_sym_value}${temp_delim}${temp_sym_old_value}
breaksw
default:
echo bad direction - $temp_direction
breaksw
endsw
endif
endif
unset temp_sym_name
unset temp_sym_old_value
unset temp_direction
unset temp_delim
else
if ( ! $?temp_file) then
if ( $?setup_file ) then
set temp_file=$setup_file
else if ( -r ./envsyms ) then
set temp_file=envsyms
else if ( -r $MDSPLUS_DIR/etc/envsyms ) then
set temp_file=$MDSPLUS_DIR/etc/envsyms
else
set temp_file=asdjklasdjasdjlkasd
endif
endif
if ( -r $temp_file ) then
if ( -r ./setup.csh ) then
set temp_setup_script=./setup.csh
else if ( -r $MDSPLUS_DIR/setup.csh ) then
set temp_setup_script=$MDSPLUS_DIR/setup.csh
else
set temp_setup_script=unknown_setup_script
endif
if ( $?verify_setup ) echo Processing $temp_file
set awkcmd='{ if (($3 != "") && ((substr($3,2,1) == ":") || (substr($3,2,1) == ";"))) $3 = substr($3,1,1) "\\" substr($3,2) } '
set awkcmd="$awkcmd"'{ if ((NF > 0) && ($1 !~ /^#.*/) && (NF < 3) && ($1 != "source") && ($1 != ".") && ($1 != "include")) print "setenv " $1 " " $2 ";" ;'
set awkcmd="$awkcmd"'else if ((NF > 0) && ($1 == "source")) print $0 ";" ; '
set awkcmd="$awkcmd"'else if ((NF > 0) && ($1 == "include")) print "set temp_file=" $2 "; source $temp_setup_script ; " ; '
set awkcmd="$awkcmd"'else if ((NF > 0) && ($1 == ".")) print "" ; '
set awkcmd="$awkcmd"'else if ((NF > 0) && ($1 !~ /^#.*/)) print "set temp_sym_name=" $1 "; set temp_sym_value=" $2 "; set temp_direction='
set awkcmd="$awkcmd""'"
set awkcmd="$awkcmd"'" substr($3,1,1) "'
set awkcmd="$awkcmd""'"
set awkcmd="$awkcmd"'; set temp_delim='
set awkcmd="$awkcmd"'" substr($3,2) "'
set awkcmd="$awkcmd"'; source $temp_setup_script;" ; }'
if (-x /bin/awk) then
set shellcmd=`/bin/awk "$awkcmd" $temp_file`
else if (-x /usr/bin/awk) then
set shellcmd=`/usr/bin/awk "$awkcmd" $temp_file`
else
set shellcmd=`awk "$awkcmd" $temp_file`
endif
unset temp_file
eval $shellcmd
# unset temp_setup_script
unset shellcmd
unset awkcmd
else
unset temp_file
endif
endif
if ( ! $?PyLib ) then
set pyver=`python -V >& /dev/stdout`
if ( $? == 0 ) then
set PyLib=`echo $pyver | awk '{print $2}' | awk -F. '{print "python"$1"."$2;}'`
endif
unset pyver
endif