Many thanks, Mike. That saved me quite a bit of mucking around.

Atb,
Oliver


PS: I think there's a teeny bugette at line 70 which is: 
    -- build the list of files; currently no /s sftopts='FL'
I changed this to:
    -- build the list of files; currently no /s 
    sftopts='FL'
And all was fine. 

 

-----Original Message-----
From: Mike Cowlishaw [mailto:m...@speleotrove.com] 
Sent: 20 February 2012 14:03
To: 'Open Object Rexx Developer Mailing List'
Subject: Re: [Oorexx-devel] ooDialog Guide - Possible conflict in repos.

 
> If you haven't met this problemette before, then please don't spend 
> any time on it - I'll just convert it to Windows format with a little 
> oorexx program...

It's a "one-liner":

  /* Change LF to CRLF in a file */
  call changefile arg(1) '/'||'0a'x'/'||'0d0a'x

assuming you have changefile (which can now be shortened by using
changestr):

/* ChangeAll in a file or files */

-- Syntax:  changefile  spec  pattern
--
-- Where:
--
--   spec is file-specification or wildcard (no blanks)
--           Add /s to the spec-word to include subdirectories
--
--   pattern is (for example) /fred/bert to change 'fred' to 'bert'
--           Where the delimiter character '/' is any character; the
--           first character of word 2
--
-- Example:
--
--   changefile *.html /old text/new text string
--
-- If pattern is omitted then you will be prompted for the old and
-- new strings (use this to include > < & etc., in the strings)
--
-- Blanks are not allowed because of command line risks (trailing
-- blanks, etc.).  Use a backquote (`) for a blank, in a pattern,
-- or omit the pattern for prompts.
-- [Later maybe use URL encoding .. %20, etc.]

parse arg spec change
change=strip(change)
parse var change delim +1 old (delim) new

if spec='' then do
  say 'Enter file specification (may include wildcards):'
  parse pull spec
  end

subdirs=0                          -- subdirectories flag
if pos('/s',spec)>0 then do
  parse var spec pre '/s' post
  spec=pre''post
  subdirs=1
  end

if spec='' then do
  say 'No specification, so no change'
  exit; end

if old='' then do                  -- prompt please
  say 'Enter old (source) string:'
  parse pull old
  if old=='' then do
    say 'Empty old string not allowed -- exiting'
    exit; end
  say 'Enter new (target) string:'
  parse pull new
  end
 else do                           -- pattern supplied
  if pos(' ', old)>0 | pos(' ', new)>0 then do
    say 'blanks detected; unsafe change -- exiting'
    exit
    end
  old=translate(strip(old), ' ', '`')
  new=translate(strip(new), ' ', '`')
  end

if old==new then do
  say 'New and old strings identical -- exiting'
  exit; end



-- build the list of files; currently no /s sftopts='FL'
if subdirs then sftopts=sftopts'S'
call sysfiletree spec, 'LIST', sftopts
files=list.0
if files=0 then do
  say 'No files match "'spec'"'
  exit; end

say 'Changing' spec '('files') from "'old'" to "'new'"...'

if files>1 then do
  say 'Enter Y to confirm, anything else to quit'
  pull ans
  if left(ans,1)\='Y' then exit
  end

do f=1 to files
  parse var list.f date time size . qfile    /* may have blanks.. */
  if size=0 then iterate f
  file=strip(qfile)                          /* else leading blank */
  -- say ''''file''' to update'

  doc=charin(file, 1, chars(file))
  call charout file

  doc=change(doc, old, new)

  if changed>0 then do
    backfile=file'.'date('s')
    '@copy' file backfile '>nul'     -- backup
    if rc<>0 then exit rc
    call sysfiledelete file
    call charout file, doc, 1
    if result\=0 then do
      say '***' result 'characters could not be written to: '''file''''
      say '***  backup should still be on disk: '''backfile''''
      exit
      end
    call charout file
    if changed=1 then add='one change'; else add=changed 'changes'
    say ''''file''' updated ['add']'
    call sysfiledelete backfile
    end
  end f

exit

/* Internal function:  CHANGE(string,old,new)              */
/*                                                         */
/* (Like XEDIT  "C/old/new/1 *")                           */
/*                                                         */
/* Changes all occurrences of "old" in "string" to "new".  */
/* If "old"=='', then "new" is prefixed to "string".   MFC */
Change: procedure expose changed
  parse arg string, old, new
  if old=='' then do; changed=1; return new||string; end
  out=''; changed=0
  do while pos(old,string)\=0
    parse var string prefix (old) string
    out=out||prefix||new
    changed=changed+1
    end
  return out||string


----------------------------------------------------------------------------
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel



------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to