home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls089.ibmaix.Z / tls089.ibmaix / lib / vtcl / examples / cron.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  4.0 KB  |  137 lines

  1. #!/bin/vtcl
  2. # ---------------------------------------------------------------------
  3. # Copyright 1994 by SCO, Inc.
  4. # Permission to use, copy, modify, distribute, and sell this software
  5. # and its documentation for any purpose is hereby granted without fee,
  6. # provided that the above copyright notice appear in all copies and that
  7. # both that copyright  notice  and  this  permission  notice  appear  in
  8. # supporting documentation, and that the name  of  SCO  not  be used  in
  9. # advertising or publicity pertaining  to distribution of  the  software
  10. # without   specific,   written  prior   permission.    SCO   makes   no
  11. # representations  about  the  suitability  of  this  software  for  any
  12. # purpose.  It is provided "as is" without express or implied warranty.
  13. # ---------------------------------------------------------------------
  14. #
  15. # Demo        : cron.tcl
  16. # Description    : Example used on a SCO tech journal article.
  17. # Comments    : This demo allows the user to view the contents of
  18. #          a crontabs file.  NEED root permission.
  19. # Highlights    - file I/O, use of rowcolumn widget, keyed list.
  20. #
  21. proc GetCronRecordList {filename} {
  22.     set fd [open $filename r]
  23.     while { ! [eof $fd] } {
  24.         if {[gets $fd record] > 0 } {
  25.             # We'll skip commented records
  26.             if { [cindex $record 0] != "#"} {
  27.                 lappend cronRecordList $record
  28.             }
  29.         }
  30.     }
  31.     close $fd
  32.     return $cronRecordList
  33. }
  34.  
  35. proc ParseCronRec {record} {
  36.     set itemList [split $record "\t " ]
  37.     set scheduleFields [lrange $itemList 0 4]
  38.     set commandField [lrange $itemList 5 end]
  39.     keylset parsedCronRec MINUTE [lindex $scheduleFields 0]
  40.     keylset parsedCronRec HOUR [lindex $scheduleFields 1]
  41.     keylset parsedCronRec MONTHDAY [lindex $scheduleFields 2]
  42.     keylset parsedCronRec YEAR [lindex $scheduleFields 3]
  43.     keylset parsedCronRec WEEKDAY [lindex $scheduleFields 4]
  44.     keylset parsedCronRec COMMAND $commandField
  45.     return $parsedCronRec
  46. }
  47.     
  48. proc ShowDetailsCB {cbs} {
  49.     set parent [keylget cbs dialog]
  50.     set dlog [VtFormDialog $parent.dlog \
  51.         -title "Cron Record Details" \
  52.         -okCallback WxEndFormCB \
  53.         ]    
  54.     set leftColumnW [VtRowColumn $dlog.left \
  55.         ]
  56.     set rightColumnW [VtRowColumn $dlog.right \
  57.         -leftSide $leftColumnW \
  58.         -alignTop $leftColumnW \
  59.         -leftOffset 0 \
  60.         ]
  61.     set labelList [list Minute: Hour: "Day in Month:" Year: "Week Day:" ]
  62.     foreach label $labelList {
  63.         VtLabel $leftColumnW.$label \
  64.             -label $label \
  65.             -labelRight
  66.     }
  67.     set fieldKeyList {MINUTE HOUR MONTHDAY YEAR WEEKDAY}
  68.     set record [keylget cbs selectedItemList]
  69.     set cronList [ParseCronRec [lvarpop record]]
  70.     foreach fieldKey $fieldKeyList {
  71.         VtLabel $rightColumnW.$fieldKey \
  72.             -label [keylget cronList $fieldKey] \
  73.             -labelLeft
  74.     }
  75.  
  76.     VtText $dlog.command \
  77.         -below $leftColumnW \
  78.         -value [keylget cronList COMMAND] \
  79.         -columns 40 \
  80.         -horizontalScrollBar True \
  81.         -bottomSide FORM
  82.  
  83.     VtShow $dlog
  84.     
  85.     
  86.     
  87. }
  88.  
  89. proc BuildMainDialog {dialog filename cronRecords} {
  90.     set titleLabelW [VtLabel $dialog.title \
  91.         -label "Cron entries in $filename" \
  92.         ]
  93.     set cronListW [VtList $dialog.cronList \
  94.         -itemList $cronRecords \
  95.         -rightSide FORM \
  96.         -bottomSide FORM \
  97.         -callback ShowDetailsCB \
  98.         ]
  99. }
  100.  
  101. proc CloseProgramCB {cbs} {
  102.     VtClose; exit 0
  103. }
  104. set appShell [VtOpen CronBrowser]
  105. set mainDialog [VtFormDialog $appShell.mainD \
  106.     -title "Cron Browser Program" \
  107.     -okLabel Exit \
  108.     -okCallback CloseProgramCB \
  109.     -wmCloseCallback CloseProgramCB \
  110.     ]
  111.     
  112. set filename /usr/spool/cron/crontabs/root
  113.  
  114. if { ! [file readable $filename] } {
  115.     set errDlog [VtErrorDialog $mainDialog.errDlog \
  116.         -message "You must have permission to read:\n$filename \
  117.             \n\n        OR\n \
  118.             \nsimply rename the crontab file in this \
  119.             \nprogram to one that you can read." \
  120.         -ok \
  121.         -okCallback CloseProgramCB \
  122.         ]
  123.     VtShow $errDlog
  124.     # Need to put a main loop here since the program shouldn't
  125.     # go on from here and we need to enter an event-loop in order
  126.     # 1) prevent the rest of the code from getting executed, and 
  127.     # 2) to get the CloseProgramCB called.
  128.     #
  129.     VtMainLoop
  130. }
  131. set cronRecords [GetCronRecordList $filename]
  132.  
  133. BuildMainDialog $mainDialog $filename $cronRecords
  134. VtShow $mainDialog
  135. VtMainLoop
  136.  
  137.