home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
ktfc
/
ktfc.zip
/
SCAN0.5
< prev
next >
Wrap
Text File
|
2000-05-24
|
8KB
|
247 lines
; File scan0.5, copyright (C) Peter Lyall Easthope, 2000.
; All rights reserved.
take prolog0.5 ; User configuration and procedures for login.
; ============ Begin user configuration section ============
; Messages older than MsgLife will be deleted from the Mailbox.
asg MsgLife 3
; "Other" defines a list of directory index vectors to be scanned.
; Each directory index vector is a sequence of indexes of directories
; which enclose the target directory, the last in the sequence. Each
; index vector is the content of a \%d[i].
def Other {
def dLen 0 ; Number of directories.
declare \&d[\m(dLen)] ; Declare the directory list array
; def \&d[1] {3 6} ; FirstClass Support
; def \&d[2] {3 7} ; FirstClass News
; HndlMsg is used in ScanDirs.
def HndlMsg {
if equal {\fsubstr(\m(Title),1,1)} {*} RecvMsg
}
}
; ============ End user configuration section ============
; MB defines a directory list containing only the Mailbox.
def MB {
local string
asg string {This message has been on the server for at least}
def dLen 1 ; Number of directories.
declare \&d[\m(dLen)] ; Declare the directory list array
def \&d[1] {1} ; Path from Home to Mailbox.
def HndlMsg {
xif equal {\fsubstr(\m(Title),1,1)} {*} { RecvMsg } else {
GetAge
; echo {age of this message is \v(return) days.}
xif > \v(return) \m(MsgLife) {
DelMsg {\m(string) \m(MsgLife) days.}
}
}
}
}
; Beginning of procedures used to receive messages or to tidy the mailbox.
def minputJ {
clear input
minput \m(WaitTime) {J} {Item number:}
switch \v(minput) {
:0, errext {Response after GetDir sends dir. number not recognizable.}
:1, break
:2, errext {faulty directory number; check path in User Configuration.}
:default, errext {Undefined switch value in GetDir}
}
}
; This procedure takes two arguments. The second is a string which is the
; index of a directory in the current directory. If the first argument
; is 1 a listing of the contents of the directory is put in a file named DIR.
; If the first argument is 0 the directory listing is discarded.
def GetDir {
local str
xif equal {\%1} {1} {
open write DIR
if failure errext {Can't open directory file DIR for writing.}
echo {File DIR opened to write the directory at {\&d[\%f]}.}
}
output {\%2\13}
minputJ
IInputLine
SaveLine
if equal {\%1} {1} writeln file {\m(InLine)}
asg str \fsubstr(\m(InLine),\feval(\flength(\m(InLine))-8),9)
xif equal {\m(str)} {No items.} {
; echo {Directory is empty.}
IInputLine
IInputLine
GetPrompt
} else {
; echo {Directory is not empty.}
local ExitMB
def ExitMB 0
while equal \m(ExitMB) 0 {
clear input
minput \m(WaitTime) {\10} {[More]}
switch \v(minput) {
:0, errext {Unrecognized characters when receiving directory}
:1, SaveLine, InputMB1 {\%1}, break
:2, InputMB2, break
:default, errext {Undefined switch in directory reading loop}
}
}
}
xif equal {\%1} {1} { close write-file }
}
def FindDir {
; Initialize index for locating the start of the terminal directory number.
asg beginD \flength(\&d[\%f])
; Step backwards through the path from the end.
while equal {\fsubstr(\&d[\%f ],\m(beginD),1)} { } {
if = \m(beginD) 1 errext {No directory number found}
asg beginD \feval(\m(beginD)-1)
}
while = 1 1 {
; echo {Searching for beginning of directory string}
if = \m(beginD) 1 break
asg tmp \feval(\m(beginD)-1)
if equal {\fsubstr(\&d[\%f],\m(tmp),1)} { } break
asg beginD \m(tmp)
}
; beginD now contains the index in \&d[\%f] of the start of the
; target directory.
}
def TracePath {
; Step through the path from the beginning.
asg begini 1
while = 1 1 {
if = \m(begini) \m(beginD) break
while = 1 1 {
if not equal {\fsubstr(\&d[\%f],\m(begini),1)} { } break
asg begini \feval(\m(begini)+1)
}
; echo {begini = \m(begini)}
if = \m(begini) \m(beginD) break
asg endi \feval(\m(begini)+1)
while = 1 1 {
if < \flength(\&d[\%f]) \m(endi) break
if equal {\fsubstr(\&d[\%f],\m(endi),1)} { } break
asg endi \feval(\m(endi)+1)
}
; echo {endi = \m(endi)}
asg tmp {\fsubstr(\&d[\%f],\m(begini),\feval(\m(endi)-\m(begini)))}
; echo {GetDir is called with argument \m(tmp)}
GetDir 0 {\m(tmp)}
asg begini \m(endi)
}
}
; Days takes the month number and date as arguments and returns
; the inclusive number of days from January 1. Eg. Days {03} {04}
; returns 63. February is assumed to have 28 days.
def Days {
local tmp
switch \%1 {
:01, asg tmp 0, break
:02, asg tmp 31, break
:03, asg tmp 59, break
:04, asg tmp 90, break
:05, asg tmp 120, break
:06, asg tmp 151, break
:07, asg tmp 181, break
:08, asg tmp 212, break
:09, asg tmp 243, break
:10, asg tmp 273, break
:11, asg tmp 304, break
:12, asg tmp 334, break
:default, errext {Undefined switch in Days}
}
return \feval(\m(tmp)+\%2)
}
def GetAge {
; Sindx represents the offset of the first / in the date, in a
; line from the Mailbox.
local age year month day Sindx
asg Sindx 32
while = 0 0 {
if equal {\fsubstr(\m(Title),\m(Sindx),1)} {/} break
asg Sindx \feval(\m(Sindx)+1)
}
asg year {\fsubstr(\m(Title),\feval(\m(Sindx)+4),4)}
; echo {year = \m(year)}
if not numeric {\m(year)} return 0
; Current year - (year of message creation) expressed in days:
asg age \feval((\m(year)-\fsubstr(\v(ndate),1,4))*365 )
; Add days from Jan 1 to present.
asg month {\fsubstr(\v(ndate),5,2)}
asg day {\fsubstr(\v(ndate),7,2)}
; echo {Current month and day = \m(month) \m(day)}
Days {\m(month)} {\m(day)}
asg age \feval(\m(age)+\v(return))
; echo {Diff. in years + days from jan 1 to present = \m(age)}
; Subtract days from Jan1 to message date.
asg month {\fsubstr(\m(Title),\feval(\m(Sindx)-2),2)}
if not numeric {\m(month)} return 0
asg day {\fsubstr(\m(Title),\feval(\m(Sindx)+1),2)}
if not numeric {\m(day)} return 0
; echo {month and day of message = \m(month) \m(day)}
Days {\m(month)} {\m(day)}
asg age \feval(\m(age)-\v(return))
return \m(age)
}
; ScanDirs reads unread messages in a list of directories. The first
; argument receives the number of directories to be scanned.
def ScanDirs {
local beginD begini endi tmp
\%1 ; Define the directory list and HndlMsg.
; Loop over the directories in the list.
for \%f 1 \m(dLen) 1 {
; Go to the Desktop or Home directory on the server.
output {home\13}
GetPrompt
FindDir
TracePath
; Get the directory into the file DIR.
GetDir 1 {\fsubstr(\&d[\%f],\m(beginD))}
echo {DIR written and closed. Checking each entry. Patience. ...}
open read DIR
if failure errext {can't open DIR for reading}
read Title
if failure errext {Nothing in DIR file}
while = 1 1 {
read Title
if failure break
; echo {Checking a line in the directory file ...}
if < \flength(\m(Title)) 49 continue
; This is a message; otherwise it is a directory.
GetMsgNum
if = \m(MsgNum) 0 continue
HndlMsg
}
close read-file
echo {Finished with this directory. DIR closed.}
echo {}
}
}
; End of procedures used to receive messages or to tidy the mailbox.
def Communicate {
Login
ScanDirs MB ; Scan the Mailbox.
ScanDirs Other ; Scan directories other than the Mailbox.
; echo {}
output {logout y\13}
hangup
close session ; Close session log
quit
}
; Finished macro definitions.
Communicate ; Make it happen.