/ scripts / linuxcnc_var.in
linuxcnc_var.in
  1  #!/bin/bash
  2  # maintainer: when adding items update three places:
  3  #             usage(), show_all(), and show_item()
  4  #
  5  # note: report LINUXCNVERSION=$EMC2VERSION (as does linuxcnc.in)
  6  
  7  # Copyright: 2014
  8  # Author:    Dewey Garrett <dgarrett@panix.com>
  9  #
 10  # This program is free software; you can redistribute it and/or modify
 11  # it under the terms of the GNU General Public License as published by
 12  # the Free Software Foundation; either version 2 of the License, or
 13  # (at your option) any later version.
 14  #
 15  # This program is distributed in the hope that it will be useful,
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  # GNU General Public License for more details.
 19  #
 20  # You should have received a copy of the GNU General Public License
 21  # along with this program; if not, write to the Free Software
 22  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 23  function usage () {
 24    cat <<EOF
 25  
 26  Retrieve Linuxcnc Variables
 27  Usage:
 28        $(basename $0) [ varname | all ]
 29  
 30  Varnames supported:
 31           LINUXCNCVERSION
 32           LINUXCNC_AUX_GLADEVCP
 33           LINUXCNC_AUX_EXAMPLES
 34           REALTIME
 35           RTS
 36           HALLIB_DIR
 37  
 38  Option 'all' returns varname=value for all supported varnames
 39  EOF
 40  exit 1
 41  }
 42  
 43  function show_all () {
 44    echo "LINUXCNCVERSION=@EMC2VERSION@
 45  LINUXCNC_AUX_GLADEVCP=@LINUXCNC_AUX_GLADEVCP@
 46  LINUXCNC_AUX_EXAMPLES=@LINUXCNC_AUX_EXAMPLES@
 47  REALTIME=@REALTIME@
 48  RTS=@RTS@
 49  HALLIB_DIR=@HALLIB_DIR@"
 50  }
 51  
 52  function show_item () {
 53    case $1 in
 54      LINUXCNCVERSION) echo @EMC2VERSION@;;
 55      LINUXCNC_AUX_GLADEVCP) echo @LINUXCNC_AUX_GLADEVCP@;;
 56      LINUXCNC_AUX_EXAMPLES) echo @LINUXCNC_AUX_EXAMPLES@;;
 57      REALTIME) echo @REALTIME@;;
 58      RTS) echo @RTS@;;
 59      HALLIB_DIR) echo @HALLIB_DIR@;;
 60      all) show_all;;
 61      *) echo UNKNOWN; exit 1;;
 62    esac
 63  }
 64  
 65  case $# in
 66     0) usage;;
 67     1) show_item $1;;
 68     *) usage;;
 69  esac
 70  exit 0
 71  
 72  # Example shell usage to populate environment in a sourced script:
 73  # for line in $(linuxcnc_var all) ; do
 74  #   name=${line%%=*}
 75  #   value=${line##*=}
 76  #   echo "name=$name value=$value"
 77  #   export "$name"="$value"
 78  # done
 79  
 80  # Example tcl usage:
 81  # foreach line [exec linuxcnc_var all] {
 82  #   set l [split $line =]
 83  #   set name  [lindex $l 0]
 84  #   set value [lindex $l 1]
 85  #   set V($name) $value
 86  # }
 87  # parray V
 88  
 89  # Example python usage:
 90  # import subprocess
 91  # s   = subprocess.Popen(['linuxcnc_var','all']
 92  #                       ,stdout=subprocess.PIPE
 93  #                       ,stderr=subprocess.PIPE
 94  # p,e = s.communicate()
 95  # v={}
 96  # for line in p.split('\n'):
 97  #     if line == '': continue
 98  #     name = line.split('=')[0]
 99  #     value = line.split('=')[1]
100  #     v[name] = value
101  # print(v)