Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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 :oops:

Test.zip

Posted
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 :oops:

 

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

Posted

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). :D

Groetjes,

Christina

@Bigal,

Thank you very much for the link and will take a look on it

Posted
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). :D

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...