diff options
Diffstat (limited to 'tools/idevicesyslog.c')
-rw-r--r-- | tools/idevicesyslog.c | 82 |
1 files changed, 59 insertions, 23 deletions
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c index 1415040..67eaf69 100644 --- a/tools/idevicesyslog.c +++ b/tools/idevicesyslog.c | |||
@@ -690,6 +690,64 @@ static int write_callback(const void* buf, size_t len, void *user_data) | |||
690 | return 0; | 690 | return 0; |
691 | } | 691 | } |
692 | 692 | ||
693 | static void print_sorted_pidlist(plist_t list) | ||
694 | { | ||
695 | struct listelem; | ||
696 | struct listelem { | ||
697 | int val; | ||
698 | struct listelem *next; | ||
699 | }; | ||
700 | struct listelem* sortedlist = NULL; | ||
701 | |||
702 | plist_dict_iter iter = NULL; | ||
703 | plist_dict_new_iter(list, &iter); | ||
704 | if (iter) { | ||
705 | plist_t node = NULL; | ||
706 | do { | ||
707 | char* key = NULL; | ||
708 | node = NULL; | ||
709 | plist_dict_next_item(list, iter, &key, &node); | ||
710 | if (key) { | ||
711 | int pidval = (int)strtol(key, NULL, 10); | ||
712 | struct listelem* elem = (struct listelem*)malloc(sizeof(struct listelem)); | ||
713 | elem->val = pidval; | ||
714 | elem->next = NULL; | ||
715 | struct listelem* prev = NULL; | ||
716 | struct listelem* curr = sortedlist; | ||
717 | |||
718 | while (curr && pidval > curr->val) { | ||
719 | prev = curr; | ||
720 | curr = curr->next; | ||
721 | } | ||
722 | |||
723 | elem->next = curr; | ||
724 | if (prev == NULL) { | ||
725 | sortedlist = elem; | ||
726 | } else { | ||
727 | prev->next = elem; | ||
728 | } | ||
729 | free(key); | ||
730 | } | ||
731 | } while (node); | ||
732 | plist_mem_free(iter); | ||
733 | } | ||
734 | struct listelem *listp = sortedlist; | ||
735 | char pidstr[16]; | ||
736 | while (listp) { | ||
737 | snprintf(pidstr, 16, "%d", listp->val); | ||
738 | plist_t node = plist_dict_get_item(list, pidstr); | ||
739 | if (PLIST_IS_DICT(node)) { | ||
740 | plist_t pname = plist_dict_get_item(node, "ProcessName"); | ||
741 | if (PLIST_IS_STRING(pname)) { | ||
742 | printf("%d %s\n", listp->val, plist_get_string_ptr(pname, NULL)); | ||
743 | } | ||
744 | } | ||
745 | struct listelem *curr = listp; | ||
746 | listp = listp->next; | ||
747 | free(curr); | ||
748 | } | ||
749 | } | ||
750 | |||
693 | static void device_event_cb(const idevice_event_t* event, void* userdata) | 751 | static void device_event_cb(const idevice_event_t* event, void* userdata) |
694 | { | 752 | { |
695 | if (use_network && event->conn_type != CONNECTION_NETWORK) { | 753 | if (use_network && event->conn_type != CONNECTION_NETWORK) { |
@@ -1042,29 +1100,7 @@ int main(int argc, char *argv[]) | |||
1042 | if (!list) { | 1100 | if (!list) { |
1043 | return 1; | 1101 | return 1; |
1044 | } | 1102 | } |
1045 | plist_sort(list); | 1103 | print_sorted_pidlist(list); |
1046 | plist_dict_iter iter = NULL; | ||
1047 | plist_dict_new_iter(list, &iter); | ||
1048 | if (iter) { | ||
1049 | plist_t node = NULL; | ||
1050 | do { | ||
1051 | char* key = NULL; | ||
1052 | node = NULL; | ||
1053 | plist_dict_next_item(list, iter, &key, &node); | ||
1054 | if (key) { | ||
1055 | printf("%s", key); | ||
1056 | free(key); | ||
1057 | if (PLIST_IS_DICT(node)) { | ||
1058 | plist_t pname = plist_dict_get_item(node, "ProcessName"); | ||
1059 | if (PLIST_IS_STRING(pname)) { | ||
1060 | printf(" %s", plist_get_string_ptr(pname, NULL)); | ||
1061 | } | ||
1062 | } | ||
1063 | printf("\n"); | ||
1064 | } | ||
1065 | } while (node); | ||
1066 | plist_mem_free(iter); | ||
1067 | } | ||
1068 | plist_free(list); | 1104 | plist_free(list); |
1069 | return 0; | 1105 | return 0; |
1070 | } else if (!strcmp(argv[0], "archive")) { | 1106 | } else if (!strcmp(argv[0], "archive")) { |