# vim: syntax=sh
# $Id: lr_functions.in,v 1.8 2006/07/23 13:16:33 vanbaal Exp $

#
# Copyright (C) 2003 Stichting LogReport Foundation LogReport@LogReport.org
#
#     This file is part of Lire.
# 
#     Lire 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.
# 
#     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 (see COPYING); if not, check with
#     http://www.gnu.org/copyleft/gpl.html. 
#

########################################################################
# lire_log ()
#
# Write a message using Lire logging format.
lire_log () {
    echo "${LR_SUPERSERVICE:-all} ${LR_SERVICE:-all} ${LR_ID:-none} ${PROGRAM:-unknown} $@" >&2
}

########################################################################
# lr_tag ()
#
# Generate something that can be used as LR_ID
lr_tag () {
    echo lr_tag-`date +%Y%m%d%H%M%S`-${$}
}

########################################################################
# lire_tempfile( template )
#
# Create a temporary file and prints the filename on stdout
lr_tempfile () {
    if test $# -ne 1
    then
        lire_log "missing 'template' parameter to lr_tempfile"
        return 1
    fi
    perl -MLire::Utils=tempfile -e '
my ( $template, $suffix ) = $ARGV[0] =~ /(.*?)(\.[^\.]+)$/;
my ( $fh, $filename ) = tempfile( $template, SUFFIX => $suffix ); 
print $filename, "\n"
' $1
}

########################################################################
# lr_tempdir ( template )
#
# Create temporary directory print its name
lr_tempdir () {
    if test $# -ne 1
    then
        lire_log "missing 'template' parameter to lr_tempdir"
        return 1
    fi
    perl -MLire::Utils=tempdir -e 'print tempdir( $ARGV[0] ), "\n"' $1
}

# Local Variables:
# mode: sh
# End:


