Page 1 of 1

Remove problem with main-args in script vs executable

PostPosted: Fri Feb 26, 2016 11:21 am
by hotcore
Maybe somebody is interested in the code below.
The main function is to show the contents of the Windows path, line by line. You may specify a search string on the comaand line to filter the output.

More important is the separate code for a function which takes care of the difference in command line arguments between running as a script and running as an executable.

Code to be "included" (loaded) by the main porogram:
Code: Select all
(define (mainargs)
   (letn (osargs (main-args)
            (srch (lower-case (osargs 0))))
      (if (or (= srch "newlisp") (= srch "newlisp.exe"))
         (1 osargs)

Main program which loads the above code:
Code: Select all
(load "mainargs.lsp")

(define (showpath myargs)
   (let (pathlist (parse (lower-case (env "PATH")) ";")
            osargs (mainargs))
      (dolist (line  pathlist)
            (if (> (length osargs) 1)
                  (if (not (nil? (find (lower-case (osargs 1)) line)))
                        (println line))
                  (println line)))))

(println "=====================================================")
(println "=====================================================")