乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 160|回复: 0

[编程交流] 文件被关闭,不知道什么原因。

[复制链接]

13

主题

16

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-8-26 04:25:24 来自手机 | 显示全部楼层 |阅读模式
根据我的另一个线程,您应该能够从 DCL 文件生成密钥列表。我今天下午开始工作,我很困惑。我收到一个非常特殊的错误:在(读取文件)命令上关闭了流。我的意图是让文件成为一个全局变量 fe,它始终是打开的。         
这是相关代码:
这是发生错误的地方:
  1. (defun readline (fe)  (setq curline nextline        nextline (read-line fe)        lineindex (+ lineindex 1)))
让我们看看这个函数在哪里被调用:
  1. (defun find (str fe / entry) ;Returns next instance of string str in a line of the document.  (while (and (not(= (getline) nil)) (= (wcmatch (getline) str) nil))      (readline fe)           )  (princ (getline)))(defun findnext (str fe / entry) ;Returns next instance of string str in a line of the document.  Excludes current line.  (readline fe)  (while (and (not(= (getline) nil)) (= (wcmatch (getline) str) nil))      (readline fe)           )  (princ (getline)))(defun skipto (indexno fe) ;Takes index no > 0, sets pointer to that line of document.  (repeat (- indexno (getindex))   (readline fe)   ))
如果没有明确的 fe,这些都不应被调用。我们来看看代码中唯一的地方(close)被调用:
  1. (defun startinstance (/)  (if (/= fe nil)    (close fe)  )  (setq fe (open fileloc "r")        nextline (read-line fe)        lineindex 0  )  (readline fe)  (princ fe))
该文件应关闭,然后立即重新打开。readline 函数仅在明确定义 fe 时调用。  
这是完整的 lisp:
  1. (defun find (str fe / entry) ;Returns next instance of string str in a line of the document.  (while (and (not(= (getline) nil)) (= (wcmatch (getline) str) nil))      (readline fe)           )  (princ (getline)))(defun findnext (str fe / entry) ;Returns next instance of string str in a line of the document.  Excludes current line.  (readline fe)  (while (and (not(= (getline) nil)) (= (wcmatch (getline) str) nil))      (readline fe)           )  (princ (getline)))(defun skipto (indexno fe) ;Takes index no > 0, sets pointer to that line of document.  (repeat (- indexno (getindex))   (readline fe)   ))(defun maintain()  (setq prevpov (getindex)))(defun return()  (startinstance)  (skipto prevpov fe))(defun c:getfile ()  (setq fileloc (findfile (getfiled "Select a .txt file:" "" "txt" 8))))(defun startinstance (/)  (if (/= fe nil)    (close fe)  )  (setq fe (open fileloc "r")        nextline (read-line fe)        lineindex 0  )  (readline fe)  (princ fe))(defun getline ()  (princ curline))(defun getnext ()  (princ nextline))(defun getindex ()  (princ lineindex))(defun readline (fe)  (setq curline nextline        nextline (read-line fe)        lineindex (+ lineindex 1)))(defun startparse (instance searchlst / toplevel p1)  (setq outputlst (list ))  (while (/= (getnext) nil)    (setq outputlst (append outputlst (list (find (nth 0 searchlst) instance))))    (setq p1 (getindex))    (findnext (nth 0 searchlst) instance)    (setq toplevel (getindex))    (setq outputlst (append outputlst (list (recurseparse (startinstance) (cdr searchlst) p1 (getindex) ))))    (skipto toplevel instance)  ))(defun recurseparse (instance searchlst startbound endbound  / storage p1 outputlist)  (setq outputlist (list))  (skipto startbound instance)  (setq tempval (find (nth 0 searchlst) instance))  (setq outputlist (append outputlist (list tempval)))  (if (/= searchlst nil)    (if (/= tempval nil)      (while (< (getindex) endbound)        (setq p1 (getindex))        (findnext (nth 0 searchlst) instance)        (setq storage (getindex))        (setq outputlist (append outputlist (list (recurseparse (startinstance) (cdr searchlst) p1 (getindex) ))))        (skipto storage instance)        ;append to list      )    )  )  (princ outputlist))
它仍然是一个WIP,但最终目标是获取以下形式的列表列表(dialog1 (row 1 (key1 key2...) row2 (key1 key2....))dialog2 (row 1 (key1 key2. ..) row2 (key1 key2....))...)。  
要运行代码,请在 autocad 中运行 GETFILE,选择您保存为 TXT 文件的 DCL 文件,然后输入:
  1. (startparse (startinstance) (list "*: dialog*" "*key*=*"))
在命令行中。这应该从您选择的 DCL 中将全局变量“outputlst”设置为 (dialog (key...) dialog (key...)...) 形式的列表。  希望有大佬帮帮我啊,谢谢了
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-3 18:23 , Processed in 0.540324 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表