Example of Code Generated by LIBMAKE

If you run LIBMAKE on Example 1, it generates the include file shown below.

Example 2 Include file generated by LIBMAKE:

 1
 2
 3 
 4 
 5 
 6 
 7 
 8 
 9
10
11
12 
13 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* C structs for database SALESORD at generation 0*/
#define SALESORD_GENERATION 0

#define _CUSTOMER 4107
#define _REGION 4104
struct CUSTOMER
{
  short l;
  short typenr;
  short generation;
  short flags;
  long timestamp;
  double customer_number;
  char region_code[3];
  char _p1000;
  char address[3][30];
  double credit_limit;
  double balance;
  char name[30];
  boolean credit_customer;
  char _p1001;
};
struct REGION
{
  short l;
  short typenr;
  short generation;
  short flags;
  long timestamp;
  char region_code[3];
  char _p1002;
  short employee_number;
  char name[30];
};
struct CUSTOMER customer = {sizeof(struct CUSTOMER),4107};
struct REGION region = {sizeof(struct REGION),4104};
void init()
{
  df_libtype = 1;
  db_open("SALESORD",0,SHARED+PRIVATE_DB);
  map_load("TEMPLATE");
}
void finish()
{
  db_close();
}

Lines 3-36 arise from the #tables directive in the example code, Lines 4, 6-22 and 35 from specifying customer. These lines of code enable you to use the C structure called customer to use records from the CUSTOMER table.

For example, the CUSTOMER_NUMBER field on the database corresponds to the C structure element customer.customer_number.

The other lines in this section allow you to use records from the REGION table similarly.

LIBMAKE also generates two functions, init() and finish(). When any DP4 C program runs, the function init() is called first. You will see that the function init contains a call to another function, db_open().

The function db_open() is discussed in Opening and Closing Databases. In this case, it opens the SALESORD database as a private database, because the example contains the #private directive.

Also, a call to the function map_load() appears on line 41 of the example above. This defines the mapset that you use within the program as being of the same name as your program. A mapset of the correct name must exist within the database defined with the #db directive. If you want to use a different mapset you can specify the #mapname directive, or you can call the map_load() function at any point in your program.