#! /bin/sh

# Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE).
#
# This file is part of Olena.
#
# Olena 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, version 2 of the License.
#
# Olena 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 Olena.  If not, see <http://www.gnu.org/licenses/>.

me=`basename $0`

# Use the C locale to have a deterministic sort.
export LC_ALL=C

test $# -gt 1 || { echo "usage: $me VARIABLE FILES..."; exit 1; }

# backslashify 
# ------------
# Read lines from the standard input and write them on the standard
# output with an extra trailing backslash, except for the last line.
backslashify() 
{
  # Set IFS to nothing to prevent `read' from trimming spaces or tabs.
  IFS= read last_line
  while IFS= read line; do
    echo "$last_line \\"
    last_line=$line
  done
  echo "$last_line"
}

cat<<EOF
## Generated by $me.  Do not edit by hand.

EOF
{
  echo "$1 ="
  shift
  for var; do
    echo "$var"
    shift
  done | sort | sed 's/\(.*\)/  \1/'
} | backslashify
