home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / SORTEPM.E < prev    next >
Text File  |  1995-04-20  |  4KB  |  113 lines

  1. compile if EVERSION < '5.60'
  2.  Error:  SORTEPM.E (SORT_TYPE = 'EPM') can only be used with EPM 5.60 or above.
  3. compile endif
  4.  
  5. defproc sort(firstline, lastline, firstcol, lastcol, fileid)
  6. compile if EVERSION >= '6.01b'  -- Using BitOr, we can accept either Reverse or Descending
  7.    flags = (not verify('R',upcase(arg(6)))) bitor    -- Reverse
  8.            (not verify('D',upcase(arg(6)))) bitor    -- Descending
  9.         (2*(not verify('I',upcase(arg(6))))) bitor   -- case Insensitive
  10.         (4*(not verify('C',upcase(arg(6)))))         -- Collating order
  11. compile else
  12.    flags = not verify('R',upcase(arg(6))) + 2*(not verify('I',upcase(arg(6)))) + 4*(not verify('C',upcase(arg(6))))
  13. compile endif
  14. compile if EPM32
  15.    return dynalink32(E_DLL, 'EtkSort',
  16.                      gethwndc(5)     || atol(fileid)   ||
  17.                      atol(firstline) || atol(lastline) ||
  18.                      atol(firstcol)  || atol(lastcol)  ||
  19.                      atol(flags),
  20.                      2)
  21. compile else
  22.    return dynalinkc( E_DLL, '_EtkSort',      /* function name                 */
  23.                      gethwndc(5)     || atol(fileid)   ||
  24.                      atol(firstline) || atol(lastline) ||
  25.                      atoi(firstcol)  || atoi(lastcol)  ||
  26.                      atol(flags),
  27.                      2);
  28. compile endif
  29.  
  30. defc sort =
  31.    if browse() then
  32.       sayerror BROWSE_IS__MSG ON__MSG
  33.       return
  34.    endif
  35.    TypeMark=marktype()
  36.    if TypeMark='' then  /* if no mark, default to entire file */
  37.       getfileid fileid
  38.       firstline=1 ; lastline=.last ; firstcol=1; lastcol = 40
  39.    else
  40.       getmark firstline, lastline, firstcol, lastcol, fileid
  41.       /* If it was a line mark, the LastCol value can be 255.  Can't */
  42.       /* imagine anyone needing a key longer than 40.                */
  43.       if TypeMark='LINE' then lastcol=40 endif
  44.    endif
  45. compile if EVERSION >= '6.03'
  46.    if fileid.readonly then
  47.       sayerror READ_ONLY__MSG
  48.       return
  49.    endif
  50. compile endif
  51.  
  52.    sayerror SORTING__MSG lastline-firstline+1 LINES__MSG'...'
  53.  
  54.    /* Pass the sort switches "rc", if any, as a sixth argument to sort().    */
  55.    result = sort(firstline, lastline, firstcol, lastcol, fileid, arg(1) )
  56.    if result then
  57.       sayerror 'SORT' ERROR_NUMBER__MSG result
  58.    else
  59.       sayerror 0
  60.    endif
  61.  
  62. /* To sort a new-format directory listing by date & time, enter the command:
  63.       sortcols 11 15 16 16 1 5   7 8
  64.                hh:mm  a/p  mm/dd  yy
  65.    For an old-format directory listing, enter:
  66.       sortcols 34 38 39 39 23 28 30 31
  67.                hh:mm  a/p  mm/dd  yy
  68. */
  69. defc sortcols =
  70.    if browse() then
  71.       sayerror BROWSE_IS__MSG ON__MSG
  72.       return
  73.    endif
  74.    TypeMark=marktype()
  75.    if TypeMark='' then  /* if no mark, default to entire file */
  76.       getfileid fileid
  77.       firstline=1 ; lastline=.last
  78.    else
  79.       getmark firstline, lastline, firstcol, lastcol, fileid
  80.    endif
  81. compile if EVERSION >= '6.03'
  82.    if fileid.readonly then
  83.       sayerror READ_ONLY__MSG
  84.       return
  85.    endif
  86. compile endif
  87.  
  88.    cols = arg(1)
  89.    sort_flags = ''
  90.    do while cols <> ''
  91.       if not isnum(word(cols,1)) then
  92.          parse value cols with sort_flags c1 c2 cols
  93.       else
  94.          parse value cols with c1 c2 cols
  95.       endif
  96.       if not isnum(c1) or not isnum(c2) then
  97.          sayerror -336
  98.          stop
  99.       endif
  100.  
  101.       sayerror SORTING__MSG lastline-firstline+1 LINES__MSG '('c1 '-' c2') ...'
  102.  
  103.       /* Pass the sort switches "rc", if any, as a sixth argument to sort().    */
  104.       result = sort(firstline, lastline, c1, c2, fileid, sort_flags )
  105.       if result then
  106.          sayerror 'SORT' ERROR_NUMBER__MSG result
  107.          stop
  108.       endif
  109.  
  110.    enddo
  111.    sayerror 0
  112.  
  113.