Author Topic: Merge a DCL file and a LSP file  (Read 1302 times)

0 Members and 1 Guest are viewing this topic.

baitang36

  • Bull Frog
  • Posts: 213
Merge a DCL file and a LSP file
« on: June 07, 2022, 12:57:58 AM »
;Merge a DCL file and a LSP file
;Requirement: there can only be one DCL file, and the main file name and LSP file name are the same. For example, only merge abcd.DCL and abcd.LSP
;the command is BDL
Code - Auto/Visual Lisp: [Select]
  1. (defun C:BDL (/ dclFName dcl lspFName lsp str n j k m str1 str2 str5  nstr5 start1 lstr1 yh)
  2.  
  3. (setq dclFName (findfile (getfiled "select a DCL file" "" "dcl"  16)))
  4.  
  5.   (setq lspFName
  6.          (strcat (substr dclFName 1 (- (strlen dclFName) 4)) ".lsp")
  7.   )
  8.   (setq newFName (strcat (substr dclFName 1 (- (strlen dclFName) 4))
  9.                          "_new.lsp"
  10.                  )
  11.   )
  12.   (setq dcl (open dclFName "r")        
  13.         lsp (open newFName "w")        
  14.   )
  15.   (setq f0 (open lspFName "r"))
  16.   (setq str1 "")
  17.   (while (setq nstr5 (read-char f0))
  18.     (setq str5 (chr nstr5))
  19.     (setq str1 (strcat str1 str5))
  20.   )
  21.   (close f0)
  22.   (setq lstr1 (strlen str1))
  23.   (setq start1 1)                      
  24.   (setq j 1
  25.         k 0
  26.         m 0
  27.         n 0
  28.   ) ;_ setq
  29.   (setq str2 "")
  30.  
  31.   (while (< j lstr1)
  32.     (if
  33.       (OR
  34.         (eq (substr str1 j 13) "(load_dialog ")
  35.         (eq (substr str1 j 13) "(LOAD_DIALOG ")
  36.       ) ;_ OR
  37.  
  38.        (progn
  39.          (setq m j)
  40.          (setq str2 (strcat str2 (substr str1 start1 (- m start1))))
  41.          (setq j (+ j 1))
  42.          (setq k 1)
  43.          (setq yh 0)
  44.          (while (/= 0 k)
  45.            (if (eq "\"" (substr str1 j 1))
  46.              (setq yh (boole 6 yh 1))
  47.            )                           
  48.  
  49.            (if (eq "(" (substr str1 j 1))
  50.              (if (= yh 0)
  51.                (setq k (1+ k))
  52.              )
  53.            ) ;_ if
  54.            (if (eq ")" (substr str1 j 1))
  55.              (if (= yh 0)
  56.                (setq k (- k 1))
  57.              )
  58.            ) ;_ if
  59.  
  60.            (setq j (+ j 1))
  61.          ) ;_ while
  62.          (setq n j)
  63.          (setq str3 (substr str1 m (- n m))) ;IF
  64.  
  65.  
  66.  
  67.  
  68.          (setq str4 "(load_dialog tmp-dcl-file-name)")
  69.          (setq str2 (strcat str2 str4))
  70.          (setq start1 n)
  71.        )
  72.     )
  73.     (setq j (+ j 1))
  74.   )
  75.  
  76.  
  77.   (setq str2 (strcat str2 (substr str1 start1 (+ (- lstr1 start1) 1))))
  78.   ;; Start LSP
  79.   (setq str
  80.          (strcat
  81.            ";<<<<<<(c)  baitang36 20220606 >>>>>> \n\n"
  82.            "   (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil  \".DCL\")) \"w\"))\n"
  83.            "              (progn\n" "                 (foreach x \n"
  84.            "                   '(  \n") ;_ end of strcat
  85.   ) ;_ end of setq
  86.  
  87.   (write-line str lsp)
  88.  
  89.   (while (setq str (read-line dcl))
  90.  
  91.     (setq n 1)
  92.     (while (<= n (strlen str))
  93.       (if (= (substr str n 1) "\\")
  94.         (progn
  95.           (if (= n 1)
  96.             (setq str (strcat "\\" str))
  97.             (setq
  98.               str (strcat (substr str 1 (- n 1)) "\\" (substr str n))
  99.             )
  100.           ) ;_ end of if
  101.           (setq n (+ n 2))
  102.         ) ;_ end of progn
  103.         (setq n (1+ n))
  104.       ) ;_ end of if
  105.     ) ;_ end of while
  106.  
  107.  
  108.     (setq n 1)
  109.     (while (<= n (strlen str))
  110.       (if (= (substr str n 1) "\"")
  111.         (progn
  112.           (if (= n 1)
  113.             (setq str (strcat "\\" str))
  114.             (setq
  115.               str (strcat (substr str 1 (- n 1)) "\\" (substr str n))
  116.             )
  117.           ) ;_ end of if
  118.           (setq n (+ n 2))
  119.         ) ;_ end of progn
  120.         (setq n (1+ n))
  121.       ) ;_ end of if
  122.     ) ;_ end of while
  123.  
  124.  
  125.     (write-line
  126.       (strcat "                     \"" str "\"  ")
  127.       lsp
  128.     )
  129.  
  130.   ) ;_ end of while
  131.  
  132.  
  133.   (setq str (strcat "     ) (write-line x dcl_file) )\n"
  134.                     "     (setq dcl_file (close dcl_file)))\n"
  135.             )
  136.   )
  137.  
  138.   (write-line str lsp)
  139.   (write-line str2 lsp)
  140.  
  141.   (close lsp)
  142.   (close dcl)
  143.  
  144.   (princ "\n")
  145.   (prompt (strcat " << ok >> filen_ame:"
  146.                   newFName
  147.           )
  148.   )
  149.   (prin1)
  150. ) ;_ end of defun
  151.  
  152.  
« Last Edit: June 07, 2022, 01:09:38 AM by baitang36 »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Merge a DCL file and a LSP file
« Reply #1 on: June 07, 2022, 02:26:15 AM »
@baitang36

This very much reminds me on this :
http://www.theswamp.org/index.php?topic=52907.msg608920#msg608920

(I don't know if you looked at it already...)

In what scenario do we need to merge DCL and LSP that are performing things accordingly to predominantly LSP codings (callings) when DCL is supposed to be called?
The problem is that with my link, master LSP also needs to point to location (path) of file itself (LSP/DCL), wasting time therefore... I can see that you also forces (getfiled) to browse for file(s)...
Are you after that establishing treatment of DCL in native form flexible for manipulations and in the same time applying it's real runtime performance through master LSP?
In what case do we really need merging, if DCL can't be hooked to normal compact textual expression reserved for Dialog Control Language in it's true basic written language formulation (how it's supposed to be used/written when writing it from scratch/starting point)?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

baitang36

  • Bull Frog
  • Posts: 213
Re: Merge a DCL file and a LSP file
« Reply #2 on: June 07, 2022, 03:43:30 AM »
@baitang36

This very much reminds me on this :
http://www.theswamp.org/index.php?topic=52907.msg608920#msg608920

(I don't know if you looked at it already...)

In what scenario do we need to merge DCL and LSP that are performing things accordingly to predominantly LSP codings (callings) when DCL is supposed to be called?
The problem is that with my link, master LSP also needs to point to location (path) of file itself (LSP/DCL), wasting time therefore... I can see that you also forces (getfiled) to browse for file(s)...
Are you after that establishing treatment of DCL in native form flexible for manipulations and in the same time applying it's real runtime performance through master LSP?
In what case do we really need merging, if DCL can't be hooked to normal compact textual expression reserved for Dialog Control Language in it's true basic written language formulation (how it's supposed to be used/written when writing it from scratch/starting point)?
This is a tool, one click merge. One file is simpler and better managed than two files

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Merge a DCL file and a LSP file
« Reply #3 on: June 07, 2022, 06:37:57 AM »
I can't recall now for what I did in past, but it was very similar to this... Here is the topic - on the swamp - search for @Inreb and me, and "DCL to LSP" or similar...
And regarding that of your code and based on my previous experiences : consider using (vl-prin1-to-string) function to parse it to (write-line) to DCL->LSP on the fly... Much simpler, and much more effective and also very proficient in terms of errors - with "" characters or... RegEx... or...wildchar */?@#$% ...???
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

baitang36

  • Bull Frog
  • Posts: 213
Re: Merge a DCL file and a LSP file
« Reply #4 on: June 07, 2022, 08:02:56 PM »
I can't recall now for what I did in past, but it was very similar to this... Here is the topic - on the swamp - search for @Inreb and me, and "DCL to LSP" or similar...
And regarding that of your code and based on my previous experiences : consider using (vl-prin1-to-string) function to parse it to (write-line) to DCL->LSP on the fly... Much simpler, and much more effective and also very proficient in terms of errors - with "" characters or... RegEx... or...wildchar */?@#$% ...???
Indeed, many people have done DCL to LSP before. My innovation is to automatically process load_ Dialog statement. It is very simple for the program to automatically find and replace.