Rocket Uniface User Forum

 View Only

Assignment File Expressions

By Kathy Larson posted 04-16-2024 09:54

  

by Etienne Thijsse

Assignment files are how you configure your Uniface applications. However, currently assignment files are not very flexible. Often you need several assignment files that are almost identical, except for one or two settings. For example, two users on the same system that use the same application each need their own assignment file, if in the [files] section, the user’s home directory needs to be set. Or, if there are multiple versions of the application and the version number is part of the path to the Uniface archive files (.uar), then you also need a separate assignment file for each of these versions, even if this is the only difference. 

Dynamic Assignment Files 

To solve this profusion of almost identical assignment files, we have introduced the ability to use environment variables in the files, enabling assignment files to be more dynamic. The actual values of some of the settings are not hardcoded anymore but are derived from environment variables. 

However, just being able to use environment variables may not be enough. Sometimes you do not need the complete value of an environment variable but only a part of it. Or you need to manipulate it in some way before it can be used. For example, if you have the installation path to your application in an environment variable and this path includes the version of your application, then it would be nice if you could extract that version number from this path instead of having to set a separate environment variable for the version number, or worse, still having to hardcode the version number in the assignment file in some logical. To do things like this, we have introduced the concept of expressions in Uniface assignment files. 

Expressions 

Expressions start with %and end with )”. This is a familiar syntax to Uniface programmers: you can already use it inside a string in Uniface proc code to evaluate expressions inline. In the assignment file, you can now use this syntax to evaluate expressions inline. In proc code you can use variables inside %%(and). In the assignment file logicals declared in the [logicals] section fulfill the role of variables. An environment variable is indicated by a $ sign prefix, which you can use as variables in the same way as logicals in an expression. 

Expressions can contain the following arithmetic operators: 

  • + addition 

  • - subtraction 

  • * multiplication 

  • / division 

  • % modulus 

  • ( … ) brackets to control precedence 

For string values, the following substring operators are available: 

  • [x,y] extract the characters at the positions x up to y 

  • [x:y] extract y characters starting at position x 

  • [x] remove characters 1 to (x-1) from the string 

  • [?x] extract item x from a string in which tokens are separated by the ? 

The first three substring operators are familiar to Uniface proc programmers; they function the same way as they do in proc. The fourth one is an additional operator specific to assignment file expressions. Valid characters for ? are all ASCII characters that are not alphanumeric. Alphanumeric and non-ASCII characters are not valid because then it would be the name of a logical whose value needs to be substituted. 

Below is an example assignment file snippet for application MyApp: 
(assumes user Someone is running Uniface application MyApp on Windows and environment variable MYAPP_INSTALL points to the installation directory of MyApp) 

[logicals] 
nr1 = 150 
nr2 = 65 
nr_days = %%(nr2 + 2* nr1) ; 365 
message = There are %%(nr_days) in a year. ; There are 365 days in a year. 
home = %%($USERPROFILE) ; C:\Users\Someone 
root = %%(home[\1]) ; C: 
my_app_path = %%($MYAPP_INSTALL) ; C:\Program Files\MyApp\3.0.4 
my_app_version = %%(my_app_path[\4]) ; 3.0.4 
major = %%(my_app_version[.1]) ; 3 
minor = %%(my_app_version[.2]) ; 0 
 

[files] 
*.appext %%(home)\my_app%%(major)%%(minor)\*.appext 
; *.appext C:\Users\Someone\myapp30\*.appext 

[resources] 
%%(my_app_path)\usys\myapp.uar 

Scope 

When reading and interpreting an assignment file, Uniface will first process the [logicals] section. This means that logicals that are defined can be used in all other sections, even if they precede the [logicals] section in which they are defined. However, inside the [logicals] section the order is important. You can only use logicals as variables in an expression in the [logicals] section that have previously been declared in the [logicals] section. If you are including another assignment file using the #file directive and need to use logicals from that file in an expression in the [logicals] section assignment file, then the #file directive must precede the [logicals] section in which you use those logicals. Besides these rules, you can use logicals defined in usys.asn in expressions in other application assignment files, but not the other way around. 


#tofp
#tofp
1 comment
13 views

Permalink

Comments

19 days ago

Hi Kathy,

This looks interesting.
What would be really useful with this new / added functionality;
A "viewer" of that UF "thinks" the ASN looks like once the session 
is up and running...  This would significantly cut down on trials,
tribulations and errors....

;-)

Regards,
Knut