命令: (LOAD "C:/去除注释/relsp.fas")
lsp文件删除注释工具 V1.0 2007.12.4
bug发至xshrimp@163.com.网络U盘http:\\shlisp.ys168.com
启动命令名relsp
命令: RELSP
Error: 输入的列表有缺陷 扔给AI不就行了 zhangrunze 发表于 2025-4-28 10:26
运行终止了
命令: (LOAD "C:/去除注释/relsp.fas")
(defun c:RELSP ( / infile outfile backup fin fout line inBlock)
;; -------------------------------
;; Utility: timestamp for file names
;; -------------------------------
(defun NowStamp ( / dt)
(setq dt (menucmd "m=$(edtime,$(getvar,cdate),YYYYMMDD_HHMMSS)"))
)
;; -------------------------------
;; Check if position is inside string quotes
;; -------------------------------
(defun inside-string-p (s pos / i c count)
(setq i 1 count 0)
(while (< i pos)
(setq c (substr s i 1))
(if (= c "\"") (setq count (1+ count)))
(setq i (1+ i))
)
(= 1 (rem count 2)) ; odd = inside string
)
;; -------------------------------
;; Strip inline trailing comments
;; -------------------------------
(defun strip-inline (s / pos)
(if (and s (> (strlen s) 0))
(progn
(setq pos (vl-string-search ";" s))
(while (and pos (>= pos 0))
(if (inside-string-p s (1+ pos)) ; adjust for 1-index
(setq pos (vl-string-search ";" s (1+ pos))) ; skip this ;
(setq s (substr s 1 pos) ; cut here
pos nil
)
)
)
(vl-string-trim " \t" s)
)
""
)
)
;; -------------------------------
;; Ask user for file
;; -------------------------------
(setq infile (getfiled "Select LSP file to clean" "" "lsp" 8))
(if (not infile) (progn (princ "\nERROR: No file selected.") (exit)))
(setq infile (findfile infile))
(if (not infile) (progn (princ "\nERROR: Could not resolve input file path.") (exit)))
;; Generate output file names with timestamp
(setq ts (NowStamp))
(setq backup (strcat (vl-filename-directory infile) "\\" (vl-filename-base infile) "_backup_" ts ".lsp"))
(setq outfile (strcat (vl-filename-directory infile) "\\" (vl-filename-base infile) "_clean_" ts ".lsp"))
;; Try to copy backup
(if (not (vl-file-copy infile backup))
(princ "\nWARNING: Could not create backup file.")
)
;; Open files
(setq fin (open infile "r"))
(setq fout (open outfile "w"))
(if (and fin fout)
(progn
(setq inBlock nil)
(while (setq line (read-line fin))
(if line
(cond
;; If inside a block comment
(inBlock
(if (vl-string-search "|;" line)
(setq inBlock nil) ; block ends
)
;; skip line
)
;; detect start of block comment
((vl-string-search ";|" line)
(if (not (vl-string-search "|;" line))
(setq inBlock t)
)
;; skip line
)
;; whole line comment
((= (substr (vl-string-trim " \t" line) 1 1) ";")
;; skip
)
;; normal line
(t
(setq line (strip-inline line))
(if (> (strlen (vl-string-trim " \t" line)) 0)
(write-line line fout)
)
)
)
)
)
(close fin) (close fout)
(princ "\n+----------------------------------------------+")
(princ "\n| RELSP v2.0 (Cleaner) |")
(princ "\n| Removes line, block & inline comments |")
(princ "\n| Adds backup & cleaned file timestamps |")
(princ "\n+----------------------------------------------+")
(princ (strcat "\nInput : " infile))
(princ (strcat "\nBackup: " backup))
(princ (strcat "\nOutput: " outfile))
)
(progn
(if fin (close fin))
(if fout (close fout))
(princ "\nERROR: Could not open input/output files.")
)
)
(princ)
)
页:
1
[2]