本帖最后由 kucha007 于 2023-3-14 01:44 编辑
不保证通用性,只是自己的程序需要:http://bbs.mjtd.com/thread-187339-1-1.html
;配置文件内部是这样的,第一个分号后面的是注释,前面的是值。更新也是这个逻辑。
- 1;PlotStyle
- 0;PaperSize
- 0;PrintName
复制代码
相关的三个函数:
- ;串联用分隔符字符串@LeeMac
- (defun K:Lst2Str (Lst Del / itm str)
- (setq str (car Lst))
- (foreach itm (cdr Lst)
- (setq str (strcat str del itm))
- )
- str
- )
- ;新建配置文件并获取数据
- (defun K:ReadPtVar (FPath / Lst FName des lin)
- (setq Lst '())
- (if (not (setq FName (findfile FPath)));文件不存在
- (progn
- (setq des (open FPath "w"))
- (princ
- (K:Lst2Str '("1;PrintName" "0;PaperSize" "0;PlotStyle") "\n")
- des
- )
- (close des)
- )
- )
- (if (setq FName (findfile FPath))
- (progn
- (setq des (open FName "r"))
- (while (setq lin (read-line des))
- (setq lin (substr lin 1 (vl-string-position (ascii ";") lin)))
- (setq Lst (cons lin Lst))
- )
- (close des)
- )
- )
- (reverse Lst)
- )
- ;将最新的设置记录到配置文件
- (defun K:RecordPtVar (FPath NewLst / NewData FName des Nam lin)
- (setq NewData '())
- (if (setq FName (findfile FPath));文件存在
- (progn
- (setq des (open FName "r"))
- (setq Nam 0)
- (while (setq lin (read-line des))
- (setq lin (strcat
- (nth Nam (reverse NewLst))
- (substr lin (1+ (vl-string-position (ascii ";") lin)))
- )
- )
- (setq NewData (cons lin NewData))
- (setq Nam (1+ Nam))
- )
- (close des)
- (setq des (open FPath "w"))
- (princ (K:Lst2Str NewData "\n") des)
- (close des)
- )
- )
- )
|