TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Peter2 on January 30, 2014, 09:31:22 AM
-
Hi
maybe I missed a standard feature, but how to handle read/write INI-files in (V)Lisp without DosLib?
Regards
-
I use Lisp files as INI for my settings, in my archive I have this:
;; PROFILE.LSP Copyright 1994-97 Tony Tanzillo All rights reserved.
;;
;; Reads Windows-style .ini files
;;
;; Usage:
;;
;; (ini:load <filename>)
;;
;; Loads an .ini file into a list and returns
;; the list to its caller, for access using
;; other functions in this library.
;;
;; (GetItem <section> <item> <data>)
;;
;; Returns the value of an item in an .ini
;; file that has been loaded by the (ini:load)
;; function.
;;
;; <section> is the name of the section
;; from the ini file (do not include the
;; brackets!!!).
;;
;; <item> is the name of the item within
;; the specified <section>
;;
;; <data> is the list containing the ini
;; file data in the format returned by
;; the (ini:load) function.
;;
;; Example:
;;
;; ;; Load .ini file into a list
;; (setq data (Ini:load "acad.ini"))
;;
;; ;; Read the item 'Color' from the
;; ;; [Font] section of the .ini file
;; ;;
;; ;; [Font]
;; ;; Color=RED
;; ;; Size=12
;; ;; Bold=1
;; ;; Italic=0
;;
;; (setq color (GetItem "Font" "Color" data))
;;
-
Looks interesting. Could you also upload the code?
EDIT: But there is no write-function.
-
I use DosLib and its INI functions to read/write to an INI file, it's just SOOO much easier. Do you not want to use DosLib because you don't want to rely on a third-party program?
-
- read the file into a list
- parse the list to create a list of section headers; usually included in [___] but helps to be flexible
- parse a section to create a list of dotted pairs of elements; usually indicated with ELEMENT=VALUE but again, helps to be flexible
- handle comments, usually indicated with a single or double semi-colon
This was one of my first LISP tool libraries. Highly useful for developing list, string, and file handling coding practices.
-
I use DosLib and its INI functions to read/write to an INI file, it's just SOOO much easier....
Yes, I know. Normally I use it too.
...Do you not want to use DosLib because you don't want to rely on a third-party program?
I'm thinking about it. In this case I would only need the INI features, and maybe I can abstain from DosLib for this code.
-
Looks interesting. Could you also upload the code?
EDIT: But there is no write-function.
I'm sorry but I do not remember where I copied it and I do not know if I can do it for the Copyright, I made a mistake of this kind years ago... Write me a personal message and I will send to you.
-
You can use Express Tools acet- functions "acet-ini-set" and "acet-ini-get" :
; Write to INI
(acet-ini-set "c:\\filename.ini" "dir_name" "name1" "value1")
(acet-ini-set "c:\\filename.ini" "dir_name" "name2" "value2")
; Read from INI
(acet-ini-get "c:\\filename.ini" "dir_name" "name1") ; will return "value1"
;or
(acet-ini-get "c:\\filename.ini" "dir_name" ) ; will return list ("name1" "name2")
Contents of Filename.ini:
[dir_name]
name1=value1
name2=value2
-
You can use Express Tools acet- functions "acet-ini-set" and "acet-ini-get" ....
That's fine, thanks. But because some people don't have the Express Tools I will take a look at the copyright of the code - maybe I can integrate it.