Author Topic: Handling of INI files?  (Read 5048 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 650
Handling of INI files?
« 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
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Handling of INI files?
« Reply #1 on: January 30, 2014, 10:05:13 AM »
I use Lisp files as INI for my settings, in my archive I have this:
Code: [Select]
;; 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))
;;       

Peter2

  • Swamp Rat
  • Posts: 650
Re: Handling of INI files?
« Reply #2 on: January 30, 2014, 10:28:05 AM »
Looks interesting. Could you also upload the code?

EDIT: But there is no write-function.
« Last Edit: January 30, 2014, 10:32:28 AM by Peter2 »
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Handling of INI files?
« Reply #3 on: January 30, 2014, 10:32:13 AM »
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?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Handling of INI files?
« Reply #4 on: January 30, 2014, 10:35:28 AM »
- 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Peter2

  • Swamp Rat
  • Posts: 650
Re: Handling of INI files?
« Reply #5 on: January 30, 2014, 10:35:59 AM »
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.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Handling of INI files?
« Reply #6 on: January 30, 2014, 11:36:36 AM »
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.

NICK_VNV

  • Newt
  • Posts: 63
Re: Handling of INI files?
« Reply #7 on: January 30, 2014, 12:56:56 PM »
You can use Express Tools acet- functions "acet-ini-set" and "acet-ini-get" :
Code: [Select]
; 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
« Last Edit: January 30, 2014, 01:02:41 PM by NICK_VNV »
Sorry for my English...

Peter2

  • Swamp Rat
  • Posts: 650
Re: Handling of INI files?
« Reply #8 on: January 30, 2014, 02:35:45 PM »
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.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23