1  #include "config.h"
       2  #include <ctf-api.h>
       3  #include <stdio.h>
       4  #include <stdlib.h>
       5  #include <string.h>
       6  
       7  int
       8  main (int argc, char *argv[])
       9  {
      10    ctf_archive_t *ctf;
      11    ctf_dict_t *a_fp, *ignore1_fp, *b_fp, *ignore2_fp, *tmp_fp;
      12    int err;
      13    ctf_id_t a, b, ignore1, ignore2, tmp;
      14    char *foo;
      15  
      16    if (argc != 2)
      17      {
      18        fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]);
      19        exit(1);
      20      }
      21  
      22    if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
      23      goto open_err;
      24  
      25    /* Fish out each symbol in turn: also try to fish out a nonexistent one.  */
      26  
      27    if ((a_fp = ctf_arc_lookup_symbol_name (ctf, "a", &a, &err)) == NULL)
      28      goto sym_err;
      29    printf ("Type of a is %s\n", foo = ctf_type_aname (a_fp, a));
      30  
      31    if ((b_fp = ctf_arc_lookup_symbol_name (ctf, "b", &b, &err)) == NULL)
      32      goto sym_err;
      33    printf ("Type of b is %s\n", foo = ctf_type_aname (b_fp, b));
      34  
      35    if ((ignore1_fp = ctf_arc_lookup_symbol_name (ctf, "ignore1", &ignore1, &err)) == NULL)
      36      goto sym_err;
      37    printf ("Type of ignore1 is %s\n", foo = ctf_type_aname (ignore1_fp, ignore1));
      38  
      39    if ((ignore2_fp = ctf_arc_lookup_symbol_name (ctf, "ignore2", &ignore2, &err)) == NULL)
      40      goto sym_err;
      41    printf ("Type of ignore2 is %s\n", foo = ctf_type_aname (ignore2_fp, ignore1));
      42  
      43    /* Try a call in just-get-the-dict mode and make sure it doesn't fail.  */
      44    if ((tmp_fp = ctf_arc_lookup_symbol_name (ctf, "ignore2", NULL, &err)) == NULL)
      45      goto sym_err;
      46    ctf_dict_close (tmp_fp);
      47  
      48    /* Make sure failures fail.  */
      49    if  ((ctf_arc_lookup_symbol_name (ctf, "nonexistent", NULL, &err) != NULL)
      50         || err != ECTF_NOTYPEDAT)
      51      goto nosym_err;
      52  
      53    /* Fish them out again to check the caching layer.  */
      54    if (((tmp_fp = ctf_arc_lookup_symbol_name (ctf, "a", &tmp, &err)) != a_fp)
      55        || (tmp != a))
      56      goto sym_cache_err;
      57    ctf_dict_close (tmp_fp);
      58  
      59    if (((tmp_fp = ctf_arc_lookup_symbol_name (ctf, "b", &tmp, &err)) != b_fp)
      60        || (tmp != b))
      61      goto sym_cache_err;
      62    ctf_dict_close (tmp_fp);
      63  
      64    if (((tmp_fp = ctf_arc_lookup_symbol_name (ctf, "ignore1", &tmp, &err)) != ignore1_fp)
      65        || (tmp != ignore1))
      66      goto sym_cache_err;
      67    ctf_dict_close (tmp_fp);
      68  
      69    if (((tmp_fp = ctf_arc_lookup_symbol_name (ctf, "ignore2", &tmp, &err)) != ignore2_fp)
      70        || (tmp != ignore2))
      71      goto sym_cache_err;
      72    ctf_dict_close (tmp_fp);
      73  
      74    ctf_dict_close (a_fp);
      75    ctf_dict_close (b_fp);
      76    ctf_dict_close (ignore1_fp);
      77    ctf_dict_close (ignore2_fp);
      78    ctf_close (ctf);
      79  
      80    return 0;
      81  
      82   open_err:
      83    fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
      84    return 1;
      85   sym_err:
      86    fprintf (stderr, "%s: Symbol lookup error: %s\n", argv[0], ctf_errmsg (err));
      87    return 1;
      88   nosym_err:
      89    fprintf (stderr, "%s: Nonexistent symbol lookup unexpected error: %s\n", argv[0],
      90  	   ctf_errmsg (err));
      91    return 1;
      92   sym_cache_err:
      93    fprintf (stderr, "%s: Symbol re-lookup error (caching bug): %s\n", argv[0],
      94  	   ctf_errmsg (err));
      95    return 1;
      96  }