home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / CDTools / GoFetch! / arexx / Olivier_Fabre / AminetExtract.rexx next >
OS/2 REXX Batch file  |  1999-12-10  |  3KB  |  124 lines

  1. /*
  2. ** $VER: AminetExtract.rexx 1.0 (10.12.1999) by Olivier Fabre <off@free.fr>
  3. **
  4. ** Extract selected lines out of an Aminet INDEX based on date and/or type
  5. **
  6. ** Template :
  7. **   IF=INDEXFILE,EF=EXTRACTFILE,FW=FIRSTWEEK/N,LW=LASTWEEK/N,NT=NOTYPE/S,T=TYPE/M
  8. **
  9. **   INDEXFILE
  10. **       INDEX file name.
  11. **       Default : "INDEX".
  12. **
  13. **   EXTRACTFILE
  14. **       Destination file name.
  15. **       Default : "AMINET_EXTRACTED".
  16. **
  17. **   FIRSTWEEK/N
  18. **       Oldest week, numbered from 0 (current week) to x (x weeks old).
  19. **       Default : 52
  20. **
  21. **   LASTWEEK/N
  22. **       More recent week, numbered from 0 (current week) to x (x weeks old).
  23. **       Default : 0
  24. **
  25. **     NB : "current week" means "the week the INDEX file was created" of course...
  26. **
  27. **   TYPE/M
  28. **       The type of files to extract, in the form "dir/subdir" or "dir".
  29. **       Default : all types.
  30. **
  31. **   NOTYPE/S
  32. **       If set, the files of the given type will NOT be included in the list.
  33. **
  34. ** Requires :
  35. **   RexxDOSSupport.library (Copyright (C) 1994-1997 by hartmut Goebel)
  36. **   (Aminet:util/rexx/rexxdossupport.lha)
  37. */
  38.  
  39. /**************************************************************************/
  40. /* Edit the following lines to suit your taste                            */
  41. /* These are the default options; they are overridden by the command line */
  42. /**************************************************************************/
  43.  
  44. IndexFile   = "INDEX"
  45. ExtractFile = "AMINET_EXTRACTED"
  46. FirstWeek   = 52
  47. LastWeek    = 0
  48. NoType      = 0                /* Set to 1 to NOT include files of the given Type */
  49. Type.count  = 0                /* Set to the number of types */
  50. /* Type.0      = "comm"            */    /* List types from Type.0 to Type.x */
  51. /* Type.1      = "biz/dopus"    */
  52.  
  53. /********************************/
  54. /* Do not change anything below */
  55. /********************************/
  56.  
  57.  
  58. SAY "AminetExtract.rexx 1.0 (10.12.1999) by Olivier Fabre <off@free.fr>"
  59.  
  60. IF ~SHOW('L', 'rexxdossupport.library') THEN DO
  61.     IF ~ADDLIB('rexxdossupport.library', 0, -30, 2) THEN DO
  62.         SAY "RexxDOSSupport.library not available, go to hell :->"
  63.         EXIT 20
  64.     END
  65. END
  66.  
  67. PARSE ARG args
  68.  
  69. template = "INDEXFILE=IF,EXTRACTFILE=EF,FIRSTWEEK=FW/N,LASTWEEK=LW/N,NOTYPE=NT/S,TYPE=T/M"
  70.  
  71. IF ~ReadArgs(args,template) THEN DO
  72.     SAY "Error parsing arguments."
  73.     SAY "Template :" template
  74.     EXIT 20
  75. END
  76.  
  77. IF ~OPEN( "idx", IndexFile, "R" ) THEN DO
  78.     SAY 'Error opening "'IndexFile'" for reading.'
  79.     EXIT 20
  80. END
  81.  
  82. IF ~OPEN( "rec", ExtractFile, "W" ) THEN DO
  83.     SAY 'Error opening "'ExtractFile'" for writing.'
  84.     EXIT 20
  85. END
  86.  
  87.  
  88. /* Skip the headers */
  89.  
  90. DO WHILE ~EOF( "idx" )
  91.     l = READLN( "idx" )
  92.     IF SUBSTR( l, 2, 5 ) = "-----" THEN BREAK
  93. END
  94.  
  95.  
  96. /* Scan file */
  97.  
  98. DO WHILE ~EOF( "idx" )
  99.  
  100.     l = READLN( "idx" )
  101.     week = SUBSTR( l, 36, 3 )
  102.     IF (week <= FirstWeek) & (week >= LastWeek) THEN DO
  103.  
  104.         flag = 1
  105.         IF Type.count > 0 THEN DO
  106.             flag = NoType
  107.             type2 = SUBSTR( l, 20, 10 )
  108.             type1 = LEFT( type2, POS( "/", type2 )-1 )
  109.             DO i=0 TO Type.count-1
  110.                 IF Type.i = type1 | Type.i = type2 THEN DO
  111.                     flag = 1-NoType
  112.                     BREAK
  113.                 END
  114.             END
  115.         END    /* IF Type.count */
  116.  
  117.         IF flag=1 THEN WRITELN( "rec", l )
  118.  
  119.     END    /* IF week */
  120.  
  121. END    /* WHILE ~EOF */
  122.  
  123. SAY "Done."
  124.