Christina_ Posted April 19, 2017 Posted April 19, 2017 Hello CadTutor Users, I read by lisp ini file with (ini_read "Myfile.ini" "OPTIONS" "Name1"). Myfile.ini : [OPTIONS] Name1=10 Name2=210 Name3=0 This will nicely return me “10”. The problem is that I will like to comment the ini file but no need comments in the results : [OPTIONS] Name1=10 “comment1” Name2=210 “comment2” Name3=0 “comment3” Can someone please edit my code? No problem if the comment begins by /comment or #comment or… Lisp code: (defun ini_read (inifile section entry ) (if (and (= 'STR (type section)) (/= "[" (substr section 1 1))) (setq section (strcat "[" section "]"))) (setq section (ini_readsection inifile section)) (cadr (assoc entry section)) ) (defun ini_readsection (inifile section / ofile line result ) (if (and (= 'STR (type section)) (/= "[" (substr section 1 1))) (setq section (strcat "[" section "]"))) (if (findfile inifile) (cdr (assoc section (ini_readini (findfile inifile)))) (alert (STRCAT inifile "\nNiet Gevonden!")) ) ) Thank you to read my problem Christina Quote
rlx Posted April 19, 2017 Posted April 19, 2017 Hoi Christina, zoiets? ; strip comment ; (strip-comment "hallo ; goodbey" ";") (defun strip-comment ( $s $c / i )(if (setq i (vl-string-position (ascii $c) $s 1))(substr $s 1 i) $s)) gr. Rlx Quote
Christina_ Posted April 19, 2017 Author Posted April 19, 2017 Dag Rlx, Very thank you for the reply but sorry that i don't see how to work with your code in my code So hope you don't mind i put my code in the attachments Test.zip Quote
rlx Posted April 19, 2017 Posted April 19, 2017 Dag Rlx, Very thank you for the reply but sorry that i don't see how to work with your code in my code So hope you don't mind i put my code in the attachments I see you use a space (spatie) and a tab after your ini value so I break the ini value (string) at the tab character ("\t") and then remove the space. If your ini values never contain a space you also can break your ini value at the space character (strip-comment (cadr (assoc entry section)) " ") ;(ini_read "Test.ini" "OPTIONS" "Name1") ;(ini_read (findfile "Test.ini") "OPTIONS" "Name1") (vl-load-com) (defun ini_read (inifile section entry / result) (if (and (= 'STR (type section)) (/= "[" (substr section 1 1))) (setq section (strcat "[" section "]"))) (setq section (ini_readsection inifile section)) ; remove everything from the first tab ("\t") (setq result (strip-comment (cadr (assoc entry section)) "\t")) ; result is "10 " (with a space (spatie) , so remove space "10 " -> "10" (vl-string-right-trim " " result) ; you can combine line 2,3 & 4 into one line : ; (vl-string-right-trim " " (strip-comment (cadr (assoc entry (ini_readsection inifile section))) "\t")) ) ;(vl-string-right-trim character-set string) ; strip comment ; (strip-comment "hallo ; goodbye" ";") (defun strip-comment ( $s $c / i )(if (setq i (vl-string-position (ascii $c) $s 1))(substr $s 1 i) $s)) gr. Rlx Quote
BIGAL Posted April 20, 2017 Posted April 20, 2017 Look at this post for the lee-mac code you can use a comma as the seperator and make a list very easy. http://www.cadtutor.net/forum/showthread.php?100466-Lisp-for-remove-one-line-from-mtext Quote
Christina_ Posted April 20, 2017 Author Posted April 20, 2017 Dag Rlx, This work like a charm and will like to thank you for the very clear explanation . Finally I have my ini file like I want (mijn dag kan niet meer stuk). Groetjes, Christina @Bigal, Thank you very much for the link and will take a look on it Quote
rlx Posted April 20, 2017 Posted April 20, 2017 Dag Rlx, This work like a charm and will like to thank you for the very clear explanation . Finally I have my ini file like I want (mijn dag kan niet meer stuk). Groetjes, Christina @Bigal, Thank you very much for the link and will take a look on it Youre welcome Christina_ , succes met je appie :-) gr.Rlx Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.