Click to See Complete Forum and Search --> : lisp rep script


angustia
10-02-2004, 10:26 PM
hi, sombody knows why i got :

..... // all files uncompressed ok
"ok"*** Unbound variable:0Aä
(You're accessing an undefined variable or function 0Aä')

when i run this rep script with some args:

#!/bin/sh
exec rep "$0" "$@"
!#

(defun descomprime-archivos (archs)
; function uncompress-files
; for each filename in archs: check if it exists, if it's regular and if it's tgz o
; tbz2, those that fail, are put in a list of not-found non-regular
; non-compressed
(let ((no-encontrados nil) (no-comprimidos nil) (no-archivos nil))
(do ((i 0 (1+ i))) ((= i (length archs)) (if (or no-encontrados no-comprimidos no-archivos) (list no-encontrados no-comprimidos no-archivos) nil))
(let ((archivo (nth i archs)))
(if (file-exists-p archivo)
(if (file-regular-p archivo)
(let ((nombre (file-name-nondirectory archivo)))
(cond
((or (string-match "\S?.tar.gz" nombre) (string-match "\S?.tgz" nombre))
(system (concat "tar -xvzf " archivo)))
((or (string-match "\S?.tar.bz2" nombre) (string-match "\S?.tbz2" nombre))
(system (concat "tar -xvjf " archivo)))
(t (setq no-comprimidos (append no-comprimidos (list archivo))))))
(setq no-archivos (append no-archivos (list archivo))))
(setq no-encontrados (append no-encontrados (list archivo))))))))

(defun ppal ()
(let ((malos (descomprime-archivos command-line-args)))
(if malos
malos ; in the future it display a dialog reporting errors
(print "ok"))))

(ppal)

************************************************** ****

all works but after the last function on debug:

------> "ok"
-----> "ok"
----> "ok"
---> "ok"
--> "ok"
#7 #undefined
\\\
"ok"rep-db>
#10 #undefined
(validate-byte-code 11 0)
rep-db>

thanks in advance, i would post on the project forum, but it's full of garbage

sasKuatch
10-06-2004, 07:24 PM
I'm not familiar with rep, but what does "$0" "$@" do after exec rep?

Would #!/path/to/rep work instead of #!/bin/sh ... ?

angustia
10-06-2004, 08:11 PM
from TFM:
Implicitly Interpreting rep Scripts

The rep interpreter also supports automatic invocation of scripts, using the operating system's support for #! interpreter invocation (i.e. if the first line of an executable text file contains #! prog, the program prog is used to execute the script.

However there is a problem with this method, in that the PATH environment variable is not searched for the location of the interpreter, and thus the full file name of the interpreter program must be hard-coded into the script. To work around this problem rep supports a slightly different method of invocation.

If the first two characters of a loaded Lisp file are #!, then everything is treated as a comment until the first occurrence of the string !#. This allows the first part of the script to be executed as a shell script invoking the rep interpreter.

What this means, is that you want to put something like the following at the start of any scripts you want to execute implicitly (and chmod +x the file as well):

#!/bin/sh
exec rep "$0" "$@"
!#

;; Lisp code follows...
Other way it doesn't like it
command-line-args variable doesn't contain the program name.