15.6. Using macros in command scripts

You can use macros in command scripts to perform complex operations that cannot be done with CLI commands alone.

Example 15.1 shows an example command script with a macro.

Example 15.1. Example command script with a macro

// The C-style escape character \\ is used in the FOPEN command and fopen()
// macro, because the path is in double quotes.
// You can use single quotes in the FOPEN command without the escape character,
// but you cannot use single quotes in the fopen() predefined macro.
FOPEN 200, "c:\\myfiles\\data.txt"
FPRINTF 200, "message printed to user-defined file"
VCLOSE 200

define /R void read_msg()
{
    char buffer[37];
    int nbytes;
    int retval;
    retval = fopen(250,"c:\\myfiles\\data.txt","r"); // open for read-only
    if (retval < 0)
        error(2,"Source file not opened!\n",101);
    else {
        nbytes = fread(buffer, 1, 21, 250);
        $FPRINTF 1, "%s\n", buffer$;                // Output to Code window
        fclose(250);                                 // Close file
    }
}
.
// Run the macro
read_msg()

You can also use CLI commands within macros, if required. However, RealView Debugger prohibits the use of some commands in macros.

See also:

Copyright © 2002-2011 ARM. All rights reserved.ARM DUI 0153N
Non-ConfidentialID052111