From 1eb804e3a2a7e39771deb4b50f38e21d500f9423 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 18 Mar 2013 15:02:11 +0100 Subject: renamed plutil to plistutil to not mask Apple's plutil on OSX --- CMakeLists.txt | 4 +- cmake/libplistPackaging.cmake | 4 +- plistutil/CMakeLists.txt | 9 +++ plistutil/plistutil.c | 164 ++++++++++++++++++++++++++++++++++++++++++ plistutil/plistutil.h | 29 ++++++++ plutil/CMakeLists.txt | 9 --- plutil/plutil.c | 164 ------------------------------------------ plutil/plutil.h | 29 -------- 8 files changed, 206 insertions(+), 206 deletions(-) create mode 100644 plistutil/CMakeLists.txt create mode 100644 plistutil/plistutil.c create mode 100644 plistutil/plistutil.h delete mode 100644 plutil/CMakeLists.txt delete mode 100644 plutil/plutil.c delete mode 100644 plutil/plutil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 494c74d..5c95fea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ SET( LIBPLIST_VERSION_MINOR "9" ) SET( LIBPLIST_SOVERSION "1" ) SET( LIBPLIST_VERSION "${LIBPLIST_VERSION_MAJOR}.${LIBPLIST_VERSION_MINOR}" ) SET( LIBPLIST_LIBVERSION "${LIBPLIST_SOVERSION}.${LIBPLIST_VERSION}" ) -SET( PLUTIL_VERSION ${LIBPLIST_VERSION} ) +SET( PLISTUTIL_VERSION ${LIBPLIST_VERSION} ) SET( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake/modules ) @@ -53,7 +53,7 @@ SET ( PLIST_BYTE_ORDER ${endianess} ) ADD_SUBDIRECTORY( libcnary ) ADD_SUBDIRECTORY( src ) -ADD_SUBDIRECTORY( plutil ) +ADD_SUBDIRECTORY( plistutil ) ADD_SUBDIRECTORY( include ) ADD_SUBDIRECTORY( test ) diff --git a/cmake/libplistPackaging.cmake b/cmake/libplistPackaging.cmake index 1a5fd92..fbd865f 100644 --- a/cmake/libplistPackaging.cmake +++ b/cmake/libplistPackaging.cmake @@ -7,9 +7,9 @@ MACRO( LIBPLIST_PACKAGE _major _minor) SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LESSER") SET(CPACK_COMPONENT_LIB_DISPLAY_NAME "PList library") SET(CPACK_COMPONENT_DEV_DISPLAY_NAME "PList development files") - SET(CPACK_COMPONENT_PLUTIL_DISPLAY_NAME "PList conversion tool") + SET(CPACK_COMPONENT_PLISTUTIL_DISPLAY_NAME "PList conversion tool") set(CPACK_COMPONENT_DEV_DEPENDS lib) - set(CPACK_COMPONENT_PLUTIL_DEPENDS lib) + set(CPACK_COMPONENT_PLISTUTIL_DEPENDS lib) INCLUDE( CPack ) ENDMACRO( LIBPLIST_PACKAGE ) diff --git a/plistutil/CMakeLists.txt b/plistutil/CMakeLists.txt new file mode 100644 index 0000000..68382ee --- /dev/null +++ b/plistutil/CMakeLists.txt @@ -0,0 +1,9 @@ + +SET(plistutil_SRC + plistutil.c) + +ADD_EXECUTABLE(plistutil ${plistutil_SRC}) +TARGET_LINK_LIBRARIES(plistutil plist) +SET_TARGET_PROPERTIES( plistutil PROPERTIES VERSION ${PLISTUTIL_VERSION} ) + +INSTALL( TARGETS plistutil RUNTIME DESTINATION bin COMPONENT plistutil ) diff --git a/plistutil/plistutil.c b/plistutil/plistutil.c new file mode 100644 index 0000000..3e09bb2 --- /dev/null +++ b/plistutil/plistutil.c @@ -0,0 +1,164 @@ +/* + * plistutil.c + * source for plist convertion tool + * + * Copyright (c) 2008 Zach C. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include "plist/plist.h" +#include "plistutil.h" + +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(disable:4996) +#endif + + +int main(int argc, char *argv[]) +{ + FILE *iplist = NULL; + plist_t root_node = NULL; + char *plist_out = NULL; + uint32_t size = 0; + int read_size = 0; + char *plist_entire = NULL; + struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); + Options *options = parse_arguments(argc, argv); + + if (!options) + { + print_usage(); + free(filestats); + return 0; + } + //read input file + iplist = fopen(options->in_file, "rb"); + if (!iplist) + return 1; + stat(options->in_file, filestats); + plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); + read_size = fread(plist_entire, sizeof(char), filestats->st_size, iplist); + fclose(iplist); + + + //convert one format to another + + + if (memcmp(plist_entire, "bplist00", 8) == 0) + { + plist_from_bin(plist_entire, read_size, &root_node); + plist_to_xml(root_node, &plist_out, &size); + } + else + { + plist_from_xml(plist_entire, read_size, &root_node); + plist_to_bin(root_node, &plist_out, &size); + } + plist_free(root_node); + free(plist_entire); + free(filestats); + + if (plist_out) + { + if (options->out_file != NULL) + { + FILE *oplist = fopen(options->out_file, "wb"); + if (!oplist) + return 1; + fwrite(plist_out, size, sizeof(char), oplist); + fclose(oplist); + } + //if no output file specified, write to stdout + else + fwrite(plist_out, size, sizeof(char), stdout); + + free(plist_out); + } + else + printf("ERROR\n"); + + free(options); + return 0; +} + +Options *parse_arguments(int argc, char *argv[]) +{ + int i = 0; + + 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) + { + free(options); + return NULL; + } + options->in_file = argv[i + 1]; + i++; + continue; + } + + if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) + { + if ((i + 1) == argc) + { + free(options); + return NULL; + } + 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 */ ) + { + free(options); + return NULL; + } + + return options; +} + +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"); + printf("\t-o or --outfile: The file to convert to.\n"); + printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); +} diff --git a/plistutil/plistutil.h b/plistutil/plistutil.h new file mode 100644 index 0000000..40421a3 --- /dev/null +++ b/plistutil/plistutil.h @@ -0,0 +1,29 @@ +/* + * plistutil.h + * header for plist convertion tool + * + * Copyright (c) 2008 Zach C. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +typedef struct _options +{ + char *in_file, *out_file; + uint8_t debug, in_fmt, out_fmt; +} Options; + +Options *parse_arguments(int argc, char *argv[]); +void print_usage(); diff --git a/plutil/CMakeLists.txt b/plutil/CMakeLists.txt deleted file mode 100644 index 149d68f..0000000 --- a/plutil/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -SET(plutil_SRC - plutil.c) - -ADD_EXECUTABLE(plutil ${plutil_SRC}) -TARGET_LINK_LIBRARIES(plutil plist) -SET_TARGET_PROPERTIES( plutil PROPERTIES VERSION ${PLUTIL_VERSION} ) - -INSTALL( TARGETS plutil RUNTIME DESTINATION bin COMPONENT plutil ) \ No newline at end of file diff --git a/plutil/plutil.c b/plutil/plutil.c deleted file mode 100644 index 88df080..0000000 --- a/plutil/plutil.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * plutil.C - * source for plist convertion tool - * - * Copyright (c) 2008 Zach C. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#include "plist/plist.h" -#include "plutil.h" - -#include -#include -#include -#include - -#ifdef _MSC_VER -#pragma warning(disable:4996) -#endif - - -int main(int argc, char *argv[]) -{ - FILE *iplist = NULL; - plist_t root_node = NULL; - char *plist_out = NULL; - uint32_t size = 0; - int read_size = 0; - char *plist_entire = NULL; - struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); - Options *options = parse_arguments(argc, argv); - - if (!options) - { - print_usage(); - free(filestats); - return 0; - } - //read input file - iplist = fopen(options->in_file, "rb"); - if (!iplist) - return 1; - stat(options->in_file, filestats); - plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); - read_size = fread(plist_entire, sizeof(char), filestats->st_size, iplist); - fclose(iplist); - - - //convert one format to another - - - if (memcmp(plist_entire, "bplist00", 8) == 0) - { - plist_from_bin(plist_entire, read_size, &root_node); - plist_to_xml(root_node, &plist_out, &size); - } - else - { - plist_from_xml(plist_entire, read_size, &root_node); - plist_to_bin(root_node, &plist_out, &size); - } - plist_free(root_node); - free(plist_entire); - free(filestats); - - if (plist_out) - { - if (options->out_file != NULL) - { - FILE *oplist = fopen(options->out_file, "wb"); - if (!oplist) - return 1; - fwrite(plist_out, size, sizeof(char), oplist); - fclose(oplist); - } - //if no output file specified, write to stdout - else - fwrite(plist_out, size, sizeof(char), stdout); - - free(plist_out); - } - else - printf("ERROR\n"); - - free(options); - return 0; -} - -Options *parse_arguments(int argc, char *argv[]) -{ - int i = 0; - - 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) - { - free(options); - return NULL; - } - options->in_file = argv[i + 1]; - i++; - continue; - } - - if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) - { - if ((i + 1) == argc) - { - free(options); - return NULL; - } - 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 */ ) - { - free(options); - return NULL; - } - - return options; -} - -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"); - printf("\t-o or --outfile: The file to convert to.\n"); - printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); -} diff --git a/plutil/plutil.h b/plutil/plutil.h deleted file mode 100644 index 4be716e..0000000 --- a/plutil/plutil.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * plutil.h - * header for plist convertion tool - * - * Copyright (c) 2008 Zach C. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -typedef struct _options -{ - char *in_file, *out_file; - uint8_t debug, in_fmt, out_fmt; -} Options; - -Options *parse_arguments(int argc, char *argv[]); -void print_usage(); -- cgit v1.1-32-gdbae