hi,

I made the first preview (but I currently use it...).

It has some bugs (with some commands it hangs-up)..
However, I think it already more efficient than standard ms-dos console
(where I currently work, even if I don't like ms-dos & windows).

However, this is the first version of ReSH (Rebol Shell). It uses licenced
Rebol to let the interpreter recall external commands (ms-dos shell commands
like dir, format, etc...).

It appears like a normal shell ('current-dir' >), but works to three
"levels":

IF YOU TYPE A COMMAND:

1) ReSH try to exec like a native Rebol command;
2) If (1) fails, then try to exec like a Rebol block;
3) If (2) fails, then try to exec an external command.

I wanted to "integrate" the power of a shell (think about Unix commands) and
Rebol language.

The first integration is to use rebol code that returns a valid shell datum;
A trivial example:

  1) Read the directory contained in Rebol variable "a"

  >> a: [to-local-file %/c/temp/]
  >> dir (/a/)

as you can see, you can type an external command (like DIR) and evaluate a
Rebol code which returns a valid ms-dos path.
To evaluate Rebol code in ms-dos commands, put Rebol between (/ REBOL-CODE
/) (parenthesis and slash).

Think to store some paths, some peace of text, etc.. in Rebol variables and
using them in ms-dos environment....

ReSH can even make the "reverse" process: use a rebol program and insert
external calls... now you can say... why not use CALL directly? Good
question... because ReSH decoder has some useful refiniments (only 2 for
now, but I have to implement some more...) to simplify the life to the user!

ReSH engine (a rebol function) is built so it can be recalled even inside
the ReSH shell!
Look at the following example (you can type it in ReSH environment):

  1) Read directory "C:\", find out the dirs, then call MsDOS "DIR" command
to show its contents
  >> foreach x read %/c/ [if (last x) = #"/" [resh rejoin ["dir c:\"
copy/part x ((length? x) - 1)] ] ]

For ReSH, you can type:

>> resh "dir"

is the same to digit:
>> DIR

But now, look at the refiniments. In the following example I recall DIR
command and ReSH will give me this output:

/C/rebol/view/local/ReSH/ > dir

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-
---8----+----9----+----0
 Volume in drive C has no label.
 Volume Serial Number is 1953-11D6

 Directory of C:\rebol\view\local\ReSH

04/20/2002  01:57 AM    <DIR>          .
04/20/2002  01:57 AM    <DIR>          ..
04/19/2002  02:37 PM               405 ls.r
04/19/2002  02:37 PM               420 ls.r.bak
04/19/2002  11:58 AM               423 prefs.r
04/20/2002  09:40 PM             3,461 ReSH.r
04/20/2002  09:40 PM             3,461 ReSH.r.bak
04/19/2002  11:58 AM               249 user.r
04/19/2002  05:00 PM             1,056 user_commands.r
04/19/2002  05:00 PM             1,085 user_commands.r.bak
04/20/2002  01:58 AM           731,648 rebol.exe
               9 File(s)        742,208 bytes
               2 Dir(s)     382,451,712 bytes free
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\

/C/rebol/view/local/ReSH/ >

The first line ("----+----1----+----2-- ....") is a char meter. ReSH
refiniment "/col" let you manage column outputs.
Syntax (with an example):

ReSH/col "dir" 7 2 1

Value "7" tell to ReSH to discard the first 7 lines (starting from the
char-meter);
Value "2" tell to ReSH to discard last 2 lines (starting from "/\ /\ /\ /\
/\ /\ /\ /\ /\ /\").
Value "1" tell to ReSH to get the values of the first column.

This is the output:

/C/rebol/view/local/ReSH/ > resh/col "dir" 7 2 1

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-
---8----+----9----+----0
04/19/2002
04/19/2002
04/19/2002
04/20/2002
04/20/2002
04/19/2002
04/19/2002
04/19/2002
04/20/2002
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\

/C/rebol/view/local/ReSH/ >

And... if you wish to get more than 1 column, look at the following (note
the "[2 3]": it means... get the columns 2 and three):

/C/rebol/view/local/ReSH/ > resh/col "dir" 7 2 [2 3]

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-
---8----+----9----+----0
02:37   PM
02:37   PM
11:58   AM
09:40   PM
09:40   PM
11:58   AM
05:00   PM
05:00   PM
01:58   AM
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\

/C/rebol/view/local/ReSH/ >

And now... something about char-meter: use this tool to get the output from
a char to another one.
Example: I want to get the first column, and only the chars contained from
position 34 to 70 (a block inside another block):

/C/rebol/view/local/ReSH/ > resh/col "dir" 7 2 [1 [34 70]]

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-
---8----+----9----+----0
04/19/2002    405 ls.r
04/19/2002    420 ls.r.bak
04/19/2002    423 prefs.r
04/20/2002  3,461 ReSH.r
04/20/2002  3,461 ReSH.r.bak
04/19/2002    249 user.r
04/19/2002  1,056 user_commands.r
04/19/2002  1,085 user_commands.r.bak
04/20/2002  1,648 rebol.exe
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\

/C/rebol/view/local/ReSH/ >


Ok... now the last refiniment available: it is "/out". Use it to make a copy
of the output into a variable called "resh-out". It is very useful to store
your output and manage it later.


/C/rebol/view/local/ReSH/ > resh/out "dir"

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-
---8----+----9----+----0
Volume in drive C has no label.
Volume Serial Number is 1953-11D6

Directory of C:\rebol\view\local\ReSH

04/20/2002 01:57 AM <DIR> .
04/20/2002 01:57 AM <DIR> ..
04/19/2002 02:37 PM 405 ls.r
04/19/2002 02:37 PM 420 ls.r.bak
04/19/2002 11:58 AM 423 prefs.r
04/20/2002 09:40 PM 3 461 ReSH.r
04/20/2002 09:40 PM 3 461 ReSH.r.bak
04/19/2002 11:58 AM 249 user.r
04/19/2002 05:00 PM 1 056 user_commands.r
04/19/2002 05:00 PM 1 085 user_commands.r.bak
04/20/2002 01:58 AM 731 648 rebol.exe
9 File(s) 742 208 bytes
2 Dir(s) 382 451 712 bytes free
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\

/C/rebol/view/local/ReSH/ > probe resh-out
[["Volume" "in" "drive" "C" "has" "no" "label."] ["Volume" "Serial" "Number"
"is" "1953-11D6"] [] ["Directory" "of" "C:\rebol\
view\local\ReSH"] [] ["04/20/2002" "01:57" "AM" "<DIR>" "."] ["04/20/2002"
"01:57" "AM" "<DIR>" ".."] ["04/19/2002" "02:37" "P
M" "405" "ls.r"] ["04/19/2002" "02:37" "PM" "420" "ls.r.bak"] ["04/19/2002"
"11:58" "AM" "423" "prefs.r"] ["04/20/2002" "09:40
" "PM" "3" "461" "ReSH.r"] ["04/20/2002" "09:40" "PM" "3" "461"
"ReSH.r.bak"] ["04/19/2002" "11:58" "AM" "249" "user.r"] ["04/
19/2002" "05:00" "PM" "1" "056" "user_commands.r"] ["04/19/2002" "05:00"
"PM" "1" "085" "user_commands.r.bak"] ["04/20/2002" "
01:58" "AM" "731" "648" "rebol.exe"] ["9" "File(s)" "742" "208" "bytes"]
["2" "Dir(s)" "382" "451" "712" "bytes" "free"]]
/C/rebol/view/local/ReSH/ >


As you can see, "resh-out" contains every printed line in blocks: [ [line-1]
[line-2] [line-3] ... ]

NOTE: don't use these refiniments if your external command has some
interactive input (since CALL function works very bad...).


Let me know what you think about it.
Remeber that this is only a preview.
bye!

--Alessandro--



-----Messaggio originale-----
Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]Per conto di
Gabriele Santilli
Inviato: Saturday, April 20, 2002 9:11 PM
A: Alessandro Manotti
Oggetto: [REBOL] Re: R: pwd cd ls - anyone ??


Hi Alessandro,

On Saturday, April 20, 2002, 4:53:42 PM, you wrote:

AM> since Rebol is a powerful system in console mode, I'm using my
Rebol/Command
AM> licence to create a Rebol shell (I called it ReSH) to embed the power of

I'd  like  to have a look. I have some ideas on a REBOL shell too,
but as usual very few time to materialize them. :)

Regards,
   Gabriele.
--
Gabriele Santilli <[EMAIL PROTECTED]>  --  REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.



--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f

Sponsor:
Iscriviti al "club primo capitolo" di Airbook.it.
Riceverai gratuitamente il primo capitolo delle ultime novit� editoriali.
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=346&d=21-4  

-- Attached file included as plaintext by Listar --
-- File: ReSH.r

Rebol[]

{LOOK AT SOME EXAMPLES ABOUT THE POWER OF RESH (EXAMPLES MADE UNDER MS WINDOWS 
ENVIRONMENT).

Read directory "C:\", find out the dirs, then call MsDOS "DIR" command to show its 
contents
>> foreach x read %/c/ [if (last x) = #"/" [resh rejoin ["dir c:\" copy/part x 
>((length? x) - 1)] ] ]

Read the directory contained in Rebol variable "a"
>> a: [to-local-file %/c/temp/]
>> dir (/a/)

}

do %user_commands.r

;=============================================================================

ReSH: func ["This function let you run SYSTEM commands."
                                                command [string!] 
                                                /col "Read a output column (from-top 
from-bottom column-number)"
                                                from-top from-bottom col-num [integer! 
block!] 
                                                /out "Store data in resh-out 
variable"] [
        if error? result: 
                try [

                        if error? result: try [ do command 0] [ ; Try to exec command 
from Rebol interpreter

                                if error? result:
                                        try [                                          
                                                                                 ; Try 
to exec command as a user command
                                                disarm result 
                                                do to-block command
                                        ];try
                                [
                                        disarm result

                                        parsed: parse/all command "()"

                                        forall parsed [
                                                if all [(last first parsed) = #"/"
                                                                                (first 
first parsed) = #"/" ]
                                                                                [
                                                                                       
 res: (copy/part next first parsed (length? next first parsed) - 1)
                                                                                       
 change first parsed (do do load to-block res)
                        
                                                ];if

                                        ];forall
                                        
                                        parsed: head parsed
                                        parsed: rejoin parsed

                                        print 
"^/----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0"

                                        if out [
                                                resh-out: make block! 1000
                                        ];if

                                        ; /COL refiniment
                                        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                                        either col [
                                                reshTemp: make string! 1000

                                                call/output parsed reshTemp

                                                tempParse: parse/all reshTemp "^/"
                                                tempParse: skip tempParse from-top 
                                                tempParse: copy/part tempParse ( 
(length? tempParse) - from-bottom)

                                                foreach x tempParse [
                                                        line: parse x none

                                                        either (type? col-num) = 
integer! [
                                                                print line/:col-num
                                                        ] [

                                                                if (type? col-num) = 
block! [

                                                                        foreach col 
col-num [
                                                                                either 
(type? col) = integer! [
                                                                                       
 prin rejoin [line/:col tab]
                                                                                ] [ 
                                                                                       
 prin rejoin [copy/part skip x (col/1 - 1) col/2 tab]
                                                                                
];either

                                                                        ];foreach

                                                                        print ""

                                                                ];if

                                                        ];either

                                                        if out [
                                                                append/only resh-out 
line
                                                        ];if

                                                ];foreach

                                        ] [

                                                either out [
                                                        
                                                        ; /OUT refiniment
                                                        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                                                        reshTemp: make string! 1000

                                                        call/output parsed reshTemp
                                                        tempParse: parse/all reshTemp 
"^/"

                                                        foreach x tempParse [
                                                                line: parse x none
                                                                append/only resh-out 
line

                                                                print line
                                                        ];foreach

                                                ] [
                                                        call/console parsed            
                 ; Try to exec as an external command
                                                ];either

                                        ];either
                                        
                                        print "/\ /\ /\ /\ /\ /\ /\ /\ /\ /\^/"

                                        0
                                ];if

                        ];if

                ];try
        [
                        probe disarm result

        ];if

];parse-shell

;=============================================================================

command: make string! 100
lastPath: what-dir

forever [
        oldCommand: copy command
        command: ask rejoin [what-dir " > "]

        ReSH command
        recycle

];forever





-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to