### 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 jobs {} {
  # jobs

  Desc "Here you configure tcsh's job control. For more information on job"\
      "related command see the \"jobs\" sections in the tcsh manual."
  
  ShortDesc "Configuration on job related commands"

  ############################### Widgets ##############################
  CheckBox listjobs \
      -text "list all jobs when a job is suspended"

  CheckBox longformat \
      -text "Use long format for job list" 

  CheckBox notify \
      -text "notify job completion asynchronously" \
      -default 1 

  Line l1

  Int seconds \
      -text "Lower limit of cpu seconds before printing time info" 

  Line l2
  
  FillOutElm U \
      -text "The time the processor spent in user mode" \
      -show {print "\[User Time\]"} \
      -save "print %U" 

  FillOutElm S \
      -text "The time the processor spent in kernel mode" \
      -show {print "\[Kernel Time\]"} \
      -save "print %S" 

  FillOutElm E \
      -text "The Elapsed time (wall clock)" \
      -show {print "\[Real Time\]"}\
      -save "print %E" 

  FillOutElm P \
      -text "The CPU percentage" \
      -show {print "\[CPU percentage\]"} \
      -save "print %P" 

  FillOutElm W \
      -text "The number of times the process was swapped" \
      -show {print "\[\#swapped\]"}\
      -save "print %W"

  FillOutElm X \
      -text "Average amount in (shared) text space used" \
      -show {print "\[shared space\]"} \
      -save "print %X" 

  FillOutElm D \
      -text "Average amount in (unshared) data/stack space used" \
      -show {print "\[unshared space\]"} \
      -save "print %D" 

  FillOutElm K \
      -text "Total spaced Used" \
      -show {print "\[total space\]"}\
      -save "print %K"

  FillOutElm M \
      -text "Maximum amount of memory the processor had in use at any time"\
      -show {print "\[max memory\]"}\
      -save "print %M" 

  FillOutElm F \
      -text "The number of major page fault" \
      -show {print "\[major page Fault\]"} \
      -save "print %F"

  FillOutElm R \
      -text "The number of minor pages fault" \
      -show {print "\[minor page fault\]"} \
      -save "print %R"

  FillOutElm I \
      -text "The number of input operations" \
      -show {print "\[input operations\]"} \
      -save "print %I"

  FillOutElm O \
      -text "The number of output operations" \
      -show {print "\[output operations\]"} \
      -save "print %O"

  FillOutElm r \
      -text "The number of socket messages received" \
      -show {print "\[socket messages received\]"} \
      -save "print %r"

  FillOutElm s \
      -text "The number of socket messages sent" \
      -show {print "\[socket messages sent\]"} \
      -save "print %s"

  FillOutElm k \
      -text "The number of signals received" \
      -show {print "\[signal received\]"} \
      -save "print %k"

  FillOutElm w \
      -text "The number of voluntary context switches (waits)" \
      -show {print "\[waits\]"} \
      -save "print %w"

  FillOutElm c \
      -text "The number of involuntary context switches" \
      -show {print "\[in-waits\]"} \
      -save "print %c"

  FillOut time \
      -text "Format of the time string" \
      -entries {U S E P W X D K M F R I O r s k w c} \
      -default "%U%u %S%s %E% %P% %X%+%D%k %I%+%O%io%F%pf+%W%w"\
      -listbox:width 60

  ################################ Help ################################
  Help listjobs \
      "If this option is selected, all jobs which are suspended or"\
      "in the background are listed when a job is stopped with Ctrl-Z"

  Help longformat \
      "In the long format, working directory and process id are"\
      "printed as well as the information in the short format,"\
      "which are job number, job name, status (Running/Suspended)"
  
  Help notify \
      "If this option is set, the shell tells you, that a job is"\
      "finished at once, otherwise it will wait until the next prompt"\
      "is shown"
  
  Help seconds \
      "This is the amount of time that the process has to use,"\
      "before the time builtin will execute. Blank means never execute"\
      "the time builtin"
  
  Help U \
      "This is the time the cpu spent in user mode (in seconds)\n"\
      "user mode is the total amount of time the cpu has used on the process"
  
  Help S \
      "This is the time the processor spent in kernel mode in seconds"

  Help E \
      "this is the total amount of seconds that the processor has used"\
      "for the process."
  
  Help P \
      "This is calculated as (user mode time + kernel time) /"\
      "wall clock time"
  
  Help X \
      "This amount is in Kilobytes"

  Help D \
      "This amount is in Kilobytes"
  
  Help K \
      "This is in Kilobytes and is calculated as:\n"\
      "average shared + average unshared"

  Help M \
      "This is in Kilobytes"

  Help F \
      "This is the number of pages needed to be brought from disk"\
      "due to a page fault"

  Help time \
      "This is the format, that the builtin command \"time\" will use to"\
      "print. The \"time\" command, can either be invoked explicit with"\
      "\"time <command>\" or implicit, if the lower limit, above, is set."
  
  ############################### Change ###############################
  Change {
    switch $changeElm {
      listjobs {
        if {$listjobs} {
          Enable longformat
        } else {
          Disable longformat
        }
      }
    }
  }

  ################################ Save ################################
  Save {
    ########## listjobs ##########
    if {$listjobs || $generateDefault} {
      if {!$listjobs} {
        print "unset listjobs"
      } else {
        if {$longformat} {
          print "set listjobs=long"
        } else {
          print set listjobs
        }
      }
    }
    ########## notify ##########
    if {$notify || $generateDefault} {
      print "[pick $notify set unset] notify"
    }
    ########## time ##########
    if {$seconds != "" || $generateDefault} {
      if {$time != "%Uu %Ss %E %P %X+%Dk %I+%Oio%Fpf+%Ww" || $generateDefault} {
        if {$time == "%Uu %Ss %E %P %X+%Dk %I+%Oio%Fpf+%Ww" && $seconds == ""} {
          print "unset time"
        } else {
          print "set time = ($seconds \"$time\")"
        }
      } else {
        print "set time = $seconds"
      }
    }
  }
}

  
