#!/usr/bin/env expect
############################################################################
# Purpose: Establish global state information for Slurm hetergeneous job tests
#
# To define site-specific state information, set the values in a file
# named 'globals.local'. Those values will override any specified here.
# for example:
#
# $ cat globals.local
# set slurm_dir "/usr/local"
# set mpicc     "/usr/local/bin/mpicc"
#
############################################################################
# Copyright (C) SchedMD LLC.

# This file is part of Slurm, a resource management program.
# For details, see <https://slurm.schedmd.com/>.
# Please also read the supplied file: DISCLAIMER.
#
# Slurm is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with SLURM; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
############################################################################

source ./globals


# parse the string contained in HET_JOB_ID_SET
# only use if there are three components to 
# het_job

proc parse_id_set {id_set job_id} {

	set result [list]

	set r1 [split $id_set ,]
	if {[llength $r1]==3} {
		set result $r1
	} elseif {[llength $r1]==1} {
		set r1 [split $id_set -]
		lappend result [lindex $r1 0]
		lappend result [expr {[lindex $r1 0]+1}]
		lappend result [lindex $r1 1]
	} elseif {[string first - [lindex $r1 0]] == -1} {
		lappend result [lindex $r1 0]
		set r1 [split [lindex $r1 1] -]
		lappend result [lindex $r1 0]
		lappend result [lindex $r1 1]
	} else {
		lappend result [lindex $r1 1]
		set r1 [split [lindex $r1 0] -]
		lappend result [lindex $r1 0]
		lappend result [lindex $r1 1]
	}

	set result [lsearch -all -inline -not -exact $result $job_id]

	return $result
}


