I'm trying to update my SYSVARDLG.LSP (just updated all sysvars to at least R2004 and soon for R2005) and want to provide a search technique like in ET's SYSVDLG where it can list all sysvars beginning with some letter. For example, "C*" will list all system variables that start with "C".
But, I want to provide wildcard matching without the user having to type wildcards explicitly. The catch is that padding a search string with wildcards automatically does not give an option of finding words by beginning. So I thought that if the user starts a search word in capital then a wildcard won't be added to the left. If search word is started in lowercase then it means the search critera could be anywhere within the word. If the search word is ended in uppercase then it means "match words ending with this criteria" - i.e. no wildcard to the right.
Of course, if the user types wildcards, they will be respected.
Does the search scheme sound confusing?? Any comments welcome.
Here's the search routine:
(defun svsearch (alist astr / hitlist flag)
(and (= (strlen astr) 1)(/= astr "*")(setq astr (strcat astr "*")))
(and (not (= (substr astr 1 1)(strcase (substr astr 1 1))))
(setq astr (strcat "*" astr)))
(and (not (= (substr astr (strlen astr) 1)(strcase (substr astr (strlen astr) 1))))
(setq astr (strcat astr "*")))
(foreach n alist
(mapcar '(lambda (x)
(if (= (type x) 'STR)
(cond ((or (wcmatch x astr)
(wcmatch x (strcase astr nil))
(wcmatch x (strcase astr T))
)
(if (not (member (car n) hitlist))
(setq hitlist (cons (car n) hitlist))
)
)
(T nil)
)
)
)
n
)
)
hitlist
)
And some results (the routine returns CAR element of a sublist if a match is made on any member(s) in the sublist):
(setq alist '(("XYZ" "zxy")("abc" "BCD")("no way" "yes way")))
(("XYZ" "zxy") ("abc" "BCD") ("no way" "yes way"))
(svsearch alist "Y")
("no way")
-> "Y" becomes "Y*" and "y*" and only matches "yes way"
(svsearch alist "y")
("no way" "XYZ")
-> "Y" becomes "*y*" and "*Y*" and matches "XYZ", "xyz", "no way" and "yes way"
(svsearch alist "c")
("abc")
-> "c" becomes "*c*" and "*C*" and matches both "abc" and "BCD"
(svsearch alist "C")
nil
-> "C" becomes "C*" and "c*" and matches nothing because nothing begins with "c"
(svsearch alist "*C*")
("abc")
-> wildcards are respected and matches the same as just "c" (above)
(svsearch alist "*C")
("abc")
-> wildcard is respected, no wildcard is added to the right because C is uppercase
-> matches only "abc" which ends with "c"