Linking newLISP source/executable and command line options?

For the Compleat Fan
Locked
fred
Posts: 8
Joined: Wed Oct 15, 2008 2:24 pm

Linking newLISP source/executable and command line options?

Post by fred »

Is it possible to use command line options like -n when you link a source to an executable using link.lsp?

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

Post by newdep »

You mean for the linked file or while linking the file?
-- (define? (Cornflakes))

fred
Posts: 8
Joined: Wed Oct 15, 2008 2:24 pm

Post by fred »

For the new file/executable, i don't need startup files and perhaps options for memory sizes.
But i don't think it exists otherwise it would have been documented and i could not find it.

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

Post by newdep »

I cant think of a way to do this...would be a nice option though to do that...
-- (define? (Cornflakes))

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

Post by Lutz »

Just like in any other newLISP script you can use the function 'main-args' to get command-line option into a linked script. E.g. if you link the following as myprog (or myprog.exe):

Code: Select all

(println (main-args))
(exit)
and execute myprog, you can do:

Code: Select all

myprog a b c
and the program prints (Mac OS X):

Code: Select all

("./myprog" "a" "b" "c")
this way your linked program can process its command line options.

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

Post by newdep »

yes thats true Lutz, but you cant supress the use of the init.lsp with it..
or make newlisp http directly..I think that is what fred ment..
-- (define? (Cornflakes))

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

Post by Lutz »

but you cant supress the use of the init.lsp with it..
programs made with link.lsp do not load init.lsp or .init.lsp

ps: I will add this to the documentation of link.lsp

fred
Posts: 8
Joined: Wed Oct 15, 2008 2:24 pm

Post by fred »

Thanks all :)
So making a stand-alone executable made with link.lsp has a kind of "-n" option build in.
This is enough for me but what about the other options like -s and -m?
Perhaps if the first line of the included executed code looks like ":-s 4000" it could be processed as command line, adding the first line as a parameter for link, just a thought.
I continue my small steps with newLISP :)

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

He, I just did my first standalone exe with Newlisp. I had no clue it was that easy.

Few questions:

Is it possible to make executables for other OS-es except one I use?

What is the license for distribution?

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

Post by newdep »

If you have the binary's it should be possible..

I can give it a try.. ill let you know..
-- (define? (Cornflakes))

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

Post by newdep »

Linking a newlisp.exe under unix creates nicly a executable ;-)

oke here some proof ;-) I first copied the newlisp.exe from windows
to my linux machine..and started the linux newlisp..

newLISP v.10.0.3 on Linux IPv4, execute 'newlisp -h' for more info.

(MAIN)-> (load "link.lsp")
(lambda (orgExe newExeName lispSourceName) (set 'size (first (file-info orgExe)))
(copy-file orgExe newExeName)
(set 'buff (pack "ld" size))
(set 'handle (open newExeName "u"))
(search handle "@@@@@@@@")
(write-buffer handle buff 4)
(set 'buff (read-file lispSourceName))
(set 'keylen (pack "ld" (length buff)))
(write-buffer handle keylen 4)
(seek handle size)
(set 'buff (encrypt buff (string (length buff))))
(write-buffer handle buff (length buff))
(close handle))
(MAIN)-> (link "newlisp.exe" "update.exe" "update.lsp")
true

(set 'X:zeep '("~/prog/nl/progs")) $ ls -al update.exe
-rw-r--r-- 1 X users 225456 2009-03-25 20:34 update.exe
(set 'X:zeep '("~/prog/nl/progs")) $ wine update.exe
** never mind the command-prompt above, that a nerd thing **

+ v1.13 newlisp Updater (Win32)
+ Running version => 10002
+ Found version => 10003
+ Retrieving file => newlisp-10003-win-gs-128.exe (1005024 Bytes)
+ Download speed => 200403 Bps
+ Writing file => C:\windows\temp/newlisp-10003-win-gs-128.exe
+ Done...



PS: License issues for distribution, As long as you provide the GNU license
and the source code...(but im not sure if taht should be readable instantly or decoded first ;-)
-- (define? (Cornflakes))

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

Post by newdep »

and here is de delink.lsp for the current 10+ version
(always need to keep track on the coding of Lutz when decoding ;-)


(define (delink orgExe LispSourceName )

;; open linked newlisp file
(set 'infile (open orgExe "r"))

;; start seeking for the light..
(seek infile (+ (search infile "for more info.") 15))
(read-buffer infile buff 4)
(set 'bin (unpack "ld" buff))
(read-buffer infile buff 4)
(set 'code (unpack "ld" buff))
(seek infile (first bin))
(read-buffer infile buff (first code))
(set 'buff (encrypt buff (string (first code))))

;; create a new and write-to LispSourcefile
(set 'outfile (open LispSourceName "w"))
(write-buffer outfile buff (length buff))
(close infile)
(close outfile))



(MAIN)-> (load "delink.lsp")
(lambda (orgExe LispSourceName) (set 'infile (open orgExe "r")) (seek infile (+ (
search infile "for more info.") 15))
(read-buffer infile buff 4)
(set 'bin (unpack "ld" buff))
(read-buffer infile buff 4)
(set 'code (unpack "ld" buff))
(seek infile (first bin))
(read-buffer infile buff (first code))
(set 'buff (encrypt buff (string (first code))))
(set 'outfile (open LispSourceName "w"))
(write-buffer outfile buff (length buff))
(close infile)
(close outfile))
(MAIN)-> (delink "update.exe" "t.t")
true


(MAIN)-> !cat t.t

#!/usr/bin/newlisp
;;-----------------------------------------------------------------
;; A newlisp update script.
;; Checks both official and development release availebility
;; Stores the highest version found. Enjoy, nodep (c) 2004
;;
;; No standard in filenaming for newlisp releases yet so no
;; support for utf8 or other predefined OS types.
;;-----------------------------------------------------------------
..
..
..
..
..
-- (define? (Cornflakes))

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Works well on Vista 64. And what is delink?

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

Post by newdep »

a reverse link.lsp

If you get a linked package you dont see the source code
or if you lost the source code (as i did) you want it back from
the linked package ;-)
-- (define? (Cornflakes))

Locked