Paste: Windows new-line converter

Author: Rayne
Mode: factor
Date: Wed, 22 Jul 2009 20:24:35
Plain Text |
! Copyright (C) 2009 Anthony Simpson.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel namespaces sequences command-line io.files io.encodings.utf8 ;
IN: wnlc


: convert ( seq -- seq ) [ CHAR: \r = not ] filter ;
: read-convert ( -- seq )
    (command-line) first utf8 file-contents convert ;
: write-file ( seq -- )
    (command-line) first utf8 set-file-contents ;
: main ( -- ) read-convert write-file ;

MAIN: main

Annotation: Can now take any number of files

Author: Rayne
Mode: factor
Date: Wed, 22 Jul 2009 22:09:13
Plain Text |
! Copyright (C) 2009 Anthony Simpson.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel namespaces sequences command-line io.files io.encodings.utf8 io ;
IN: wnlc

: convert ( seq -- seq ) [ CHAR: \r = not ] filter ;

: read-convert ( path -- seq ) utf8 file-contents convert ;

: write-file ( seq path -- ) utf8 set-file-contents ;

: doconvert ( -- )
    (command-line) rest [ dup read-convert swap write-file ] each ;
    
: main ( -- ) doconvert ;

MAIN: main

Annotation: Generalized it some.

Author: Rayne
Mode: factor
Date: Wed, 22 Jul 2009 22:37:57
Plain Text |
! Copyright (C) 2009 Anthony Simpson.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel namespaces sequences command-line io.files io.encodings.utf8 io ;
IN: wnlc

: convert ( seq -- seq ) [ CHAR: \r = not ] filter ;

: read-file ( path -- seq ) utf8 file-contents ;

: write-file ( seq path -- ) utf8 set-file-contents ;

: doconvert ( -- )
    (command-line) rest [ dup read-file convert swap write-file ] each ;
    
: main ( -- ) doconvert ;

MAIN: main

Annotation: Using a TUPLE

Author: Rayne
Mode: factor
Date: Thu, 23 Jul 2009 01:55:37
Plain Text |
! Copyright (C) 2009 Anthony Simpson.
USING: kernel namespaces sequences command-line
       io.files io.encodings.utf8 io accessors ;
IN: wnlc

TUPLE: cmdargs os-conf files ;
C: <cmdargs> cmdargs

: convert ( seq -- seq ) [ CHAR: \r = not ] filter ;

: read-file ( path -- seq ) utf8 file-contents ;

: write-file ( seq path -- ) utf8 set-file-contents ;

: doconvert ( cmdargs -- )
    files>> [ dup read-file convert swap write-file ] each ;

: cmdwork ( -- cmdargs ) (command-line) dup first swap rest <cmdargs> ;

: main ( -- ) cmdwork doconvert ;

MAIN: main

New Annotation

Summary:
Author:
Mode:
Body: