#!/bin/sh
# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
#
# © 2010,2011 Canonical Ltd
#
# This program 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 3 of the License.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Michael Terry <michael.terry@canonical.com>
# =====================================================================

# Usage: pkgme_autoconf_initfield FIELD

# Example AC_INIT line:
# AC_INIT([Example Project],[1.0],[http://bugs.example.com/],[example-project],[http://example.com/])

CONFIG_NAME=$(pkgme_autoconf_config)
if [ -z "$CONFIG_NAME" ]; then
  exit 0
fi

acinit=$(grep --max-count=1 AC_INIT "$CONFIG_NAME" 2>/dev/null)
rv=$(echo $acinit | sed 's/AC_INIT//')
rv=$(echo $rv | cut -d, -f"$1")
# Find end (either , or ending ')')
rv=$(echo $rv | sed 's/[[( ]*\([^,)]*\).*/\1/')
# chop off ending odd characters
rv=$(echo $rv | sed 's/[] ]*$//')
echo $rv
exit 0
