![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||||
|
|
|||||
| Initialization and termination rules | |||||
In regular OmniMark programs, there is no real distinction between process-start, process, and process-end rules except that they are performed in that order. Additionally, process-start and process-end rules can be used in any of the aided-translation-type programs. OmniMark doesn't distinguish what can be done with these rules, but process-start and process-end rules should be used only for performing processes that must be executed at the beginning or end of a program, respectively. Usually these processes include whole-program initiation and termination functions. process rules should be used for the main processing within a program.
process-start rules allow you to do processing and produce output at the earliest stages of a program, more or less adjacent to macro and function definitions and global variable declarations. One use of a process-start rule would be to allocate handles and connect to a database:
process-start
local SQL_Handle_type EnvironmentHandle
local SQL_Handle_type ConnectionHandle
local SQL_Handle_type StatementHandle
local counter RetCode
set RetCode to SQLAllocEnv (EnvironmentHandle)
output "Allocating environment handle - "
do when RetCode != SQL_SUCCESS
output "failed%n"
halt with 1
else
output "passed%n"
done
set RetCode to SQLAllocHandle
( SQL_HANDLE_DBC, EnvironmentHandle, ConnectionHandle )
output "Allocating connection handle - "
do when RetCode != SQL_SUCCESS
output "failed%n"
halt with 1
else
output "passed%n"
done
set RetCode to SQLConnect ( ConnectionHandle, "omodbc", 20, "", 0, "", 0 )
output "Connecting to database - "
do when RetCode != SQL_SUCCESS
output "failed%n"
halt with 1
else
output "passed%n"
done
Similarly, a process-end rule could be used to disconnect from the database and free the handle resources:
process-end
set RetCode to SQLDisconnect ( ConnectionHandle )
output "Disconnecting from database - "
do when RetCode != SQL_SUCCESS
output "failed%n"
halt with 1
else
output "passed%n"
done
set RetCode to SQLFreeHandle (SQL_HANDLE_DBC, ConnectionHandle)
output "Freeing connection handle resources - "
do when RetCode != SQL_SUCCESS
output "failed%n"
halt with 1
else
output "passed%n"
done
set RetCode to SQLFreeHandle (SQL_HANDLE_ENV, EnvironmentHandle)
output "Freeing environment handle resources - "
do when RetCode != SQL_SUCCESS
output "failed%n"
halt with 1
else
output "passed%n"
done
| ---- |