Example project with local resources

The following describes an example C project with local resources. The contents of files and configuration settings are provided as plain text rather than screen shots, so you can drag and drop from this help page.

Alternatively you can click here to let Eclipse create the project for you. You must then select a connection to a BS2000 system, and you can specify another name for the project.

This example project expects the following products and/or subsystems on the BS2000 system:
  • SDF-P as of V2.4A
  • C/C++ as of V2.2D

Creating the project and its resources

Project demo1

We start with creating a new Remote Build Project demo1, see BS2000 Remote Build Projects. In this project we then create three folders common, hello, and tools. Within these folders we create the following files:

Header file common/person.h

#ifndef __PERSON_H
#define __PERSON_H

#define PERSON_NAME_LENGTH 10

struct Person {
    char firstName[PERSON_NAME_LENGTH];
    char lastName[PERSON_NAME_LENGTH];
};

#endif

Header file common/initialize.h

#ifndef __INITIALIZE_H
#define __INITIALIZE_H

#include "person.h"

void initialize(struct Person *);

#endif

Source file common/initialize.c

#include "initialize.h"

void initialize(struct Person *person) {
    strncpy(person->firstName, "Fred",       PERSON_NAME_LENGTH);
    strncpy(person->lastName,  "Flintstone", PERSON_NAME_LENGTH);
}

Source file hello/main.c

#include <stdio.h>
#include "person.h"
#include "initialize.h"

int main () {
    struct Person user;
    initialize(&user);
    printf("Hello %s!\n", user.firstName);
    return 0;
}

Command procedure tools/cplus

/BEGIN-PARAMETER-DECLARATION  "Compile a C source"
/    DECLARE-PARAMETER  LIB (TYPE = STRING)
/    DECLARE-PARAMETER  SRC (TYPE = STRING)
/END-PARAMETER-DECLARATION
/START-CPLUS-COMPILER
//MODIFY-SOURCE-PROPERTIES LANGUAGE = *C
//MODIFY-LISTING-PROPERTIES                                        -
//   SOURCE          = *YES,                                       -
//   OUTPUT          = *LIBRARY-ELEMENT (LIBRARY = &LIB),          -
//   CROSS-REFERENCE = *YES (VAR = *NO, FUNC = *NO, LABELS = *NO), -
//   OPTIONS         = *YES,                                       -
//   SUMMARY         = *YES
//MODIFY-INCLUDE-LIBRARIES                                         -
//   USER-INCLUDE-LIBRARY = (DELEGATES.DEMO1.COMMON,               -
//                           DELEGATES.DEMO1.HELLO)
//MODIFY-OPTIMIZATION-PROPERTIES LEVEL = *LOW
//MODIFY-TEST-PROPERTIES TEST-SUPPORT = *YES
//COMPILE *LIBRARY-ELEMENT (LIBRARY = &LIB , ELEMENT = &SRC..C),   - 
//   MODULE-OUTPUT = *LIBRARY-ELEMENT (LIBRARY = &LIB, ELEMENT = &SRC)
//STEP
//END
/EXIT-PROCEDURE
The //STEP statement guarantees that the procedures returns with exit code 0 even if the compiler encounters syntax errors.

Command procedure tools/bind

/REMARK Bind the application
/START-BINDER
//START-LLM-CREATION INTERNAL-NAME = HELLO, -
//    INCLUSION-DEFAULTS = *PARAMETERS (TEST-SUPPORT = *YES)
//INCLUDE-MODULES MODULE-CONTAINER = -
//    *LIBRARY-ELEMENT (LIBRARY = DELEGATES.DEMO1.HELLO)
//RESOLVE-BY-AUTOLINK LIBRARY = -
//    ($TSOS.SYSLNK.CRTE, DELEGATES.DEMO1.COMMON)
//SAVE-LLM LIBRARY = DEMO1, OVERWRITE = *YES, -
//    MAP = *NO, TEST-SUPPORT = *YES
//END
/EXIT-PROCEDURE
This procedure does neither contain a /SET-JOB-STEP command nor a //STEP statement. Possible errors will be reported to the caller with an exit code different from 0.

Command procedure tools/clean

/REAMRK Clean derived resources
/DELETE-FILE DELEGATES.DEMO1.*
/SET-JOB-STEP 
/DELETE-FILE DEMO1 
/SET-JOB-STEP
/EXIT-PROCEDURE
The /SET-JOB-STEP commands guarantee that this procedure returns with exit code 0 even if the files should not exist.

Command procedure tools/run

/REMARK   "Run the program"
/START-EXECUTABLE-PROGRAM (LIBRARY = DEMO1, ELEMENT = HELLO), TEST-OPTIONS = *AID
/EXIT-PROCEDURE

Defining delegate rules

For remote compilation of the local source files we need to define delegates, see Remote compilation of local files. We decide to associate a remote delegates library delegates.demo1.folder with each local folder. This can be achieved with the following universal rule:

Delegate rule for the entire project demo1

Delegate Rule: Folder PLAM library
Library name prefix: delegates
Element type: s

Delegate rule for the folder tool

For the folder demo1/tools we wish to define delegates of element type j rather than s. Thus we need to define another rule for that folder differing from the universal rule only in the element type:
Delegate Rule: Folder PLAM library
Library name prefix: delegates
Element type: j

Defining commands

To call the command procedures provided in demo1/tools we need to define commands and compilation rules, see Defining Compile Commands and Defining Compile Rules. Note, the command procedures are stored locally but will be transferred to their delegates in delegates.demo1.tools/j/, and the commands must call these delegates. We define the following commands and rules:

Compile command cplus - demo1

/CALL-PROC (LIB = DELEGATES.DEMO1.TOOLS, ELEM = CPLUS), (LIB = &{src-full-lib-name}, SRC = &{source})
The called procedure returns with exit code 0 even if the compiler encountered syntax errors, so the default setting of expected exit codes is all right.

Compile rule cplus - demo1

Name: cplus - demo1
Source file type: PLAM library elements
Source pattern: */s/&{source}.c
Listing expression: &{src-full-lib-name}/p/&{source}.lst
Command: cplus - demo1

This compile rule must then be configured to be the only one selected for project demo1, see BS2000 Remote Build Projects.

Command bind - demo1

/CALL-PROC (LIB = DELEGATES.DEMO1.TOOLS, ELEM = BIND)
See BS2000 Remote Build Projects how to configure this command as post-build command for project demo1. In case of problems the called procedure will return with an exit code other than 0. Such exit codes should be treated as bad causing the build to fail. Thus the default setting of 0 as expected good exit code is all right.

Command clean - demo1

/CALL-PROC (LIB = DELEGATES.DEMO1.TOOLS, ELEM = CLEAN)
See BS2000 Remote Build Projects how to configure this command for project demo1. The called procedure always returns with exit code 0, so the default setting of expected exit codes is all right.

Command run - demo1

/CALL-PROC (LIB = DELEGATES.DEMO1.TOOLS, ELEM = RUN)
See Run and Debug Configurations how to configure this command for project demo2.

Building the project

Now we should be able to build the project e.g. by pressing Ctrl+B, see BS2000 Remote Build Projects. Afterwards we can run the created program by calling the procedure demo1/tools/run with the default call command for library elements, see Remote Command Procedure Call. Note, this will actually call its delegate delegates.demo1.tools/j/run. As result "Hello Fred!" should be displayed in the console view.