Page 1 of 1

where am I messing up here?

Posted: Sat Aug 26, 2006 6:59 pm
by tom
I'm not doing something right, here. It's something
obvious, I'm sure..

Code: Select all

 
(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?
:-)

Posted: Sat Aug 26, 2006 10:10 pm
by cormullion
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?

Posted: Sun Aug 27, 2006 1:11 am
by tom
cormullion wrote: 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...

Posted: Sun Aug 27, 2006 12:02 pm
by tom
Here's an update:

Code: Select all

#!/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

Code: Select all

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

Code: Select all

bash$ script.lsp 2Sa 1:7
it balks on the leading "2"
Can I work around this too?

Posted: Sun Aug 27, 2006 12:24 pm
by Lutz
You would have to put single quotes around the argument:

Code: Select all

bash$ script.lsp '2Sa' 1:7
or you could quote the whole argument line and parse it yourself in your program:

Code: Select all

bash$ 'script.lsp 2Sa 1:7'
Lutz

Posted: Mon Aug 28, 2006 4:25 am
by tom
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:

Code: Select all

#!/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) "\n\n")
(close file)

(exit)