Debian Codegraph @

install/unix/ed_moptions

raw symbols SCIP
1 #! /bin/shscip-shell filesystem . . `/bin/sh`.
2 # @(#)ed_moptions.sh 19.1 (ESO-IPG) 02/25/03 13:51:10
3 # .COPYRIGHT: Copyright (c) 1988 European Southern Observatory,
4 # all rights reserved
5 # .TYPE command
6 # .NAME ed_make_options.sh
7 # .LANGUAGE shell script
8 # .ENVIRONMENT Unix Systems. Executable under SHELL and C-SHELL
9 # .COMMENTS Editing the file make_options.
10 #
11 # .AUTHOR Carlos Guirao
12 # .VERSION 1.1 17-Jul-1992: Implementation
13 # .VERSION 2.1 20-Jan-1993: "ex" instead of "ed" (for PC/Linux)
14 # .VERSION 3.1 990324 Checking EDITOR (default ex, otherwise ed)
15
16 if [scip-shell system . . `[`. $# -lt 1 ]; then
17 echoscip-shell system . . echo. "Usage: $0 get/replace/add/delete key[=options]"
18 exit 1
19 fi
20
21 if [scip-shell system . . `[`. "$1" != "get" -a "$1" != "replace" -a "$1" != "add" -a "$1" != "delete" ]; then
22 echoscip-shell system . . echo. "Usage: $0 get/replace/add/delete key[=options]"
23 exit 1
24 fi
25
26 if [scip-shell system . . `[`. "$1" != "delete" -a $$ -lt 2 ]; then
27 echoscip-shell system . . echo. "Usage: $0 replace/add key=options"
28 exit 1
29 fi
30
31 #
32 # Check if 'ex' editor exists otherwise use 'ed'
33 # "ed" is substituted by "ex" for PC/Linux except in SuSE
34 #
35 EDITOR=ex
36 whichscip-shell system . . which. ex > /dev/nullscip-shell filesystem . . `/dev/null`.
37 if [scip-shell system . . `[`. $? != 0 ]; then
38 EDITOR=ed
39 fi
40
41 if [scip-shell system . . `[`. -z "$MID_HOME" ]; then
42 cd `echoscip-shell system . . echo. $0 | sedscip-shell system . . sed. -e 's/[^\/]*$//' -e 's/^$/./' -e 's/\/$//'`
43 MID_INSTALL=`pwdscip-shell system . . pwd.`
44 VERSDIR=`echoscip-shell system . . echo. $MID_INSTALL | sedscip-shell system . . sed. 's/\/install\/unix$//'`
45 MIDVERS=`echoscip-shell system . . echo. $VERSDIR | sedscip-shell system . . sed. -e 's/^.*\///'`
46 MIDASHOME=`echoscip-shell system . . echo. $VERSDIR | sedscip-shell system . . sed. -e 's/[^\/]*$//' -e 's/^$/./' -e 's/\/$//'`
47 MID_HOME=$MIDASHOME/$MIDVERS
48 fi
49
50 file=$MID_HOME/local/make_options
51 op=$1
52 key=`echoscip-shell system . . echo. $2 | awkscip-shell system . . awk. -F= '{print $1}'`
53 options=`echoscip-shell system . . echo. $2 | sedscip-shell system . . sed. 's/^'$key'=//'`
54 options=`eval echo $options`
55 oldoptions=""
56
57 if [scip-shell system . . `[`. -f $file ]; then
58 oldoptions=`grepscip-shell system . . grep. "^${key}=" $file | sedscip-shell system . . sed. 's/^'$key'=//'`
59 fi
60
61 if [scip-shell system . . `[`. -n "$oldoptions" ]; then
62 echoscip-shell system . . echo. $oldoptions
63 fi
64
65 if [scip-shell system . . `[`. "$op" = "get" ]; then
66 exit 0
67 fi
68
69 # Remove previous definition of $key if existed
70 $EDITOR $file << EOF >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
71 1
72 /${key}=/d
73 w
74 q
75 EOF
76
77 if [scip-shell system . . `[`. "$op" = "delete" ]; then
78 exit 0
79 fi
80
81 if [scip-shell system . . `[`. "$op" = "add" ]; then
82 options=`eval echo $oldoptions $options`
83 fi
84
85 if [scip-shell system . . `[`. -n "$options" ]; then
86 echoscip-shell system . . echo. "$key=$options" >> $file
87 fi
88 exit 0