;; | ---------------------------------------------------------------------------- ;; | LI_FindNested ;; | ---------------------------------------------------------------------------- ;; | Function : Finds out the nested part of the list ;; | Argument : [Lst] - the linear list ;; | [LstBeg] - the list begin marker ;; | [LstEnd] - the list end marker (if nil, then the section is read ;; | until the next occurence of the '[' character) ;; | [Multiple - If T, read multiple number of times for same section ;; | until EOF ;; | Returns : The nested part of the list between 'LstBeg' and 'LstEnd' ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | ---------------------------------------------------------------------------- (defun LI_FindNested ( Lst LstBeg LstEnd Multiple / len itm cnt Lst1 More Found tmp BigLst retVal ) (setq BigLst '() cnt 0 Lst1 '() More T Found nil len (length Lst) tmp (strcat " of " (itoa len)) LstBeg (strcase LstBeg) ) (if LstEnd (setq LstEnd (strcase LstEnd)) ) (if #Verbose (princ "\n") ) (while More (setq itm (nth cnt Lst) cnt (1+ cnt) ) (if (= (type itm) 'STR) (setq itm (ST_Trim itm)) ) (if #Verbose (princ (strcat "\rProcessing list..." (itoa cnt) tmp)) ) (cond ( (or (= itm LstBeg) (and (= (type itm) 'STR) (= (strcase itm) LstBeg)) ) (if Lst1 (setq Lst1 (reverse Lst1) BigLst (append BigLst (list Lst1)) Lst1 '() ) ) (setq Lst1 (cons itm Lst1)) ) (T (if LstEnd (progn (if (or (= itm LstEnd) (and (= (type itm) 'STR) (= (strcase itm) LstEnd)) ) (progn (if Lst1 (progn (setq Lst1 (cons itm Lst1) Lst1 (reverse Lst1) BigLst (append BigLst (list Lst1)) ) (setq Lst1 '() Found T ) )) ) (progn (if Lst1 (setq Lst1 (cons itm Lst1)) ) ) ) ) (progn (if (and (= (type itm) 'STR) (equal (substr itm 1 1) "[") (equal (substr itm (strlen itm) 1) "]") ) (progn (setq Lst1 (reverse Lst1)) (if Lst1 (setq BigLst (append BigLst (list Lst1))) ) (if (= (strcase itm) LstBeg) (setq Lst1 (list itm)) (setq Lst1 '()) ) (setq Found T) ) (progn (if Lst1 (setq Lst1 (cons itm Lst1)) ) ) ) )) ) ) (if (= cnt len) (setq More nil) ) ) (if (not LstEnd) (progn (if Lst1 (setq Lst1 (reverse Lst1) BigLst (append BigLst (list Lst1)) Found T ) ) )) (if Found (progn (if Multiple (setq retVal BigLst) (setq retVal (nth 0 BigLst)) ) ) (setq retVal nil) ) retVal )