home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
amigalibdisks
/
disk948
/
snoopy
/
ini
/
ini.manual
< prev
next >
Wrap
Text File
|
1993-12-21
|
16KB
|
413 lines
ini.library
Release Version 2.0
I-WANT-TO-BE-FREE-WARE
written by Gerson Kurz
Nov.21,1993
PURPOSE
The ini.library was written to give the amiga user a more consistent
configuration file format, and programmers a much easier way of
storing config or project information on disks.
Most programs have config files to store global settings and such.
These files have all different structures people in the real world
(the users) cannot examine or understand; and, worse yet, often differ
from version to version. We all know the hassle with those 'old->new'
configuration file converters...With the ini.library this changes: you
have access to a standardized ini file format known from other
operating systems such as unix, windows and so on; it allows
you to save your config stuff much easier (less code), and it
enables the user to read and even modify configuration data with
a simple text editor (or, a wide-range field for unemployed PD
programmers: using an INI editor)
As the ini.library is I-WANT-TO-BE-FREE-WARE you are ENCOURAGED to
use it - its free of charge! (go ahead, do it!) and it offers much
more comfort to your applications. PD dealers, diskmags, everyone,
I'd like you to push'n'hype the ini.library ;-).
INI files are plain line-oriented ASCII texts that can contain three
possible types of lines : COMMENTS, HEADERS and VARIABLES. COMMENTS are
lines that include additional information not used by the parser.
You can use these comment lines to give the user ideas about what
your variables mean and what reasonable changes s(he) is allowed
to make to that variables. HEADERS are identifiers for sections and
are enclosed in [] brackets. A SECTION is a group of zero to infinite (?)
number of variables and provides a simple but efficient means of
logically grouping data. VARIABLES are simple statements in the
form "<variable>=<contents>" where both <variable> and <contents>
could be virtually anything - you name it.
Each INI file must start with a sequence of 4 characters ";INI"
otherwise the ini.library will return the INIERROR_INVALID_INI_FILE.
This was included to prevent misuse of the ini.library: imagine your
program has a 'load user configuration' menu and the user tries out
some binary hack or an IFF picture (you know users, don't you?! ;-)
If you watch out for INIERROR_INVALID_INI_FILE, you can send the user
a message of complaint and ignore its wishes -> great.
Since this is a cause for many first-time problems, from version 2.1
upwards this checking can be made optional; see ini_NewConfig() for
details
COMMENTS
Comments can be placed anywhere [well, almost]. If you want
to have a full-line comment, place a ';' or a '*' in the first
column of that line. Anything after these two characters will be ignored.
If you want to place a comment at the end of a line you should use
the ';' sign ONLY. Also note that if you make a comment after a
variable you should probably enclose its contents in quotation marks;
otherwise the whitespaces between the last character of the contents
and the comment start will be part of the contents. This is
no problem if you are using integer or boolean variables; it might
be a problem for SOME string variables, but doesn't necessarily have
to - its up to your interpretation of the input data.
Examples:
;INI for MUIMon release version
* another piece of wisdom
best part of munich=ULTRAWORLD ; 100% wild techno
SECTIONS
Sections are used to group variables logically. You should try to place
all your data in groups so that your inifiles have a more consistent
look and both you and the user can find data easier. The concept of
sections can have various usages, one is to handle logic groupings
for one program, another is to handle data related to different
programs accessing the same INI file, yet another is to just make
your INI more readable. Of course,the ini.library is flexible enough
to ignore sections altogether, but you shouldn't force it! Sections
cost you nothing and make for a lot better programs.
HEADERS
Headers start a new section. Headers are strings enclosed in
[] brackets and can be any string you like. Everything following
a header is logically assigned to that header - up to the next
section header or an end-of-file.
Examples:
[drivers]
pc0=storage:dosdrivers/pc0
cd=devs:CDROM
[Disko Lovers,International]
best ULTRAWORLD DJs=MONIKA,TIN-A-303,BLEEP & TRIPPLE R,DJ HELL
; hi to SMC all ravers around the globe. See you on MAYDAY V
[hermeneutic philosophy revisited]
zizek=no meta language exists
VARIABLES
Variables are basically strings that are assigned a name. The
names is what you search for, the strings is what you get -it is as
simple as that. For instance, in "TABS=8" the string "TABS" is
the name (also called the variable), the string "8" is its value.
The interpretation of the string value is up to you. The ini.library
provides three basic types of interpretation : Strings, Integers (LONGs)
and boolean Values (BOOLs). You can of course add your own
interpretations as you like, and this is why the ini concept is so
flexible: You can virtually store ALL information you need in such
a way that it is represented as an ASCII string. If you want your
strings to be of a certain length, you can enclose them in
brackets, for example such as in
user="T\"N\"I and THE DREAM TEAM"
where you can assign the string >T"N"I AND THE DREAM TEAM< to
the variable named >user<. Note that a sequence of \" is used
as an escape character in the above example.
If you have ideas for additional datatypes of general interest
the ini.library should understand, please contact me. If possible,
I'll include them.
Examples:
--------------------------------------------------------------
;INI
[GLOBAL]
user="T'N'I and The Dream Team" ;from INTENSE Records
tabs=8
indent=YES
autofold=FALSE
preferences=
[DIRECTORYS]
home=work:assembler/
; add multiple directorys by using '+' or ','
include=include:+dh1:more_includes/
libs=dh2:code/libs/asm/+lib:+disko:love
--------------------------------------------------------------
The above example shows you some ideas of inifiles: Two groups
are part of this inifile: GLOBAL and DIRECTORYS. Each section
can (but doesn't have to) have different variables, each variable
can be any string enclosed in quotation marks or from the = sign
to the end of the line. If you want to add comments, enclose the
string in quotes, and add a comment like in the "user=" line above.
Note that the feature described as "add multiple directorys by ..."
is a description of an add-on datatype used by the application for
this INI file and NOT provided by the ini.library itself.
Now you should be able to read inifiles. More complex features such
as section protection and file location are described in the
"programmers.guide" document which should be part of this distribution.
HINTS
If you decide to use the ini.library -WHICH I STRONGLY HOPE YOU DO-
you should always check for error returns - you may never know when
they come in handy for you.
If you save your files, make use of the grouping feature; that is,
at least provide some GLOBAL section so that the user knows what
he's up for. It makes INIfiles more readable and doesn't cost
you anything.
LIMITATIONS
Yes, there are some.
* currently no whitespaces before and after the "=" are allowed.
This means that the two following lines are different for
the ini.library parser functions
ultraworld=great
ultraworld = great
There is a simple workaround for this: just do your own variable
and contents parsing (explicit datatypes, see above). Future
versions WILL include a fix on that, I PROMISE.
* the ini.library uses approximately twice as much memory as the
ini file is in size (less for larger files). This is not a
proble