Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought



PRINTF(3spp)        RISC/os Reference Manual         PRINTF(3spp)



NAME
     printf - formatted output conversion

SYNOPSIS
     #include <saio/saioctl.h>

     void printf(format [, arg ] ...  )
     char *format;

DESCRIPTION
     printf places output on the console.  Printf converts, for-
     mats, and prints its arguments to the screen as specified by
     the first argument.  The first argument is a character
     string that contains two types of objects:  plain charac-
     ters, which are simply copied to the output stream, and
     conversion specifications, which causes conversion and
     printing of the next successive arg.

     Each conversion specification is introduced by the character
     % followed by a conversion character.

     The conversion characters and their meanings are

     dox  The integer arg is converted to decimal, octal, or hex-
          adecimal notation, respectively.

     c    The character arg is printed.

     s    Arg is taken to be a string (character pointer) and
          characters from the string are printed until a null
          character.

     u    The unsigned integer arg is converted to decimal and
          printed.

     b    The conversion character is used to decode device error
          registers and other values made up of single bit flags.
          Two arguments are required by this format character.
          The first arg should be an integer, the second arg
          should be a null terminated string of the form
          "<base><bitfmt>*" where:

          <base> is either \10 for octal or \20 for hex

          Each <bitfmt> is a sequence of characters, the first of
          which gives the bit number to be inspected (origin 1)
          and the next characters (up to a control character,
          i.e., a character <= 32), give the name of the bit.
          Thus:

               printf("reg=%b0, 3, "102BITTWO1BITONE")




                         Printed 1/6/92                    Page 1





PRINTF(3spp)        RISC/os Reference Manual         PRINTF(3spp)



          would print

               reg=3<BITTWO,BITONE>


     rR   The %r and %R formats allow formatted prints of bit
          fields.  Both %r and %R require two arguments, the
          first arg should be an integer and the second arg
          should be a pointer to the first element of an array of
          struct reg_desc . Each bit field is described by a
          struct reg_desc, multiple bit fields within a single
          word can be described by an array of reg_desc struc-
          tures.  The r conversion character outputs a string of
          the format "<bit field descriptions>" The R conversion
          character outputs a string of the format "0x%x<bit
          field descriptions>"

     struct reg_desc is defined as:
     struct reg_desc {
          unsigned rd_mask;   /* mask to extract field */
          int rd_shift;       /* shift for extracted value, - >>, + << */
          char *rd_name;      /* field name */
          char *rd_format;    /* format to print field */
          struct reg_values *rd_values; /* symbolic names of values */
     };
     The fields in a struct reg_desc are:

     unsigned rd_mask
                    An appropriate mask to isolate the bit field
                    within a word.  A zero mask terminates the
                    array of struct  reg_desc.

     int rd_shift   A shift amount to be done to the isolated bit
                    field.  Shift is done before printing the
                    isolated bit field with rd_format and before
                    searching for symbolic value names in
                    rd_values.

     char *rd_name  If non-null, a bit field name to label any
                    output from rd_format or searching rd_values.
                    If both rd_format or rd_values are null,
                    rd_name is printed only if the isolated bit
                    field is non-null.

     char *rd_format
                    If non-null, the shifted bit field value is
                    printed using this format.

     struct reg_values *rd_values
                    If non-null, a pointer to a table pairing
                    numeric values with symbolic names.
                    Rd_values is searched and the symbolic name



 Page 2                  Printed 1/6/92





PRINTF(3spp)        RISC/os Reference Manual         PRINTF(3spp)



                    is printed if a match is found for the value
                    of the bit field.

     A struct reg_values is defined as:
     struct reg_values {
          unsigned rv_value;
          char *rv_name;
     };
     The fields in a struct reg_values are:

     unsigned rv_value
                    A numeric value for a bit field.

     char *rv_name  The symbolic name for this value.

     %              Print a `%'; no argument is converted.

     An example of a description for the R2000 cause registers
     follows:
     /*
      * CP0 cause register description
      */
     struct reg_values exc_values[] = {
          { EXC_INT,     "INT" },
          { EXC_MOD,     "MOD" },
          { EXC_RMISS,   "RMISS" },
          { EXC_WMISS,   "WMISS" },
          { EXC_RADE,    "RADE" },
          { EXC_WADE,    "WADE" },
          { EXC_IBE,     "IBE" },
          { EXC_DBE,     "DBE" },
          { EXC_SYSCALL, "SYSCALL" },
          { EXC_BREAK,   "BREAK" },
          { EXC_II, "II" },
          { EXC_CPU,     "CPU" },
          { EXC_OV, "OV" },
          { 0,      NULL },
     };

     struct reg_desc cause_desc[] = {
          /* mask        shift      name   format  values */
          { CAUSE_BD,    0,   "BD",     NULL,     NULL },
          { CAUSE_CEMASK,     -CAUSE_CESHIFT,     "CE",     "%d",     NULL },
          { CAUSE_IP8,   0,   "IP8",    NULL,     NULL },
          { CAUSE_IP7,   0,   "IP7",    NULL,     NULL },
          { CAUSE_IP6,   0,   "IP6",    NULL,     NULL },
          { CAUSE_IP5,   0,   "IP5",    NULL,     NULL },
          { CAUSE_IP4,   0,   "IP4",    NULL,     NULL },
          { CAUSE_IP3,   0,   "IP3",    NULL,     NULL },
          { CAUSE_SW2,   0,   "SW2",    NULL,     NULL },
          { CAUSE_SW1,   0,   "SW1",    NULL,     NULL },
          { CAUSE_EXCMASK,0,  "EXC",    NULL,     exc_values },



                         Printed 1/6/92                    Page 3





PRINTF(3spp)        RISC/os Reference Manual         PRINTF(3spp)



          { 0,      0,   NULL,     NULL,     NULL },
     };





















































 Page 4                  Printed 1/6/92



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026