Thursday, December 24, 2009

NSXMLParser : Nuggets

I was trying to parse an xml of the form between the tags: text xml1 & text xml

NSXMLParser was for some reason was considering & as a delimiter and was calling - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string thrice, once for text xml1, second time for & and third time for text xml2.

Using escape sequence%26 instead of & solved the solved the problem.

Ergo use escape sequence wherever possible instead of &, if parsing with NSXMLParser. I do think there is such problem with xerces and tinyxml.

Below are some commonly used escape sequences:
CharacterEscape Code
SPACE%20
<%3C
>%3E
#%23
%%25
{%7B
}%7D
|%7C
\%5C
^%5E
~%7E
CharacterEscape Code
[%5B
]%5D
`%60
;%3B
/%2F
?%3F
:%3A
@%40
=%3D
&%26
$%24

Friday, November 6, 2009

Shell scripting 101

I had to automate the build system today. The task was simple however my shell scripting knowledge is somewhat limited. I've done itsy-bitsy work on shell scripting but nothing extensive. Today in the process of automating the build I got to learn a few things, might be trivial but they were learning for me.

  • To check if the file already exists on the filesystem
    [ -f filename ] && echo"file exists"


  • To check if the directory exists on the filesystem
    [ -f dirname ] && echo"dir exists"


  • To copy the output of the command executed in the script to a variable.
    result=`pwd`


  • export command is used to set a environment variable.


  • Use = for comparisons not ==.
    if [ $name = "shiv" ];
    then
    echo "its me"
    fi


  • Use option "o" with unzip command to overwrite existing files without prompting.
    unzip -o myArchive.zip

  • Use option "r" to travel recurcively with zip command
    zip -r zipfilename sourcedir *


Following link points to a quick shell scripting reference.
http://www.opengroup.org/onlinepubs/007908799/xcu/shellix.html

Working with dylibs : Deployment Issues - Part 3

Read Part 1
Read Part 2

if you are using install_name_tool extensively. I'd recommend you use the linker flag -headerpad_max_install_names. Man page of ld describes this flag as follows.


-headerpad_max_install_names
Automatically adds space for future expansion of load commands such that all paths could expand to MAXPATHLEN. Only useful if intend to run install_name_tool to alter the load commands later. Size is a hexadecimal number.


Read Part 1
Read Part 2

Tuesday, November 3, 2009

Obtaining Current Date and Time

I had a simple task of adding a time stamp for a resource request. By time stamp I mean the year-date-time when the resource was requested. It was C++ code I did not want to add objective-c code in there. So the option I had was to use Core-Foundation CFDate or to use simple unix calls. I hate Carbon anyways, whenever I get a chance I try avoid it. Same was the case here. I used unix apis. They turned out be simple and did the job with charm.

Code snippet:

time_t currtime;
time(&currtime);

struct tm *dateAndTime = locattime(&currtime);

int year = 1900 + timedate->tm_year;
int month = dateAndTime->tm_mon+1;
int date = dateAndTime->tm_mday;
int hour = dateAndTime->tm_hour;
int min = dateAndTime->tm_min;
int sec = dateAndTime->tm_sec;

Now I can format the time-stamp string in any damn way I want. If objective-c was an option NSDate would have done the job for me.

Monday, November 2, 2009

Working with dylibs : Deployment Issues - Part 2

Read Part 1 of the post
Read Part 3 of the post

In addition to what I had already written on dylib deployment. My friend, Vishvesh, pointed out some additional notes.


  • dylib execution path can be specified in Xcode project "Installation Directory" field. Using this will not require to use complex command line tools to specify the dylib installation path [I have yet verified this].

  • otool when run against a static libraries (.a) lists all the object files.

  • Command file can be used to detect the architecture type a dylib or a static lib is built for.

    example :
    %file myCustom.dylib
    myCustom.dylib: Mach-O universal binary with 2 architectures
    myCustom.dylib(for architecture i386): Mach-O dynamically linked shared library i386
    myCustom.dylib(for architecture ppc): Mach-O dynamically linked shared library ppc


    %file libdoCustomProcessing.a
    libdoCustomProcessing.a: Mach-O universal binary with 2 architectures
    libdoCustomProcessing.a (for architecture i386): current ar archive
    libdoCustomProcessing.a (for architecture ppc): current ar archive



Read Part 1 of the post
Read Part 3 of the post

Friday, October 30, 2009

How To - svn:externals

Today I had to add webkit as an external directory to my trunk in SVN.

My SVN folder structure is like this.
/SVN/Repos/Trunk
              /Lib1
              /Lib2
              /App


I wanted to add an external directory to trunk folder. As shown below.
/SVN/Repos/Trunk
              /Lib1
              /Lib2
              /webkit
              /App


I tried various ways to set the svn:externals property all in vain. Thanks to the following link I got to know how to do it right.

%cd /SVN/Repos/Trunk
%svn propset svn:externals 'webkit http://svn.webkit.org/repository/webkit/trunk' .


This did the trick.

%svn propget svn:externals
can be used to verify if the externals are properly set.

Wednesday, October 28, 2009

Working with dylibs : Deployment Issues

Working with dylibs can be a troublesome at times. I encountered troubles with it few days back.

Application I was developing links with a custom dylib, I developed. All was working well while running through XCode. However on deployment, the application would not launch. On investigation, I realized that OSX was unable to find a dylib, Hence the application failed to launch.

I was faced with the problem of the OSX not knowing where to find the dylibs required by my application in deployment environment.

otool and install_name_tool came to my rescue.

As per Apple documentation


First I wanted see to all the library install names in my application. In simple terms paths of all the libraries my application is linked with.

On terminal in cd into my app package Contents/Macos.
% otool -L myAppUnixBinay

The output listed all the library install names.

libmycustom.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)


My application linked against libmycustom.dylib, it failed to load it since no proper path was provided.

Now I used install_name_tool to set the right path to the dylib.
% install_name_tool -change libmycustom.dylib @executable_path/../Frameworks/libmycustom.dylib myAppUnixBinay

The above line tell the OSX to find the library in /Contents/Frameworks of the application package.

Now when I ran the application all worked well.

I automated this process by adding a runscript to XCode target that runs post build process.

Read Part 2 of the post
Read Part 3 of the post

LinkWithin

Related Posts with Thumbnails