#! /bin/tcsh -f

#
# fsr-getxopts
#
# USAGE: fsr-getxopts cmd xoptsfile
#
# Parses expert options for freesurfer recon.
# Looks in xoptsfile for a line with cmd as the first item,
# then returns the rest of the items on that line. Ignores
# all lines with # in them, regardless of where on the line
# they occur.
#
# Eg, if the file expert.opts contains:
#   mri_em_register -p .5
# Then
#   fsr-getxopts mri_em_register expert.opts
# will return
#   -p .5
#
# Original Author: Doug Greve
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/06 00:01:14 $
#    $Revision: 1.4 $
#
# Copyright (C) 2002-2007,
# The General Hospital Corporation (Boston, MA).
# All rights reserved.
#
# Distribution, usage and copying of this software is covered under the
# terms found in the License Agreement file named 'COPYING' found in the
# FreeSurfer source code root directory, and duplicated here:
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense
#
# General inquiries: freesurfer@nmr.mgh.harvard.edu
# Bug reports: analysis-bugs@nmr.mgh.harvard.edu
#

set VERSION = '$Id: fsr-getxopts,v 1.4 2007/01/06 00:01:14 nicks Exp $';

if($#argv < 2) exit 0;

set cmd       = $argv[1];
set xoptsfile = $argv[2];

if(! -e $xoptsfile) then
  echo "ERROR: cannot find $xoptsfile"
  exit 1;
endif

set tmp = `grep $cmd $xoptsfile | wc -l`;
if($tmp == 0) exit(0);
if($tmp > 1) then
  echo "ERROR: cmd $cmd represented more than once in $xoptsfile"
  exit 1;
endif

set tmp = `grep -v \# $xoptsfile | grep $cmd `;
echo "$tmp[2-$#tmp]"

exit 0
