save to string instead of file

Started by HPW, February 14, 2004, 10:47:06 AM

Previous topic - Next topic

nigelbrown

#15
link.lsp worked great!



As a first test I added this code :

...



;; main for linker.exe usage: linker out.exe in.lsp

(begin

   (if (not (file-info "newlisp.exe")) (begin

      (print "err: Newlisp.exe not found - must be in same directory as linker") (exit 1)))

   (if (not (file-info (nth 2 (main-args)))) (begin

      (print "err: " (nth 2 (main-args)) " not found - cannot produce linked exe file") (exit 1)))

   (print "Linking in "  (nth 2 (main-args)) " to create " (nth 1 (main-args)) "n")

   (link "newlisp.exe" (nth 1 (main-args)) (nth 2 (main-args)))

   (exit 0))



to the bottom of link.lsp and saved it as linker.lsp, then in newLISP-tk did

> (link "newlisp.exe" "linker.exe" "linker.lsp")

true



and linker.exe worked fine so...

then used linker to link in txttopdf.lsp viz

C:newlisp>linker txttopdf.exe txttopdf.lsp

Linking in txttopdf.lsp to create txttopdf.exe



Now txttopdf.lsp is txt2pdf.lsp with Sammo's wrapper function and a modification of the linker.lsp command line arg handling added at the end viz:

...

(context 'MAIN)



;; copy-text-to-pdf

;; simple wrapper for Nigel's 'txt2pdf' code

;;

(define (copy-text-to-pdf text-filename pdf-filename)

    (let

        ( (infile (open text-filename "read")) )

        (TXT2PDF:txt2pdf (lambda () (read-line infile)) pdf-filename)

        (close infile) ))

(begin

   (if (not (file-info (nth 1 (main-args)))) (begin

      (print "err: " (nth 1 (main-args)) " not found - cannot produce pdf file") (exit 1)))

   (print "Pdfing "  (nth 1 (main-args)) " to create " (nth 2 (main-args)) "n")

   (copy-text-to-pdf (nth 1 (main-args)) (nth 2 (main-args)))

   (exit 0))



So that now txttopdf is a command line utility for making pdf's viz



C:newlisp>txttopdf README.txt readme.pdf

Pdfing README.txt to create readme.pdf



C:newlisp>txttopdf READYOU.txt readme.pdf

err: READYOU.txt not found - cannot produce pdf file

C:newlisp>



Which is just what I want! (I tried Easy Txt2pdf at http://www.easyhr.com.au">www.easyhr.com.au but it doesn't/didn't handle brackets properly - not good for pdfing lisp code!)



Thanks Lutz for the exe building mod.



PS I've noticed that txt2pdf.lsp isn't quite right at handling long lines

try

C:newlisp>txttopdf linker.lsp linker.pdf

Pdfing linker.lsp to create linker.pdf



and look at line that should be

      (print "err: " (nth 2 (main-args)) " not found - cannot produce linked exe file") (exit 1)))



the 1))) is chopped off - I'll see what I can do.

HPW

#16
Many, many thanks for the new 'source' command in 7.5.4.

Comes a lot faster than I hope!
Hans-Peter

Lutz

#17
I could leverage pretty much on what was there already and it also simplified the newlisp-tk frontend tremendously. It is now rather simple to create frontends to newLISP from other environments / languages.



Lutz