|
|
4f3327 |
#!/bin/bash
|
|
|
4f3327 |
#
|
|
|
6713ca |
# cli_readFileContent.sh -- This function outputs content of files,
|
|
|
6713ca |
# passed as first argument, to standard output as specified by second
|
|
|
4f3327 |
# argument.
|
|
|
4f3327 |
#
|
|
|
4f3327 |
# Copyright (C) 2009-2011 Alain Reguera Delgado
|
|
|
4f3327 |
#
|
|
|
4f3327 |
# This program is free software; you can redistribute it and/or
|
|
|
4f3327 |
# modify it under the terms of the GNU General Public License as
|
|
|
4f3327 |
# published by the Free Software Foundation; either version 2 of the
|
|
|
4f3327 |
# License, or (at your option) any later version.
|
|
|
4f3327 |
#
|
|
|
4f3327 |
# This program is distributed in the hope that it will be useful, but
|
|
|
4f3327 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
4f3327 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
4f3327 |
# General Public License for more details.
|
|
|
4f3327 |
#
|
|
|
4f3327 |
# You should have received a copy of the GNU General Public License
|
|
|
4f3327 |
# along with this program; if not, write to the Free Software
|
|
|
4f3327 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
4f3327 |
# USA.
|
|
|
4f3327 |
#
|
|
|
4f3327 |
# ----------------------------------------------------------------------
|
|
|
4f3327 |
# $Id$
|
|
|
4f3327 |
# ----------------------------------------------------------------------
|
|
|
4f3327 |
|
|
|
4f3327 |
function cli_readFileContent {
|
|
|
4f3327 |
|
|
|
4f3327 |
local FILES="$1"
|
|
|
4f3327 |
|
|
|
6713ca |
# Verify existence of files but don't stop if it doesn't exist.
|
|
|
4f3327 |
cli_checkFiles "$FILES"
|
|
|
4f3327 |
|
|
|
4f3327 |
# Print content of files to standard output.
|
|
|
4f3327 |
case "$2" in
|
|
|
4f3327 |
|
|
|
4f3327 |
'--first-line' )
|
|
|
4f3327 |
cat "$FILES" | head -n 1
|
|
|
4f3327 |
;;
|
|
|
4f3327 |
|
|
|
4f3327 |
'--last-line' )
|
|
|
4f3327 |
cat "$FILES" | tail -n 1
|
|
|
4f3327 |
;;
|
|
|
4f3327 |
|
|
|
4f3327 |
'--copyright' )
|
|
|
4f3327 |
# This option prints the first line of a file, if it has a
|
|
|
4f3327 |
# copyright format. This option is mainly used to retrive
|
|
|
4f3327 |
# artistic motif author copyright note from artistic
|
|
|
4f3327 |
# motifs `authors.txt' file.
|
|
|
4f3327 |
local PATTERN='^Copyright (\(C\)|©) [0-9]+(-[0-9]+)? .+$'
|
|
|
4f3327 |
if [[ $(cli_readFileContent "$FILES" '--first-line') =~ "${PATTERN}" ]];then
|
|
|
4f3327 |
cli_readFileContent "$FILES" '--first-line'
|
|
|
4f3327 |
fi
|
|
|
4f3327 |
;;
|
|
|
4f3327 |
|
|
|
4f3327 |
'--all-lines' | * )
|
|
|
4f3327 |
cat "$FILES"
|
|
|
4f3327 |
esac
|
|
|
4f3327 |
|
|
|
4f3327 |
}
|