common-lispccl

Clozure CL compiled executable losing certain command line arguments


I'm writing a utility program in Common Lisp and building it with Clozure CL; I would like to be able to use the command-line option -d with the program, but for some reason this particular option won't make it through to (ccl::command-line-arguments). Here is a minimal example:

(defun main ()
  (format t "~s~%" (ccl::command-line-arguments))
  (quit))

I compiled with

(save-application "opts"
  :toplevel-function 'main
  :prepend-kernel t)

and here's some sample output:

~/dev/scratch$ ./opts -c -a -e
("./opts" "-c" "-a" "-e")
~/dev/scratch$ ./opts -c -d -e
("./opts" "-c" "-e")
~/dev/scratch$ ./opts -b --frogs -c -d -e -f -g -h --eye --jay -k -l
("./opts" "--frogs" "-c" "-e" "-f" "-g" "-h" "--eye" "--jay" "-k" "-l")

The -b and -d options appear to be getting lost. The documentation on command line arguments for ccl isn't very helpful. I thought maybe because ccl itself takes -b as an argument, that option might have gotten eaten for some reason, but it doesn't take -d (which is eaten), and it does take -e and -l which aren't. Nothing on saving applications seemed helpful.

I'm pretty sure it's Clozure-specific (and not, say, the shell eating them), because other stuff seems to be getting all the arguments:

#!/usr/bin/python
import sys
print sys.argv

yields

~/dev/scratch$ ./opts.py -a -b -c -d -e
['./opts.py', '-a', '-b', '-c', '-d', '-e']

and

#!/bin/bash
echo "$@"

gives

~/dev/scratch$ ./opts.sh -a -b -c -d -e
-a -b -c -d -e

This is all taking place on lubuntu 15.10 with bash as the shell.

If anyone could shed some light on why this is happening or how I can end up with all my command-line switches, I'd be appreciative.

Thanks.


Solution

  • According to the source code of the 1.11 release, -b and -d are options used by the lisp kernel.

    Since I'm unsure about licence issues, I just provide the link to the relevant file: http://svn.clozure.com/publicsvn/openmcl/release/1.11/source/lisp-kernel/pmcl-kernel.c

    Command line arguments are processed in the function process_options, where for options -b (--batch) and -d (--debug) - among others - a variable num_elide is set to 1. A bit further down, this leads to overwriting the option with the following argument (argv[k] = argv[j];).

    The code also shows a possible fix: Supply -- (two dashes) once as argument before -b or -d. When above function encounters a -- it stops processing the rest of the arguments, thus leaving them unchanged to be possibly taken up into "lisp world" shortly after.


    Turns out this has already been solved at SO before: https://stackoverflow.com/a/5522169/1116364