main args, all arguments

Q&A's, tips, howto's
Locked
tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

main args, all arguments

Post by tom »

hey guys,

How can I make

(nth 3 (main-args))

into

(nth * (main-args))

Well, not quite like that, but so that main-args can use any number of arguments?

thanks.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

I do not understand the question.

Code: Select all

newlisp 1 2 3 4 . . .

> (main-args) =>  ("/usr/bin/newlisp" "1" "2" "3" "4" .  .  . )
(main-args) is not limited how much parameter are passed (Maybe the OS).

Tried later:

Code: Select all

C:\Programme\newlisp>newlisp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
newLISP v.8.7.1 on Win32 MinGW, execute 'newlisp -h' for more info.

> (main-args)
("newlisp" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13"
 "14" "15" "16" "17" "18" "19" "20")
>
Hans-Peter

tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

Post by tom »

I can't quite seem to get what I'm trying to work.

I've been messing with rox-filer. in rox, you can open
a sort of "send to" menu for a file or multiple files.
I wrote a single line script to send files to.

#!/usr/bin/newlisp
(!(append "aterm -e w3m " (nth 3 (main-args))))
(exit)

...it uses my favorite browser/pager w3m, of course :-)
it works if one file is selected.

if I call w3m from an xterm with "-N" then multiple
files or sites open up in tabs.

When I add the "-N" to my one-liner, and take away the
"nth 3" nothing happens.

I'm probably not being clear. let me try this: I want
somthing like

$ w3m -N file file file file file file

(in rox, I may select multiple files to send to my
script)

any ideas?

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Still not sure what you do!
Do you use direct execution mode or load a lisp-file for startup?
Do you start newlisp only to start w3m?
Why not direct?
And from where come the file-titles?

Maybe you want:

(rest (rest (main-args)))

Return all main-args without first and second.
Hans-Peter

tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

Post by tom »

Image

that's a rox window with the send-to (open-with)
context menu open.

I just can't get my script to work. I can't launch w3m
directly because it's a console app, have to launch an
xterm and tell it to.


(print(append "aterm -e w3m -N " main-args)


If I can get that line to print out

aterm -e w3m -N blah blah blah foo whatever

then I could replace the print with a ! and my thing
would work. I can't do it. grrrr. frustrating.

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

So you want ROX to call a newlisp script that does execute an aterm / xterm
which executes w3m ? If i look in the manpage of xterm it does tell that the "-e" needs to be the LAST option in the line, not sure if aterm has that too.

this works here..

> (exec "xterm -e \"lynx http://www.newlisp.org\" ")

or

> (! "xterm -e \"lynx http://www.newlisp.org\" ")
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

This works also ->

#!/usr/bin/newlisp
(! (append {xterm -e "lynx } ((main-args) 2) {"}) )


run it like ->

# script.lsp "http://www.newlisp.org"
and xterm is started with lynx running the webpage...

(Using (start length (main-args)) here can be used to inside the "!" too)
-- (define? (Cornflakes))

tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

Post by tom »

sorry, guys!

I'm really parading my ignorance around. Here's what I have.

Code: Select all

#!/usr/bin/newlisp

(set 'a (string (rest (rest (main-args)))))

(print (append "aterm -e w3m -N " "\"" a "\""))
;(exit)
run like this,

$ stupidthing.lsp a-good-day.txt a-hot-day.txt

I get

aterm -e w3m -N "("a-good-day.txt" "a-hot-day.txt")"

how do I get rid of the parens?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Try this:

Code: Select all

#!/usr/bin/newlisp 

(set 'a (join (rest (rest (main-args))) " ")) 

(! (append "aterm -e w3m -N " a)) 
(exit) 
or shorter

Code: Select all

#!/usr/bin/newlisp 

(set 'a (join (2  (main-args)) " ")) 

(! (append "aterm -e w3m -N " a)) 
(exit) 
Lutz

tom
Posts: 168
Joined: Wed Jul 14, 2004 10:32 pm

Post by tom »

ta daaaa!

that's it. Thanks Lutz and everybody :-)

Locked