diff options
Diffstat (limited to 'src/plist.c')
| -rw-r--r-- | src/plist.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/plist.c b/src/plist.c index 2d2a832..73cdffc 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -29,6 +29,29 @@ const char *plist_base = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ | |||
| 29 | <plist version=\"1.0\">\n\ | 29 | <plist version=\"1.0\">\n\ |
| 30 | </plist>\0"; | 30 | </plist>\0"; |
| 31 | 31 | ||
| 32 | char* format_string(char* buf, int cols, int depth) | ||
| 33 | { | ||
| 34 | int colw = depth + cols + 1; //new buf cols width | ||
| 35 | int len = strlen(buf); | ||
| 36 | //int nlines = ceil((float)len / (float)cols); | ||
| 37 | int nlines = len / cols + 1; | ||
| 38 | char* new_buf = (char*)malloc(nlines * colw + depth + 1); | ||
| 39 | int i = 0; | ||
| 40 | int j = 0; | ||
| 41 | for (i = 0; i < nlines; i++){ | ||
| 42 | new_buf[i * colw] = '\n'; | ||
| 43 | for (j = 0; j < depth; j++) | ||
| 44 | new_buf[i * colw + 1 + j] = '\t'; | ||
| 45 | memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, cols); | ||
| 46 | } | ||
| 47 | new_buf[len+(1+depth)*nlines] = '\n'; | ||
| 48 | for (j = 0; j < depth; j++) | ||
| 49 | new_buf[len+(1+depth)*nlines + 1 + j] = '\t'; | ||
| 50 | new_buf[len+(1+depth)*nlines+depth+1] = '\0'; | ||
| 51 | free(buf); | ||
| 52 | return new_buf; | ||
| 53 | } | ||
| 54 | |||
| 32 | xmlDocPtr new_plist() { | 55 | xmlDocPtr new_plist() { |
| 33 | char *plist = strdup(plist_base); | 56 | char *plist = strdup(plist_base); |
| 34 | xmlDocPtr plist_xml = xmlReadMemory(plist, strlen(plist), NULL, NULL, 0); | 57 | xmlDocPtr plist_xml = xmlReadMemory(plist, strlen(plist), NULL, NULL, 0); |
| @@ -62,10 +85,17 @@ xmlNode *add_key_str_dict_element(xmlDocPtr plist, xmlNode *dict, const char *ke | |||
| 62 | return keyPtr; | 85 | return keyPtr; |
| 63 | } | 86 | } |
| 64 | 87 | ||
| 88 | xmlNode *add_key_dict_node(xmlDocPtr plist, xmlNode *dict, const char *key, const char *value, int depth) { | ||
| 89 | xmlNode *child; | ||
| 90 | add_child_to_plist(plist, "key", key, dict, depth); | ||
| 91 | child = add_child_to_plist(plist, "dict", value, dict, depth); | ||
| 92 | return child; | ||
| 93 | } | ||
| 94 | |||
| 65 | xmlNode *add_key_data_dict_element(xmlDocPtr plist, xmlNode *dict, const char *key, const char *value, int depth) { | 95 | xmlNode *add_key_data_dict_element(xmlDocPtr plist, xmlNode *dict, const char *key, const char *value, int depth) { |
| 66 | xmlNode *keyPtr; | 96 | xmlNode *keyPtr; |
| 67 | keyPtr = add_child_to_plist(plist, "key", key, dict, depth); | 97 | keyPtr = add_child_to_plist(plist, "key", key, dict, depth); |
| 68 | add_child_to_plist(plist, "data", value, dict, depth); | 98 | add_child_to_plist(plist, "data", format_string(value, 60, depth), dict, depth); |
| 69 | return keyPtr; | 99 | return keyPtr; |
| 70 | } | 100 | } |
| 71 | 101 | ||
