Diff for /wikisrc/examples/proplib.mdwn between versions 1.1 and 1.2

version 1.1, 2010/04/17 17:01:32 version 1.2, 2011/05/13 08:47:34
Line 4  Here's a little example code to show som Line 4  Here's a little example code to show som
   
 This will create a dictionary and store it as an xml file on the disk:  This will create a dictionary and store it as an xml file on the disk:
   
 int      int
 main()      main(void)
 {      {
    prop_dictionary_t d;          prop_dictionary_t d;
    bool r;          bool r;
   
    d = prop_dictionary_create();          d = prop_dictionary_create();
   
    if (d == NULL)          if (d == NULL)
        goto error;              goto error;
   
    r = prop_dictionary_set_cstring(d, "name", "Adam");          r = prop_dictionary_set_cstring(d, "name", "Adam");
    if (!r)          if (!r)
        goto error;              goto error;
    r = prop_dictionary_set_uint32(d, "year", 1986);          r = prop_dictionary_set_uint32(d, "year", 1986);
    if (!r)          if (!r)
        goto error;              goto error;
   
    r = prop_dictionary_externalize_to_file(d, "test.plist");          r = prop_dictionary_externalize_to_file(d, "test.plist");
    if (!r)          if (!r)
        goto error;              goto error;
   
    return EXIT_SUCCESS;          return EXIT_SUCCESS;
   
 error :          error :
    fprintf(stderr, "error\n");              fprintf(stderr, "error\n");
    return EXIT_FAILURE;              return EXIT_FAILURE;
 }      }
   
   
 And this will read it and display the values:  And this will read it and display the values:
   
 int      int
 main()      main(void)
 {      {
    prop_dictionary_t d;          prop_dictionary_t d;
    uint32_t year;          uint32_t year;
    char *name;          char *name;
    bool r;          bool r;
   
    d = prop_dictionary_internalize_from_file("test.plist");          d = prop_dictionary_internalize_from_file("test.plist");
    if (d == NULL)          if (d == NULL)
        goto error;              goto error;
   
    r = prop_dictionary_get_cstring(d, "name", &name);          r = prop_dictionary_get_cstring(d, "name", &name);
    if (!r)          if (!r)
        goto error;              goto error;
    r = prop_dictionary_get_uint32(d, "year", &year);          r = prop_dictionary_get_uint32(d, "year", &year);
    if (!r)          if (!r)
        goto error;              goto error;
   
    printf("name: %s, year: %u\n", name, year);          printf("name: %s, year: %u\n", name, year);
   
    return EXIT_SUCCESS;          return EXIT_SUCCESS;
   
 error :          error :
    fprintf(stderr, "error\n");              fprintf(stderr, "error\n");
    return EXIT_FAILURE;              return EXIT_FAILURE;
 }      }

Removed from v.1.1  
changed lines
  Added in v.1.2


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb