home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / fiasco_2.1 / databases / aminet / scancont.frx < prev   
Text File  |  1997-10-06  |  7KB  |  285 lines

  1. /* ScanAminetCont.frx
  2.  * Scans Aminet contents files
  3.  * Copyright © 1997 Nils Bandener
  4.  * $VER: ScanAminetCont.frx 6.4 (6.10.97)
  5.  */
  6.  
  7. scriptname = "Import Aminet Contents"
  8.  
  9. Options Results
  10.  
  11. /*
  12.  *  If not called from Fiasco, try to address the active
  13.  *  Fiasco project
  14.  */
  15.  
  16. if ~abbrev(address(), "FIASCO.") then
  17. do
  18.     ports = show("Ports")
  19.  
  20.     do i = 1 to words(ports)
  21.  
  22.         if abbrev(word(ports, i), "FIASCO.") then
  23.         do
  24.             Address Value word(ports, i)
  25.  
  26.             GetAttr Project Name Active ARexx
  27.  
  28.             Address Value Result
  29.  
  30.             break
  31.         end
  32.     end
  33. end
  34.  
  35. fiasco_port = address()
  36.  
  37. Signal on Syntax
  38. Signal on Halt
  39. Signal on Break_C
  40. Signal on Failure
  41.  
  42. LockGUI
  43.  
  44.  
  45. ageinfile = 0
  46. ignoreage = 0
  47. cdname = ""
  48.  
  49. CountRecords Var lastrec
  50.  
  51. /*
  52.  *  Request file to import
  53.  */
  54.  
  55. RequestFile '"INDEX" Title "Select contents file" NoIcons'
  56.  
  57. if rc = 0 then
  58. do
  59.  
  60.     file = result
  61.  
  62.     /*
  63.      *  Open file
  64.      */
  65.  
  66.     if open("c", file, "read") then
  67.     do
  68.         /*
  69.          *  Read file line by line
  70.          */
  71.  
  72.         say "Scanning contents file"
  73.         say "Ctrl-C for break"
  74.  
  75.         do while ~eof("c")
  76.  
  77.             line = readln("c")
  78.  
  79.             if left(line, 1) = "|" then
  80.             do
  81.                 /* This is a comment */
  82.  
  83.                 /* However, look for a date of the file
  84.                  * and a CD that contains the files
  85.                  */
  86.  
  87.                 if pos("Age in weeks", line) ~= 0 then
  88.                     ageinfile = 1
  89.  
  90.                 atpos = pos("Local files at ", line)
  91.  
  92.                 if atpos ~= 0 then
  93.                 do
  94.                     cd = substr(line, atpos + 15)
  95.  
  96.                     if word(cd, 1) = "Aminet" then
  97.                     do
  98.                         if word(cd, 2) = "CD" then
  99.                         do
  100.  
  101.                             cdname = "Aminet" || word(cd, 3)
  102.  
  103.                         end
  104.                         else if word(cd, 2) = "Set" then
  105.                         do
  106.  
  107.                             cdname = "Set" || word(cd, 3)
  108.  
  109.                         end
  110.                     end
  111.                 end
  112.  
  113.                 onpos = pos(" on ", line)
  114.  
  115.                 if onpos ~= 0 then
  116.                 do
  117.                     /* Parse date */
  118.  
  119.                     day = substr(line, onpos + 4, 2)
  120.                     month = substr(line, onpos + 7, 3)
  121.                     year = substr(line, onpos + 11, 2)
  122.  
  123.                     if (verify(day, "0123456789") = 0) & (verify(year, "0123456789") = 0) then
  124.                     do
  125.                         /* day and year are valid numbers */
  126.  
  127.                         if (day > 0) & (day <= 31) then
  128.                         do
  129.                             /*
  130.                              *  Computer number of days since beginning
  131.                              *  of the year
  132.                              */
  133.  
  134.                             select
  135.                                 when month = "Jan" then totaldays = 0
  136.                                 when month = "Feb" then totaldays = 31 * 1 + 30 * 0
  137.                                 when month = "Mar" then totaldays = 31 * 1 + 30 * 0 + 28
  138.                                 when month = "Apr" then totaldays = 31 * 2 + 30 * 0 + 28
  139.                                 when month = "May" then totaldays = 31 * 2 + 30 * 1 + 28
  140.                                 when month = "Jun" then totaldays = 31 * 3 + 30 * 1 + 28
  141.                                 when month = "Jul" then totaldays = 31 * 3 + 30 * 2 + 28
  142.                                 when month = "Aug" then totaldays = 31 * 4 + 30 * 3 + 28
  143.                                 when month = "Sep" then totaldays = 31 * 5 + 30 * 3 + 28
  144.                                 when month = "Oct" then totaldays = 31 * 5 + 30 * 4 + 28
  145.                                 when month = "Nov" then totaldays = 31 * 6 + 30 * 4 + 28
  146.                                 when month = "Dec" then totaldays = 31 * 6 + 30 * 5 + 28
  147.                                 otherwise totaldays = -1
  148.                             end
  149.  
  150.                             if totaldays ~= -1 then
  151.                             do
  152.                                 totaldays = totaldays + day
  153.  
  154.                                 /*
  155.                                  *  Compute number of weeks in that year so far
  156.                                  */
  157.  
  158.                                 week = totaldays / 7
  159.                             end
  160.                         end
  161.                     end
  162.                 end
  163.  
  164.             end
  165.             else
  166.             do
  167.                 /* Not a comment */
  168.  
  169.  
  170.                 if ~ignoreage then
  171.                 do
  172.  
  173.                     if ~ageinfile then
  174.                     do
  175.  
  176.                         RequestChoice '"This file does not contain age information!*nDo you want to import the file nethertheless?" "Yes|No" Title "Import Aminet Index"'
  177.  
  178.                         if result = 0 then do
  179.  
  180.                             call close("c")
  181.  
  182.                             call bail_out
  183.                         end
  184.  
  185.                         ignoreage = 1
  186.                     end
  187.                 end
  188.  
  189.                 /*
  190.                  *  Parse an index line
  191.                  */
  192.  
  193.                 anfile = substr(line, 1, 18)
  194.                 andir  = substr(line, 20, 10)
  195.                 ansize = substr(line, 31, 4)
  196.  
  197.                 AddRecord Record lastrec Inactive
  198.                 lastrec = result
  199.  
  200.                 if ageinfile then
  201.                 do
  202.                     anage = substr(line, 36, 3)
  203.  
  204.                     age_years = trunc(anage / 52)
  205.                     age_weeks = anage - age_years * 52
  206.  
  207.                     abs_week = week - age_weeks
  208.                     abs_year = year - age_years
  209.  
  210.                     if abs_week < 1 then do
  211.  
  212.                         abs_year = abs_year - 1
  213.                         abs_week = 52 + abs_week
  214.  
  215.                     end
  216.  
  217.                     SetField "Week" Record lastrec abs_week
  218.                     SetField "Year" Record lastrec abs_year
  219.  
  220.                     andesc = substr(line, 40, 40)
  221.                 end
  222.                 else
  223.                 do
  224.                     andesc = substr(line, 36, 40)
  225.                 end
  226.  
  227.                 SetField "Directory" record lastrec andir
  228.                 SetField "Archive" record lastrec anfile
  229.                 SetField "Size" record lastrec ansize
  230.                 SetField "Short" record lastrec andesc
  231.                 SetField "CD" record lastrec cdname
  232.             end
  233.         end
  234.  
  235.         call close("c")
  236.     end
  237. end
  238.  
  239. bail_out:
  240. Address Value fiasco_port
  241.  
  242. UnlockGUI
  243. ResetStatus
  244.  
  245. exit
  246.  
  247. syntax:
  248. failure:
  249.  
  250. if show("Ports", fiasco_port) then
  251. do
  252.     Address Value fiasco_port
  253.  
  254.     RequestChoice '"Error ' || rc || ' in line ' || sigl || ':*n' || errortext(rc) || '" "Cancel" Title "' || scriptname || '"'
  255. end
  256. else
  257. do
  258.     say "Error" rc "in line" sigl ":" errortext(rc)
  259.     say "Enter to continue"
  260.     pull dummy
  261. end
  262.  
  263. call bail_out
  264.  
  265. halt:
  266. break_c:
  267.  
  268. if show("Ports", fiasco_port) then
  269. do
  270.     Address Value fiasco_port
  271.  
  272.     RequestChoice '"Script Abort Requested" "Abort Script" Title "' || scriptname || '"'
  273. end
  274. else
  275. do
  276.     say "*** Break"
  277.     say "Enter to continue"
  278.     pull dummy
  279. end
  280.  
  281. call bail_out
  282.  
  283.  
  284.  
  285.