Blame Scripts/Bash/Functions/Render/render_doIdentityTextFormats.sh

4c79b5
#!/bin/bash
4c79b5
#
07c2fe
# render_doIdentityTextFormats.sh -- This function gives format to
4c79b5
# text files.
4c79b5
#
7cd8e9
# Copyright (C) 2009, 2010 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or
4c79b5
# modify it under the terms of the GNU General Public License as
4c79b5
# published by the Free Software Foundation; either version 2 of the
4c79b5
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function render_doIdentityTextFormats {
4c79b5
07c2fe
   # Define file path.
4c79b5
   local FILE="$1"
4c79b5
07c2fe
   # Define temporal file path.
07c2fe
   local TMPFILE=$(cli_getTemporalFile "${FILE}")
07c2fe
4c79b5
   # Get action to do over text file.
eb0e14
   local OPTIONS=$(render_getConfOption "$2" '2-')
4c79b5
4c79b5
   # Remove some fmt's options. As we are applying fmt's options to a
4c79b5
   # file directly, there are some options like --version and --help
4c79b5
   # that are of little use here.
4c79b5
   OPTIONS=$(echo "$OPTIONS" | sed -r 's!--(version|help)!!g')
4c79b5
4c79b5
   # Define current file format. Use just the first word returned by
4c79b5
   # the command `file' as identifier.
4c79b5
   local FILE_FORMAT=$(file $FILE | cut -d' ' -f2)
4c79b5
4c79b5
   # Do format based on file format.
4c79b5
   case $FILE_FORMAT in
4c79b5
4c79b5
      ASCII | UTF-8 )
4c79b5
      # Apply OPTIONS to plain text files. Doing the same with html
4c79b5
      # (and similar) files can mess up the markup, so apply format
4c79b5
      # options to plain text only.
07c2fe
      cat $FILE | fmt $(echo -n "$OPTIONS") > ${TMPFILE}
07c2fe
      mv ${TMPFILE} ${FILE}
4c79b5
      ;;
4c79b5
4c79b5
   esac
4c79b5
4c79b5
}