Next Previous Contents

12. The VIEWITEM and VIEWITEMS objects

#Specification: VIEWITEMS / principle ([fviews.cc,1])

The VIEWITEMS object is used to parse a configuration file with comments and continuation line. The special character starting comments is configurable. The default is the # character. All comments before statements and at the end of the statements are preserved. Application using that object will generally scan the VIEWITEM ( VIEWITEMS is derived from ARRAY) and extract various configuration statement they can handle. While doing so, they generally remember the VIEWITEM holding that statement. This allows application to make correction to the file and preserve comment as much as possible. This preserve also the original ordering of the file. New statement are generally append at the end though. This could be used for simple module. The first client for this code is the wuftpd module.

12.1 VIEWITEM Alphabetical function listing

Classe VIEWITEM, vue publique

12.2 VIEWITEMS Alphabetical function listing

Classe VIEWITEMS, vue publique

12.3 Some specs

#Specification: VIEWITEMS / various file format ([fviews.cc,345])

VIEWITEMS may be used to managed two types of configuration files. You have normal keyed configuration file of the form:

        keyword value ...
and you have the shell type ones of the form:
        #!/bin/sh
        VAR1=value
        VAR2=value
Functions like VIEWITEMS::locate() and VIEWITEMS::locateassign() are used to dig into the VIEWITEMS object.

#Specification: VIEWITEMS / update strategy ([fviews.cc,655])

When updating a config file using the VIEWITEMS object, the code generally goes like this.

        CONFIG_FILE cf (...);
        VIEWITEMS items;
        items.read (cf);
        .
        items.update (var,value);
        .
        items.write(cf,(PRIVILEGE*)NULL);
There are several VIEWITEMS::update() function to support various data type. For some project, you may be better to write your own update function. An update function always looks like the following pseudo-code
        // Used one of the VIEWITEMS::locate or write your own
        VIEWITEM *it = items.locate (key);
        if (it == NULL){
            // No record found, add a new empty one
            // It will go at the end of the config file
            it = new VIEWITEM;
            items.add (it);
        }
        // formats the updated value of the record and stores it
        // in the VIEWITEM object.
        char line[1000];
        snprintf (line,sizeof(line)-1,"....",....);
        it->line.setfrom (line);

#Specbeg: VIEWITEM / layout ([fviews.h,44])

        class VIEWITEM: public ARRAY_OBJ{
        public:
            SSTRING line;
            SSTRING comment;    // Comment at the end of the statement
            int type;

Next Previous Contents