2 #---- smpitools.sh --------------------------------------------------------#
4 # Copyright (c) 2013-2014. The SimGrid Team.
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the license (GNU LGPL) which comes with this package.
11 LISTSEP="$(printf '\b')"
13 # Create a temporary file, with its name of the form $1_XXX$2, where XXX is
14 # replaced by an unique string.
15 # $1: prefix, $2: suffix
17 tmp=$(mktemp --suffix="$2" "$1_XXXXXXXXXX" 2> /dev/null)
18 if [ -z "$tmp" ]; then
19 # mktemp failed (unsupported --suffix ?), try unsafe mode
20 tmp=$(mktemp -u "$1_XXXXXXXXXX" 2> /dev/null)
21 if [ -z "$tmp" ]; then
22 # mktemp failed again (doesn't exist ?), try very unsafe mode
23 if [ -z "${mymktemp_seq}" ]; then
24 mymktemp_seq=$(date +%d%H%M%S)
26 tmp="$1_$$x${mymktemp_seq}"
27 mymktemp_seq=$((mymktemp_seq + 1))
30 # create temp file, and exit if it existed before
31 sh -C -c "true > \"${tmp}\"" || exit 1
36 # Add a word to the end of a list (words separated by LISTSEP)
37 # $1: list, $2...: words to add
39 local list content newcontent
43 eval content=\"\${$list}\"
47 if [ -z "$content" ]; then
50 content="$content${LISTSEP}$newcontent"
52 eval $list=\"\${content}\"
56 # Like list_add, but only if first word to add ($2) is not empty
57 list_add_not_empty () {
63 # Set contents of a list (words separated by LISTSEP)
64 # $1: list, $2...: words to set
70 # Get the content of a list: positional parameters ($1, $2, ...) are set to the
73 # usage: eval $(list_get list)
75 printf 'IFS="$LISTSEP"; eval set -- \\$%s; IFS="$SAVEIFS"' "$1"
78 #---- end of smpitools.sh -------------------------------------------------#