明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: xshrimp

[原创]lsp文件注释删除工具V1.0

[复制链接]
发表于 2024-11-3 22:44:04 | 显示全部楼层
有bug,转出来程序用不了了
发表于 2024-11-7 15:24:07 | 显示全部楼层
我也有,影刀写的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

不错呢~还有函数变量统计,可以分享下吗?  发表于 2025-5-9 16:45
发表于 2025-4-28 10:26:12 | 显示全部楼层
运行终止了

命令: (LOAD "C:/去除注释/relsp.fas")
lsp文件删除注释工具 V1.0 2007.12.4
bug发至xshrimp@163.com.网络U盘http:\\shlisp.ys168.com
启动命令名relsp
命令: RELSP
Error: 输入的列表有缺陷
回复 支持 反对

使用道具 举报

发表于 6 天前 | 显示全部楼层
扔给AI  不就行了
回复 支持 反对

使用道具 举报

发表于 4 天前 | 显示全部楼层
zhangrunze 发表于 2025-4-28 10:26
运行终止了

命令: (LOAD "C:/去除注释/relsp.fas")
  1. (defun c:RELSP ( / infile outfile backup fin fout line inBlock)

  2.   ;; -------------------------------
  3.   ;; Utility: timestamp for file names
  4.   ;; -------------------------------
  5.   (defun NowStamp ( / dt)
  6.     (setq dt (menucmd "m=$(edtime,$(getvar,cdate),YYYYMMDD_HHMMSS)"))
  7.   )

  8.   ;; -------------------------------
  9.   ;; Check if position is inside string quotes
  10.   ;; -------------------------------
  11.   (defun inside-string-p (s pos / i c count)
  12.     (setq i 1 count 0)
  13.     (while (< i pos)
  14.       (setq c (substr s i 1))
  15.       (if (= c """) (setq count (1+ count)))
  16.       (setq i (1+ i))
  17.     )
  18.     (= 1 (rem count 2)) ; odd = inside string
  19.   )

  20.   ;; -------------------------------
  21.   ;; Strip inline trailing comments
  22.   ;; -------------------------------
  23.   (defun strip-inline (s / pos)
  24.     (if (and s (> (strlen s) 0))
  25.       (progn
  26.         (setq pos (vl-string-search ";" s))
  27.         (while (and pos (>= pos 0))
  28.           (if (inside-string-p s (1+ pos)) ; adjust for 1-index
  29.             (setq pos (vl-string-search ";" s (1+ pos))) ; skip this ;
  30.             (setq s (substr s 1 pos) ; cut here
  31.                   pos nil
  32.             )
  33.           )
  34.         )
  35.         (vl-string-trim " \t" s)
  36.       )
  37.       ""
  38.     )
  39.   )

  40.   ;; -------------------------------
  41.   ;; Ask user for file
  42.   ;; -------------------------------
  43.   (setq infile (getfiled "Select LSP file to clean" "" "lsp" 8))
  44.   (if (not infile) (progn (princ "\nERROR: No file selected.") (exit)))
  45.   (setq infile (findfile infile))
  46.   (if (not infile) (progn (princ "\nERROR: Could not resolve input file path.") (exit)))

  47.   ;; Generate output file names with timestamp
  48.   (setq ts (NowStamp))
  49.   (setq backup (strcat (vl-filename-directory infile) "\" (vl-filename-base infile) "_backup_" ts ".lsp"))
  50.   (setq outfile (strcat (vl-filename-directory infile) "\" (vl-filename-base infile) "_clean_" ts ".lsp"))

  51.   ;; Try to copy backup
  52.   (if (not (vl-file-copy infile backup))
  53.     (princ "\nWARNING: Could not create backup file.")
  54.   )

  55.   ;; Open files
  56.   (setq fin (open infile "r"))
  57.   (setq fout (open outfile "w"))

  58.   (if (and fin fout)
  59.     (progn
  60.       (setq inBlock nil)
  61.       (while (setq line (read-line fin))
  62.         (if line
  63.           (cond
  64.             ;; If inside a block comment
  65.             (inBlock
  66.               (if (vl-string-search "|;" line)
  67.                 (setq inBlock nil) ; block ends
  68.               )
  69.               ;; skip line
  70.             )

  71.             ;; detect start of block comment
  72.             ((vl-string-search ";|" line)
  73.               (if (not (vl-string-search "|;" line))
  74.                 (setq inBlock t)
  75.               )
  76.               ;; skip line
  77.             )

  78.             ;; whole line comment
  79.             ((= (substr (vl-string-trim " \t" line) 1 1) ";")
  80.               ;; skip
  81.             )

  82.             ;; normal line
  83.             (t
  84.               (setq line (strip-inline line))
  85.               (if (> (strlen (vl-string-trim " \t" line)) 0)
  86.                 (write-line line fout)
  87.               )
  88.             )
  89.           )
  90.         )
  91.       )
  92.       (close fin) (close fout)

  93.       (princ "\n+----------------------------------------------+")
  94.       (princ "\n|              RELSP v2.0 (Cleaner)            |")
  95.       (princ "\n|      Removes line, block & inline comments   |")
  96.       (princ "\n|     Adds backup & cleaned file timestamps    |")
  97.       (princ "\n+----------------------------------------------+")
  98.       (princ (strcat "\nInput : " infile))
  99.       (princ (strcat "\nBackup: " backup))
  100.       (princ (strcat "\nOutput: " outfile))
  101.     )
  102.     (progn
  103.       (if fin (close fin))
  104.       (if fout (close fout))
  105.       (princ "\nERROR: Could not open input/output files.")
  106.     )
  107.   )
  108.   (princ)
  109. )
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-9-3 16:55 , Processed in 0.160228 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表