Embedded Wizard Studio: Start export and/or import dialog ...

With this dialog you configure and perform an export and/or import operation of project contents. This dialog appears when activating the command Export and/or import tool ...:

The actual export/import operation is carried out by an external tool, which can be a Windows executable, command line tool or just a script written in your preferred language. In any case, when using this feature Embedded Wizard starts the external tool and provides it with all project contents intended for the export. The project contents are encoded as text in Chora syntax. The tool can thereupon process this text and depending on the purpose of the tool, extract interesting project parts, transcode them in other formats, etc.

In the similar manner, the tool can provide Embedded Wizard with project contents intended for the import. Again, the contents are encoded as text in Chora syntax. Embedded Wizard can evaluate the contents and integrate them into the project structure. Depending on the configuration of the import operation, new imported contents can replace existing contents or can be just appended to the project. This allows incremental imports and re-imports (updates of already made imports).

In addition to the export and import operations, the new functionality is also suitable for evaluating project contents with external tools, for example to extract statistical information from the project or to carry out sophisticated search/evaluation processes on the project that go beyond the search functions integrated in Embedded Wizard. In such case it is convenient that the external tool has the possibility to provide Embedded Wizard with information, warning and error messages which thereupon are listed in the Log window.

Use case 1: Export of project contents

The external tool evaluates the project contents provided by Embedded Wizard and transcodes them in the desired format. The results can then be stored in files, etc. depending on the implementation of the external tool. For example:

Export of string constants

Export of bitmap and SVG resources

Export of enumerations in C code

Export of Device Interface properties as ready to use C interfaces to middleware

...

Use case 2: Import of project contents

The external tool reads external contents (e.g. files) and synthesizes from the read information Chora syntax describing project members. The members can thereupon be added to the project. For example:

Import of string constants

Import of bitmap and SVG resources

Import of enumerations from C header files

import of Device Interface properties from C interfaces

Import of Photoshop/Figma/... designs

...

Use case 3: Evaluation of project contents

The external tool evaluates the project contents provided by Embedded Wizard and generates messages which are listed in Embedded Wizard Log window. For example:

Complex searching in exiting project

Statistic and measuring project complexity

...

Use case 4: Adaptation of project contents

In this case export and import are combined. The external tool evaluates the project contents provided by Embedded Wizard, modifies them and returns the modified contents back to Embedded Wizard. For example:

Complex searching/replacing in exiting project

Complex refactoring of project contents

...

Chora syntax

The external tool used for export/import operations will receive and/or send project contents encoded in Chora syntax. A basic understanding of the syntax is therefore unavoidable when you plan to implement an external export/import tools. The section Programming language Chora provides for this purpose detailed specification of project members, the relevant attributes and other Chora language constructs.

TIP

If you have any doubts about how a particular expression or element is formulated in Chora, we recommend to analyze the content of *.ewu files. These contain project contents, stored in Chora syntax.

Specify the external tool

With the export/import functionality, Embedded Wizard provides a general purpose infrastructure to perform export, import or evaluation of project contents. This functionality depends on an external application, a command line tool or a script written in your preferred programming language. To specify the external tool use the edit field in the upper area of the dialog. Usually you will specify here a path to the executable followed by its optional parameters. The following screenshot demonstrates how the PHP script interpreter is specified together with a file containing the PHP script to interpret:

The Browse ... button on the right of the edit field provides an alternative, more comfortable way to select the desired executable directly in a file open dialog:

Configure export operation

To perform an export operation of project contents, you have to enable one of the following check boxes. The first check box exists for your convenience and has the effect of all members in the actual Composer being provided for the export operation. The second box is more selective, when using it, you can determine the exported members individually. For this purpose select the desired members in Composer beforehand. Non selected members are not exported in that case:

IMPORTANT

The export operation limits always to members found in the actually opened Composer window. For example, when Composer shows the content of a unit, then only members existing in the unit are affected by the export operation. To export contents of several units, you would need to repeat the export operation for each affected unit. A general overall project export is not available.

During an export operation Embedded Wizard encodes all affected members in Chora syntax and sends the encoded content to the external tool as UTF-8 text. The external tool can read and parse this text. For example, it can search for text patterns enclosing some interesting project fragments and so extract or transcode these fragments accordingly. What exact the external tool is doing with the text is in fact a detail of the tool's implementation. All information relevant for the exported members is available in Chora syntax. It's thus up to the developer of the external tool to decide what should be done with this information.

The data exchange (the communication) with the external tool occurs through the tool's own STDIN (standard input) stream. In the implementation of your tool you read from STDIN until the end of data. For example a script written in PHP could implement following code to read the entire content provided in the STDIN stream. The content can therefore be evaluated as text in Chora syntax:

<?php $data = file_get_contents( "php://stdin" ); // Now, $data contains all exported members and can be evaluated, parsed, etc. ... ?>

Configure import operation

To perform an import operation of project contents, you have to enable the following check box. As soon as import is enabled, additional check boxes are available where the operation mode can be configured more in detail:

The per default enabled mode is Replace already existing members .... The effect of this mode is that in case of name conflicts between imported and already existing project members, the existing members are replaced by new imported contents. Doing that, the new imported members will assume the stacking order and the brick position of the respective replaced members. Members that don't yet exist in the project are simply appended. This mode is therefore ideal if you are re-importing or updating previously imported content to a newer version.

When the selected mode is Rename imported members ..., the imported members will be renamed automatically in order to resolve name conflicts with already existing members. That means already existing members will remain unchanged and new imported homonymous members will become unique names before they are appended to the project. Eventual relations between the imported members are updated when members are renamed so that the imported content remains consistent on its own in such case.

The third mode Delete all members which ... is available only when the export and import are enabled simultaneously. With this mode the system tracks which members have been exported (sent to the external tool) and which members have been received (imported) from the tool. Members which have been exported but not imported are considered in such case as outdated or dropped out. These members are then removed from the project. This mode is therefore also convenient if you are re-importing or updating previously imported content to a newer version. Previously imported but in the meantime outdated members are then deleted.

During an import operation the external tool encodes all affected members in Chora syntax and sends the encoded content to Embedded Wizard as UTF-8 text. Embedded Wizard can thereupon read and process this text. What exact the external tool is doing with the text is in fact a detail of the tool's implementation. In the simplest case it can format Chora code fragments describing the members to import.

The data exchange (the communication) with the external tool occurs through the tool's own STDOUT (standard output) stream. In the implementation of your tool you write to STDOUT all the contents you want to be imported. For example a script written in PHP could implement following code to write in Chora syntax a constant with three language variants. This content can therefore be evaluated by Embedded Wizard Studio:

<?php echo '$version 14.00' . "\n"; echo '$scope' . "\n"; echo '$output false' . "\n"; echo "const string WelcomeText=\n"; echo "(\n"; echo " Default=\"Welcome\";\n"; echo " German=\"Willkommen\";\n"; echo " Spanish=\"Bienvenidos\";\n"; echo ");\n"; ?>

Collect error and status messages

By activating the following checkbox, the export/import functionality is configured to listen for messages received from the external tool. Such messages appear thereupon in the Log window similar to all other messages, warnings or errors reported during the workflow with Embedded Wizard Studio:

To receive the messages, Embedded Wizard Studio communicates with the tool through the tool's own STDERR (standard error) stream. In the implementation of your tool you write to STDERR all the messages you want to be reported in Embedded Wizard as UTF-8 encoded text. The messages have to be separated by \n (new line) sign. For example a script written in PHP could implement following code to report a status messages about the number of processed members:

<?php $no_of_members = 123; fwrite( STDERR, "Totally {$no_of_members} members processed.\n" ); ?>

The message appears thereupon in the Log window:

Each reported message may optionally start with a message type indicator, literally: [ERROR], [WARNING], [SUCCESS] or [INFORMATION]. This message type indicator determines the type of the message in the Log window. For example, the message with type indicator [ERROR] will appear with a red error icon. If the message type indicator is omitted, the type [INFORMATION] is assumed per default. For example, an implementation in PHP could look like this:

<?php fwrite( STDERR, "[ERROR]Could not open the FIGMA import file.\n" ); ?>

The message type indicator itself can be followed by the location addressing the affected member within the project. The location is again enclosed between a pair of [...] (square brackets) and has following syntax: [path-to-the-member] or [path-to-the-member[line:column]]. path-to-the-member determines the full qualified name of the member. For example, a constant named WelcomeText and existing within the unit Strings is addressed by the path Strings::WelcomeText. In turn, a method OnButtonClick existing within a component Alert, which itself exists within the unit Components is addressed by the path Components::Alert.OnButtonClick. Double clicking on such message will reveal the corresponding member in Composer window. For example, an implementation in PHP could look like this:

<?php fwrite( STDERR, "[SUCCESS][Application::StringConstant123]The constant could be read.\n" ); ?>

In case of locations addressing a position inside a method or property initialization, the corresponding line and column numbers can be specified in the optional parameter line and column. Double clicking on such message will show the corresponding position in the Code Editor or in the Inspector window. For example, an implementation in PHP could look like this:

<?php fwrite( STDERR, "[WARNING][Application::Alert.OnUpdate[4:2]]Not sure whether it is o.k.\n" ); ?>

Start the export/import tool

To start the configured export/import operation, press the button Start the export/import tool ...:

During the runtime of the external tool appears following dialog window. It permits you to abort the external tool process in case of a problem with the tool, etc.:

Please note, if you plan to start the external tool frequently, the recently configured external tools are recorded in the project and available in a list box which appears after clicking on the small arrow .

Example 1: export string constants

The following example demonstrates a practical use case of an external tool to transcode string contents of exported constant members in simple text format which is suitable for localization by a translator office. This example is written in PHP and uses regular expressions to find Chora code fragments representing constants:

<?php $re_name = '([a-zA-Z][a-zA-Z0-9_]*)'; $re_value = '(["][^"]*["])'; $re_list = '[(]([^\)]*[)])'; $re_const = '/const\s+string\s+' . $re_name . '\s*=\s*(' . $re_value . '|' . $re_list . ')/'; $re_variants = '/' . $re_name . '\s*=\s*' . $re_value . '/'; // Read the text from STDIN $data = file_get_contents( "php://stdin" ); // Extract from the text all constants preg_match_all( $re_const, $data, $constants, PREG_SET_ORDER, 0 ); // Process all constants foreach ( $constants as $const ) { // Single language constant if ( str_starts_with( $const[2], '"' )) file_put_contents( 'lang_Default.txt', "{$const[1]}={$const[2]}\n", FILE_APPEND ); // Multi-lingual constant else { // Process the language specific values of the constant preg_match_all( $re_variants, $const[2], $variants, PREG_SET_ORDER, 0 ); foreach ( $variants as $variant ) file_put_contents( "lang_{$variant[1]}.txt", "{$const[1]}={$variant[2]}\n", FILE_APPEND ); } } ?>

At the runtime this tool creates *.txt files with all processed strings constants. It creates one file for each language variant existing in the project. The content of the created files lists the constants by their names followed by the content of the respective constant for the particular language. The usage of this export tool is demonstrated in the following example project:

DOWNLOAD EXAMPLE

Please note, the example presents eventually features available as of version 14.00

Step 1: The external tool existing in this example requires a PHP interpreter of at least 8 version. Ensure such interpreter is installed on your Windows system.

Step 2: Download and open the example project in Embedded Wizard Studio.

Step 3: Ensure, the Composer shows the content of the unit Application.

Step 4: Note, the unit Application in this example contains few constants:

Step 5: By selecting the menu item PROJECTExport and or import tool... open the dialog to configure and start the external tool.

Step 6: Adapt the Tool command line to refer your installed PHP interpreter:

Step 7: Press the button Start the export/import tool ... to start the operation.

Once the tool is finished you will find following three files in the project folder. These files contain the exported string constants mentioned in step 4 and divided according to their language variants. The files could now be sent to a translation office, etc. for further processing:

Example 2: import string constants

The following example demonstrates a practical use case of an external tool to process text files and syntheses from the information found inside them constant members containing strings. In practice, such text files can be provided by external translation offices, etc.. This example is written in PHP and uses regular expressions to process the text file contents:

<?php $re_name = '([a-zA-Z][a-zA-Z0-9_]*)'; $re_value = '(["][^"]*["])'; $re_const = '/'. $re_name . '\s*=\s*' . $re_value . '/'; $lang_files = glob( 'lang_*.txt' ); $results = []; // Read the strings from different language specific files foreach ( $lang_files as $lang_file ) { $lang_name = substr( $lang_file, 5, -4 ); $data = file_get_contents( $lang_file ); // Extract from the text all constants preg_match_all( $re_const, $data, $constants, PREG_SET_ORDER, 0 ); // Process all constants foreach ( $constants as $const ) { if ( !array_key_exists( $const[1], $results )) $results[$const[1]] = []; $results[$const[1]][$lang_name]=$const[2]; } } // The list of resulting constants $const_names = array_keys( $results ); // Start Chora Synthese echo '$version 14.00' . "\n"; echo '$scope' . "\n"; // Process all constants foreach ( $const_names as $const_name ) { $const_values = $results[$const_name]; $const_langs = array_keys( $const_values ); // Start of a constant echo '$output false' . "\n"; echo "const string {$const_name}=\n(\n"; // Append language specific values of the constants foreach ( $const_langs as $const_lang ) echo " {$const_lang}={$const_values[$const_lang]};\n"; // End of a constant echo ");\n"; } ?>

At the runtime this tool reads *.txt files existing in the actual project directory. The tool assumes that each *.txt file contains a list of constant names followed by the content of the respective constant. The name of a file determines the corresponding language variant. For example:

The usage of this import tool is demonstrated in the following example project:

DOWNLOAD EXAMPLE

Please note, the example presents eventually features available as of version 14.00

Step 1: The external tool existing in this example requires a PHP interpreter of at least 8 version. Ensure such interpreter is installed on your Windows system.

Step 2: Download and open the example project in Embedded Wizard Studio.

Step 3: Ensure, the Composer shows the content of the unit Application.

Step 4: Note, before you start the export/import tool the unit Application in this example contains few constants. These are still empty:

Step 5: By selecting the menu item PROJECTExport and or import tool... open the dialog to configure and start the external tool.

Step 6: Adapt the Tool command line to refer your installed PHP interpreter:

Step 7: Press the button Start the export/import tool ... to start the operation.

Once the tool is finished the constants inside the unit Application have been updated. The constants contain now strings found originally in the above mentioned *.txt files: