### Copyright (C) 1995-1997 Jesper K. Pedersen
### 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; 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; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


proc files {} {
  # files

  Desc "Here you configure things which are related to files, and"\
      "listings of those."
  
  ShortDesc "configuration of files"

  ############################### Widgets ##############################
  
  Header lsF \
      -text "What to show on ls-F" 

  CheckBox x \
      -text "sort horizontally" 

  Menu a \
      -text "Which files to show" \
      -entries {all "all but `.' and `..'" "all but hidden files"}\
      -defaultIndex 2 

  Radio listlinks \
      -text "What information to show on links" \
      -entries {"A Link" "The type of the file the links point to"}

  CheckBox classify \
      -text "Appand a classify character to each file" -default 1
  
  Line l1
  
  CheckBox noclober \
      -text "check use of > and >>" \
      -default 1 

  CheckBox noglob \
      -text "Disable filename and directory stack substitution" 

  CheckBox rmstar \
      -text "Ask for confirmation on \"rm *\"" \
      -default 1

  Menu symlinks \
      -text "How to control symbolic links" \
      -entries {"Do nothing" chase  ignore expand}\
      -default ignore 

  Header h1 -text "File creation mask" 

  Label lUser -text "User : "
  Label lGroup -text "Group :"
  Label lOther -text "Other :"
  
  foreach elm {User Group Other} {
    CheckBox read$elm -text "Read file\nls dir" -justify l\
        -help "For files, this says whether people can read it\n For"\
        "Directories, this says whether people can read the contents"\
        "(ls)"
    CheckBox write$elm -text "Write file\nWrite in dir" -justify l\
        -help "For files, this says whether people can overwrite the"\
        "file For directories, this says whether people can create a"\
        "file in it."
    CheckBox execute$elm -text "cd to dirs" \
        -help "For files, this says nothing (It's not possible to"\
        "create a file with execute permissions.)\n For Directories,"\
        "this says whether people can cd to it. If you cannot cd to a"\
        "directory, then you cannot read a file irrespective of the"\
        "permission of the file. That way you can allow users to read"\
        "your files, if they know what they are called, but not see"\
        "which files you have."
  }

  Frame user -entries lUser readUser writeUser executeUser \
      -default {"" 1 1 1}
  Frame group -entries lGroup readGroup writeGroup executeGroup \
      -default {"" 1 0 1}
  Frame other -entries lOther readOther writeOther executeOther \
      -default {"" 1 0 1}
  Frame all -entries user group other -orient top


  ################################ Help ################################
  Help lsF \
      "ls-F can be called by the user on the command line, but"\
      "ls-F is also the program which tcsh uses when it shows possible"\
      "completions of file names."  

  Help x \
      "If this option is selected, the files will be sorted"\
      "horizontally instead of vertically"

  Help a \
      "Here you can tell tcsh which files ls-F shows.  You have the"\
      "following possibilities:\n1: all files\n2: all files but the"\
      "current directory (`.') and the parent directory (`..')\nall but"\
      "hidden files.  Hidden files are files which start with a dot."

  Help listlinks \
      "ls-F shows you the type of each file with a symbol at the end of"\
      "the file.  Here you configure which symbol to show for"\
      "links:\n1: the symbol for a link\n : the symbol for the file"\
      "which the links point to."

  Help classify \
      "ls-F have the possibility to append a character to each file"\
      "name indicating the file type.  For regular files that are"\
      "executable, append a `*'.  The file type indicators are `/' for"\
      "directories, `@' for symbolic links, `|' for FIFOs, `=' for"\
      "sockets, and nothing for regular files.  \n\nThis feature may"\
      "cost some time on very slow file systems."

  Help noclober \
      "If you select this option, files must not exist when using"\
      ">, and shall exist when using >>. To force redirection, use >!"\
      "instead of > and >>! instead of >>"

  Help noglob \
      "If you select this option, filename substitution like \"*\""\
      "and \"?\" will be disabled, and directory stack substitution like"\
      "\"=1\" will likewise be disabled."

  Help rmstar \
      "If this option is selected the user is prompted before"\
      "\"rm *\" is executed."

  Help symlinks \
      "If set to `chase', whenever the current directory changes to a"\
      "directory containing a symbolic link, it is expanded to the real"\
      "name of the directory to which the link points. This does not"\
      "work for the user's home directory; this is a bug.\n\n"\
      ""\
      "If set to `ignore', the shell tries to construct a current"\
      "directory relative to the current directory before the link was"\
      "crossed.  This means that cding through a symbolic link and then"\
      "`cd ..'ing returns one to the original directory.  This only"\
      "affects builtin commands and filename completion.\n\n"\
      ""\
      "If set to `expand', the shell tries to fix symbolic links by"\
      "actually expanding arguments which look like path names. This"\
      "affects any command, not just builtins.  Unfortunately, this"\
      "does not work for hard-to-recognize filenames, such as those"\
      "embedded in command options.  Expansion may be prevented by"\
      "quoting. While this setting is usually the most convenient, it"\
      "is sometimes misleading and sometimes confusing when it fails to"\
      "recognize an argument which should be expanded.  A compromise is"\
      "to use `ignore' and use the editor command normalize-path (bound"\
      "by default to ^X-n) when necessary."

  Help h1 "This is the permission a file will get when it is created."

  Help lUser "This is the permission you get"
  Help lGroup \
      "This is the permission people in the file's group get,"\
      "type ls -lg <file>, to see which group the file belongs to."
  Help lOther \
      "This is the permissions to people"\
      "which are not in the same group as the file."
  
  ################################ Save ################################

  Save {
    ########## listlinks ##########
    if {$listlinks(index) == 1 || $generateDefault} {
      print "[pick $listlinks(index) set unset] listlinks"
    }
    ########## noclobber ##########
    if {$noclober || $generateDefault} {
      print "[pick $noclober set unset] noclobber"
    }
    ########## noglob ##########
    if {$noglob ||  $generateDefault} {
      print "[pick $noglob set unset] noglob"
    }
    ########## rmstar ##########
    if {$rmstar || $generateDefault} {
      print "[pick $rmstar set unset] rmstar"
    }
    ########## listflags ##########
    if {$x || $a(index) != 2 || $generateDefault} {
      set option ""
      if {$x} {
        append option "x"
      }
      if {$a(index) == 0} {
        append option "a"
      }
      if {$a(index) == 1} {
        append option "A"
      }
      if {$option == ""} {
        print "unset listflags"
      } else {
        print "set listflags=\"$option\""
      }
    }
    ########## classify ##########
    if {!$classify || $generateDefault} {
      print "[pick $classify unset set] nostat"
    }
    ########## symlinks ##########
    if {$symlinks(index) || $generateDefault} {
      switch $symlinks(index) {
        0 {print "unset symlinks"}
        1 {print "set symlinks chase"}
        2 {print "set symlinks ignore"}
        3 {print "set symlinks expand"}
      }
    }
    ########## umask ##########
    foreach elm {User Group Other} {
      set $elm \
          [expr (![set read$elm])*4 + (![set write$elm])*2 + ![set execute$elm]]
    }
    set permission "$User$Group$Other"
    if {$permission != "022" || $generateDefault} {
      print "umask $permission"
    }
  }
}
