10.8.7. General-Purpose Copy Routine

The cpy_tbl.h file in Copy Table Contents also contains a prototype for a general-purpose copy routine, copy_in(), which is provided as part of the run-time-support library. The copy_in() routine takes a single argument: the address of a linker-generated copy table. The routine then processes the copy table data object and performs the copy of each object component specified in the copy table.

The copy_in() function definition is provided in the cpy_tbl.c run-time-support source file shown in the following example.

/*****************************************************************************/
/* cpy_tbl.c v#####                                                          */
/*                                                                           */
/* General-purpose copy routine. Given the address of a linker-generated     */
/* COPY_TABLE data structure, effect the copy of all object components       */
/* that are designated for copy via the corresponding LCF table() operator.  */
/*****************************************************************************/
#include <cpy_tbl.h>
#include <string.h>

typedef void (*handler_fptr)(const unsigned char *in, unsigned char *out)

/*****************************************************************************/
/* COPY_IN()                                                                 */
/*****************************************************************************/
void copy_in(COPY_TABLE *tp)
{
    unsigned short I;

    for (I = 0; I < tp->num_recs; I++)
    {
        COPY_RECORD crp = tp->recs[i];
        unsigned char *ld_addr = (unsigned char *)crp.load_addr;
        unsigned char *rn_addr = (unsigned char *)crp.run_addr;

        if (crp.size)
        {
            /*------------------------------------------------------------------*/
            /* Copy record has a non-zero size so the data is not compressed.   */
            /* Just copy the data.                                              */
            /*------------------------------------------------------------------*/
            memcpy(rn_addr, ld_addr, crp.size);
        }
    }
}