NAME

parse_db - a Perl module to parse epics db-files

SYNOPSIS

use parse_db;
undef $/;

my $st= <>;

my $r_records= parse_db::parse($st);
parse_db::dump($r_records);

DESCRIPTION

Preface

This module contains a parser function for epics DB-files. The contents of the db-file are returned in a perl hash-structure that can then be used for further evaluation.

Implemented Functions:

data structures

field hash

A field hash maps field names to field values, both are perl strings. Here is an example:

(
  'PRIO' => 'LOW',
  'DESC' => 'subroutine',
  'HIGH' => ''
)

info hash

An info hash maps "info" names to "info" values. This is the information from the "info" statement in a db file. Here is an example:

(
  'Author'   => 'John Doe',
  'Revision' => '1.2',
  'Notes'    => 'not yet tested'
)

record hash

A record hash contains all information about a single record. It is part of the data structure created by the functions parse and parse_file. Depending on the "mode" parameter of these functions, the record hash may be slightly different.

It always includes a key "FIELDS" that maps to a reference of a field hash and a key "TYPE" that maps to a string that is the record type.

When parse or parse_file were called with mode "array", the hash also includes a key "NAME" that maps to the record name and a key "ORDERDFIELDS" that maps to a reference of a list of field names in the order they were found in the db file. When parse or parse_file were is called with mode "extended" the record includes a field "INFO" that maps to a reference to an info hash.

Here are some examples,

created in mode "standard":

(
  'TYPE'  => 'sub',
  'FIELDS'=> { 'PRIO' => 'LOW',
               'DESC' => 'subroutine',
               'HIGH' => ''
             }
)

created in mode "array":

(
  'NAME'  => 'UE52ID5R:BaseCmdHome',
  'TYPE'  => 'sub',
  'FIELDS'=> {
               'PRIO' => 'LOW',
               'DESC' => 'subroutine',
               'HIGH' => ''
             },
  'ORDERDFIELDS' => [ 'DESC', 'PRIO', 'HIGH' ]
)

created in mode "extended":

(
  'TYPE'  => 'sub',
  'INFO'  => {
               'Author'   => 'John Doe',
               'Revision' => '1.2',
               'Notes'    => 'not yet tested'
             },
  'FIELDS'=> {
               'PRIO' => 'LOW',
               'DESC' => 'subroutine',
               'HIGH' => ''
             }
)

db hash

A db hash is created when function "parse" is called in mode "standard". It maps record names to references of record hashes. Here is an example:

(
  'UE52ID5R:BaseCmdHome' =>
     { 'TYPE'  => 'sub',
       'FIELDS'=> { 'PRIO' => 'LOW',
                    'DESC' => 'subroutine',
                    'HIGH' => ''
                  }
     }
  'UE52ID5R:BaseStatAStat' =>
     { 'TYPE'  => 'sub',
       'FIELDS'=> { 'PRIO' => 'HIGH',
                    'DESC' => 'subroutine',
                    'HIGH' => '1'
                  }
     }
)

db array

A db array is created when function "parse" is called in mode "array". It is a list of references to record hashes. Here is an example:

[ {
    'NAME'  => 'UE52ID5R:BaseCmdHome',
    'TYPE'  => 'sub',
    'FIELDS'=> {
                 'PRIO' => 'LOW',
                 'DESC' => 'subroutine',
                 'HIGH' => ''
               },
    'ORDERDFIELDS' => [ 'DESC', 'PRIO', 'HIGH' ]
  },
  {
    'NAME'  => 'UE52ID5R:BaseStatAStat',
    'TYPE'  => 'sub',
    'FIELDS'=> {
                 'PRIO' => 'HIGH',
                 'DESC' => 'subroutine',
                 'HIGH' => '1'
               },
    'ORDERDFIELDS' => [ 'DESC', 'PRIO', 'HIGH' ]
  },

alias map

This is a hash that maps alias names of records to real names of records. There is an example:

(
  'HomeRecord' => 'UE52ID5R:BaseCmdHome',
  'StatRecord' => 'UE52ID5R:BaseStatAStat,
)

real record hash

This is a hash that maps real names of records to record hashes. Here is an example:

(
  'UE52ID5R:BaseCmdHome' =>
     { 'TYPE'  => 'sub',
       'FIELDS'=> { 'PRIO' => 'LOW',
                    'DESC' => 'subroutine',
                    'HIGH' => ''
                  }
     }
  'UE52ID5R:BaseStatAStat' =>
     { 'TYPE'  => 'sub',
       'FIELDS'=> { 'PRIO' => 'HIGH',
                    'DESC' => 'subroutine',
                    'HIGH' => '1'
                  }
     }
)

extended db hash

A db hash contains a db hash, an alias map and a real record hash. Note that aliases to record names are resolver in the db hash, meaning that this hash may contain keys that map to the same record hash. The well known Data::Dumper module doesn't handle these cases well (at least in my opinion), here is a quote from the Data::Dumper documentation:

Any references that are the same as one of those passed in will 
be named $VARn (where n is a numeric suffix), and other duplicate 
references to substructures within $VARn will be appropriately 
labeled using arrow notation.

Here is an example (not created by Data::Dumper) for a db hash:

(
  'dbhash' => {
                'UE52ID5R:BaseCmdHome' =>
                   { 'TYPE'  => 'sub',
                     'FIELDS'=> { 'PRIO' => 'LOW',
                                  'DESC' => 'subroutine',
                                  'HIGH' => ''
                                }
                   }
                'HomeRecord' =>
                   { 'TYPE'  => 'sub',
                     'FIELDS'=> { 'PRIO' => 'LOW',
                                  'DESC' => 'subroutine',
                                  'HIGH' => ''
                                }
                   }
                'UE52ID5R:BaseStatAStat' =>
                   { 'TYPE'  => 'sub',
                     'FIELDS'=> { 'PRIO' => 'HIGH',
                                  'DESC' => 'subroutine',
                                  'HIGH' => '1'
                                }
                   }
                'StatRecord' =>
                   { 'TYPE'  => 'sub',
                     'FIELDS'=> { 'PRIO' => 'HIGH',
                                  'DESC' => 'subroutine',
                                  'HIGH' => '1'
                                }
                   }
              },
  'aliasmap' => {
                  'HomeRecord' => 'UE52ID5R:BaseCmdHome',
                  'StatRecord' => 'UE52ID5R:BaseStatAStat,
                },
  'realrecords' =>
              {
                'UE52ID5R:BaseCmdHome' =>
                   { 'TYPE'  => 'sub',
                     'FIELDS'=> { 'PRIO' => 'LOW',
                                  'DESC' => 'subroutine',
                                  'HIGH' => ''
                                }
                   }
                'UE52ID5R:BaseStatAStat' =>
                   { 'TYPE'  => 'sub',
                     'FIELDS'=> { 'PRIO' => 'HIGH',
                                  'DESC' => 'subroutine',
                                  'HIGH' => '1'
                                }
                   }
              },
)

AUTHOR

Goetz Pfeiffer, Goetz.Pfeiffer@helmholtz-berlin.de

SEE ALSO

perl-documentation