Searches for a character pattern in a presentation space.
HCON Library
C (libg3270.a)
Pascal (libg3270p.a)
FORTRAN (libg3270f.a)
The g32_search function searches for the specified byte pattern in the presentation space associated with the application.
The search is performed from the row and column given in the g32_api structure to the end of the presentation space. Note that the row and column positions start at 1 (one) and not 0. If you start at 0 for row and column, an invalid position error will result.
The g32_search function is part of the Host Connection Program (HCON).
The g32_search function requires one or more adapters used to connect to a host.
In a DBCS environment, the g32_search function only searches the presentation space for an SBCS character pattern. This function does not support Katakana or DBCS characters.
Pattern Matching
In any given search pattern, the following characters have special meaning:
Character | Description |
---|---|
? | The question mark is the arbitrary character, matching any one character. |
* | The asterisk is the wildcard character, matching any sequence of zero or more characters. |
\ | The backslash is the escape character meaning the next character is to be interpreted literally. |
Pattern Matching Example
The string AB?DE matches any of ABCDE, AB9DE, ABxDE, but does not match ABCD, ABCCDE, or ABDE.
The string AB*DE matches any of ABCDE, AB9DE, ABCCDE, ABDE, but does not match ABCD, ABCDF, or ABC.
Pattern Matching in C and Pascal
If the pattern needs to contain either a question mark or an asterisk as a literal character, these symbols must be preceded by two escape characters (\\? or \\*). For example, to search for the string, How are you today?, the pattern might be:
How are you today \\?
The backslash can be used as a literal character by specifying four backslash characters (\\\\) in the pattern. For example, to search for the string, We found the \., the pattern might be:
We found the \\\\.
Pattern Matching in FORTRAN
If the pattern needs to contain either a question mark or an asterisk as a literal character, these symbols must be preceded by one escape character (\? or \*). For example, to search for the string, How are you today?, the pattern might be:
How are you today\?
The backslash can be used as a literal character by specifying two backslash characters (\\) in the pattern. For example, to search for the string, We found the \., the pattern might be:
We found the \\.
HCON application programs using the Pascal language interface must include and link both the C and Pascal libraries. Application programs using the FORTRAN language for the HCON API must include and link both the C and FORTRAN libraries.
Item | Description |
---|---|
as | Specifies a pointer to a g32_api structure. It also contains the row and column where the search should begin. Status information is returned in this structure. |
pattern | Specifies a pointer to a byte pattern, which is searched for in the presentation space. |
Item | Description |
---|---|
as | Specifies the g32_api structure. |
pattern | Specifies a pointer to a string containing the pattern to search for in the presentation space. The string must be at least as long as the length indicated in the g32_api structure. |
Item | Description |
---|---|
AS | Specifies a g32_api equivalent structure as an array of integers. |
PATTERN | Specifies a string that is searched for in the presentation space. |
Item | Description |
---|---|
0 | Indicates successful completion.
|
-1 | Indicates an error has occurred.
|
The following example fragment illustrates the use of the g32_search function in an api_3270 mode program in C language:
#include <g32_api.h> /* API include file */
#include <g32_keys.h>
main()
{
struct g32_api *as; /* g32 structure */
char *buffer; /* pointer to char string */
int return; /* return code */
char *malloc(); /* C memory allocation
function */
.
.
.
return = g32_notify(as,1); /* Turn notification on */
buffer = malloc(10);
return = g32_get_cursor(as); /* get location of cursor */
printf (" The cursor position is row: %d col: %d/n",
as -> row, as -> column);
/* Get data from host starting at the current row and column */
as -> length = 10; /* length of a pattern on host */
return = g32_get_data(as,buffer); /* get data from host */
printf("The data returned is <%s>\n",buffer);
/* Try to search for a particular pattern on host */
as ->row =1; /* row to start search */
as ->column =1; /* column to start search */
return = g32_search(as,"PATTERN");
/*Send a clear key to the host */
return = g32_send_keys(as,CLEAR);
/* Turn notification off */
return = g32_notify(as,0);
.
.
.