Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CTDAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CTDAS
CTDAS
Commits
34cbeb20
Commit
34cbeb20
authored
14 years ago
by
Peters, Wouter
Browse files
Options
Downloads
Patches
Plain Diff
source code goes to trunk before starting a new branch
parent
093d18ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
go_readrc
+180
-0
180 additions, 0 deletions
go_readrc
with
180 additions
and
0 deletions
go_readrc
0 → 100755
+
180
−
0
View file @
34cbeb20
#! /bin/sh
# --- init ---
# leave on error
set
-e
# --- external ---
basename
=
'/bin/basename'
test
!
-x
${
basename
}
&&
basename
=
'/usr/bin/basename'
egrep
=
'/bin/egrep'
test
!
-x
${
egrep
}
&&
egrep
=
'/usr/bin/egrep'
less
=
'/bin/less'
test
!
-x
${
less
}
&&
less
=
'/usr/bin/less'
test
!
-x
${
less
}
&&
less
=
'/usr/local/bin/less'
sed
=
'/bin/sed'
test
!
-x
${
sed
}
&&
sed
=
'/usr/bin/sed'
# --- definitions ---
prog
=
`
${
basename
}
$0
`
# --- help ---
DisplayHelp
()
{
${
xPAGER
:-${
less
}}
<<
EOF
$prog
General Objects
NAME
$prog
- read data value from a resource file
SYNOPSIS
go_readrc <rcfile> <key> [<default>]
go_readrc -h|--help
DESCRIPTION
A recourcefile is a text file with key/data pairs, usefull
to initialize programs (scripts, Fortran, etc).
The format of the <rcfile> is chosen close to the standard X resources:
* Comment lines start with '!'
* A key/data pair has the format:
<key> : <value>
where the white space (space or tabs) is optional.
The <key> consists of letters, numbers, '_', and '.' .
Example of a valid rcfile:
! Specify an output directory:
output.path : d/
Given a text <key>, the <rcfile> is scanned for a line starting
with this key; all text behind the ':' is written to the standard output.
Example of usage in sh script:
output_root=
\`
go_readrc test.rc output.path
\`
If the <key> is not found, an error message is issued,
unless a <default> is supplied which is then written to standard output.
The <default> might be an empty string, e.g. '' .
PREPROCESSING
The rcfile might be preprocessed by go_pprc,
to expand environment variables.
EXIT STATUS
Non zero in case of any error.
SEE ALSO
X, go_pprc
AUTHOR
Arjo Segers
EOF
exit
0
}
ErrorMessage
()
{
echo
"ERROR in
$prog
:
$1
"
1>&2
echo
" Use '
$prog
-h' for information."
1>&2
exit
1
}
# --- arguments ---
rcfile
=
''
rckey
=
''
with_default
=
''
while
[
$#
-gt
0
]
;
do
case
"
$1
"
in
-h
|
--help
)
DisplayHelp
;;
-
*
)
ErrorMessage
"unknown option '
$1
' ..."
;;
*
)
if
[
-z
"
${
rcfile
}
"
]
;
then
rcfile
=
"
$1
"
elif
[
-z
"
${
rckey
}
"
]
;
then
rckey
=
"
$1
"
elif
[
-z
"
${
with_default
}
"
]
;
then
default
=
"
$1
"
with_default
=
'true'
else
ErrorMessage
"unknown argument '
$1
'"
fi
;;
esac
shift
done
if
[
-z
"
${
rcfile
}
"
-o
-z
"
${
rckey
}
"
]
;
then
ErrorMessage
"missing arguments"
fi
# --- begin ---
# does the rcfile exist?
if
[
!
-f
${
rcfile
}
]
;
then
ErrorMessage
"rcfile '
${
rcfile
}
' does not exist ..."
fi
# replace '.' in the rckey by '\.'
rckeydots
=
`
echo
${
rckey
}
|
${
sed
}
-e
's/\./\\\\./g'
`
# 10 Apr 06: Andy Jacobson
# [[:space:]] indicates a space or tab character
#wspace='[[:space:]]*'
#
# 26 Apr 06: Arjo Segers
# The egrep on SGI system does not support the '[:space:]' ;
# use a real tab character instead ...
tab
=
' '
wspace
=
"[
${
tab
}
]*"
# A key-data line has the following synopsis:
#
# <begin-of-line><key>[<wspace>]:[<wspace>]<data>
#
# where <wspace> denote tabs or spaces.
# Set regular expression for such a line except the <data> part;
# this expression is used to search for a key and to extract
# the data part:
#
re
=
"^
${
rckeydots
}${
wspace
}
:
${
wspace
}
"
# set grep command to select matching lines:
selectlinecmd
=
"
${
egrep
}
'
${
re
}
'
${
rcfile
}
"
# count number of hits; should be exactely 1 ...
nfound
=
`
eval
"
${
selectlinecmd
}
"
| /usr/bin/wc
-l
`
if
[
${
nfound
}
-eq
0
]
;
then
if
[
-z
"
${
with_default
}
"
]
;
then
ErrorMessage
"key '
${
rckey
}
' not found in
${
rcfile
}
and no default specified ..."
else
echo
"
${
default
}
"
exit
0
fi
elif
[
${
nfound
}
-gt
1
]
;
then
ErrorMessage
"key '
${
rckey
}
' found
${
nfound
}
times in
$rcfile
..."
fi
# extract the data part for this key;
# substitute an empty string for the 'key : ' part;
# remove trailing blanks;
# output is written to standard output:
eval
"
${
selectlinecmd
}
"
|
${
sed
}
-e
"s/
${
re
}
//"
-e
"s/
${
wspace
}
$/
/"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment