BASIC CODE TO PARSE INI FILES.

For posting library code and examples.
Post Reply
User avatar
ahenry3068
Posts: 1144
Joined: Tue Apr 04, 2023 9:57 pm

BASIC CODE TO PARSE INI FILES.

Post by ahenry3068 »

Ok. First draft of my INI file parser.

1. Very preliminary. Does not and will not do [sections] (Memory constraints)

2. Will open and read larger files but will only get the first 20 entries (Deliberate choice, Memory constraints)
(In addition I'm TRIMMING and UCASING every line. It takes a bit more than 2 seconds to read & parse 20 entries, Thats an acceptable delay in code that's usually only called once at the start of a program, but I didn't want to make it any longer than that)

3. Will FAIL on Unix text files. MAC and Windows Text files only. Lines must have a CR ($0D)

4. Currently stores the INI Variables in 2 arrays but I have not written wrapper GOSUBS to manipulate the data yet.

5. At a moment its a little stupid in that it allows duplicate INIVAR values in the array. I intend to parse those out eventually.


Includes a couple of other useful GOSUBS -- RTRIM, LTRIM, & TRIM to remove leading and trailing Whitespace from a String also UCASE to force an ASCII string to Upper Case. It allows lowercase text to be used in the INIFILE. It is forced to Upper Case when read from file.

INCLUDES
HANGMAN.INI -- An example INI file
INIFILES.BAS -- BASLOAD Source file
INIFILES.PRG -- Quick Example Program

HERE IT IS
INICODE.zip
(2.31 KiB) Downloaded 324 times



I wrote the following GOSUB that really completes this library but it's not included in the first post.
The GOSUB is GETINIVALUE. Called after READINI. The GOSUB should be pasted into INIFILES.BAS.
I$="INI-VAR-NAME":GOSUB GETINIVALUE
After the call I$ will either hold the Value of INIVAR (ie the Right Hand side of =) or be empty (="")

HERE IT IS
GETINIVALUE.BAS
(124 Bytes) Downloaded 306 times
Post Reply