Variable structure and pictures
-------------------------------

Let us examine an example of compiled variable to see how it is represented
internally.
Suppose the following declaration in COBOL source:
   
	   01  TEST1  PIC  Z.Z(3).ZZ9,9(2).

it generates the assembly code:

# Field: TEST1, Stack loc: [bp-12], Desc: v_base+0
	.word	12                       
	.byte	'E',1,0
	.long	v_base+9	# v_base+9(hex)
	.byte	'Z',1
	.byte	'.',1
	.byte	'Z',3
	.byte	'.',1
	.byte	'Z',2
	.byte	'9',1
	.byte	',',1
	.byte	'9',2
	.byte	0

Obviously the first line is just a comment with 2 properties: Stack loc is the
location at the stack frame where this variable's space is allocated. The
second is the address (relative to v_base) of where the variable descriptor is.

A variable descriptor has a corresponding C struct like this:

struct fld_desc {
	unsigned short len; 
	char type;         
	unsigned char decimals;
	unsigned char times;
	char *pic;
};

Where "len" is the full storage for this variable in bytes,
"type" describes what kind of variable it is (see table below),
"decimals", where appropriate tells how many digits exists
     after the decimal point,
"times", if the variable is an array, how many times it is repeated,
"pic" is a pointer to its (compressed format) picture.

The compressed format of a picture is just a string of pairs of characters 
and 8-bit unsigned counts like this:

<picchar1> <count1> <picchar2> <count2> ...

At the library file pictures.c, there is a routine (mc_picexpand) 
to expand this picture at runtime and return an malloc char string. 
For the example given above, its
return string would be:

        Z.ZZZ.ZZ9,99

You can test this by recompiling the library with -DPICTURE_TESTING and
compiling and linking test07.cob. It will print the string, instead of
returning it.
If you use this in your functions, don't forget to free this string space.


Table:
Picture characters and fld_desc->type
-------------------------------------
pic   description              type
-------------------------------------
A     alphabetic                A
X     alphanumeric              X
Z     left (eliminatable) digit   E
9     numeric                   9
,     decimal point             E
V     decimal point             E
P
S     sign
0 \   
B  |
/  |
.  |
+  |  all those characters
-  |  don't change the "type"
*  |
$ /
-------------------------------------

Rildo Pragana

