User's Guide

Parsing the source file

To initialize your record wrapper class to represent the external function's parameters, you must parse the C header file, or COBOL copybook file that declares the data types used by the function.

To parse an external function source file, use the parseFile: class method of the AbtCLangParser class or the AbtCOBOLLangParser class. The parseFile: method takes the source file name as input and returns an object table (AbtCObjectTable or AbtCOBOLObjectTable which are subclasses of AbtObjectTable) containing information about the function and type definitions in the source file.

Tip icon
The parser runs faster if you suppress the informational and warning messages that are displayed in the System Transcript window. To suppress the messages select and run the following statements:
AbtCLangParser messageLevel: 0.
AbtCOBOLLangParser messageLevel: 0.

The parser will also run much faster if your C header or COBOL copybook file only contains the definitions it needs. If your file includes toolkit or compiler files, it will take much longer to parse.

After the source file is parsed, the object table contains an entry for each of the data types and functions defined in the file. For C, this includes the following:

For COBOL, this includes the following:

The interface information must be extracted from the object table and used to generate the appropriate getter and setter selectors for the fields of the structure. You can use the generateAllFieldsFrom:inClass: method of the AbtRecordGenerator class to generate the getter and setter selectors for all of the fields in the structure. Alternatively, you can use the generateFields:from:inClass: method to generate getter and setter selectors for a subset of the fields in the structure.

To generate the getter and setter selectors for the record wrappers created for the sample, enter the following code in a workspace, select it, and run it.

Parsing the C sample files

For the C sample header (.H) file, enter the following code:

"Parse the C header file and initialize the OSObject subclass.
 This assumes that the OSObject subclass SampleCATMStruct has
 already been created. AbtRecordGenerator adds the specified
 getter and setter selectors to the class."
| anObjectTable |
anObjectTable := AbtCLangParser parseFile: 'catm.h'.
AbtRecordGenerator new
    generateAllFieldsFrom: (anObjectTable dataStructures
            at: 'ATM_CUSTOMER' asSmalltalkGlobalIdentifier)
    inClass: SampleCATMStruct.

Parsing the COBOL sample files

For the COBOL sample copybook, enter the following code:

"Parse the COBOL cpy file and initialize the OSObject subclass.
 This assumes that the OSObject subclass SampleCOBOLATMStruct has
 already been created. AbtRecordGenerator adds the specified
 getter and setter selectors to the class."
| anObjectTable |
anObjectTable := AbtCOBOLLangParser parseFile: 'atm.cpy'.
AbtRecordGenerator new
    generateAllFieldsFrom: (anObjectTable cobol01s
            at: 'ATM-CUSTOMER' asSmalltalkGlobalIdentifier)
    inClass: SampleCOBOLATMStruct.

If IBM Smalltalk encounters any errors during processing, an error message appears in the System Transcript window.

Note:If your source file contains C #include directives or COBOL COPY statements, IBM Smalltalk will also parse the specified files. If those files are not in the current working directory, you must set the environment variable INCLUDE (for C) or COBCPY (for COBOL), indicating where the additional files are located.

The record wrapper class you created now includes the getter and setter methods for each of the fields in the structure. Open a Class Browser on the record wrapper class you just created (SampleCATMStruct or SampleCOBOLATMStruct) and you will see the getter and setter methods that were generated.

Tip icon
Selectors are not generated for nested arrays of complex types.

Performing code page conversion

When using a record structure that has been created on another platform, which most often occurs with communications parts, AbtForeignOSObject provides you with the capability to convert the information in the record structure to the proper code page. Send the message codePage: to the record structure to set the proper values for the code page for the platform on which the structure's information will be accessed, and send the message bigEndian: to indicate whether the platform on which the information will be accessed reads bytes from the "big end":

aRecordStructure codePage: 37; bigEndian: true
Note:If you are using a record that supports both IBM 370 SAA COBOL and MicroFocus COBOL, send the object table the forHostCobolSystem message when working with IBM 370 SAA COBOL, or the forLocalCobolSystem message when working with MicroFocus COBOL.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]