home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Utilities / QuickFile / ARexx / ReSort.quickfile < prev    next >
Text File  |  2000-05-26  |  2KB  |  86 lines

  1. /*
  2. $VER: ReSort.quickfile 1.5 (26 May 2000  23:29:41) By M Andre Z Eckenrode
  3.  
  4. External function for QuickFile macros which modify any number of fields in all
  5. records in an index. Tests whether any fields to be modified are used in the
  6. current index; if so, re-sorts the database using the first existing field that
  7. is not being modified; if ALL available fields are to be modified, no re-sort
  8. is performed.
  9.  
  10. Requires (rexx)reqtools.library, and an argument string containing the
  11. names of all fields to be modified, separated by commas as follows:
  12.  
  13.   (<field1>[,<field2>,...])
  14.  
  15. Returns the following string:
  16.  
  17.   <rc> <index>
  18.  
  19. Where:
  20.  
  21.   <rc>    = 0 if database was re-sorted, or re-sort not needed
  22.             1 if no re-sort was performed due to no available fields
  23.             2 if any of fieldname arguments not valid
  24.             3 if not at least one argument provided
  25.   <index> = name of current index (prior to re-sort)
  26.  
  27. <rc> may be used by the calling macro to determine whether or not the operation
  28. should proceed.
  29. */
  30.  
  31. options results
  32.  
  33. lib = 'rexxreqtools.library'
  34. if ~show(l,lib) then call addlib(lib,0,-30)
  35.  
  36. setindex
  37. ndx = result
  38.  
  39. lf = d2c(10)
  40. mfld.0 = arg()
  41. if mfld.0 < 1 then do
  42.     body = 'Function requires at least'lf'one fieldname as an argument.'
  43.     call notify
  44.     exit 3 ndx
  45. end
  46.  
  47. do i = 1 to mfld.0
  48.     mfld.i = upper(arg(i))
  49.     query field 'MFLD.'i '"'mfld.i'"'
  50.     if mfld.i.type = 'MFLD.'i'.TYPE' then do
  51.         body = '"'mfld.i'"'lf'Not a valid fieldname!'
  52.         call notify
  53.         exit 2 ndx
  54.     end
  55. end
  56.  
  57. query index xfld '"'ndx'"'
  58.  
  59. xflds = 0
  60. do i = 1 to xfld.0 until xflds = 1
  61.     do ii = 1 to mfld.0 until xflds = 1
  62.         if mfld.ii = xfld.i then xflds = 1
  63.     end
  64. end
  65. if xflds = 0 then exit 0 ndx
  66.  
  67. query field fld
  68.  
  69. flds = 0
  70. do i = 1 to fld.0+1
  71.     do ii = 1 to mfld.0 until flds = 1
  72.         if mfld.ii = fld.i then flds = 1
  73.     end
  74.     if flds = 0 then leave i
  75.     flds = 0
  76. end
  77.  
  78. if i = fld.0+1 then exit 1 ndx
  79.  
  80. sort '"'fld.i'" a'
  81. exit 0 ndx
  82.  
  83. notify:
  84.     call rtezrequest(body,'_Exit','ReSort.quickfile','rtez_flags = ezreqf_centertext')
  85. return
  86.