home *** CD-ROM | disk | FTP | other *** search
- /* ScanAminetCont.frx
- * Scans Aminet contents files
- * Copyright © 1997 Nils Bandener
- * $VER: ScanAminetCont.frx 6.4 (6.10.97)
- */
-
- scriptname = "Import Aminet Contents"
-
- Options Results
-
- /*
- * If not called from Fiasco, try to address the active
- * Fiasco project
- */
-
- if ~abbrev(address(), "FIASCO.") then
- do
- ports = show("Ports")
-
- do i = 1 to words(ports)
-
- if abbrev(word(ports, i), "FIASCO.") then
- do
- Address Value word(ports, i)
-
- GetAttr Project Name Active ARexx
-
- Address Value Result
-
- break
- end
- end
- end
-
- fiasco_port = address()
-
- Signal on Syntax
- Signal on Halt
- Signal on Break_C
- Signal on Failure
-
- LockGUI
-
-
- ageinfile = 0
- ignoreage = 0
- cdname = ""
-
- CountRecords Var lastrec
-
- /*
- * Request file to import
- */
-
- RequestFile '"INDEX" Title "Select contents file" NoIcons'
-
- if rc = 0 then
- do
-
- file = result
-
- /*
- * Open file
- */
-
- if open("c", file, "read") then
- do
- /*
- * Read file line by line
- */
-
- say "Scanning contents file"
- say "Ctrl-C for break"
-
- do while ~eof("c")
-
- line = readln("c")
-
- if left(line, 1) = "|" then
- do
- /* This is a comment */
-
- /* However, look for a date of the file
- * and a CD that contains the files
- */
-
- if pos("Age in weeks", line) ~= 0 then
- ageinfile = 1
-
- atpos = pos("Local files at ", line)
-
- if atpos ~= 0 then
- do
- cd = substr(line, atpos + 15)
-
- if word(cd, 1) = "Aminet" then
- do
- if word(cd, 2) = "CD" then
- do
-
- cdname = "Aminet" || word(cd, 3)
-
- end
- else if word(cd, 2) = "Set" then
- do
-
- cdname = "Set" || word(cd, 3)
-
- end
- end
- end
-
- onpos = pos(" on ", line)
-
- if onpos ~= 0 then
- do
- /* Parse date */
-
- day = substr(line, onpos + 4, 2)
- month = substr(line, onpos + 7, 3)
- year = substr(line, onpos + 11, 2)
-
- if (verify(day, "0123456789") = 0) & (verify(year, "0123456789") = 0) then
- do
- /* day and year are valid numbers */
-
- if (day > 0) & (day <= 31) then
- do
- /*
- * Computer number of days since beginning
- * of the year
- */
-
- select
- when month = "Jan" then totaldays = 0
- when month = "Feb" then totaldays = 31 * 1 + 30 * 0
- when month = "Mar" then totaldays = 31 * 1 + 30 * 0 + 28
- when month = "Apr" then totaldays = 31 * 2 + 30 * 0 + 28
- when month = "May" then totaldays = 31 * 2 + 30 * 1 + 28
- when month = "Jun" then totaldays = 31 * 3 + 30 * 1 + 28
- when month = "Jul" then totaldays = 31 * 3 + 30 * 2 + 28
- when month = "Aug" then totaldays = 31 * 4 + 30 * 3 + 28
- when month = "Sep" then totaldays = 31 * 5 + 30 * 3 + 28
- when month = "Oct" then totaldays = 31 * 5 + 30 * 4 + 28
- when month = "Nov" then totaldays = 31 * 6 + 30 * 4 + 28
- when month = "Dec" then totaldays = 31 * 6 + 30 * 5 + 28
- otherwise totaldays = -1
- end
-
- if totaldays ~= -1 then
- do
- totaldays = totaldays + day
-
- /*
- * Compute number of weeks in that year so far
- */
-
- week = totaldays / 7
- end
- end
- end
- end
-
- end
- else
- do
- /* Not a comment */
-
-
- if ~ignoreage then
- do
-
- if ~ageinfile then
- do
-
- RequestChoice '"This file does not contain age information!*nDo you want to import the file nethertheless?" "Yes|No" Title "Import Aminet Index"'
-
- if result = 0 then do
-
- call close("c")
-
- call bail_out
- end
-
- ignoreage = 1
- end
- end
-
- /*
- * Parse an index line
- */
-
- anfile = substr(line, 1, 18)
- andir = substr(line, 20, 10)
- ansize = substr(line, 31, 4)
-
- AddRecord Record lastrec Inactive
- lastrec = result
-
- if ageinfile then
- do
- anage = substr(line, 36, 3)
-
- age_years = trunc(anage / 52)
- age_weeks = anage - age_years * 52
-
- abs_week = week - age_weeks
- abs_year = year - age_years
-
- if abs_week < 1 then do
-
- abs_year = abs_year - 1
- abs_week = 52 + abs_week
-
- end
-
- SetField "Week" Record lastrec abs_week
- SetField "Year" Record lastrec abs_year
-
- andesc = substr(line, 40, 40)
- end
- else
- do
- andesc = substr(line, 36, 40)
- end
-
- SetField "Directory" record lastrec andir
- SetField "Archive" record lastrec anfile
- SetField "Size" record lastrec ansize
- SetField "Short" record lastrec andesc
- SetField "CD" record lastrec cdname
- end
- end
-
- call close("c")
- end
- end
-
- bail_out:
- Address Value fiasco_port
-
- UnlockGUI
- ResetStatus
-
- exit
-
- syntax:
- failure:
-
- if show("Ports", fiasco_port) then
- do
- Address Value fiasco_port
-
- RequestChoice '"Error ' || rc || ' in line ' || sigl || ':*n' || errortext(rc) || '" "Cancel" Title "' || scriptname || '"'
- end
- else
- do
- say "Error" rc "in line" sigl ":" errortext(rc)
- say "Enter to continue"
- pull dummy
- end
-
- call bail_out
-
- halt:
- break_c:
-
- if show("Ports", fiasco_port) then
- do
- Address Value fiasco_port
-
- RequestChoice '"Script Abort Requested" "Abort Script" Title "' || scriptname || '"'
- end
- else
- do
- say "*** Break"
- say "Enter to continue"
- pull dummy
- end
-
- call bail_out
-
-
-
-