(setq fname (vl-filename-mktemp nil nil ".dcl"))
(setq fn (open fname "w"))
(write-line "... ... \" ... ... \" ... ..." fn)
(write-line "... ..." fn)
...
(close fn)
(vl-file-delete fname)
(defun c:dcl2lsp ( / fname1 fn1 fname2 fn2 k fn1l fn2l )
(setq fname1 (getfiled "Select DCL file" "" "dcl" 16))
(setq fn1 (open fname1 "r"))
(setq fname2 (getfiled "File to save" "" "lsp" 1))
(setq fn2 (open fname2 "w"))
(while (setq fn1l (read-line fn1))
(setq fn2l fn1l)
(setq k 0)
(while (setq k (vl-string-search "\"" fn2l k))
(setq fn2l (vl-string-subst "\\\"" "\"" fn2l k))
(setq k (+ k 2))
)
(setq fn2l (strcat "(write-line \"" fn2l "\" fn)"))
(write-line fn2l fn2)
)
(close fn1)
(close fn2)
(princ)
)
(defun c:lsp2dcl ( / fname1 fn1 fname2 fn2 k fn1l fn2l )
(setq fname1 (getfiled "Select LSP file" "" "lsp" 16))
(setq fn1 (open fname1 "r"))
(setq fname2 (getfiled "File to save" "" "dcl" 1))
(setq fn2 (open fname2 "w"))
(while (setq fn1l (read-line fn1))
(setq fn2l fn1l)
(setq fn2l (substr fn2l (+ (vl-string-search "\"" fn2l) 2) (- (vl-string-position (ascii "\"") fn2l nil T) (+ (vl-string-search "\"" fn2l) 1))))
(setq k 0)
(while (setq k (vl-string-search "\\\"" fn2l k))
(setq fn2l (vl-string-subst "\"" "\\\"" fn2l k))
(setq k (+ k 1))
)
(write-line fn2l fn2)
)
(close fn1)
(close fn2)
(princ)
)
(defun c:viewdcl ( / dclid return# filen fn lin )
(setq dclid (load_dialog (setq filen (getfiled "" "" "dcl" 16))))
(setq fn (open filen "r"))
(while (or (eq (substr (setq lin (read-line fn)) 1 2) "//") (eq (substr lin 1 (vl-string-search " " lin)) "") (not (eq (substr lin (+ (vl-string-search " " lin) 1) 9) " : dialog"))))
(new_dialog (substr lin 1 (vl-string-search " " lin)) dclid)
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq return# (start_dialog))
(princ return#)
(unload_dialog dclid)
(princ)
)
(defun c:dcl2lsp ( / fname1 fn1 fname2 fn2 k fn1l fn2l )
(setq fname1 (getfiled "Select DCL file" "" "dcl" 16))
(setq fn1 (open fname1 "r"))
(setq fname2 (getfiled "File to save" "" "lsp" 1))
(setq fn2 (open fname2 "w"))
(while (setq fn1l (read-line fn1))
(setq fn2l fn1l)
(setq k 0)
(while (setq k (vl-string-search "\\" fn2l k))
(setq fn2l (vl-string-subst "\\\\" "\\" fn2l k))
(setq k (+ k 2))
)
(setq k 0)
(while (setq k (vl-string-search "\"" fn2l k))
(setq fn2l (vl-string-subst "\\\"" "\"" fn2l k))
(setq k (+ k 2))
)
(setq fn2l (strcat "(write-line \"" fn2l "\" fn)"))
(write-line fn2l fn2)
)
(close fn1)
(close fn2)
(princ)
)
(defun c:lsp2dcl ( / fname1 fn1 fname2 fn2 k fn1l fn2l )
(setq fname1 (getfiled "Select LSP file" "" "lsp" 16))
(setq fn1 (open fname1 "r"))
(setq fname2 (getfiled "File to save" "" "dcl" 1))
(setq fn2 (open fname2 "w"))
(while (setq fn1l (read-line fn1))
(setq fn2l fn1l)
(setq fn2l (substr fn2l (+ (vl-string-search "\"" fn2l) 2) (- (vl-string-position (ascii "\"") fn2l nil T) (+ (vl-string-search "\"" fn2l) 1))))
(setq k 0)
(while (setq k (vl-string-search "\\\"" fn2l k))
(setq fn2l (vl-string-subst "\"" "\\\"" fn2l k))
(setq k (+ k 1))
)
(setq k 0)
(while (setq k (vl-string-search "\\\\" fn2l k))
(setq fn2l (vl-string-subst "\\" "\\\\" fn2l k))
(setq k (+ k 1))
)
(write-line fn2l fn2)
)
(close fn1)
(close fn2)
(princ)
)
Command: (setq str (getstring t)) Test backslash \ and double quotes "
"Test backslash \\ and double quotes \""
Command: (progn (princ str) (princ))
Test backslash \ and double quotes "
Command: (progn (princ (vl-princ-to-string str)) (princ))
Test backslash \ and double quotes "
Command: (progn (princ (vl-prin1-to-string str)) (princ))
"Test backslash \\ and double quotes \""
So the vl-prin1-to-string "should" work perfectly. Though last time I incorporated it into my DCL2LSP it would simply double the quotes thus:(progn (princ (vl-prin1-to-string str)) (princ))
"Test backslash \\ and double quotes """
Actually why use the vl-prin1-to-string at all? Why not simply use the prin1 to print directly to the file?
;|
;; prefix all quotes and backslashes with backslashes
(setq str (strsubst "\\\"" "\"" (strsubst "\\\\" "\\" str)))
;; Write to file
(write-line (strcat " (write-line \"" str "\" f)")lsp)
|;
(princ " (write-line " lsp)
(prin1 str lsp)
(princ " f)\n" lsp)
TestDialog : dialog {
label = "Testing \\ DCL2LSP";
: edit_box {
key = "ser";
label = "Edit box";
width = 50;
}
: list_box {
key = "key";
label = "List Box";
tabs = "20 35";
multiple_select = true;
list = "One\t1\nTwo\t2\nThree\t3";
value = "1 2";
}
: text {
key = "txt";
height = 3;
value = "My long line of text\nhas a second line";
}
ok_cancel;
}
Now running mu DCL2LSP on that file (I saved it as test.DCL) I get a file named load_dialog_test.lsp:;;; Function to load test dialog
(defun load_dialog_test (/ fn f)
(setq fn (strcat (getvar "TEMPPREFIX") "test.DCL"))
(setq f (open fn "w"))
(write-line "TestDialog : dialog {" f)
(write-line " label = \"Testing \\\\ DCL2LSP\";" f)
(write-line " : edit_box {" f)
(write-line " key = \"ser\";" f)
(write-line " label = \"Edit box\";" f)
(write-line " width = 50;" f)
(write-line " }" f)
(write-line " : list_box {" f)
(write-line " key = \"key\";" f)
(write-line " label = \"List Box\";" f)
(write-line " tabs = \"20 35\";" f)
(write-line " multiple_select = true;" f)
(write-line " list = \"One\\t1\\nTwo\\t2\\nThree\\t3\";" f)
(write-line " value = \"1 2\";" f)
(write-line " }" f)
(write-line " : text {" f)
(write-line " key = \"txt\";" f)
(write-line " height = 3;" f)
(write-line " value = \"My long line of text\\nhas a second line\";" f)
(write-line " }" f)
(write-line " ok_cancel;" f)
(write-line "}" f)
(close f)
(load_dialog fn)
) ;_ end of defun
;;; Function to run the TestDialog dialog
(defun run_dialog_test_TestDialog (key_list extra / dcl return)
(if (and (setq dcl (load_dialog_test)) (new_dialog dcl))
(progn
(foreach key key_list
(if (cadr key)
(set_tile (car key) (cadr key))
)
(if (caddr key)
(action_tile (car key) (caddr key))
)
(if (cadddr key)
(progn
(start_list (car key))
(mapcar 'add_list (cdddr key))
(end_list)
)
)
)
(if extra (eval extra))
(setq return (start_dialog))
(unload_dialog dcl)
)
)
return
) ;_ end of defun
(defun c:TestDialog ( / fname fn dclid lin return# )
(setq fname (vl-filename-mktemp nil nil ".dcl"))
(setq fn (open fname "w"))
(write-line "TestDialog : dialog {" fn)
(write-line " label = \"Testing \\\\ DCL2LSP\";" fn)
(write-line " : edit_box {" fn)
(write-line " key = \"ser\";" fn)
(write-line " label = \"Edit box\";" fn)
(write-line " width = 50;" fn)
(write-line " }" fn)
(write-line " : list_box {" fn)
(write-line " key = \"key\";" fn)
(write-line " label = \"List Box\";" fn)
(write-line " tabs = \"20 35\";" fn)
(write-line " multiple_select = true;" fn)
(write-line " list = \"One\\t1\\nTwo\\t2\\nThree\\t3\";" fn)
(write-line " value = \"1 2\";" fn)
(write-line " }" fn)
(write-line " : text {" fn)
(write-line " key = \"txt\";" fn)
(write-line " height = 3;" fn)
(write-line " value = \"My long line of text\\nhas a second line\";" fn)
(write-line " }" fn)
(write-line " ok_cancel;" fn)
(write-line "}" fn)
(close fn)
(setq fn (open fname "r"))
(setq dclid (load_dialog fname))
(while (or (eq (substr (setq lin (vl-string-right-trim "\" fn)" (vl-string-left-trim "(write-line \"" (read-line fn)))) 1 2) "//") (eq (substr lin 1 (vl-string-search " " lin)) "") (not (eq (substr lin (+ (vl-string-search " " lin) 1) 9) " : dialog"))))
(new_dialog (substr lin 1 (vl-string-search " " lin)) dclid)
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq return# (start_dialog))
(princ return#)
(unload_dialog dclid)
(close fn)
(vl-file-delete fname)
(princ)
)
Here is your TestDialog.dcl example implemented into my version of TestDialog.lsp... Above and below lines are always the same and lines (write-line "..." fn) are obtained from my dcl2lsp.lsp... I've tested my TestDialog.lsp and it works (shows your *.dcl)...
M.R.
Here is my simple code, but vary powerful if you want to implement dcl content into lsp file... Of course, you have to edit main lsp with these lines :
Here is my simple code, but vary powerful if you want to implement dcl content into lsp file... Of course, you have to edit main lsp with these lines :
You view my source lisp, :coolsmiley:or text files.................
You view my gif - image
Here is my simple code, but vary powerful if you want to implement dcl content into lsp file... Of course, you have to edit main lsp with these lines :
You view my source lisp, :coolsmiley:or text files.................
You view my gif - image
The virus ??? load those vlx , Black screen , cad can't exit.
no. everything is fine. try on virtual machine.Here is my simple code, but vary powerful if you want to implement dcl content into lsp file... Of course, you have to edit main lsp with these lines :
You view my source lisp, :coolsmiley:or text files.................
You view my gif - image
The virus :? load those vlx , Black screen , cad can't exit.