不好意思。刚才忘发了。
这是程序:
(defun c:lx (/ ptlst idx OS_old)
(setq ptlst (getdata))
(setq OS_old (getvar "OSMODE"))
(setvar "OSMODE" 0)
(command "pline")
(while (/= 0 (setq idx (getint "\n请输入点号<0 to exit>: ")))
(command (cdr (assoc idx ptlst)))
);while
(command "")
(setvar "OSMODE" OS_old)
(princ)
)
(defun Getdata (/ f line rtnlst)
(setq f (open "d:\\ "*.txt" "r"))
(while (setq line (read-line f))
(setq rtnlst (cons (mapcar 'read (string_to_numbers line)) rtnlst))
)
(close f)
(reverse rtnlst)
)
;; By Bill Kramer
; ------------------------------------------------------ Listing 4.4
;
(defun String_To_Numbers (
inStr ;;Input string
/
Res ;;Result list
Buf ;;String buffer
Inx ;;Character location
CH ;;Character
)
(setq Inx 1 ;start at the beginning of the string
Buf "" ;init buffer to empty
)
;
; Loop until the end of the string.
; (I indicates where we are in the string)
;
(while (<= Inx (strlen inStr))
;
; Get the character at position Inx, increment position indicator
(setq CH (substr inStr Inx 1)
Inx (1+ Inx)
)
;
(cond
; Test to see if character is a digit.
((wcmatch CH "[0-9.]")
(if (= CH ".") ;is it decimal?
(if (not (wcmatch Buf "*`.*")) ;not already in there
(setq Buf (strcat Buf CH))
(Flush_Buf))
;
(setq Buf (strcat Buf CH)))
)
((= Buf "") ;is the buffer empty?
;Is CH minus
(if (= CH "-")
(setq Buf CH) ;Yes, save in Buf
)
)
('T ;else buffer is not empty
(Flush_Buf)
(if (= CH "-")
(setq Buf CH))
)
); End of COND
); End of WHILE
;
(if (and (/= Buf "")
(not (wcmatch Buf "[+-.]"))
)
(Flush_Buf))
(reverse Res)
)
;
; ------------------------------------------------------ Listing 4.5
;
(defun Flush_Buf ()
(if (not (wcmatch Buf "[+-.]")) ;is it not just +-.?
(progn
;Clean it up first
(if (= (substr Buf 1 1) ".")
(setq Buf (strcat "0" Buf))) ;;add zero to front if .#
(if (= (substr Buf (strlen Buf)) ".")
(setq Buf (substr Buf 1 (1- (strlen Buf))))) ;;remove decimal if #.
;Add to RES list
(setq RES (cons Buf RES))))
(setq Buf "") ;;reset Buf
)
|