I'm not doing something right, here. It's something
obvious, I'm sure..
(set 'dir-path "/path/to/dir/")
(set 'all-args (join (rest (rest (main-args))) " "))
(set 'bbook (append dir-path ((parse all-args) 0)))
(set 'bverse ((parse all-args) 1))
(set 'file (open bbook "read"))
(search file bverse)
(print (read-line file) "n")
(close file)
Help?
:-)
I'm not sure you're missing anything. I think you're trying to search for a word or phrase in a file in a directory, and your code looks good to me.
Your approach works OK for me, although there was a small problem with a 'string too long' error, which was caused by the lack of an (exit) at the end, I think.
I think the search followed by read-line is going to print out the rest of the file, following the match. Is this what you want?
What problems are you encountering?
Quote from: "cormullion"
What problems are you encountering?
The same one(s) you are. I'm going see if sticking (exit) in there works.
I'd rather have one line returned, instead of the rest of the file, but that's just the way it works if I type the path and search strings by hand.
lemme go see what happens...
Here's an update:
#!/usr/bin/newlisp
(set 'dir-path "/path/to/dir/")
(set 'all-args (join (rest (rest (main-args))) " "))
(set 'bbook (append dir-path ((parse all-args) 0)))
(set 'bverse ((parse all-args) 1))
(set 'bverse2 ((parse all-args) 2))
(set 'bverse3 ((parse all-args) 3))
;(set 'bverse4 ((parse all-args) 4))
;(set 'bverse5 ((parse all-args) 5))
(set 'bjoined (append bverse bverse2 bverse3))
(set 'file (open bbook "read"))
(search file bjoined)
(print (read-line file) "n")
(close file)
(exit)
Ok. Adding (exit) eliminated the first error, but there are a couple more
problems. I want my script to spit out a bible verse from a directory
filled with one book per file, and one verse per line.
This works
bash$ script.lsp Job 1:2
but the colon was counted as an argument by itself. I was able to
work around that.
this does not work
bash$ script.lsp 2Sa 1:7
it balks on the leading "2"
Can I work around this too?
You would have to put single quotes around the argument:
bash$ script.lsp '2Sa' 1:7
or you could quote the whole argument line and parse it yourself in your program:
bash$ 'script.lsp 2Sa 1:7'
Lutz
Hi Lutz,
the single quotes around the argument did not work. I
got this error:
value expected in function search : file
I did parse out the arguments in my script, instead of
at the bash prompt, and it works without quoting anything.
Just in case anyone
wants to see the simple thing, here it is:
#!/usr/bin/newlisp
(set
'dir-path "/path/to/dir/"
'all-args (join (rest (rest (main-args))) " ")
'args-split (parse all-args " ")
'bbook-path (append dir-path (args-split 0))
'bbook (args-split 0)
'bverse (args-split 1)
)
(set 'file (open bbook-path "read"))
(search file bverse)
(print "n" bbook " ")
(print (read-line file) "nn")
(close file)
(exit)