10.1. Low level C API #

10.1.1. Numeric behavior related functions
10.1.2. Locale related functions
10.1.3. Data source and query related functions
10.1.4. Expression related functions
10.1.5. Column data or expression result related functions
10.1.6. Variable related functions
10.1.7. Break related functions
10.1.8. Function related functions
10.1.9. Report part and report related functions
10.1.10. Layout related functions
10.1.11. Callback related functions
10.1.12. Environment related functions
10.1.13. File handling related functions
10.1.14. Color related functions
10.1.15. Paper size related functions
10.1.16. Memory handling related functions
10.1.17. List related functions
10.1.18. String related functions

The low level API extends the High level C API to either fine-tune the report behaviour, or to create a report purely from program code.

10.1.1. Numeric behavior related functions #

10.1.1.1. Set numeric precision #

The default is 256 bits of floating point precision. The expression string must evaluate to a numeric value, the integer part will be used to set the number of precision bits for numeric calculations.

void
ocrpt_set_numeric_precision_bits(opencreport *o,
                                 const char *expr_string);

10.1.1.2. Get numeric precision #

The report XML description may set the numeric precision. This function allows the application to query it.

mpfr_prec_t
ocrpt_get_numeric_precision_bits(opencreport *o);

10.1.1.3. Set rounding mode #

The expression string must evaluate to a string value. Possible values are: nearest, to_minus_inf, to_inf, to_zero, away_from_zero and faithful. The default is nearest.

void
ocrpt_set_rounding_mode(opencreport *o,
                        const char *expr_string);

10.1.2. Locale related functions #

10.1.2.1. Set up translation #

Setting up the translation needs two parameters: the so called translation domain and the toplevel directory for the translations. It relies on GNU Gettext.

void
ocrpt_bindtextdomain(opencreport *o,
                     const char *domainname,
                     const char *dirname);

10.1.2.2. Set up translation (delayed variant) #

Setting up the translation needs two parameters: the so called translation domain and the toplevel directory for the translations. It relies on GNU Gettext. This function allows setting the translation from a supplemental query. The passed in expressions strings must evaluate to string values, with potential fallbacks to plain strings in case of parse errors or if the expressions may be interpreted as query columns but no such column names exist in any query.

void
ocrpt_bindtextdomain_from_expr(opencreport *o,
                               const char *domain_expr,
                               const char *dir_expr);

10.1.2.3. Set report locale #

Setting the locale for the report does not affect the main program or other threads. A locale setting includes the language and the country. The UTF-8 suffix is necessary. E.g.: en_GB.UTF-8 or de_DE.UTF-8

void
ocrpt_set_locale(opencreport *o,
                 const char *locale);

10.1.2.4. Set report locale (delayed variant) #

This function allows setting the locale from a supplementary query of the report. It is used by the report XML parser code and it's a lower priority setting than the previous function: the application executing the report may need to be run a different locale. The expression string must evaluate to a string value that's a valid locale string.

void
ocrpt_set_locale_from_expr(opencreport *o,
                           const char *expr_string);

10.1.2.5. Print monetary data in the report locale #

A customized monetary printing function was implemented for the purposes of the report which MPFR doesn't provide. It is used in OpenCReports both internally and by unit tests.

ssize_t
ocrpt_mpfr_strfmon(opencreport *o,
                   char *s, size_t maxsize,
                   const char *format, ...);

10.1.3. Data source and query related functions #

The following enum and struct types are used by OpenCReports for datasources and queries.

enum ocrpt_result_type {
    OCRPT_RESULT_ERROR,
    OCRPT_RESULT_STRING,
    OCRPT_RESULT_NUMBER,
    OCRPT_RESULT_DATETIME
};

struct ocrpt_datasource;
typedef struct ocrpt_datasource ocrpt_datasource;

struct ocrpt_query;
typedef struct ocrpt_query ocrpt_query;

struct ocrpt_query_result;
typedef struct ocrpt_query_result ocrpt_query_result;

For more details, see Data sources and queries. Multiple queries may use the same data source.

10.1.3.1. Add a datasource #

Add a datasource of the specific type to the report handler with the associated source_name, using optional connection parameters.

ocrpt_datasource *
ocrpt_datasource_add(opencreport *o,
                     const char *source_name,
                     const char *type,
                     const ocrpt_input_connect_parameter *conn_params);

The pointer to connection parameters can be NULL for array, csv, json, and xml datasource types.

10.1.3.1.1. MariaDB connection parameters #

There are two methods to connect to a MariaDB (or MySQL) database.

The first method uses a MariaDB (MySQL) specific configuration ini file and the group name in it. The group parameter is mandatory as the main database configuration may also have such a group section, in which case the separate optionfile is not needed.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "group", .param_value = "..." },
    { .param_name = "optionfile", .param_value = "..." },
    { .param_name = NULL }
};

The second method spells out individual connection parameters. This allows local and remote database connections. The dbname parameter is mandatory, others are optional.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "dbname", .param_value = "..." },
    { .param_name = "host", .param_value = "..." },
    { .param_name = "port", .param_value = "..." },
    { .param_name = "unix_socket", .param_value = "..." },
    { .param_name = "user", .param_value = "..." },
    { .param_name = "password", .param_value = "..." },
    { .param_name = NULL }
};

These connection parameters can be used as XML node attributes, see MariaDB database connection.

10.1.3.1.2. PostgreSQL connection parameters #

There are three methods to connect to a PostgreSQL database.

The first method uses the PostgreSQL specific connection string. It is the only setting and as such, it's mandatory. Its content is almost freeform, with optional elements. See PostgreSQL connection string.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "connstr", .param_value = "..." },
    { .param_name = NULL }
};

The second method spells out individual connection parameters. This allows local database connections on a named socket. The unix_socket and dbname parameters are mandatory, others are optional.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "unix_socket", .param_value = "..." },
    { .param_name = "dbname", .param_value = "..." },
    { .param_name = "user", .param_value = "..." },
    { .param_name = "password", .param_value = "..." },
    { .param_name = NULL }
};

The third method also spells out individual connection parameters. This allows remote database connection using the host and port parameters. Only the dbname parameter is mandatory, others are optional.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "dbname", .param_value = "..." },
    { .param_name = "host", .param_value = "..." },
    { .param_name = "port", .param_value = "..." },
    { .param_name = "user", .param_value = "..." },
    { .param_name = "password", .param_value = "..." },
    { .param_name = NULL }
};

There are also two optional parameters that control the behaviour of the PostgreSQL driver in OpenCReports, rather than being actual connection parameters to a PostgreSQL server. These parameters may be used with any of the above connection methods.

  • The parameter usecursor may have a boolean value: true, false, yes, no, or a numeric value interpreted as a boolean value: non-zero values mean true, zero means false.

    When usecursor is enabled, the SQL query will be wrapped in a cursor, and the result is retrieved in parts. Otherwise, the SQL query is executed as is and the result is retrieved in whole.

    The default value is usually true but this can be controlled when OpenCReports is built.

  • When usecursor is enabled, the parameter fetchsize controls the number of rows retrieved at once. Default value is 1024.

Using a cursor as a regular SQL query is a PostgreSQL extension. Other SQL databases only allow it in stored procedures. But this allows a trade-off: queries that return a large number of rows may be processed without the risk of running out of memory, with marginally lower performance.

SQL queries added to the same PostgreSQL datasource (connection) will behave the same way. Either all of them are executed as is, or all of them will use a cursor.

These connection parameters can be used as XML node attributes, see PostgreSQL database connection.

10.1.3.1.3. ODBC connection parameters #

There are two methods to connect to an ODBC database.

The first method uses the ODBC specific connection string. It is the only setting, and as such, it's mandatory. Its content is defined by the ODBC knowledge base with optional elements. See Microsoft Open Database Connectivity and Connection string examples .

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "connstr", .param_value = "..." },
    { .param_name = NULL }
};

The second method spells out some individual connection parameters. It requires that an ODBC data source (DSN) is already configured. Whether the database connections is local or remote depends on the pre-configured DSN. The dbname parameters is mandatory, others are optional.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "dbname", .param_value = "..." },
    { .param_name = "user", .param_value = "..." },
    { .param_name = "password", .param_value = "..." },
    { .param_name = NULL }
};

These connection parameters can be used as XML node attributes, see ODBC database connection.

10.1.3.1.4. Spreadsheet connection parameters #

There is only one connection parameter for spreadsheet based datasources, the file name.

ocrpt_input_connect_parameter conn_params[] = {
    { .param_name = "filename", .param_value = "..." },
    { .param_name = NULL }
};

This parameter can be used as an XML node attribute, see Spreadsheet file type.

10.1.3.2. Find a datasource #

Find the data source using its name. It returns NULL if the named data source is not found.

ocrpt_datasource *
ocrpt_datasource_get(opencreport *o,
                     const char *source_name);

10.1.3.3. Set the encoding of a datasource #

Set the encoding of a datasource in case if it's not already UTF-8, so data provided by it is automatically converted.

void
ocrpt_datasource_set_encoding(ocrpt_datasource *source,
                              const char *encoding);

10.1.3.4. Free a datasource #

Free a datasource from the opencreport structure it was added to. It's not needed to be called, all datasources are automatically free with ocrpt_free()

void
ocrpt_datasource_free(ocrpt_datasource *source);

10.1.3.5. Add a direct data based query #

Add a direct (application internal) data based query to the report handler.

ocrpt_query *
ocrpt_query_add_data(ocrpt_datasource *source,
                     const char *name,
                     const void *data,
                     int32_t rows, int32_t cols,
                     const int32_t *types,
                     int32_t types_cols);

The built-in array datasource interprets void *data as a two-dimensional array containing pointers to C strings, a.k.a.

char *array[rows + 1][cols]

The first row of the array are the column (field) names. The types array contains cols (or fewer) number of enum ocrpt_result_type elements to indicate the column data types.

If the types pointer is NULL, the column values are treated as string data. This is how RLIB worked.

The call is only successful if the datasource is direct data based. See Section 10.1.3.9 and Datasource input driver details.

10.1.3.6. Add a symbolic data based query #

Add a "symbolic" (discoverable by name) data based query.

ocrpt_query *
ocrpt_query_add_symbolic_data(ocrpt_datasource *source,
                              const char *name,
                              const char *data_name,
                              int32_t rows, int32_t cols,
                              const char *types_name,
                              int32_t types_cols);

Symbols of the application can be discovered via dlsym() if the application was built with the compiler option -rdynamic.

The call is only successful if the datasource is symbolic data based. See Section 10.1.3.10 and Datasource input driver details.

10.1.3.7. Add a file based query #

Add a file based query to the report handler.

ocrpt_query *
ocrpt_query_add_file(ocrpt_datasource *source,
                     const char *name,
                     const char *filename,
                     const int32_t *types,
                     int32_t types_cols);

The call is only successful if the datasource is file based. See Section 10.1.3.11 and Datasource input driver details.

The types array pointer may be NULL. For file based datasource types that don't support data type specifiers internally (or they are optional and omitted), this means that the column values are of the string data type. This is how RLIB worked. In this case, conversion functions like Section 4.12.4, Section 4.10.16 and Section 4.10.10 are needed to process the values using their actual data type.

When the types array pointer is not NULL, it is used to set the data type specifiers for built-in file based datasources, even if the file contains type specifiers.

The JSON file format expected by OpenCReports is defined in JSON file type.

The XML file format expected by OpenCReports is defined in XML file type.

10.1.3.8. Add an SQL statement based query #

Add an SQL statement based query to the report handler.

ocrpt_query *
ocrpt_query_add_sql(ocrpt_datasource *source,
                    const char *name,
                    const char *querystr);

The call is only successful if the datasource is SQL based. See Section 10.1.3.12 and Datasource input driver details.

10.1.3.9. Test whether a datasource is direct data based #

bool
ocrpt_datasource_is_data(ocrpt_datasource *source);

10.1.3.10. Test whether a datasource is direct data based #

bool
ocrpt_datasource_is_symbolic_data(ocrpt_datasource *source);

10.1.3.11. Test whether a datasource is file based #

bool
ocrpt_datasource_is_file(ocrpt_datasource *source);

10.1.3.12. Test whether a datasource is SQL based #

bool
ocrpt_datasource_is_sql(ocrpt_datasource *source);

10.1.3.13. Find a query #

Find a query using its name.

ocrpt_query *
ocrpt_query_get(opencreport *o,
                const char *name);

10.1.3.14. Get the current data row from a query #

Create (first call) or get the ocrpt_query_result array from a query. Output parameter cols returns the number of columns in the result array. It must be re-run after ocrpt_navigate_next() since the previously returned pointer becomes invalid.

ocrpt_query_result *
ocrpt_query_get_result(ocrpt_query *q,
                       int32_t *cols);

10.1.3.15. Get column name #

Using the ocrpt_query_result * result from ocrpt_query_get_result(), the column names can be discovered from a query.

const char *
ocrpt_query_result_column_name(ocrpt_query_result *qr,
                               int32_t col);

10.1.3.16. Get column data #

Using the ocrpt_query_result * result from ocrpt_query_get_result(), get a pointer to the column data in its internal (hidden) representation.

ocrpt_result *
ocrpt_query_result_column_result(ocrpt_query_result *qr,
                                 int32_t col);

10.1.3.17. Add a follower query #

Add a follower query to the leader query. The leader is the primary query and the follower will run in parallel with it until the leader runs out of rows. In case the leader has more rows than the follower, then for rows in the leader where there are no follower rows, the follower fields are set to NULL.

bool
ocrpt_query_add_follower(ocrpt_query *leader,
                         ocrpt_query *follower);

10.1.3.18. Add an N:1 follower query #

Add an N:1 follower query to the leader query. The leader is the primary query and rows from the follower will be matched using the match expression. If there are multiple rows in the follower matching the leader row, then the leader row will be listed that many times. For rows in the leader where there are no matching rows in the follower, the follower fields are set to NULL. It is similar to LEFT OUTER JOIN in SQL databases. For creating an ocrpt_expr expression pointer, see the next section.

bool
ocrpt_query_add_follower_n_to_1(ocrpt_query *leader,
                                ocrpt_query *follower,
                                ocrpt_expr *match);

10.1.3.19. Refresh query contents #

Call the ocrpt_input::refresh() method for datasources that support it. It returns true if all queries were successfully refreshed.

bool
ocrpt_query_refresh(opencreport *o);

10.1.3.20. Free a query #

Free a query and remove it from the report handler. It's optional. ocrpt_free() frees the queries added to the opencreport structure.

void
ocrpt_query_free(ocrpt_query *q);

10.1.3.21. Start the main query #

Start query (or query set) navigation. q should be the primary query of the report.

void
ocrpt_query_navigate_start(ocrpt_query *q);

10.1.3.22. Navigate to the next query row #

Navigate the query (or query set) to the next row. Returns false if there was no more rows. in which case the ocrpt_query_result arrays for all queries in the query set (returned by previous ocrpt_query_get_result() calls contain invalid data.

bool
ocrpt_query_navigate_next(ocrpt_query *q);

10.1.3.23. Navigate use previous/next row #

These functions expose an implementation detail of the data traversal in OpenCReports. There is a 3-row data cache in which there is always the current row. One past row is kept so e.g. break boundaries can be detected and there is one row read-ahead to detect the end-of-data condition early. These functions allow to switch back and forth in the 3-row data cache, making the previous or next row the "current" one momentarily. The query must always be the primary query of the report. Used by unit tests that don't use ocrpt_execute().

void
ocrpt_query_navigate_use_prev_row(ocrpt_query *q);

void
ocrpt_query_navigate_use_next_row(ocrpt_query *q);

10.1.3.24. API specific data discovery function #

For direct (application internal) data based data sources and queries, OpenCReports needs a way to to find the data pointer and the supplementary type identifier array. These are language specific. The below ones are the C specific ones. An override function is also provided to set a new discovery function. The discovery function should return the dimensions for both the (usuall 2D array) data and the 1D types array. It also returns whether types must be freed by the caller.

typedef void
(*ocrpt_query_discover_func)(const char *,
                             void **,
                             int32_t *,
                             int32_t *,
                             const char *,
                             void **,
                             int32_t *,
                             bool *);

void
ocrpt_query_set_discover_func(ocrpt_query_discover_func func);

extern ocrpt_query_discover_func ocrpt_query_discover_array;

void
ocrpt_query_discover_array_c(const char *arrayname,
                             void **array,
                             int32_t *rows,
                             int32_t *cols,
                             const char *typesname,
                             void **types,
                             int32_t *types_cols,
                             bool *free_types);

Note that the C specific generic discovery function does not and cannot return the array dimensions, since there is no official API related to dlsym() that would return the size associated with a symbol. It's up to the application writers to come up with a smarter (application specific) discovery function that also returns the array dimensions. With such a smart discovery function, one can specify the array and the column types array name without the related dimensions, i.e. the rows and cols specifiers in Array queries and File based queries.

10.1.4. Expression related functions #

Expressions in OpenCReports is explained in the Expressions chapter.

10.1.4.1. Parse an expression string #

This function parses an expression string and creates an expression tree. It returns a pointer to the ocrpt_expr structure.

If an error occurs, it returns NULL and optionally returns the error message in err pointer if it's not NULL.

ocrpt_expr *
ocrpt_expr_parse(opencreport *o,
                 const char *expr_string,
                 char **err);

The returned pointer must be freed with ocrpt_expr_free().

10.1.4.2. Parse an expression string and bind it to a report #

This function parses an expression string, creates an expression tree and binds it to a report. It returns a pointer to the ocrpt_expr structure.

If an error occurs, it returns NULL and optionally returns the error message in err pointer if it's not NULL.

ocrpt_expr *
ocrpt_report_expr_parse(ocrpt_report *r,
                        const char *expr_string,
                        char **err);

The returned pointer is automatically freed by ocrpt_free()

10.1.4.3. Free an expression parse tree #

Free an expression parse tree. If it was bound to the passed-in ocrpt_report, this association is also deleted. Alternatively, the expression doesn't need to be freed if it was bound to a report when it was parsed, as it will be automatically freed when freeing either the report, or the global opencreport structure.

void
ocrpt_expr_free(ocrpt_expr *e);

10.1.4.4. Get the original expression string #

Get the original expression string from an expression parse tree.

const char *
ocrpt_expr_get_expr_string(ocrpt_expr *e);

10.1.4.5. Resolve expression references #

This function resolves variable (identifier) references in the expression. This is needed to bind query columns to expressions that use them.

void
ocrpt_expr_resolve(ocrpt_expr *e);

10.1.4.6. Optimize an expression #

This function optimizes an expression so it may needs fewer computation steps during report execution.

void
ocrpt_expr_optimize(ocrpt_expr *e);

10.1.4.7. Evaluate an expression #

This function evaluates the expression. It returns the expression's ocrpt_result result structure. The result must not be freed with ocrpt_result_free(). It will be done by ocrpt_expr_free()

For expressions with query column references, this function must be called after ocrpt_query_navigate_next otherwise the result is not valid.

ocrpt_result *
ocrpt_expr_eval(ocrpt_expr *e);

10.1.4.8. Get expression result without evaluation #

This function returns the expression result if it was already evaluated. The result must not be freed with ocrpt_result_free(). It will be done by ocrpt_expr_free(). Used by unit tests.

ocrpt_result *
ocrpt_expr_get_result(ocrpt_expr *e);

10.1.4.9. Print an expression tree #

Print an expression tree in its processed form on the standard output. Used by unit tests.

void
ocrpt_expr_print(ocrpt_expr *e);

10.1.4.10. Print an expression tree with subexpressions and their results #

Print an expression tree with subexpressions and their results in its processed form on the standard output. Used by unit tests.

void
ocrpt_expr_result_deep_print(ocrpt_expr *e);

10.1.4.11. Count the number of expression nodes #

This function returns the number of expression nodes. Used by unit tests to validate optimizazion.

int32_t
ocrpt_expr_nodes(ocrpt_expr *e);

10.1.4.12. Initialize expression result type #

OpenCReports keeps track of the last three query rows and computes three result values for expressions for internal reasons. These functions initialize the type for either the current result or all results of the expression.

enum ocrpt_result_type {
    OCRPT_RESULT_ERROR,
    OCRPT_RESULT_STRING,
    OCRPT_RESULT_NUMBER,
    OCRPT_RESULT_DATETIME
};

bool ocrpt_expr_init_result(ocrpt_expr *e,
                            enum ocrpt_result_type type);

void ocrpt_expr_init_results(ocrpt_expr *e,
                             enum ocrpt_result_type type);

10.1.4.13. Set an error string as expression result #

ocrpt_result *
ocrpt_expr_make_error_result(ocrpt_expr *e,
                             const char *format, ...);

10.1.4.14. Set start value flag for an iterative expression #

Set whether the iterative expression's first value is computed from its base expression or from its result expression.

void
ocrpt_expr_set_iterative_start_value(ocrpt_expr *e,
                                     bool start_with_init);

10.1.4.15. Get current value of an expression in base type #

Get the current value of an expression in a C base type. Used by parsing report description XML files and unit tests.

const char *
ocrpt_expr_get_string(ocrpt_expr *e);

long
ocrpt_expr_get_long(ocrpt_expr *e);

double
ocrpt_expr_get_double(ocrpt_expr *e);

10.1.4.16. Set current value of an expression in a base type #

Used by unit tests.

void
ocrpt_expr_set_string(ocrpt_expr *e,
                            const char *s);

void
ocrpt_expr_set_long(ocrpt_expr *e,
                          long l);

void
ocrpt_expr_set_double(ocrpt_expr *e,
                            double d);

10.1.4.17. Set nth value of an expression in a base type #

Expressions use OCRPT_EXPR_RESULTS number of values. With these functions, any of them can be set. Used by unit tests.

void
ocrpt_expr_set_nth_result_string(ocrpt_expr *e,
                                       int which,
                                       const char *s);

void
ocrpt_expr_set_nth_result_long(ocrpt_expr *e,
                                     int which,
                                     long l);

void
ocrpt_expr_set_nth_result_double(ocrpt_expr *e,
                                       int which,
                                       double d);

10.1.4.18. Compare the current of an expression with its previous value #

Compare the current value of an expression with its previous value and return true if they are equal. It's used to implement Report breaks.

bool
ocrpt_expr_cmp_results(ocrpt_expr *e);

10.1.4.19. Set delayed flag of an expression #

void
ocrpt_expr_set_delayed(ocrpt_expr *e,
                       bool delayed);

10.1.4.20. Set field expression reference for an expression #

If e contains r.value, the expression rvalue will be used to resolve this reference.

void
ocrpt_expr_set_field_expr(ocrpt_expr *e,
                          ocrpt_expr *rvalue);

10.1.5. Column data or expression result related functions #

The internal type ocrpt_result holds values either for query columns or expression results.

10.1.5.1. Create an expression result #

The returned pointer must be freed with ocrpt_result_free().

ocrpt_result *
ocrpt_result_new(opencreport *o);

10.1.5.2. Get expression result type #

enum ocrpt_result_type
ocrpt_result_get_type(ocrpt_result *result);

10.1.5.3. Copy an expression result #

Copy expression result from source to destination. Both results must have been created for the same opencreport structure, either explicitly with ocrpt_result_new() or implicitly with an expression parsed for this opencreport structure or a report structure owned by it.

void
ocrpt_result_copy(ocrpt_result *dst,
                  ocrpt_result *src);

10.1.5.4. Print an expression result #

Used by unit tests.

void
ocrpt_result_print(ocrpt_result *r);

10.1.5.5. Free an expression result #

void
ocrpt_result_free(ocrpt_result *r);

10.1.5.6. Detect whether a column result is NULL #

Using the ocrpt_result * result from a query column or an expression, detect whether the column value is NULL.

bool
ocrpt_result_isnull(ocrpt_result *result);

10.1.5.7. Detect whether a column result is numeric #

Using the ocrpt_result * result from a query column or an expression, detect whether the column value is numeric.

bool
ocrpt_result_isnumber(ocrpt_result *result);

10.1.5.8. Get the numeric value of a column result #

Using the ocrpt_result * result from a query column or an expression, get the numeric column value. It returns NULL if the column is:

  • not a numeric result

  • NULL

mpfr_ptr
ocrpt_result_get_number(ocrpt_result *result);

10.1.5.9. Detect whether a column result is string #

Using the ocrpt_result * result from a query column or an expression, detect whether the column value is string.

bool
ocrpt_result_isstring(ocrpt_result *result);

10.1.5.10. Get the string value of a column result #

Using the ocrpt_result * result from a query column or an expression, get the string column value. It returns NULL if the column is

  • not a string result

  • NULL

ocrpt_string *
ocrpt_result_get_string(ocrpt_result *result);

10.1.5.11. Detect whether a column result is datetime #

Using the ocrpt_result * result from a query column or an expression, detect whether the column value is datetime.

bool
ocrpt_result_isdatetime(ocrpt_result *result);

10.1.5.12. Get the datetime value of a column result #

Using the ocrpt_result * result from a query column or an expression, get the datetime column value. It returns NULL if the column is

  • not a datetime result

  • NULL

const struct tm *
ocrpt_result_get_datetime(ocrpt_result *result);

10.1.5.13. Detect whether a datetime column result is interval #

Using the ocrpt_result * result from a query column or an expression, detect whether the datetime column value is interval.

bool
ocrpt_result_datetime_is_interval(ocrpt_result *result);

10.1.5.14. Detect whether a datetime column result has valid date #

Using the ocrpt_result * result from a query column or an expression, detect whether the datetime column value has valid date.

bool
ocrpt_result_datetime_is_date_valid(ocrpt_result *result);

10.1.5.15. Detect whether a datetime column result has valid time #

Using the ocrpt_result * result from a query column or an expression, detect whether the datetime column value has valid time.

bool
ocrpt_result_datetime_is_time_valid(ocrpt_result *result);

10.1.6. Variable related functions #

Variables can be created for a report using the API.

10.1.6.1. Create a basic variable #

Using this function, any variable type except OCRPT_VARIABLE_CUSTOM may be created. For a custom variable, see the next function.

enum ocrpt_var_type {
    OCRPT_VARIABLE_INVALID,
    OCRPT_VARIABLE_EXPRESSION,
    OCRPT_VARIABLE_COUNT,
    OCRPT_VARIABLE_COUNTALL,
    OCRPT_VARIABLE_SUM,
    OCRPT_VARIABLE_AVERAGE,
    OCRPT_VARIABLE_AVERAGEALL,
    OCRPT_VARIABLE_LOWEST,
    OCRPT_VARIABLE_HIGHEST,
    OCRPT_VARIABLE_CUSTOM
};
typedef enum ocrpt_var_type ocrpt_var_type;

ocrpt_var *
ocrpt_variable_new(ocrpt_report *r,
                   ocrpt_var_type type,
                   const char *name,
                   const char *expr,
                   const char *ignoreexpr,
                   const char *reset_on_break_name,
                   bool precalculate);

10.1.6.2. Create a custom variable #

Create a custom variable of the specified type with the specified subexpressions.

ocrpt_var *
ocrpt_variable_new_full(ocrpt_report *r,
                        enum ocrpt_result_type type,
                        const char *name,
                        const char *baseexpr,
                        const char *ignoreexpr,
                        const char *intermedexpr,
                        const char *intermed2expr,
                        const char *resultexpr,
                        const char *reset_on_break_name,
                        bool precalculate);

10.1.6.3. Get the variable type #

Get the type of the variable.

ocrpt_var_type
ocrpt_variable_get_type(ocrpt_var *v);

10.1.6.4. Get subexpressions of a variable #

Get subexpressions of a previously created basic or custom variable.

ocrpt_expr *
ocrpt_variable_baseexpr(ocrpt_var *v);

ocrpt_expr *
ocrpt_variable_ignoreexpr(ocrpt_var *v);

ocrpt_expr *
ocrpt_variable_intermedexpr(ocrpt_var *v);

ocrpt_expr *
ocrpt_variable_intermed2expr(ocrpt_var *v);

ocrpt_expr *
ocrpt_variable_resultexpr(ocrpt_var *v);

10.1.6.5. Get precalculate flag for a variable #

bool
ocrpt_variable_get_precalculate(ocrpt_var *var);

10.1.6.6. Resolve a variable #

Resolve subexpressions of a variable so it can be evaluated correctly.

void
ocrpt_variable_resolve(ocrpt_var *v);

10.1.6.7. Evaluate a variable #

After evaluation, the result is in the expression returned by ocrpt_variable_resultexpr().

void
ocrpt_variable_evaluate(ocrpt_var *v);

10.1.6.8. Iterate over variables of a report #

Iterate over variables of a report. The first call needs the iterator list pointer to be set to NULL.

ocrpt_var *
ocrpt_variable_get_next(ocrpt_report *r,
                     ocrpt_list **list);

10.1.7. Break related functions #

10.1.7.1. Create a break #

Create a break. No need to free it, ocrpt_free() does it.

ocrpt_break *
ocrpt_break_new(ocrpt_report *r,
                const char *name);

10.1.7.2. Set attribute flag expressions for a break #

Set break attributes from expression strings for headernewpage and suppressblank. There is a 3rd flag accepted in the report XML DTD called newpage which is not represented (ignored) in the API, because it's also ignored in RLIB and is only handled for RLIB compatibility.

void
ocrpt_break_set_headernewpage(ocrpt_break *br,
                              const char *headernewpage);

void
ocrpt_break_set_suppressblank(ocrpt_break *br,
                              const char *suppressblank);

headernewpage="yes" instructs the layout to render <BreakHeader> on a new page.

suppressblank="yes" instructs the layout to suppress <BreakHeader> if any of the <BreakField>s are NULL value or an empty string, if the break field is of the string type.

10.1.7.3. Get break using its name #

Get the pointer to the break using its name.

ocrpt_break *
ocrpt_break_get(ocrpt_report *r,
                const char *name);

10.1.7.4. Get the name of a break #

Get the name of the break using its structure pointer.

const char *
ocrpt_break_get_name(ocrpt_break *br);

10.1.7.5. Add a watched expression to a break #

bool
ocrpt_break_add_breakfield(ocrpt_break *br,
                           ocrpt_expr *bf);

10.1.7.6. Iterate over breaks of a report #

Iterate over breaks of a report. The first call needs the iterator list pointer to be set to NULL.

ocrpt_break *
ocrpt_break_get_next(ocrpt_report *r,
                     ocrpt_list **list);

10.1.7.7. Resolve and optimize break fields #

void
ocrpt_break_resolve_fields(ocrpt_break *br);

10.1.7.8. Check whether the break triggers #

bool
ocrpt_break_check_fields(ocrpt_break *br);

10.1.7.9. Check whether break field values are blank #

The second parameter evaluate allows skipping evaluating the breakfield values. (This is an optimization in case it's executed after ocrpt_break_check_fields() which already evaluated the breakfields.)

bool
ocrpt_break_check_blank(ocrpt_break *br,
                        bool evaluate);

10.1.7.10. Reset variables for the break #

void
ocrpt_break_reset_vars(ocrpt_break *br);

10.1.8. Function related functions #

10.1.8.1. Add a user defined function #

Add a user defined function by specifying the name, the function pointer that contains the implementation, the number of operands (0 or greater for fixed number or operands, -1 is varying number of operands) and the function mathematical properties that help optimizing it.

bool
ocrpt_function_add(opencreport *o,
                   const char *fname,
                   ocrpt_function_call func,
                   void *user_data,
                   int32_t n_ops,
                   bool commutative,
                   bool associative,
                   bool left_associative,
                   bool dont_optimize);

Adding a user defined function with a name of a pre-existing function will override it.

OpenCReports functions are called with the parameters as declared below.

#define OCRPT_FUNCTION_PARAMS \
    ocrpt_expr *e, void *user_data

OpenCReports functions may be declared with these convenience symbols below.

#define OCRPT_FUNCTION(name) \
    void name(OCRPT_FUNCTION_PARAMS)

#define OCRPT_STATIC_FUNCTION(name) \
    static void name(OCRPT_FUNCTION_PARAMS)

The above function (ocrpt_function_add()) is called with a function pointer which has this type:

typedef void
(*ocrpt_function_call)(OCRPT_FUNCTION_PARAMS);

10.1.8.2. Find a named function #

const ocrpt_function *
ocrpt_function_get(opencreport *o,
                   const char *fname);

10.1.8.3. Get number of operands for an expression (function) #

In an expression tree, functions are represented as subexpressions with operands. This call may be used by OpenCReports functions to inspect whether the number of operands is in the expected range.

int32_t
ocrpt_expr_get_num_operands(ocrpt_expr *e);

10.1.8.4. Get current value of a function operand #

This function is used by OpenCReports functions internally to compute the result from its operands.

ocrpt_result *
ocrpt_expr_operand_get_result(ocrpt_expr *e,
                              int32_t opnum);

10.1.9. Report part and report related functions #

10.1.9.1. Create a report part #

ocrpt_part *
ocrpt_part_new(opencreport *o);

10.1.9.2. Create a row in a report part #

ocrpt_part_row *
ocrpt_part_new_row(ocrpt_part *p);

10.1.9.3. Create a column in report part row #

ocrpt_part_column *
ocrpt_part_row_new_column(ocrpt_part_row *pr);

10.1.9.4. Create a new report in a part column #

ocrpt_report *
ocrpt_part_column_new_report(ocrpt_part_column *pd);

10.1.9.5. Report part related iterators #

Iterators for getting report parts, part rows, columns in rows and reports in columns. Every iterator function must be called the first time with the list pointer set to NULL.

ocrpt_part *
ocrpt_part_get_next(opencreport *o,
                    ocrpt_list **list);

ocrpt_part_row *
ocrpt_part_row_get_next(ocrpt_part *p,
                        ocrpt_list **list);

ocrpt_part_column *
ocrpt_part_column_get_next(ocrpt_part_row *pr,
                           ocrpt_list **list);

ocrpt_report *
ocrpt_report_get_next(ocrpt_part_column *pd,
                      ocrpt_list **list);

10.1.9.6. Set the main query for a report #

Set the main query for a report either by the query structure pointer, or from expression. The expression must resolve to a string value, with fallback to a plain string.

void
ocrpt_report_set_main_query(ocrpt_report *r,
                            const ocrpt_query *query);

void
ocrpt_report_set_main_query_from_expr(ocrpt_report *r,
                                    const char *expr_string);

See Report query name. Unlike with the XML description, where the first globally declared query is used for the report if its main query is not set, the default via the low level API is unset.

10.1.9.7. Get the current row number of the main query #

The row number starts from 1.

long
ocrpt_report_get_query_rownum(ocrpt_report *r);

10.1.9.8. Resolve all report variables #

void
ocrpt_report_resolve_variables(ocrpt_report *r);

10.1.9.9. Evaluate all report variables #

void
ocrpt_report_evaluate_variables(ocrpt_report *r);

10.1.9.10. Resolve all report breaks #

void
ocrpt_report_resolve_breaks(ocrpt_report *r);

10.1.9.11. Resolve all report expressions #

void
ocrpt_report_resolve_expressions(ocrpt_report *r);

10.1.9.12. Evaluate all report expressions #

void
ocrpt_report_evaluate_expressions(ocrpt_report *r);

10.1.10. Layout related functions #

10.1.10.1. Global layout options #

10.1.10.1.1. Set or get "size unit" option #

See Size unit attribute. The expression string must evaluate to a string value, where points will set the layout rendering to use points for size units. Any other value will make the layout rendering use the convoluted RLIB compatible size units, mostly based on font sizes.

ocrpt_expr *
ocrpt_set_size_unit(opencreport *o,
                    const char *expr_string);

The expression also has a getter function, so its result (value) can be queried. Which may be useful, in case it's set in the report XML description and callbacks and the report processing needs to inspect it.

ocrpt_expr *
ocrpt_get_size_unit(opencreport *o);

10.1.10.1.2. Set or get "no query show NoData" option #

See No query show NoData attribute. The expression string should evaluate to a boolean value.

ocrpt_expr *
ocrpt_set_noquery_show_nodata(opencreport *o,
                              const char *expr_string);

ocrpt_expr *
ocrpt_get_noquery_show_nodata(opencreport *o);

10.1.10.1.3. Set or get "report height after last" option #

See Report height after last attribute. The expression string should evaluate to a boolean value.

ocrpt_expr *
ocrpt_set_report_height_after_last(opencreport *o,
                                   const char *expr_string);

ocrpt_expr *
ocrpt_get_report_height_after_last(opencreport *o);

10.1.10.1.4. Set "follower match single" option #

See Follower match single attribute. The expression string should evaluate to a boolean value.

ocrpt_expr *
ocrpt_set_follower_match_single(opencreport *o,
                                const char *expr_string);

ocrpt_expr *
ocrpt_get_follower_match_single(opencreport *o);

10.1.10.1.5. Set or get "follower match single" option directly #

See above and Follower match single attribute. The difference is that the modified behaviour is set directly and immediately. Used by unit tests.

void
ocrpt_set_follower_match_single_direct(opencreport *o,
                                       bool value);

bool
ocrpt_get_follower_match_single_direct(opencreport *o);

10.1.10.2. Report part options #

10.1.10.2.1. Set or get part iterations #

See Part iterations attribute. The expression string must evaluate to a numeric value.

ocrpt_expr *
ocrpt_part_set_iterations(ocrpt_part *p,
                          const char *expr_string);

ocrpt_expr *
ocrpt_part_get_iterations(ocrpt_part *p);

10.1.10.2.2. Set or get part font name #

See Part font name.

ocrpt_expr *
ocrpt_part_set_font_name(ocrpt_part *p,
                         const char *expr_string);

ocrpt_expr *
ocrpt_part_get_font_name(ocrpt_part *p);

10.1.10.2.3. Set or get part font size #

See Part font size.

ocrpt_expr *
ocrpt_part_set_font_size(ocrpt_part *p,
                         const char *expr_string);

ocrpt_expr *
ocrpt_part_get_font_size(ocrpt_part *p);

10.1.10.2.4. Set or get part paper type #

See Paper type.

ocrpt_expr *
ocrpt_part_set_paper_type(ocrpt_part *p,
                             const char *expr_string);

ocrpt_expr *
ocrpt_part_get_paper_type(ocrpt_part *p);

10.1.10.2.5. Set or get part paper's orientation #

See Part page orientation. The expression string must evaluate to a string value, with possible options of portrait and landscape. By default, the part uses portrait orientation.

ocrpt_expr *
ocrpt_part_set_orientation(ocrpt_part *p,
                           const char *expr_string);

ocrpt_expr *
ocrpt_part_get_orientation(ocrpt_part *p);

10.1.10.2.6. Set or get part margins #

See Margin settings. The margin values must be passed in via strings as they can be expressions.

ocrpt_expr *
ocrpt_part_set_top_margin(ocrpt_part *p,
                          const char *expr_string);

ocrpt_expr *
ocrpt_part_get_top_margin(ocrpt_part *p);

ocrpt_expr *
ocrpt_part_set_bottom_margin(ocrpt_part *p,
                             const char *expr_string);

ocrpt_expr *
ocrpt_part_get_bottom_margin(ocrpt_part *p);

ocrpt_expr *
ocrpt_part_set_left_margin(ocrpt_part *p,
                           const char *expr_string);

ocrpt_expr *
ocrpt_part_get_left_margin(ocrpt_part *p);

ocrpt_expr *
ocrpt_part_set_right_margin(ocrpt_part *p,
                            const char *expr_string);

ocrpt_expr *
ocrpt_part_get_right_margin(ocrpt_part *p);

10.1.10.2.7. Set or get part suppression #

See Part suppress attribute. The expression string must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_part_set_suppress(ocrpt_part *p,
                        const char *expr_string);

ocrpt_expr *
ocrpt_part_get_suppress(ocrpt_part *p);

10.1.10.2.8. Set or get part's page header suppressed on the first page #

See Suppress page header on the first page. The expression string must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_part_set_suppress_pageheader_firstpage(ocrpt_part *p,
                                             const char *expr_string);

ocrpt_expr *
ocrpt_part_get_suppress_pageheader_firstpage(ocrpt_part *p);

10.1.10.3. Part row options #

10.1.10.3.1. Set or get part row suppression #

See Part row suppress attribute. The expression string must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_part_row_set_suppress(ocrpt_part_row *pr,
                            const char *expr_string);

ocrpt_expr *
ocrpt_part_row_get_suppress(ocrpt_part_row *pr);

10.1.10.3.2. Set or get part row new page #

See Part row new page attribute. The expression string must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_part_row_set_newpage(ocrpt_part_row *pr,
                           const char *expr_string);

ocrpt_expr *
ocrpt_part_row_get_newpage(ocrpt_part_row *pr);

10.1.10.3.3. Set or get part row layout mode #

See Part row layout attribute. The expression string must evaluate to a string value, with possible options flow and fixed. This setting is ignored, it's only accepted for RLIB compatibility.

ocrpt_expr *
ocrpt_part_row_set_layout(ocrpt_part_row *pr,
                          const char *expr_string);

ocrpt_expr *
ocrpt_part_row_get_layout(ocrpt_part_row *pr);

10.1.10.4. Part column options #

10.1.10.4.1. Set or get part column suppression #

See Part column suppress attribute. The expression must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_part_column_set_suppress(ocrpt_part_column *pd,
                               const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_suppress(ocrpt_part_column *pd);

10.1.10.4.2. Set or get part column width #

See Part column width attribute. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_part_column_set_width(ocrpt_part_column *pd,
                            const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_width(ocrpt_part_column *pd);

10.1.10.4.3. Set or get part column height #

See Part column height attribute. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_part_column_set_height(ocrpt_part_column *pd,
                             const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_height(ocrpt_part_column *pd);

10.1.10.4.4. Set or get part column border width #

See Part column border width. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_part_column_set_border_width(ocrpt_part_column *pd,
                                   const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_border_width(ocrpt_part_column *pd);

10.1.10.4.5. Set or get part column border color #

See Part column border color. The expression must evaluate to a string value with a valid color name or specification.

ocrpt_expr *
ocrpt_part_column_set_border_color(ocrpt_part_column *pd,
                                   const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_border_color(ocrpt_part_column *pd);

10.1.10.4.6. Set or get part column's number of detail columns #

See Detail columns. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_part_column_set_detail_columns(ocrpt_part_column *pd,
                                     const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_detail_columns(ocrpt_part_column *pd);

10.1.10.4.7. Set or get part column's detail column padding #

See Column padding. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_part_column_set_column_padding(ocrpt_part_column *pd,
                                     const char *expr_string);

ocrpt_expr *
ocrpt_part_column_get_column_padding(ocrpt_part_column *pd);

10.1.10.5. Report options #

10.1.10.5.1. Set or get report suppression #

See Report suppress attribute. The expression must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_report_set_suppress(ocrpt_report *r,
                          const char *expr_string);

ocrpt_expr *
ocrpt_report_get_suppress(ocrpt_report *r);

10.1.10.5.2. Set or get report iterations #

See Report iterations attribute. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_report_set_iterations(ocrpt_report *r,
                            const char *expr_string);

ocrpt_expr *
ocrpt_report_get_iterations(ocrpt_report *r);

10.1.10.5.3. Set or get report font name #

See Report font name. The expression must evaluate to a string value, with fallback to plain string: in case of a parsing error, the value string is taken as is.

ocrpt_expr *
ocrpt_report_set_font_name(ocrpt_report *r,
                           const char *expr_string);

ocrpt_expr *
ocrpt_report_get_font_name(ocrpt_report *r);

10.1.10.5.4. Set or get report font size #

See Report font size. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_report_set_font_size(ocrpt_report *r,
                           const char *expr_string);

ocrpt_expr *
ocrpt_report_get_font_size(ocrpt_report *r);

10.1.10.5.5. Set or get report height #

See Report height. The expression must evaluate to a numeric value.

ocrpt_expr *
ocrpt_report_set_height(ocrpt_report *r,
                        const char *expr_string);

ocrpt_expr *
ocrpt_report_get_height(ocrpt_report *r);

10.1.10.5.6. Set or get report's field header priority #

See Report field header priority attribute. The expression must evaluate to a string value with the options of high and low. Default is low.

ocrpt_expr *
ocrpt_report_set_fieldheader_priority(ocrpt_report *r,
                                      const char *expr_string);

ocrpt_expr *
ocrpt_report_get_fieldheader_priority(ocrpt_report *r);

10.1.10.6. Get part layout sections #

Get the part's <Output> sections for <PageHeader> or <PageFooter>.

ocrpt_output *
ocrpt_layout_part_page_header(ocrpt_part *p);

ocrpt_output *
ocrpt_layout_part_page_footer(ocrpt_part *p);

10.1.10.7. Set report for part layout sections #

Set the report pointer for the part's <Output> sections for <PageHeader> or <PageFooter>.

void
ocrpt_layout_part_page_header_set_report(ocrpt_part *p,
                                         ocrpt_report *r);

void
ocrpt_layout_part_page_footer_set_report(ocrpt_part *p,
                                         ocrpt_report *r);

10.1.10.8. Get report layout sections #

Get the report's <Output> sections for <NoData>, <ReportHeader>, <ReportFooter>, <FieldHeaders> or <FieldDetails>.

ocrpt_output *
ocrpt_layout_report_nodata(ocrpt_report *r);

ocrpt_output *
ocrpt_layout_report_header(ocrpt_report *r);

ocrpt_output *
ocrpt_layout_report_footer(ocrpt_report *r);

ocrpt_output *
ocrpt_layout_report_field_header(ocrpt_report *r);

ocrpt_output *
ocrpt_layout_report_field_details(ocrpt_report *r);

10.1.10.8.1. Miscellaneous report layout and line element functions #

It is possible to load a report XML descriptor and modify the layout contents defined by it using code.

The first iterator function loops through toplevel output elements: line, horizontal line, image, barcode. An abstract opaque pointer type is returned by the iterator. Further boolean functions determine the actual element type. The void **iter pointer must point to a NULL pointer initially and the iterator function returns NULL when there are no more elements in the output section. Depending on the boolean function results, the abstract opaque pointer type can be case to the actual output element type: ocrpt_line *, ocrpt_hline *, ocrpt_image * or ocrpt_barcode *.

struct ocrpt_output_element;
typedef struct ocrpt_output_element ocrpt_output_element;

ocrpt_output_element *
ocrpt_output_element_get_next(ocrpt_output *output, ocrpt_list **iter);

bool
ocrpt_output_element_is_line(ocrpt_output_element *elem);

bool
ocrpt_output_element_is_hline(ocrpt_output_element *elem);

bool
ocrpt_output_element_is_image(ocrpt_output_element *elem);

bool
ocrpt_output_element_is_barcode(ocrpt_output_element *elem);

The second iterator function loops through line elements: text, image and barcode. An abstract opaque pointer type is returned by the iterator. Further boolean functions determine the actual element type. The void **iter pointer must point to a NULL pointer initially and the iterator function returns NULL when there are no more elements in the output section. Depending on the boolean function results, the abstract opaque pointer type can be cast to the actual output element type: ocrpt_text *, ocrpt_image * or ocrpt_barcode *.

struct ocrpt_line_element;
typedef struct ocrpt_line_element ocrpt_line_element;

ocrpt_line_element *
ocrpt_line_element_get_next(ocrpt_line *line, void **iter);

bool
ocrpt_line_element_is_text(ocrpt_line_element *elem);

bool
ocrpt_line_element_is_image(ocrpt_line_element *elem);

bool
ocrpt_line_element_is_barcode(ocrpt_line_element *elem);

10.1.10.9. Get break layout sections #

Get the break's <Output> sections for <BreakHeader> or <BreakFooter>.

ocrpt_output *
ocrpt_break_get_header(ocrpt_break *br);

ocrpt_output *
ocrpt_break_get_footer(ocrpt_break *br);

10.1.10.10. Set output section global settings #

Note that part (page) header and footer, and report header and footer sections must be constant expressions. Other sections may depend on data derived from query columns. See Expressions.

10.1.10.10.1. Set or get output section suppression #

Set suppression from an expression string.

ocrpt_expr *
ocrpt_output_set_suppress(ocrpt_output *output,
                          const char *expr_string);

ocrpt_expr *
ocrpt_output_get_suppress(ocrpt_output *output);

10.1.10.11. Add a text line to an output section #

ocrpt_line *
ocrpt_output_add_line(ocrpt_output *output);

10.1.10.12. Text line settings #

Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.

10.1.10.12.1. Set or get line font name #

Set the text line's font name from an expression string.

ocrpt_expr *
ocrpt_line_set_font_name(ocrpt_line *line,
                         const char *expr_string);

ocrpt_expr *
ocrpt_line_get_font_name(ocrpt_line *line);

10.1.10.12.2. Set line font size #

Set the text line's font size from an expression string.

ocrpt_expr *
ocrpt_line_set_font_size(ocrpt_line *line,
                         const char *expr_string);

ocrpt_expr *
ocrpt_line_get_font_size(ocrpt_line *line);

10.1.10.12.3. Set or get line bold value #

Set the text line's bold value from an expression string.

ocrpt_expr *
ocrpt_line_set_bold(ocrpt_line *line,
                    const char *expr_string);

ocrpt_expr *
ocrpt_line_get_bold(ocrpt_line *line);

10.1.10.12.4. Set or get line italic value #

Set the text line's italic value from an expression string.

ocrpt_expr *
ocrpt_line_set_italic(ocrpt_line *line,
                      const char *expr_string);

ocrpt_expr *
ocrpt_line_get_italic(ocrpt_line *line);

10.1.10.12.5. Set or get line suppression #

Set the text line's suppression value from an expression string.

ocrpt_expr *
ocrpt_line_set_suppress(ocrpt_line *line,
                        const char *expr_string);

ocrpt_expr *
ocrpt_line_get_suppress(ocrpt_line *line);

10.1.10.12.6. Set or get line text color #

Set the text line's text color from an expression string.

ocrpt_expr *
ocrpt_line_set_color(ocrpt_line *line,
                     const char *expr_string);

ocrpt_expr *
ocrpt_line_get_color(ocrpt_line *line);

10.1.10.12.7. Set or get line background color #

Set or get the text line's background color from an expression string.

ocrpt_expr *
ocrpt_line_set_bgcolor(ocrpt_line *line,
                       const char *expr_string);

ocrpt_expr *
ocrpt_line_get_bgcolor(ocrpt_line *line);

10.1.10.13. Add a text element to a text line #

ocrpt_text *
ocrpt_line_add_text(ocrpt_line *line);

10.1.10.14. Text element settings #

Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.

10.1.10.14.1. Set text element literal value #

Set the text element's literal value from a string.

ocrpt_expr *
ocrpt_text_set_value_string(ocrpt_text *text,
                            const char *string);

10.1.10.14.2. Set or get text element value #

Set the text element's value from an expression string.

ocrpt_expr *
ocrpt_text_set_value_expr(ocrpt_text *text,
                          const char *expr_string);

The getter function for the text element's value also works when the text value is set as a literal.

ocrpt_expr *
ocrpt_text_get_value(ocrpt_text *text);

10.1.10.14.3. Set or get text element value's delayed property #

Set the text element value's delayed property from an expression string.

ocrpt_expr *
ocrpt_text_set_value_delayed(ocrpt_text *text,
                             const char *expr_string);


ocrpt_expr *
ocrpt_text_get_value_delayed(ocrpt_text *text);

10.1.10.14.4. Set or get text element format string #

Set the text element's format string from an expression string.

ocrpt_expr *
ocrpt_text_set_format(ocrpt_text *text,
                      const char *expr_string);

ocrpt_expr *
ocrpt_text_get_format(ocrpt_text *text);

10.1.10.14.5. Set or get text element translation #

Set the text element's translation from an expression string.

ocrpt_expr *
ocrpt_text_set_translate(ocrpt_text *text,
                         const char *expr_string);

ocrpt_expr *
ocrpt_text_get_translate(ocrpt_text *text);

OpenCReports will attempt to translate both the format string and the text element's value.

10.1.10.14.6. Set or get text element field width #

Set the text element's field width from an expression string.

ocrpt_expr *
ocrpt_text_set_width(ocrpt_text *text,
                     const char *expr_string);

ocrpt_expr *
ocrpt_text_get_width(ocrpt_text *text);

10.1.10.14.7. Set or get text element alignment #

Set the text element's alignment from a string or an expression string.

ocrpt_expr *
ocrpt_text_set_alignment(ocrpt_text *text,
                         const char *expr_string);

ocrpt_expr *
ocrpt_text_get_alignment(ocrpt_text *text);

String values left, right, center and justified are accepted either as is, or as an expression.

10.1.10.14.8. Set or get text element text color #

Set the text element's text color from an expression string.

ocrpt_expr *
ocrpt_text_set_color(ocrpt_text *text,
                     const char *expr_string);

ocrpt_expr *
ocrpt_text_get_color(ocrpt_text *text);

10.1.10.14.9. Set or get text element background color #

Set the text element's background color from an expression string.

ocrpt_expr *
ocrpt_text_set_bgcolor(ocrpt_text *text,
                       const char *expr_string);

ocrpt_expr *
ocrpt_text_get_bgcolor(ocrpt_text *text);

10.1.10.14.10. Set or get text element font name #

Set the text element's font name from an expression string.

ocrpt_expr *
ocrpt_text_set_font_name(ocrpt_text *text,
                         const char *expr_string);

ocrpt_expr *
ocrpt_text_get_font_name(ocrpt_text *text);

10.1.10.14.11. Set or get text element font size #

Set the text element's font size from an expression string.

ocrpt_expr *
ocrpt_text_set_font_size(ocrpt_text *text,
                         const char *expr_string);

ocrpt_expr *
ocrpt_text_get_font_size(ocrpt_text *text);

10.1.10.14.12. Set or get text element bold value #

Set the text element's bold value from an expression string.

ocrpt_expr *
ocrpt_text_set_bold(ocrpt_text *text,
                    const char *expr_string);

ocrpt_expr *
ocrpt_text_get_bold(ocrpt_text *text);

10.1.10.14.13. Set or get text element italic value #

Set the text element's italic value from an expression string.

ocrpt_expr *
ocrpt_text_set_italic(ocrpt_text *text,
                      const char *expr_string);

ocrpt_expr *
ocrpt_text_get_italic(ocrpt_text *text);

10.1.10.14.15. Set or get text element multiline property #

Set the text element's multiline property from an expression string. The expression must evaluate to a numeric (boolean) value.

ocrpt_expr *
ocrpt_text_set_memo(ocrpt_text *text,
                    const char *expr_string);

ocrpt_expr *
ocrpt_text_get_memo(ocrpt_text *text);

10.1.10.14.16. Set or get text element "wrap at characters" property #

Set the text element's "wrap at characters" property from an expression string. The expression must evaluate to a numeric (boolean) value. This setting is only used for multiline fields. When unset or set to false, multiline text fields wrap at word boundaries.

ocrpt_expr *
ocrpt_text_set_memo_wrap_chars(ocrpt_text *text,
                               const char *expr_string);

ocrpt_expr *
ocrpt_text_get_memo_wrap_chars(ocrpt_text *text);

10.1.10.14.17. Set or get text element maximum lines #

Set the text element's maximum lines property from an expression string. The expression must evaluate to a numeric value. This setting is only used for multiline fields. When unset or set to 0, the whole content of the multiline field is rendered. Otherwise, not more than the maximum lines are rendered from the multiline field value. The used font size, the field's width and word/character wrapping influence the number of lines the field value is rendered into.

ocrpt_expr *
ocrpt_text_set_memo_max_lines(ocrpt_text *text,
                              const char *expr_string);

ocrpt_expr *
ocrpt_text_get_memo_max_lines(ocrpt_text *text);

10.1.10.15. Add a horizontal line to an output section #

ocrpt_hline *
ocrpt_output_add_hline(ocrpt_output *output);

10.1.10.16. Horizontal line settings #

Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.

10.1.10.16.1. Set or get horizontal line size (width) #

Set the horizontal line's size (width) from an expression string.

ocrpt_expr *
ocrpt_hline_set_size(ocrpt_hline *hline,
                     const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_size(ocrpt_hline *hline);

10.1.10.16.2. Set or get horizontal line alignment #

Set the horizontal line's alignment from an expression string. Possibly values are left, right and center. Default is left alignment. The alignment is only applied if the line length is shorter than the designated page or column width without the margins.

ocrpt_expr *
ocrpt_hline_set_alignment(ocrpt_hline *hline,
                      const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_alignment(ocrpt_hline *hline);

10.1.10.16.3. Set or get horizontal line indentation #

Set the horizontal line's indentation value from an expression string. The indentation is used if left alignment is set.

ocrpt_expr *
ocrpt_hline_set_indentation(ocrpt_hline *hline,
                       const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_indentation(ocrpt_hline *hline);

10.1.10.16.4. Set or get horizontal line length #

Set the horizontal line's length from an expression string.

ocrpt_expr *
ocrpt_hline_set_length(ocrpt_hline *hline,
                       const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_length(ocrpt_hline *hline);

10.1.10.16.5. Set or get horizontal line font size #

Set the horizontal line's font size from an expression string. It's used in indentation and length calculations if Size unit attribute is set to rlib.

ocrpt_expr *
ocrpt_hline_set_font_size(ocrpt_hline *hline,
                          const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_font_size(ocrpt_hline *hline);

10.1.10.16.6. Set or get horizontal line suppression #

Set the horizontal line's suppression from an expression string.

ocrpt_expr *
ocrpt_hline_set_suppress(ocrpt_hline *hline,
                         const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_suppress(ocrpt_hline *hline);

10.1.10.16.7. Set or get horizontal line color #

Set the horizontal line's color from an expression string.

ocrpt_expr *
ocrpt_hline_set_color(ocrpt_hline *hline,
                      const char *expr_string);

ocrpt_expr *
ocrpt_hline_get_color(ocrpt_hline *hline);

10.1.10.17. Add a barcode to an output section #

ocrpt_barcode *
ocrpt_output_add_barcode(ocrpt_output *output);

10.1.10.18. Add a barcode to a text line #

ocrpt_barcode *
ocrpt_line_add_barcode(ocrpt_line *line);

10.1.10.19. Barcode settings #

10.1.10.19.1. Set or get barcode value #

Set the barcode's value from an expression string. The expression must evaluate to a string, whose value is the string to be encoded as a barcode.

ocrpt_expr *
ocrpt_barcode_set_value(ocrpt_barcode *bc,
                        const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_value(ocrpt_barcode *bc);

10.1.10.19.2. Set or get barcode value delayed #

Set the barcode's value delayed from an expression string. The expression must evaluate to a boolean value.

ocrpt_expr *
ocrpt_barcode_set_value_delayed(ocrpt_barcode *bc,
                                const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_value_delayed(ocrpt_barcode *bc);

10.1.10.19.3. Set or get barcode suppression #

Set the barcode's suppression value from an expression string. The expression must evaluate to a boolean value.

ocrpt_expr *
ocrpt_barcode_set_suppress(ocrpt_barcode *bc,
                           const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_suppress(ocrpt_barcode *bc);

Default value is false, i.e. no suppression.

10.1.10.19.4. Set or get barcode type #

Set the barcode's type from an expression string.

ocrpt_expr *
ocrpt_barcode_set_type(ocrpt_barcode *bc,
                       const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_type(ocrpt_barcode *bc);

The type may be optional, in which case it's autodetected and the barcode is rendered in the format that first allows the value string to be rendered. Possible types (in the order of autodetection) are: upc-a, ean-13, upc-e, ean-8, isbn, code39, code39ext, code128b code128c, or code128. If type is specified, the value is rendered in that barcode type if the string is valid for the type. If value is invalid for the specified type, or autodetection fails, because the value is invalid for any of the above listed types, the barcode is not rendered.

10.1.10.19.5. Set or get barcode width #

Set the barcode's width from an expression string.

ocrpt_expr *
ocrpt_barcode_set_width(ocrpt_barcode *bc,
                        const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_width(ocrpt_barcode *bc);

The width is set according to Size unit attribute, either in points (1/72th inch) or in (monospace) font width units set by <Line>.

10.1.10.19.6. Set or get barcode width #

Set the barcode's height from an expression string.

ocrpt_expr *
ocrpt_barcode_set_height(ocrpt_barcode *bc,
                         const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_height(ocrpt_barcode *bc);

This setting is always in points, i.e. 1/72th of an inch. The line height will be determined by greatest height of all the <field>, <literal> and <Barcode> fields in the same <Line> in a way that the elements of the same line will appear (approximately) centered vertically.

10.1.10.19.7. Set or get barcode line color #

Set the barcode's line color from an expression string.

ocrpt_expr *
ocrpt_barcode_set_color(ocrpt_barcode *bc,
                         const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_color(ocrpt_barcode *bc);

10.1.10.19.8. Set or get barcode background color #

Set the barcode's background color from an expression string.

ocrpt_expr *
ocrpt_barcode_set_bgcolor(ocrpt_barcode *bc,
                         const char *expr_string);

ocrpt_expr *
ocrpt_barcode_get_bgcolor(ocrpt_barcode *bc);

10.1.10.20. Add an image to an output section #

ocrpt_image *
ocrpt_output_add_image(ocrpt_output *output);

10.1.10.21. Add an image to a text line #

ocrpt_image *
ocrpt_line_add_image(ocrpt_line *line);

10.1.10.22. Image settings #

Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.

10.1.10.22.1. Set or get image value #

Set the image's value (filename) from an expression string.

ocrpt_expr *
ocrpt_image_set_value(ocrpt_image *image,
                      const char *expr_string);

ocrpt_expr *
ocrpt_image_get_value(ocrpt_image *image);

10.1.10.22.2. Set or get image suppression #

Set the image's suppression from an expression string.

ocrpt_expr *
ocrpt_image_set_suppress(ocrpt_image *image,
                         const char *expr_string);

ocrpt_expr *
ocrpt_image_get_suppress(ocrpt_image *image);

10.1.10.22.3. Set or get image type #

Set the image's type from an expression string.

ocrpt_expr *
ocrpt_image_set_type(ocrpt_image *image,
                     const char *expr_string);

ocrpt_expr *
ocrpt_image_get_type(ocrpt_image *image);

10.1.10.22.4. Set or get image width #

Set the image's width from an expression string. Used when the image is directly added to an output section.

ocrpt_expr *
ocrpt_image_set_width(ocrpt_image *image,
                      const char *expr_string);

ocrpt_expr *
ocrpt_image_get_width(ocrpt_image *image);

10.1.10.22.5. Set or get image height #

Set the image's width from an expression string. Used when the image is directly added to an output section.

ocrpt_expr *
ocrpt_image_set_height(ocrpt_image *image,
                       const char *expr_string);

ocrpt_expr *
ocrpt_image_get_height(ocrpt_image *image);

10.1.10.22.6. Set or get image alignment #

Set the image's alignment from an expression string. Used when the image is added to text line.

ocrpt_expr *
ocrpt_image_set_alignment(ocrpt_image *image,
                      const char *expr_string);

ocrpt_expr *
ocrpt_image_get_alignment(ocrpt_image *image);

10.1.10.22.7. Set or get image background color #

Set the image's background color from an expression string.

ocrpt_expr *
ocrpt_image_set_bgcolor(ocrpt_image *image,
                        const char *expr_string);

ocrpt_expr *
ocrpt_image_get_bgcolor(ocrpt_image *image);

10.1.10.22.8. Set or get image field width #

Set the image's field width from an expression string. Used when the image is added to a text line.

ocrpt_expr *
ocrpt_image_set_text_width(ocrpt_image *image,
                           const char *expr_string);

ocrpt_expr *
ocrpt_image_get_text_width(ocrpt_image *image);

10.1.10.23. Add an image end marker to an output section #

void
ocrpt_output_add_image_end(ocrpt_output *output);

10.1.11. Callback related functions #

Certain stages of the report execution can notify the application about the stage being executed or finished.

Every "add a callback" function below return true for success, false for failure.

10.1.11.1. Add a "part added" callback #

typedef void
(*ocrpt_part_cb)(opencreport *,
                 ocrpt_part *,
                 void *data);

bool
ocrpt_add_part_added_cb(opencreport *o,
                        ocrpt_part_cb func,
                        void *data);

10.1.11.2. Add a "report added" callback #

typedef void
(*ocrpt_report_cb)(opencreport *,
                   ocrpt_report *,
                   void *data);

bool
ocrpt_add_report_added_cb(opencreport *o,
                          ocrpt_report_cb func,
                          void *data);

10.1.11.3. Add an "all precalculations done" callback #

typedef void
(*ocrpt_cb)(opencreport *,
            void *data);

bool
ocrpt_add_precalculation_done_cb(opencreport *o,
                                 ocrpt_cb func,
                                 void *data);

10.1.11.4. Add a "part iteration" callback #

bool
ocrpt_part_add_iteration_cb(ocrpt_part *r,
                            ocrpt_part_cb func,
                            void *data);

bool
ocrpt_part_add_iteration_cb2(opencreport *o,
                             ocrpt_part_cb func,
                             void *data);

The second variant adds the callback in the opencreport structure context, making the callback apply to every report part. It's for RLIB compatibility.

10.1.11.5. Add a "report started" callback #

bool
ocrpt_report_add_start_cb(ocrpt_report *r,
                          ocrpt_report_cb func,
                          void *data);

bool
ocrpt_report_add_start_cb2(opencreport *o,
                           ocrpt_report_cb func,
                           void *data);

The second variant adds the callback in the opencreport structure context, making the callback apply to every report. It's for RLIB compatibility.

10.1.11.6. Add a "report done" callback #

bool
ocrpt_report_add_done_cb(ocrpt_report *r,
                         ocrpt_report_cb func,
                         void *data);

bool
ocrpt_report_add_done_cb2(opencreport *o,
                          ocrpt_report_cb func,
                          void *data);

The second variant adds the callback in the opencreport structure context, making the callback apply to every report. It's for RLIB compatibility.

10.1.11.7. Add a "new row" callback #

bool
ocrpt_report_add_new_row_cb(ocrpt_report *r,
                            ocrpt_report_cb func,
                            void *data);

bool
ocrpt_report_add_new_row_cb2(opencreport *o,
                             ocrpt_report_cb func,
                             void *data);

The second variant adds the callback in the opencreport structure context, making the callback apply to every report. It's for RLIB compatibility.

10.1.11.8. Add a "report iteration done" callback #

bool
ocrpt_report_add_iteration_cb(ocrpt_report *r,
                              ocrpt_report_cb func,
                              void *data);

bool
ocrpt_report_add_iteration_cb2(opencreport *o,
                               ocrpt_report_cb func,
                               void *data);

The second variant adds the callback in the opencreport structure context, making the callback apply to every report. It's for RLIB compatibility.

10.1.11.9. Add a "report precalculation done" callback #

bool
ocrpt_report_add_precalculation_done_cb(ocrpt_report *r,
                                        ocrpt_report_cb func,
                                        void *data);

bool
ocrpt_report_add_precalculation_done_cb2(opencreport *o,
                                         ocrpt_report_cb func,
                                         void *data);

The second variant adds the callback in the opencreport structure context, making the callback apply to every report. It's for RLIB compatibility.

10.1.11.10. Add a "break triggers" callback #

typedef void
(*ocrpt_break_trigger_cb)(opencreport *,
                          ocrpt_report *,
                          ocrpt_break *,
                          void *);

bool
ocrpt_break_add_trigger_cb(ocrpt_break *br,
                           ocrpt_break_trigger_cb func,
                           void *data);

10.1.12. Environment related functions #

10.1.12.1. Indirect function to get an environment variable #

typedef ocrpt_result *
(*ocrpt_env_query_func)(opencreport *,
                        const char *);

extern ocrpt_env_query_func
ocrpt_env_get;

10.1.12.2. Set the environment query function #

void
ocrpt_env_set_query_func(ocrpt_env_query_func func);

10.1.12.3. C API environment query function #

ocrpt_result *
ocrpt_env_get_c(opencreport *o,
                const char *env);

10.1.12.4. Add an "m" domain variable #

Set an "m" domain variable. If such a variable name didn't exist yet, and value is not NULL, then the variable is set. If value is NULL, the variable is removed. Such an explicit variable takes precedence over the environment variable of the same name when used in expressions.

void
ocrpt_set_mvariable(opencreport *o,
                    const char *name,
                    const char *value);

10.1.13. File handling related functions #

10.1.13.1. Return a canonical file path #

The returned path contains only single directory separators and doesn't contains symlinks.

char *
ocrpt_canonicalize_path(const char *path);

10.1.13.2. Add search path #

Add a new directory path to the list of search paths. It's useful to find files referenced with relative path.

void
ocrpt_add_search_path(opencreport *o,
                      const char *path);

10.1.13.3. Add search path (delayed variant) #

Add a new directory path from an expression string to the list of search paths. It's useful to find files referenced with relative path. The expression must evaluate to a string value. It is evaluated at the beginning of the report execution. This function may be used explicitly but it's also used when parsing the <Path> nodes in a report XML description.

void
ocrpt_add_search_path_from_expr(opencreport *o,
                                const char *expr_string);

10.1.13.4. Resolve search paths #

Resolve expressions added by ocrpt_add_search_path_from_expr(). It's used internally when executing the report.

void
ocrpt_resolve_search_paths(opencreport *o);

10.1.13.5. Find a file #

Find a file and return the canonicalized path to it. This function takes the search paths into account.

char *
ocrpt_find_file(opencreport *o,
                const char *filename);

Note that search paths added by ocrpt_add_search_path() and ocrpt_add_search_path_from_expr() are used in their order of appearance when searching for files during executing the report.

10.1.14. Color related functions #

10.1.14.1. Find a color by its name #

The function fills in the ocrpt_color structure with RGB values in Cairo values (0.0 ... 1.0).

If the color name starts with # or 0x or 0X then it must be in HTML notation.

Otherwise, the color name is looked up in the color name database in a case insensitive way. If found, the passed-in ocrpt_color structure is filled with the RGB color value of that name.

If not found or the passed-in color name is NULL, depending on the the expected usage (foreground or background color), the ocrpt_color structure is filled with either white or black.

void
ocrpt_get_color(opencreport *o,
                const char *cname,
                ocrpt_color *color,
                bool bgcolor);

10.1.15. Paper size related functions #

Paper size in OpenCReports is handled via libpaper.

This structure is used in OpenCReports to represent paper name and size:

struct ocrpt_paper {
    const char *name;
    double width;
    double height;
};
typedef struct ocrpt_paper ocrpt_paper;

10.1.15.1. Get the system default paper #

const ocrpt_paper *
ocrpt_get_system_paper(void);

10.1.15.2. Get the paper specified by name #

const ocrpt_paper *
ocrpt_get_paper_by_name(const char *paper);

10.1.15.3. Set the global paper #

Set global paper using an ocrpt_paper structure. The contents of the structure is copied.

void
ocrpt_set_paper(opencreport *o,
                const ocrpt_paper *paper);

10.1.15.4. Set global paper specified by name #

Set paper for the report using a paper name. If the paper name is unknown, the system default paper is set.

void
ocrpt_set_paper_by_name(opencreport *o,
                        const char *paper);

10.1.15.5. Get currently set global paper #

const ocrpt_paper *
ocrpt_get_paper(opencreport *o);

10.1.15.6. Iterate over paper sizes #

Get the next ocrpt_paper structure in the iterator. For the first call, the iterator pointer must be NULL. It returns NULL when there are no more papers known to the system.

const ocrpt_paper *
ocrpt_paper_next(opencreport *o,
                 void **iter);

10.1.16. Memory handling related functions #

Memory handling is done through an indirection, to help with bindings (that may do their own memory handling) override the default.

10.1.16.1. Indirect function pointers #

typedef void *
(*ocrpt_mem_malloc_t)(size_t);

typedef void *
(*ocrpt_mem_realloc_t)(void *,
                       size_t);

typedef void *
(*ocrpt_mem_reallocarray_t)(void *,
                            size_t,
                            size_t);

typedef void
(*ocrpt_mem_free_t)(const void *);

typedef char *
(*ocrpt_mem_strdup_t)(const char *);

typedef char *
(*ocrpt_mem_strndup_t)(const char *,
                       size_t);

typedef void
(*ocrpt_mem_free_size_t)(void *,
                         size_t);

extern ocrpt_mem_malloc_t ocrpt_mem_malloc0;
extern ocrpt_mem_realloc_t ocrpt_mem_realloc0;
extern ocrpt_mem_reallocarray_t ocrpt_mem_reallocarray0;
extern ocrpt_mem_free_t ocrpt_mem_free0;
extern ocrpt_mem_strdup_t ocrpt_mem_strdup0;
extern ocrpt_mem_strndup_t ocrpt_mem_strndup0;

10.1.16.2. Allocate memory #

void *
ocrpt_mem_malloc(size_t sz);

10.1.16.3. Reallocate memory #

void *
ocrpt_mem_realloc(void *ptr,
                  size_t sz);

10.1.16.4. Reallocate array of memory #

void *
ocrpt_mem_reallocarray(void *ptr,
                       size_t nmemb,
                       size_t sz);

10.1.16.5. Free memory #

void
ocrpt_mem_free(const void *ptr);

10.1.16.6. Duplicate C string #

void *
ocrpt_mem_strdup(const char *ptr);

10.1.16.7. Duplicate C string up to the specified length #

void *
ocrpt_mem_strndup(const char *ptr,
                  size_t sz);

10.1.16.8. Free a C string #

It'a convenience alias for ocrpt_mem_free().

void
ocrpt_strfree(const char *s);

10.1.16.9. Set indirect allocation functions #

void
ocrpt_mem_set_alloc_funcs(ocrpt_mem_malloc_t rmalloc,
                          ocrpt_mem_realloc_t rrealloc,
                          ocrpt_mem_reallocarray_t rreallocarray,
                          ocrpt_mem_free_t rfree,
                          ocrpt_mem_strdup_t rstrdup,
                          ocrpt_mem_strndup_t rstrndup);

10.1.17. List related functions #

These functions implement a single linked list. The list element structure is hidden:

struct ocrpt_list;
typedef struct ocrpt_list ocrpt_list;

10.1.17.1. Get the list length #

size_t
ocrpt_list_length(ocrpt_list *l);

10.1.17.2. Make a list from one element #

ocrpt_list *
ocrpt_makelist1(const void *data);

10.1.17.3. Make a list from multiple elements #

This function can be used with variable number of arguments.

ocrpt_list *
ocrpt_makelist(const void *data1, ...);

10.1.17.4. Get the last element of a list #

ocrpt_list *
ocrpt_list_last(const ocrpt_list *l);

10.1.17.5. Get the nth element of a list #

ocrpt_list *
ocrpt_list_nth(const ocrpt_list *l, uint32_t n);

10.1.17.6. Append a new element to a list #

ocrpt_list *
ocrpt_list_append(ocrpt_list *l,
                  const void *data);

10.1.17.7. Append to list using the last element #

This function make appending to the list work O(1) instead of O(n).

ocrpt_list *
ocrpt_list_end_append(ocrpt_list *l,
                      ocrpt_list **e,
                      const void *data);

10.1.17.8. Prepend a new element to a list #

ocrpt_list *
ocrpt_list_prepend(ocrpt_list *l,
                   const void *data);

10.1.17.9. Remove a data element from a list #

ocrpt_list *
ocrpt_list_remove(ocrpt_list *l,
                  const void *data);

10.1.17.10. Remove a data element from a list and update the last link #

ocrpt_list *
ocrpt_list_end_remove(ocrpt_list *l,
                      ocrpt_list **endptr,
                      const void *data);

10.1.17.11. Get next link in the list #

This can be used to iterate through a list. It returns NULL if the passed-in link is the last list in the list or it's an empty list.

ocrpt_list *
ocrpt_list_next(ocrpt_list *l);

10.1.17.12. Get the data element from a list #

void *
ocrpt_list_get_data(ocrpt_list *l);

10.1.17.13. Free a list #

void
ocrpt_list_free(ocrpt_list *l);

10.1.17.14. Free a list and its data elements #

void
ocrpt_list_free_deep(ocrpt_list *l,
                     ocrpt_mem_free_t freefunc);

10.1.18. String related functions #

For memory safety and higher performance, a wrapper structure is used over C functions.

struct ocrpt_string {
    char *str;
    size_t allocated_len;
    size_t len;
};
typedef struct ocrpt_string ocrpt_string;

10.1.18.1. Create a new string #

Create a new string from a C string. The ownership of the input string may be taken over, or the original string's contents are copied.

ocrpt_string *
ocrpt_mem_string_new(const char *str,
                     bool copy);

10.1.18.2. Create a new string with specified allocated length #

Create a new string with specified allocated length so future growth can be done without reallocation. The input string is always copied.

ocrpt_string *
ocrpt_mem_string_new_with_len(const char *str,
                              size_t len);

10.1.18.3. Create a string from a formatted string with maximum length #

ocrpt_string *
ocrpt_mem_string_new_vnprintf(size_t len,
                              const char *format,
                              va_list va);

10.1.18.4. Create a string from a formatted string #

ocrpt_string *
ocrpt_mem_string_new_printf(const char *format, ...);

10.1.18.5. Resize a string #

Resize the string to the specified allocated length.

ocrpt_string *
ocrpt_mem_string_resize(ocrpt_string *string,
                        size_t len);

10.1.18.6. Free a string #

char *
ocrpt_mem_string_free(ocrpt_string *string,
                      bool free_str);

10.1.18.7. Append a C string of the specified length to a string #

void
ocrpt_mem_string_append_len(ocrpt_string *string,
                            const char *str,
                            const size_t len);

10.1.18.8. Append a binary string of the specified length to a string #

void
ocrpt_mem_string_append_len_binary(ocrpt_string *string,
                                   const char *str,
                                   const size_t len);

10.1.18.9. Append a C string of unspecified length to a string #

void
ocrpt_mem_string_append(ocrpt_string *string,
                        const char *str);

10.1.18.10. Append a byte to a string #

void
ocrpt_mem_string_append_c(ocrpt_string *string,
                          const char c);

10.1.18.11. Append a formatted string to a string #

void
ocrpt_mem_string_append_printf(ocrpt_string *string,
                               const char *format, ...);