Created
April 24, 2015 18:47
-
-
Save mlabbe/5586f0f73b1029578547 to your computer and use it in GitHub Desktop.
libplist example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 7 dictionary keys: | |
| Nice is type number | |
| OnDemand is type bool | |
| ProgramArguments is type dict | |
| StandardErrorPath is type string | |
| StandardOutPath is type string | |
| StartInterval is type number | |
| label is type string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <prop/proplib.h> | |
| const char IN_PATH[]="./sample1.plist"; | |
| static void PrintType(prop_object_t object) | |
| { | |
| switch( prop_object_type(object) ) | |
| { | |
| case PROP_TYPE_BOOL: | |
| printf("bool"); | |
| break; | |
| case PROP_TYPE_NUMBER: | |
| printf("number"); | |
| break; | |
| case PROP_TYPE_STRING: | |
| printf("string"); | |
| break; | |
| case PROP_TYPE_DATA: | |
| printf("data"); | |
| break; | |
| case PROP_TYPE_ARRAY: | |
| printf("dict"); | |
| break; | |
| case PROP_TYPE_DICT_KEYSYM: | |
| printf("keysym"); | |
| break; | |
| default: | |
| printf("unknown"); | |
| } | |
| } | |
| int main(void) | |
| { | |
| // parse buffer with dict root | |
| prop_dictionary_t dict = prop_dictionary_internalize_from_file(IN_PATH); | |
| // Get keys for iteration | |
| prop_array_t keys = prop_dictionary_all_keys(dict); | |
| printf("%i dictionary keys:", prop_array_count(keys) ); | |
| // Iterate over keys | |
| prop_object_iterator_t iter = prop_array_iterator(keys); | |
| prop_object_t current_key; | |
| while( (current_key = prop_object_iterator_next(iter)) != NULL ) | |
| { | |
| if ( prop_object_type(current_key) == PROP_TYPE_DICT_KEYSYM ) | |
| { | |
| printf("%s is type ", | |
| prop_dictionary_keysym_cstring_nocopy((prop_dictionary_keysym_t)current_key)); | |
| prop_object_t value = prop_dictionary_get_keysym(dict, (prop_dictionary_keysym_t)current_key); | |
| PrintType(value); | |
| puts(""); | |
| } | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>label</key> | |
| <string>com.devdaily.pingwebsites</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/Users/al/bin/crontab-test.sh</string> | |
| </array> | |
| <key>OnDemand</key> | |
| <false/> | |
| <key>Nice</key> | |
| <integer>1</integer> | |
| <key>StartInterval</key> | |
| <integer>60</integer> | |
| <key>StandardErrorPath</key> | |
| <string>/tmp/AlTest1.err</string> | |
| <key>StandardOutPath</key> | |
| <string>/tmp/AlTest1.out</string> | |
| </dict> | |
| </plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment