cont tbl_errmsg.3

Go back to listing by section, keyword search or top of cont man page tree.




TBLLIB(3)                                                           TBLLIB(3)



NAME
    tbl read, tbl name, tbl node, tbl int, tbl param, tbl errmsg, tbl errend


LIBRARY
    table handling library for KEK-Linac (tbllib.a)


SYNOPSYS
    #include "tbl.h"
    extern int tbl errno, tbl lines;

    int tbl read(
            const char *tblabbr ) ;

    char *tbl name(
            int n ) ;

    char *tbl node(
            const char *name ) ;
    int tbl int(
            const char *name,
            const char *keyword,
            int *value )
    int tbl param(
            const char *name,
            int *values )

    int tbl errmsg(
            char *errmsg )
    int tbl errend( )



PARAMETERS

    tblabbr   In tbl read(), tblabbr is a abbreviated name of the table to be
              read-in. For the case of tblabbr="out16", tbl read() try to
              read "/usr/users/control/tbl/out16tbl.tbl". Default directry
              (in this case "/usr/users/control/tbl") is predefined in
              "tbl.h", and may differ for other computer systems (DOS, OS-9,
              etc.).

    tbl lines After the successful completion of tbl read(), tbl lines
              contains number of recoreds (lines) in the table.

    n         In tbl name(), n is the serial-number of the records (0,1,2,..)
              in the table. tbl name() returns the string written in the
              specified table in the NAME field at the n-th record.

    name      In tbl node(), tbl int(), tbl param() functions, name is used
              as a pilot to determine the record number. For example,
              tbl node() returns the string written in NODE filed, which is
              at the same record where the specified name is found.

    keyword   Typical table contains many interger field, and each filed is
              identified with a keyword.

    value     tbl int() returns an integer value, which is in the field
              identified by keyword, in the record determined with name.

    values    tbl param() returns all integer values, which are defined in
              the record determined with specified name.

    errmsg    tbl errmsg() is used just after other tbl xx() functions.
              tbl errmsg() pick-up an appropriate error message (or infor-
              mation) to inform the origin of the error.
              tbl errend() print-outs a message, then terminate the program.

    tbl errno Used internally by tbl xx() functions. Error code (zero when
              successful, negative when error) is saved here. Error codes are
              defined in "tbl.h".



DESCRIPTION

    For tables with the format used at KEK-Linac, tbl xx() functions provide
  functionalities to read parameters in tables.
    Typical table is shown below (this is part of the adc12tbl.tbl):

   !
   !       adc12tbl.tbl    t.o. & n.k.     Feb.1995
   !
   !separator = '  '
   !keyword   = "NAME      NODE    BASE    TYPE    CH      MIN     MAX"
   !format    = "%s        %s      %x      %x      %d      %d      %d"
   !
   T1-1    hatsuhi fc480000        301     0       0       10
   T1-2    hatsuhi fc480000        301     1       0       10
   T2-1    hatsuhi fc480000        301     2       0       10
   T2-2    hatsuhi fc480000        301     3       0       10

    a) "!" at the beginning of lines indicate comment lines.
    b) "separator" is a field separator (usually TAB). It is  used in
       "keyword" and "format".
    c) "keyword" indicates names of fields.
    d) "format" indicates read-in format (scanf() format) for each field.
    e) NAME and NODE fields should be string-type and appear always at the
       beginning of "keyword".
    f) NAME field should exist always, while NODE field is not.

    The above example shows first 4 records of the table. Each record con-
  tains NAME field (string), NODE field (string) and five integer fields
  (BASE, etc.). The procedure to use tbllib functions is as follows:

    The tbl read() function read the table specified.
    The tbl errend() function is used to indicate error message and to ter-
  minate the program.
      rtn = tbl read( "adc12" );          /* read the table */
      if( rtn < 0 )  tbl errend();        /* exit with message when error */
      printf( "# of data is %d0, tbl lines );     /* print # of data */

    The tbl node() function return the NODE field at the record of specified
  name. It returns NULL when name is not found in the table.
      if( tbl node( "T2-1" ) != NULL ) {  /* print NODE field of "T2-1" */
        printf( "NODE is '%s'0, tbl node("T2-1")
      }                                   /* result will be "hatsuhi" */

    The tbl int() function return the integer field specified by keyword.
  Note that the argument of variable (type and ch, in the above case) is
  address-type.
      tbl int( "T1-2", "TYPE", &type );   /* get type field */
      tbl int( "T1-2", "CH", &ch );       /* get channel(CH) field */
      printf( "BASE,TYPE is %x,%d0, type,ch );    /* result will be 301,1 */

    The tbl param() function can be used to get all of integer fields.
      int values[5];
      tbl param( "T2-2", values )         /* get interger fields */
      printf( "param. are %x,%x,%d,..0,
        values[0],values[1],values[2] );  /* result: fc480000,301,3,.. */

    The tbl name() function is a different from others. It returns a string
  of NAME field.
      if( tbl name( 2 ) != NULL ) {
        printf( "3rd name is '%s'0, tbl name( 2 ) );
      }                                   /* result will be "T2-1" */



NOTES

    Current version of tbllib.a accepts the record number of 380 and 14
  integer fields. These maximum numbers are predefined in the "tbl.h" as
  N BUFMAX and N KEYS. You may find different versions with smaller buffer
  sizes (tbl16.a, tbl128.a, etc.). Those are prefarable for smaller tables in
  order to save compuetr memory.



RETURN VALUES

    On successful completion, the tbl read(), tbl int(), and tbl param()
  functions return zero. Otherwise, return negative value depending on the
  error status.

    On successful completion, the tbl node() and tbl name() functions return
  a pointer to the resulting string. Otherwise, these functions return a null
  pointer.

    The tbl errend() and tbl errmsg() functions return always zero.



RELATED INFORMATION

    tblkey(1), tblchk(1)