#!/bin/sh

# sam_edit
# Copyright (C) 2003, 2004, 2005, 2006, 2007 Joseph Rosevear

# This file is part of an application of SAM for GNU/Linux Slackware
# known as SAM-GLS.

# SAM-GLS 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 3 of the License, or (at
# your option) any later version.

# SAM-GLS 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/>.

# (Slackware is a registered trademark of Patrick Volkerding and
# Slackware Linux, Inc.)


# some definitions
BIG=16

#if [ -e "$1" ]; then

   du $1 > $sam_temp_dir/du.dat

   read size balance < $sam_temp_dir/du.dat

   #get perms:
   perms="`ls -l $balance | grab 1`"

   #get pu, pg and po
   pu="`echo $perms | cut -c 3`"
   pg="`echo $perms | cut -c 6`"
   po="`echo $perms | cut -c 9`"
     
   writable=false
   #check if writable
   if [ \( "$pu" = "w" \) -o \
        \( "$pg" = "w" \) -o \
        \( "$po" = "w" \) ]; then
        
      writable=true
   fi

   big=false
   #Is the file big?
   if [ "$size" -gt BIG ]; then
   
      big=true;
   fi

   if [ "$big" = "true" ] && [ "$writable" = "true" ]; then

      echo
      echo "File $1 is too big.  Shame on you.  It's time to mv it to"
      echo "$1<n> and make it read-only.  Do that and try again."

   else

      #Warn if really writable even though no w was found perms.
      #This happens when you are root.
      if [ -w "$1" ]; then
      
      
      cat << done
You must be root.  That is OK, but be careful since you can write to
the file even though it has no write permission.  You 
         
      

      # JHR 060424 I changed $1 to "$2 $1" to allow passing parmameters like
      # -overwrite as $2
      # I made a complementary change to ment.f, so the scripts made by ment
      # can accept parameters like -overwrite as $3.
      $sam_distro/example/handy/exed "$2 $1"

   fi

#else

#   echo
#   echo "File $1 does not exist"

#fi
