home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac2.zip / TREEIT.E < prev   
Text File  |  1995-05-15  |  4KB  |  108 lines

  1. const
  2.    NOT_TREE__MSG = "This is not a tree file.  You must be in a tree buffer to invoke TREE."
  3.    NO_TREEIT_CMD__MSG = "You must provide the command that you want to invoke against the tree'd files."
  4.  
  5. compile if EVERSION >= 6
  6.    EA_comment 'This defines the TREEIT command; it can be linked in or executed directly.'
  7. compile endif
  8.  
  9. --------------------- End of MRI for translation ----------------------------
  10.  
  11. defproc replace_str(from_str, to_str, source_str)
  12.    do forever
  13.       p = pos(from_str, source_str)
  14.       if not p then leave; endif
  15.       source_str=insertstr(to_str, delstr(source_str, p, length(from_str)), p-1)
  16.    enddo
  17.    return source_str
  18.  
  19. defc treeit
  20.    getfileid treefileid
  21. ;; if .last<2 then
  22. ;;    sayerror "This is not a tree file.  You must be in a tree buffer to invoke TREE."
  23. ;;    return
  24. ;; endif
  25. ;; getline content, 2
  26. ;; -- if line two isn't a bunch of underlines, something is wrong.
  27. ;; if leftstr(content, 33) /== "══════════  ════════  ═════════  " then
  28.    if .filename <> '.tree' then
  29.       sayerror NOT_TREE__MSG
  30.       return
  31.    endif
  32. ; Fileman uses:
  33. ; /o   /e   /n   /f        /p      /d  /q    /l   /+ /           //
  34. ; omit ext  name name.ext  \path\  d:  quiet list +  everything   literal '/'
  35.    arg1 = arg(1)
  36.    if upcase(word(arg1,1))='/D' then
  37.       include_dirs = 1
  38.       arg1 = subword(arg1, 2)
  39.    else
  40.       include_dirs = 0
  41.    endif
  42.    if arg1=="" then
  43.       sayerror NO_TREEIT_CMD__MSG
  44.       return
  45.    endif
  46.    p1 = pos('%', arg1)  -- Loop invariant
  47.    firstline = 1; lastline = .last   -- Could be 3 to (.last-1), but allow for user editing file.
  48.    if leftstr(marktype(), 1)='L' then
  49.       getmark l1, l2, c1, c2, markfid
  50.       if markfid = treefileid then
  51.          firstline = l1; lastline = l2
  52.       endif
  53.    endif
  54.    display -1
  55.    for linenum = firstline to lastline
  56.       getline content, linenum, treefileid
  57.       filenamex = substr(content, 52)
  58.       if pos(substr(filenamex,2,1), ":\.") then
  59.          if substr(content, 46, 1) = 'D' & not include_dirs then
  60.             iterate
  61.          endif
  62.          if not p1 then   -- No %'s ?
  63.             arg1 filenamex  -- Default is to append full name to command
  64.          else
  65.             filenamex = translate(filenamex, \0, '%')  -- Get rid of %'s in filename.
  66.             if substr(filenamex,2,1)==":" then
  67.                drive = leftstr(filenamex, 2)
  68.             elseif leftstr(filenamex, 1)=="." then
  69.                drive = leftstr(directory(), 2)
  70.             else
  71.                drive = ''
  72.             endif
  73.             if leftstr(filenamex,1)='.' then
  74.                slash1 = 1
  75.             else
  76.                slash1 = pos('\', filenamex)
  77.             endif
  78.             slashn = lastpos('\', filenamex)
  79.             path = substr(filenamex, slash1, slashn - slash1 + 1)
  80.             nameext = substr(filenamex, slashn+1)
  81.             dot = lastpos('.', nameext)
  82.             if dot then
  83.                name = leftstr(nameext, dot-1)
  84.                ext = substr(nameext, dot+1)
  85.             else
  86.                name = nameext
  87.                ext = ''
  88.             endif
  89.             cmd = replace_str("%%", \0, arg1)      -- Change all %% to nulls
  90.             cmd = replace_str("%x", filenamex, cmd)  -- %x = d:\path\name.ext
  91.             cmd = replace_str("%f", nameext, cmd)    -- %f = name.ext
  92.             cmd = replace_str("%p", path, cmd)       -- %p = \path\
  93.             cmd = replace_str("%d", drive, cmd)      -- %d = d:
  94.             cmd = replace_str("%n", name, cmd)       -- %n = name
  95.             cmd = replace_str("%e", ext, cmd)        -- %e = ext
  96.             cmd = replace_str("%", filenamex, cmd)   -- %  = d:\path\name.ext
  97.             cmd = replace_str(\0, "%", cmd)      -- Change all nulls back to %
  98.             cmd                                  -- Execute the resulting command.
  99.          endif
  100.       endif
  101.    endfor
  102.    display 1
  103.    activatefile treefileid
  104.  
  105. defmain
  106.    "treeit" arg(1)
  107.  
  108.