Down and dirty documentation for the Prefs package
- Edit your Makefile and be sure "-lprefs" is in the definition of
"LIBS".
- Look at the file testprefs.h, which can also
be found in /afs/ncsa.uiuc.edu/.u10/spowers/class/public/misc-examples.
You should note all the "Values" declarations happen before the main
Prefs declaration. Note this is an example file.
- Look at the file prefs.h, which can also be
found in /afs/ncsa.uiuc.edu/.u10/spowers/class/public/include. This
contains the typedef strcutures for Values and for Prefs. You should
be able to understand what each field is in the testprefs.h file now.
- In any C file you want to access the prefs functions from, you will
need to add "#include <prefs.h>".
- To use the prefs library, you have to initialize it. You do this by
calling "initPrefs()" passing your "Prefs" variable to it (like what
is done in "ptest.c" (also found in /afs/ncsa.uiuc.edu/.u10/spowers/class/public/misc-examples)).
This let's the library know what is valid and what is invalid.
- Once you have initialized, then you'll want to read in the prefs you
have created. For the purpose of this example, I created a file called
.prefs-prj3 (also found in /afs/ncsa.uiuc.edu/.u10/spowers/class/public/misc-examples).
You will see there are some mistakes, this is done on purpose to
illustrate the types of error messages you could recieve. The proper
format of a preference line is "<Valid_Token>: <Valid_Value>". If
"LeftMouseButton" was a valid token and "Clip X" was a valid value,
then you could put "LeftMouseButton: Clip X" in your prefs file. To
actually read in the prefs file, you call "readPrefs()" passing the
name of your prefs file.
- Writing out your preferences is very simple. You only need to call
"writePrefs()". You should probably check the return value as it
should match your readPrefs return value. See the "ptest.c" example
code.
- More later...