1 /* BEGINNING OF:    translator_temp_alloc.incl.pl1            *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  */
 2 
 3           /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * */
 4           /*                                                                                        */
 5           /* N^H__^Ha_^Hm_^He:  translator_temp_alloc.incl.pl1                                                */
 6           /*                                                                                        */
 7           /*      This include segment allocates space in a translator's temporary segment.  It     */
 8           /* contains a complete space allocation function 'allocate' which can be a quick PL/I     */
 9           /* internal procedure in the program which includes this include segment.  The temporary  */
10           /* segment should be one obtained by using the translator_temp_ subroutine.               */
11           /*                                                                                        */
12           /* S^H__^Ht_^Ha_^Ht_^Hu_^Hs                                                                                   */
13           /*                                                                                        */
14           /* 0) Created by:  G. C. Dixon  in  January, 1975.                                        */
15           /* 1) Modified by: G. C. Dixon  in  February, 1981 - use limit area structure.            */
16           /*                                                                                        */
17           /*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * */
18 
19 
20 
21 allocate: procedure (Parea, ANwords) returns (ptr);
22 
23      dcl  Parea                         ptr,                /* ptr to the temporary segment. (In)             */
24           ANwords                       fixed bin;          /* number of words to be allocated. (In)          */
25 
26      dcl  Nwords                        fixed bin,          /* number of words to be allocated, rounded up    */
27                                                             /* to a 0 mod 2 quantity.                         */
28           P                             ptr,                /* a temporary pointer.                           */
29           code                          fixed bin(35),      /* a status code.                                 */
30          (mod, null, ptr)               builtin;
31 
32      dcl  1 area                        based (Parea),
33             2 Pfirst_temp_seg           ptr unal,           /*   ptr to first temp seg of a group.            */
34             2 Ofree                     fixed bin(35),      /*   offset of next free word in temp seg.        */
35             2 Lfree                     fixed bin(35);      /*   length of remaining free space in temp seg.  */
36 
37      dcl  translator_temp_$get_next_segment
38                                         entry (ptr, ptr, fixed bin(35));
39 
40           Nwords = ANwords + mod (ANwords, 2);              /* round up word count to 0 + mod 2 quantity.     */
41           if Nwords > Lfree then do;                        /* handle area overflow.                          */
42                call translator_temp_$get_next_segment (Parea, P, code);
43                if P = null then return (null);
44                Parea = P;
45                if Nwords > area.Lfree then return (null);
46                end;
47           P = ptr (Parea, area.Ofree);                      /* get pointer to next free word of area.         */
48           area.Ofree = area.Ofree + Nwords;                 /* increase offset of remaining free space.       */
49           area.Lfree = area.Lfree - Nwords;                 /* decrease length of remaining free space.       */
50           return (P);
51 
52           end allocate;
53 
54 /* END OF:          translator_temp_alloc.incl.pl1            *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  */