Advanced Resource Embedder 1.1.0

By Stephane Carrez

Release 1.1.0 of the Advanced Resource Embedder is available with new formats to represent files in the generated Ada and C sources.

The resource embedder allows to embed files in binaries by producing C, Ada or Go source files that contain the original files. The first version of the tool was representing the file content as an array of bytes. In Ada, they are accessed through an Ada.Streams.Stream_Element_Array which is not easy to use when you need the content as a string.

The new release introduces the customization of the format for each resource. The format is controlled through the XML description by the format attribute. The following data formats are supported:

  • binary format provides the file content as a binary data,
  • string format provides the file content as string,
  • lines format splits the content in several lines and according to a set of customizable rules.

With the string format, the Ada code generator can generate the following function:

  function Get_Content (Name : in String)
    return access constant String;

The lines format tells the code generator to represent the content as an array of separate lines. For this integration, some control is available to indicate how the content must be split and optionally apply some filter on the input content. These controls are made within the XML description by using the line-separator and line-filter description: The line-separator indicates the characters that represent a line separation. There can be several line-separator definition. The line-filter defines a regular expression that when matched must be replaced by an empty string or a specified content. The line-filter are applied in the order of the XML definition.

The example below is intended to integrate an SQL scripts with:

  • a separate line for each SQL statement,
  • remove spurious empty lines and SQL comments.

The SQL statements are separated by ; (semi-colon) and the line-separator indicates to split lines on that character. By splitting on the ; we allow to have an SQL statement on multiple lines in the original SQL source file.

<package>
  <resource name='Scripts'
            format='lines'
            type='access constant String'>
    <line-separator>;</line-separator>

    <!-- Remove new lines -->
    <line-filter>[\r\n]</line-filter>

    <!-- Remove C comments -->
    <line-filter>/\*[^/]*\*/</line-filter>

    <!-- Remove contiguous spaces after C comments removal -->
    <line-filter replace=' '>[ \t][ \t]+</line-filter>

    <install mode='copy' strip-extension='yes'>
      <fileset dir="sql">
        <include name="**/*.sql"/>
      </fileset>
    </install>
  </resource>
</package>

Then the first line-filter will remove the \r and \n characters.

The regular expression /\\\*\[./]\*\\\*/ matches a C style comment and remove it.

The last line-filter replaces multiple tabs and spaces by a single occurrence.

Below is an example of generated code with the above resource description. Each file is accessed through a separate variable whose name is built from the base name of the original file.

Resource Embedder Overview

The command used to generate this code was:

are --lang=Ada -o src --var-access --content-only --rule=package.xml .

and the sql directory contains only two files: create-database.sql and drop-database.sql.

The complete example is available for two languages:

To install the tool, follow the instructions given in the initial announcement: Advanced Resource Embedder for Ada, C and Go.

If you want to know more about the tool, have a look at its documentation:

and if you have ideas for improvements, fork the project and submit a pull request!

Add a comment

To add a comment, you must be connected. Login