this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

make PlistBuddy print as apple does

Bob Pan 903320ab 3cddc192

+34 -42
+34 -42
src/PlistBuddy/PlistBuddy.c
··· 843 843 CFRelease(newValue); 844 844 } 845 845 846 - char* strtok_empty(char* str, char delim) 846 + static const char* strtok_empty(char** pstr, char delim) 847 847 { 848 - static char* src = NULL; 849 - char* p, *ret = NULL; 848 + char* p; 849 + char* str = *pstr; 850 850 851 - if (str != NULL) 852 - src = str; 851 + if (str == NULL) 852 + return NULL; 853 853 854 - if (src == NULL) 855 - return NULL; 854 + while (str[0] == delim) 855 + str++; 856 856 857 - if ((p = strchr (src, delim)) != NULL) 857 + if ((p = strchr (str, delim)) != NULL) 858 858 { 859 859 *p = '\0'; 860 - ret = src; 861 - src = ++p; 862 - } 863 - else 864 - { 865 - ret = src; 866 - src = NULL; 860 + *pstr = p + 1; 861 + } else { 862 + *pstr = NULL; 867 863 } 868 864 869 - return ret; 865 + return str; 870 866 } 871 867 872 868 void resolvePlistEntry(const char* whatStr, CFPropertyListRef* parent, CFPropertyListRef* entry, char** last, bool autoCreate) ··· 876 872 877 873 const char *tok, *lastTok = ""; 878 874 879 - if (whatStr[0] == ':') 875 + // trim head 876 + while (whatStr[0] == ':') 880 877 whatStr++; 881 878 882 - char* whatStr2 = strdup(whatStr); 883 - const char* finalTok = strrchr(whatStr2, ':'); 884 - 885 - if (finalTok == NULL) 886 - finalTok = whatStr2; 887 - else 888 - finalTok++; 879 + // trim tail 880 + size_t len = strlen(whatStr); 881 + while(len > 0 && whatStr[len - 1] == ':') { 882 + len--; 883 + } 889 884 890 - if (*whatStr2) 891 - tok = strtok_empty(whatStr2, ':'); 892 - else 893 - tok = NULL; 885 + char* whatStr2 = strndup(whatStr, len); 886 + char* p = whatStr2; 894 887 895 - while (tok != NULL && pos != NULL) 888 + while ((tok = strtok_empty(&p, ':')) && pos != NULL) 896 889 { 897 890 lastPos = pos; 898 891 if (*tok) ··· 903 896 { 904 897 CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, tok, kCFStringEncodingUTF8); 905 898 pos = (CFPropertyListRef) CFDictionaryGetValue((CFDictionaryRef) pos, key); 906 - 907 - if (pos == NULL && autoCreate && tok != finalTok) 899 + if (pos == NULL && autoCreate && p != NULL) 908 900 { 909 901 pos = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 910 902 CFDictionaryAddValue((CFMutableDictionaryRef) lastPos, key, pos); ··· 928 920 pos = NULL; 929 921 } 930 922 } 931 - else 932 - pos = NULL; 933 923 934 924 lastTok = tok; 935 - tok = strtok_empty(NULL, ':'); 936 925 } 937 926 938 927 if (last != NULL) ··· 975 964 printf("\n"); 976 965 } 977 966 978 - printf("%s}\n", indent); 967 + printf("%s}", indent); 979 968 } 980 969 else if (typeId == CFDictionaryGetTypeID()) 981 970 { ··· 1000 989 printf("\n"); 1001 990 } 1002 991 1003 - printf("%s}\n", indent); 992 + printf("%s}", indent); 1004 993 1005 994 free(keys); 1006 995 free(values); ··· 1063 1052 CFIndex len = CFDataGetLength(data); 1064 1053 1065 1054 fwrite(bytes, 1, len, stdout); 1066 - putchar('\n'); 1067 1055 } 1068 1056 } 1069 1057 1070 1058 void doPrint(const char* whatStr) 1071 1059 { 1072 1060 CFPropertyListRef what = plist; 1061 + CFPropertyListRef entry = plist; 1073 1062 1074 1063 if (whatStr != NULL) 1075 1064 { 1076 - resolvePlistEntry(whatStr, &what, NULL, NULL, false); 1077 - if (what == NULL) 1065 + resolvePlistEntry(whatStr, &what, &entry, NULL, false); 1066 + if (entry == NULL) 1078 1067 { 1079 1068 printf("Print: Entry, \"%s\", Does Not Exist\n", whatStr); 1080 1069 return; 1081 1070 } 1082 1071 } 1083 1072 1084 - if (!forceXML) 1085 - prettyPrintPlist(what, 0); 1073 + if (!forceXML) { 1074 + prettyPrintPlist(entry, 0); 1075 + printf("\n"); 1076 + } 1086 1077 else 1087 1078 { 1088 - CFDataRef data = CFPropertyListCreateXMLData(kCFAllocatorDefault, plist); 1079 + CFDataRef data = CFPropertyListCreateXMLData(kCFAllocatorDefault, entry); 1089 1080 1090 1081 if (data != NULL) 1091 1082 { 1092 1083 prettyPrintPlist(data, 0); 1084 + printf("\n"); 1093 1085 1094 1086 CFRelease(data); 1095 1087 }