This is an eXode documentation for review by eXode members and other interested parties. It is a released document but may be updated, replaced or obsoleted by other documents in future relases.
This document explains the eXdbm (eXode Database Manager) file format. This is the configuration file format of the eXode clients (esp. the core tools). The provided API is also explained here.
Dec-27-97:
- version 1.0beta1 to be released
- removed keyword concept (too eXode specific)
Dec-10-97:
- new keyword specification.
- few changes in the API
- no more disk media
- new error code (-1)
Oct-04-97:
- First draft translated and modified, renamed eXdbm
July-xx-97:
- First draft (was eXhcl)
The X Resource manager is a normal choice for Motif based applications configuration but it lacks of high level data structures like lists or trees. Derived from the fof's configuration file format, eXdbm is an ASCII-based database format. eXdbm will be used to manage the configuration files of the eXode clients. The resource files will also be generated by eXconfig from the eXdbm files. The proposed API for the eXdbm management follows the description of the format.
The library uses a tree of hash tables structures stored in memory, favouring speed upon memory consumption. This is not a general purpose database library, its efficiency is based on the fact that the databases managed contain less than a few thousand entries.
Note that eXdbm is a general purpose configuration library, it can be used in many other applications without relations to the eXode project.
The eXdbm files are standard text files. Each line of text is a definition (the end of line char is a delimiter).
The possible definitions are :
An empty line doesn't contain any definition and is simply ignored.
The following characters are reserved :
Exceptions :
A comment begins with the reserved char # and continues until the next end of line character (this is a sh-like behaviour). Each comment is associated to the first entry definition that follows.
Ex.: # I am a comment Variable = 12
The basic datatypes are :
You can declare a variable using the syntax :
VarName = Value
Where VarName is a string (no spaces or special chars) and Value is of type int, real, bool or string.
note : the type of the variable is implicit
Ex.: DefaultBackgroundColor = "Red" RefreshInterval = 1000 AlwaysConfirm = TRUE # according to eXdbm, pi is a variable ! PI = 3.14159265
A list definition starts on a new line by the name of the list followed by a {. Each element of a list is a variable definition or a sublist. A list is ended with a } on a new line.
note : The variable declared outside a list is called a global variable.
Ex.:
FORMAT_LIST {
TAR_GZ {
Description = "gzipped tar archive"
Magic = "\\032\\341"
Pattern = "*.tar.gz:*.tgz:*_tar.gz"
ViewCommand = "%DEFAULT"
EditCommand = "eXtar"
}
IMAGE {
Description = "graphic image"
Magic = "%NONE"
Pattern = "*.gif":"*.jpg":"*.tga"
ViewCommand = "%DEFAULT"
EditCommand = "gimp"
}
IMAGE_GIF {
Description = "gif image"
Magic = "\\0123\\0321"
Pattern = "*.gif"
ViewCommand = "%DEFAULT"
EditCommand = "gimp"
}
}
DB_ID -> a database identifier DB_LIST -> a list variable
The eXdbm functions return 0 on error and 1 on success.
NAME eXdbmGetLastError() SYNOPSIS int eXdbmGetLastError(void); DESCRIPTION Get the last error code RETURN VALUE An eXode error code
NAME eXdbmGetErrorString() SYNOPSIS const char * eXdbmGetErrorString(int errorcode); DESCRIPTION Get an error message corresponding to the error parameter RETURN VALUE A string containing the error message
NAME eXdbmLastLineParsed(); SYNOPSIS int eXdbmLastLineParsed(void); DESCRIPTION This function returns the number of the last line parsed while reading the last database file. This is usefull to locate a parsing error. EXAMPLE The following code prints a detailed error message : #include#include int ret; DB_ID dbid; int error; char *message; int last_line; ... ret = eXdbmOpenDatabse("mydb.cfg", &dbid); if(ret == -1) { printf("\nAn error has occured\n); /* get the error number */ error = eXdbmGetLastError(); /* get the standard error message */ message = eXdbmGetErrorString(error); /* get the last line parsed */ last_line = eXdbmLastLineParsed(); /* print a detailed error message */ printf("Error number %d : %s\n", error, message); printf("Last line parsed = %d\n", last_line); } ... Example of output : An error has occured eXdbmOpenDatabase : Cannot parse variable value Last line parsed = 25 RETURN VALUE -1 on error >0 on success
NAME eXdbmInit() SYNOPSIS int eXdbmInit(void); DESCRIPTION Initialize the database manager. This function must be call before any other eXdbm function call. RETURN VALUE -1 on error >0 on success
NAME eXdbmOpenDatabase() SYNOPSIS int eXdbmOpenDatabase(char *filename, DBID *dbid); DESCRIPTION Open the filename database file. dbid is a pointer to an integer : an unique identifier for the opened database RETURN VALUE -1 on error >0 on success
NAME eXdbmNewDatabase() SYNOPSIS int eXdbmOpenDatabase(char *filename, DB_ID *dbid); DESCRIPTION Create a new database which will use the file filename. dbid is a pointer to an integer : an unique identifier for the opened database RETURN VALUE -1 on error >0 on success
NAME eXdbmUpdateDatabase() SYNOPSIS int eXdbmUpdateDatabase(DB_ID dbid); DESCRIPTION Save the database identified by dbid. This assure the actual database contents is the same in memory and on disk. RETURN VALUE -1 on error >0 on success
NAME eXdbmBackupDatabase() SYNOPSIS int eXdbmBackupDatabase(DB_ID dbid, char *filename); DESCRIPTION Make a backup copy of the database identified by dbid in the file filename. This file must be writeable by the current user. RETURN VALUE -1 on error >0 on success
NAME eXdbmCloseDatabase() SYNOPSIS int eXdbmCloseDatabase(DBID dbid, int update) DESCRIPTION The function you have to call to close a database. If udate = 1 (defined as TRUE in eXdbm.h), the database file will be updated, see eXdbmUpdateDatabase(). RETURN VALUE -1 on error >0 on success
NAME
eXdbmGetEntryType()
SYNOPSIS
int eXdbmGetEntryType(DB_ID dbid, DB_LIST list, char *entryname);
DESCRIPTION
This function returns the type of the entry identified by :
dbid : the database identifier
list : the parent's list of the entry (NULL for level 0 entry)
entryname : the name of the entry
RETURN VALUE
-1 (DBM_ENTRY_NOT_FOUND) on error
On succes, the type of the entry :
- DBM_ENTRY_LIST : a list entry
- DBM_ENTRY_VAR_INT : an integer variable
- DBM_ENTRY_VAR_BOOL : a boolean variable
- DBM_ENTRY_VAR_REAL : a real number variable
- DBM_ENTRY_VAR_STRING : a string variable
- DBM_ENTRY_VAR_ID : an identifier variable
NAME eXdbmGetEntryComment() SYNOPSIS char * eXdbmGetEntryComment(DB_ID dbid, DB_LIST list, char *entryname); DESCRIPTION Returns the associated comment of an entry if it exists, or NULL. The entry is specified by : dbid : the database identifier list : the parent's list of the entry (NULL for level 0 entry) entryname : the name of the entry RETURN VALUE A pointer to the comment string or NULL NAME eXdbmChangeEntryComment() SYNOPSIS int eXdbmChangeEntryComment(DB_ID dbid, DB_LIST list, char *entryname, char *comment); DESCRIPTION Changes the associated comment of an entry. The entry is specified by : dbid : the database identifier list : the parent's list of the entry (NULL for level 0 entry) entryname : the name of the entry comment is the new comment string NOTE The function allocates the memory needed for the comment and copy the string you provide. You must ensure the specifier string starts with a # character. If this is not the case, eXdbm won't be able to parse the database file containing a comment that is not starting with #. RETURN VALUE -1 on error >0 on success
NAME eXdbmDeleteEntry() SYNOPSIS int eXdbmDeleteEntry(DB_ID dbid, DB_LIST list, char *entryname); DESCRIPTION This function deletes the entry specified by dbid : the database identifier list : the parent's list of the entry (NULL for level 0 entry) entryname : the name of the entry if the entry is a list, all the entries is contains are also destroyed, recursively. RETURN VALUE -1 on error >0 on sucess
NAME eXdbmGetList() SYNOPSIS DB_LIST eXdbmGetList(DB_ID dbid, DB_LIST list, char *listname); DESCRIPTION get the identifier of the sublist of name listname in list. if list is NULL, sublistname is the name of a first level list RETURN VALUE A pointer to the found DB_LIST structure. If the value is NULL, the Sublist doesn't exist (an error is raised, the eXdbmGetError returns an error).
NAME eXdbmSearchList() SYNOPSIS DB_LIST eXdbmSearchList(DB_ID dbid, DB_LIST list, char *listname); DESCRIPTION search recursively the list of name listname in list and all of its sublists. If list is NULL, search in all the lists of the database. NOTE The behaviour of this function is hard to predict if more than one list is of name listname. RETURN VALUE A pointer to the found LIST structure. If the value is NULL, the Sublist doesn't exist (an error is raised, the eXdbmGetError returns an error).
NAME eXdbmPathList() SYNOPSIS DB_LIST eXdbmPathList(DB_ID dbid, char *path); DESCRIPTION This function returns the list referenced by its full path name in the database. A pathname is a serie of list names separated by colons. EXAMPLE list:sublist:susublist refers to the list of name subsublist defined in sublist which is defined in list. NOTE The root list (referenced as NULL) is implicit RETURN VALUE A pointer to the found LIST structure. If the value is NULL, the list doesn't exist (an error is raised, the eXdbmGetError returns an error).
NAME eXdbmCreateList() SYNOPSIS int eXdbmCreateList(DBID dbid, LIST *list, char *entryname, char *comment); DESCRIPTION Create an empty list of name entryname list is the parent list (NULL is the new list is global) comment is a string to comment the new list RETURN VALUE -1 on error >0 on success
In the following functions : First, get the file :
where status is : alpha, beta or empty (final)
version is the version number (1.0b1 is the last version)
Then uncompress the file :
Now, cd to eXdbm-status-version/
Then type :
and, as root :
The default installation directories are :
You can change these defaults by modifying the LIBDIR, INCDIR and DOCDIR make variable in Makefile.orig
This is the command line you have to use in order to link your C programs with the eXdbm library :
NOTE :
Don't forget the -lm statement, eXdbm uses a few math functions.
The following programs demonstrates the use of the eXdbm library :
4.6.1. read a value
NAME
eXdbmGetVar
4.6.2. create a variable
NAME
eXdbmCreateVar
4.6.3. Modify a variable
NAME
eXdbmChangeVar
5. Using the library
5.1. Installation instructions
eXdbm-status-version.tar.gz
gzip -d eXdbm-status-version.tar.gz
tar xvf eXdbm-status-version.tar
make
make install
/usr/local/include : header files
/usr/local/lib : library
/usr/local/doc/eXdbm : documentation
5.2. Linking programs with libeXdbm.a
cc myprogram.c -I/usr/local/include -L/usr/local/lib -leXdbm -lm
5.3. Sample programs
- test1 (test1.c)
Basic open/update/close functions
- test2 (test2.c)
Backup function test
- test3 (test3.c)
A console oriented small database manager that uses every functions
provided in the eXdbm library.