home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d939 / upcat.lha / Upcat / SetCategory.upcat < prev    next >
Text File  |  1993-12-20  |  5KB  |  188 lines

  1. /*-----------------------------------------------------------------------*/
  2. /* ARexx macro SetCategory for Upcat.                                    */
  3. /*                                                                       */
  4. /* This macro will put all selected files in a specified category.       */
  5. /*                                                                       */
  6. /* A selection must be made in the File Selection requester of Upcat,    */
  7. /* before this macro may be called.                                      */
  8. /*                                                                       */
  9. /* Example : Select all files, which names end with '.doc'. Then start   */
  10. /* this macro and select an appropriate category (e.g. Documentation).   */
  11. /* When the macro is finished, all '.doc' files will be in category      */
  12. /* Documentation.                                                        */
  13. /*                                                                       */
  14. /* You may adapt this macro or use parts of it for your own needs, but   */
  15. /* this macro must be distributed unchanged.                             */
  16. /*                                                                       */
  17. /* Author : Frans Zuydwijk                                               */
  18. /* Date   : 24 September 1993                                            */
  19. /*-----------------------------------------------------------------------*/
  20.  
  21. Trace Off
  22.  
  23. Options Results    /* Get information returned in Result */
  24.  
  25. "FileSelect ON"
  26.  
  27. If RC = 11
  28. Then Do
  29.      "Requester" "Continue" "No file selection criteria set|End of macro"
  30.      Exit
  31.      End
  32.  
  33. Call OpenWindow
  34.  
  35. Call GetCategories
  36.  
  37. Call AskCategory
  38.  
  39. OldCount = Cats.Category.Count
  40.  
  41. Call DoChanges
  42.  
  43. WriteLn('Console', '')
  44. WriteLn('Console', 'Old count was ' || OldCount || ,
  45.                    ', new count is ' || Cats.Category.Count)
  46.  
  47. WriteLn('Console', '')
  48. WriteCh('Console', 'Press RETURN')
  49. ReadLn('Console')
  50.  
  51. Close('Console')
  52.  
  53. Exit
  54.  
  55. /*-----------------------------------------------------------------------*/
  56. /* Open window on Upcat screen.                                          */
  57. /*-----------------------------------------------------------------------*/
  58.  
  59. OpenWindow : Procedure
  60.  
  61. "ScreenName"
  62.  
  63. WindowParms = 'CON:0/10/640/150/Set category/Screen' Result
  64.  
  65. If Open('Console', WindowParms) = 0
  66. Then Do
  67.      "Requester" "Continue" "Cannot open window|End of macro"
  68.      Exit 
  69.      End
  70.  
  71. Return
  72.  
  73. /*-----------------------------------------------------------------------*/
  74. /* Get categories in stem Cats.                                          */
  75. /*-----------------------------------------------------------------------*/
  76.  
  77. GetCategories : Procedure Expose Cats.
  78.  
  79. Cats. = ''
  80. i = 0
  81.  
  82. "FirstCat"
  83.  
  84. Do While RC = 0
  85.    i = i + 1
  86.    Parse Var Result Cats.i.Name '/' Cats.i.Number '/' Cats.i.Count
  87.  
  88.    "NextCat"
  89. End
  90.  
  91. Cats.0 = i
  92.  
  93. If RC ~= 5
  94. Then Do
  95.      Call Close('Console')
  96.      "Requester" "Continue" "FirstCat/NextCat returned error" RC ,
  97.                          || "|End of macro"    
  98.      Exit 
  99.      End
  100.  
  101. Return
  102.  
  103. /*-----------------------------------------------------------------------*/
  104. /* Ask user to select category                                           */
  105. /*-----------------------------------------------------------------------*/
  106.  
  107. AskCategory : Procedure Expose Cats. Category
  108.  
  109. Do i = 1 To Cats.0
  110.    If i // 4 = 1 Then Line = '' 
  111.  
  112.    Line = Line Right(i,2) Left(Cats.i.Name,15)  
  113.  
  114.    If i // 4 = 0 Then WriteLn('Console', Line)
  115. End  
  116.  
  117. Do Forever
  118.    WriteLn('Console', '')
  119.    WriteCh('Console', 'Select category : ')
  120.  
  121.    Category = ReadLn('Console')
  122.  
  123.    Select
  124.       When Category = ''
  125.       Then Nop
  126.  
  127.       When Datatype(Category) ~= 'NUM' 
  128.       Then WriteLn('Console', 'Not a number')
  129.  
  130.       When Category < 1 | Category > 32 
  131.       Then WriteLn('Console', 'Invalid category number')
  132.  
  133.       When Cats.Category.Name = ''
  134.       Then WriteLn('Console', 'Undefined category')
  135.  
  136.       Otherwise Leave
  137.    End 
  138. End
  139.  
  140. Return
  141.  
  142. /*-----------------------------------------------------------------------*/
  143. /* Add selected files to selected category.                              */
  144. /*-----------------------------------------------------------------------*/
  145.  
  146. DoChanges : Procedure Expose Cats. Category
  147.  
  148. "FirstFile"
  149.  
  150. Do While RC = 0
  151.    Parse Var Result . '/' . '/' FileName '/' . 
  152.  
  153.    "SetCategory ON" Cats.Category.Number 
  154.  
  155.    Select
  156.       When RC = 0
  157.       Then Do
  158.            Cats.Category.Count = Cats.Category.Count + 1
  159.            "Path"
  160.            Message = 'Added :' Result || FileName
  161.            WriteLn('Console', Message) 
  162.            End
  163.  
  164.       When RC = 5    /* Already in category */
  165.       Then Nop
  166.  
  167.       Otherwise
  168.            Do
  169.            Call Close('Console')
  170.            "Requester" "Continue" "SetCategory returned error" RC ,
  171.                                || "|End of macro"    
  172.            Exit 
  173.            End
  174.    End
  175.  
  176.    "NextFile"
  177. End
  178.  
  179. If RC ~= 5
  180. Then Do
  181.      Call Close('Console')
  182.      "Requester" "Continue" "FirstFile/NextFile returned error" RC ,
  183.                          || "|End of macro"    
  184.      Exit 
  185.      End
  186.  
  187. Return
  188.