summaryrefslogtreecommitdiffstats
path: root/dev
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-11-25 19:14:27 +0100
committerGravatar Jonathan Beck2008-11-25 19:14:27 +0100
commitaed2c025f6e47dc769675e564cc574adc496a88a (patch)
tree6cb14e4c511dabc40fdf6c24714a2be48567f847 /dev
parent0bca81e7c8ce5ba53390271e5c7eaa7a5f281c91 (diff)
downloadlibplist-aed2c025f6e47dc769675e564cc574adc496a88a.tar.gz
libplist-aed2c025f6e47dc769675e564cc574adc496a88a.tar.bz2
fix some warnings and indent
Diffstat (limited to 'dev')
-rw-r--r--dev/lckdclient.c1
-rw-r--r--dev/main.c2
-rw-r--r--dev/plutil.c219
3 files changed, 115 insertions, 107 deletions
diff --git a/dev/lckdclient.c b/dev/lckdclient.c
index 96bc27d..c96f052 100644
--- a/dev/lckdclient.c
+++ b/dev/lckdclient.c
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <readline/readline.h>
diff --git a/dev/main.c b/dev/main.c
index 2dbfb4a..4974eef 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf);
if (IPHONE_E_SUCCESS ==
iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) {
- printf("A file size: %i\n", stbuf.st_size);
+ printf("A file size: %i\n", (int) stbuf.st_size);
char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size);
iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes);
if (bytes >= 0) {
diff --git a/dev/plutil.c b/dev/plutil.c
index 1c7b140..d1c3ddd 100644
--- a/dev/plutil.c
+++ b/dev/plutil.c
@@ -5,171 +5,178 @@
#include "../src/plist.h"
#include "plutil.h"
+#include <glib.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
-int debug = 0;
-
-void print_nodes(bplist_node *root_node) {
+void print_nodes(bplist_node * root_node)
+{
// Yay, great. Let's print the list of nodes recursively...
int i = 0;
- if (!root_node) return; // or not, because the programmer's stupid.
-
+ if (!root_node)
+ return; // or not, because the programmer's stupid.
+
switch (root_node->type) {
- case BPLIST_DICT:
- printf("Dictionary node.\nLength %i\n", root_node->length);
- for (i = 0; i < (root_node->length * 2); i+=2) {
- // HI!
- printf("Key: ");
- print_nodes(root_node->subnodes[i]);
- printf("Value: ");
- print_nodes(root_node->subnodes[i+1]);
- }
- printf("End dictionary node.\n\n");
- break;
-
- case BPLIST_ARRAY:
- printf("Array node.\n");
- for (i = 0; i < root_node->length; i++) {
- printf("\tElement %i: ", i);
- print_nodes(root_node->subnodes[i]);
- }
- break;
-
- case BPLIST_INT:
- if (root_node->length == sizeof(uint8_t)) {
- printf("Integer: %i\n", root_node->intval8);
- } else if (root_node->length == sizeof(uint16_t)) {
- printf("Integer: %i\n", root_node->intval16);
- } else if (root_node->length == sizeof(uint32_t)) {
- printf("Integer: %i\n", root_node->intval32);
- }
- break;
-
- case BPLIST_STRING:
- printf("String: ");
- fwrite(root_node->strval, sizeof(char), root_node->length, stdout);
- fflush(stdout);
- printf("\n");
- break;
-
- case BPLIST_DATA:
- printf("Data: ");
- char* data = g_base64_encode(root_node->strval,root_node->length);
- fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout);
- fflush(stdout);
- printf("\n");
- break;
-
- case BPLIST_UNICODE:
- printf("Unicode data, may appear crappy: ");
- fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout);
- fflush(stdout);
- printf("\n");
- break;
-
- case BPLIST_TRUE:
- printf("True.\n");
- break;
-
- case BPLIST_FALSE:
- printf("False.\n");
- break;
-
- case BPLIST_REAL:
- case BPLIST_DATE:
- printf("Real(?): %f\n", root_node->realval);
- break;
-
- default:
- printf("oops\nType set to %x and length is %i\n", root_node->type, root_node->length);
- break;
+ case BPLIST_DICT:
+ printf("Dictionary node.\nLength %lu\n", (long unsigned int) root_node->length);
+ for (i = 0; i < (root_node->length * 2); i += 2) {
+ // HI!
+ printf("Key: ");
+ print_nodes(root_node->subnodes[i]);
+ printf("Value: ");
+ print_nodes(root_node->subnodes[i + 1]);
+ }
+ printf("End dictionary node.\n\n");
+ break;
+
+ case BPLIST_ARRAY:
+ printf("Array node.\n");
+ for (i = 0; i < root_node->length; i++) {
+ printf("\tElement %i: ", i);
+ print_nodes(root_node->subnodes[i]);
+ }
+ break;
+
+ case BPLIST_INT:
+ if (root_node->length == sizeof(uint8_t)) {
+ printf("Integer: %i\n", root_node->intval8);
+ } else if (root_node->length == sizeof(uint16_t)) {
+ printf("Integer: %i\n", root_node->intval16);
+ } else if (root_node->length == sizeof(uint32_t)) {
+ printf("Integer: %i\n", root_node->intval32);
+ }
+ break;
+
+ case BPLIST_STRING:
+ printf("String: ");
+ fwrite(root_node->strval, sizeof(char), root_node->length, stdout);
+ fflush(stdout);
+ printf("\n");
+ break;
+
+ case BPLIST_DATA:
+ printf("Data: ");
+ char *data = g_base64_encode(root_node->strval, root_node->length);
+ fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout);
+ fflush(stdout);
+ printf("\n");
+ break;
+
+ case BPLIST_UNICODE:
+ printf("Unicode data, may appear crappy: ");
+ fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout);
+ fflush(stdout);
+ printf("\n");
+ break;
+
+ case BPLIST_TRUE:
+ printf("True.\n");
+ break;
+
+ case BPLIST_FALSE:
+ printf("False.\n");
+ break;
+
+ case BPLIST_REAL:
+ case BPLIST_DATE:
+ printf("Real(?): %f\n", root_node->realval);
+ break;
+
+ default:
+ printf("oops\nType set to %x and length is %lu\n", root_node->type, (long unsigned int) root_node->length);
+ break;
}
}
-int main(int argc, char *argv[]) {
- struct stat *filestats = (struct stat *)malloc(sizeof(struct stat));
+int main(int argc, char *argv[])
+{
+ struct stat *filestats = (struct stat *) malloc(sizeof(struct stat));
uint32_t position = 0;
Options *options = parse_arguments(argc, argv);
int argh = 0;
-
+
printf("plistutil version 0.2 written by FxChiP\n");
-
+
if (!options) {
print_usage();
return 0;
}
- debug = options->debug;
-
+ iphone_set_debug(options->debug);
+
FILE *bplist = fopen(options->in_file, "r");
-
+
stat(options->in_file, filestats);
printf("here?\n");
- char *bplist_entire = (char*)malloc(sizeof(char) * (filestats->st_size + 1));
+ char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1));
//argh = fgets(bplist_entire, filestats->st_size, bplist);
argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist);
printf("read %i bytes\n", argh);
fclose(bplist);
printf("or here?\n");
// bplist_entire contains our stuff
- bplist_node *root_node;
- root_node = parse_nodes(bplist_entire, filestats->st_size, &position);
- printf("plutil debug mode\n\n");
- printf("file size %i\n\n", filestats->st_size);
- if (!root_node) {
- printf("Invalid binary plist (or some other error occurred.)\n");
- return 0;
+ bplist_node *root_node;
+ root_node = parse_nodes(bplist_entire, filestats->st_size, &position);
+ printf("plutil debug mode\n\n");
+ printf("file size %i\n\n", (int) filestats->st_size);
+ if (!root_node) {
+ printf("Invalid binary plist (or some other error occurred.)\n");
+ return 0;
}
- print_nodes(root_node);
- return 0;
- }
+ print_nodes(root_node);
+ return 0;
+}
-Options *parse_arguments(int argc, char *argv[]) {
+Options *parse_arguments(int argc, char *argv[])
+{
int i = 0;
-
- Options *options = (Options*)malloc(sizeof(Options));
+
+ Options *options = (Options *) malloc(sizeof(Options));
memset(options, 0, sizeof(Options));
-
+
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) {
- if ((i+1) == argc) {
+ if ((i + 1) == argc) {
free(options);
return NULL;
}
- options->in_file = argv[i+1];
+ options->in_file = argv[i + 1];
i++;
continue;
}
-
+
if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) {
- if ((i+1) == argc) {
+ if ((i + 1) == argc) {
free(options);
return NULL;
}
- options->out_file = argv[i+1];
+ options->out_file = argv[i + 1];
i++;
continue;
}
-
+
if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) {
options->debug = 1;
}
-
+
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
free(options);
return NULL;
}
}
-
- if (!options->in_file /*|| !options->out_file*/) {
+
+ if (!options->in_file /*|| !options->out_file */ ) {
free(options);
return NULL;
}
-
+
return options;
}
-void print_usage() {
+void print_usage()
+{
printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n");
printf("\n");
printf("\t-i or --infile: The file to read in.\n");