Sep 27, 2010

"country of purchase"

Anar here...

Finally it has just happened. If you bought an iOS devise (iPhone for example) in one EU country, you can use your warranty rights in another EU country!!!
Brussels, 25 September 2010, Antitrust: Statement on Apple's iPhone policy changes (Reference:  IP/10/1175    Date:  25/09/2010):
...One focused on the "country of purchase" rule, whereby repairs service is only available in the country where the iPhone was bought, which made the exercise of warranty rights difficult for consumers who had purchased an iPhone in another EU/EEA country than their home country. The Commission had concerns that this rule could amount to territorial restrictions aimed at dissuading European consumers from buying iPhones outside their country of residence and so leading to a partitioning of the market...
Previously, if people buy an unlocked iPhone in Italy while being residents of Germany, for example, they will be refused to get it fixed by warranty in Germany. They were forced to send devices to Apple Service in Italy (by providing home addresses in Italy) :(

Now it seems to be over and the cross-border warranty repair is now allowed. Let's see...

Sep 20, 2010

Xcode + AStyle

Anar here...

You know, I think there are many people, who find the auto-formatting of source code in Xcode is really terrible :( I mean, it is very weak (in terms of configuration) for such a descent development environment, which XCode actually is.

Since a very long time I use AStyle (Artistic Style) to format my code. It actually does remarkable job and it is an extremely tunable tool. You can adjust it almost for all, if not for all, indentations schemas...

I have already posted a long time ago a recipe of how to setup astyle for eclipse. Now, it is time to use it in XCode.

I use a user script menu to add my own script, which will than trigger the astyle command to format a source code for me.

Use the User Script menu to add a new script. You should add your script to a section "Text", the type of the script should - a shell script.
Next is the properties of the script:
Input: Entire Document
Directory: Selection
Output: Replace Document Contents
Errors: Display in Alert

And the content of the script:

#!/bin/bash

# I pass selected file instead of a selection, because astyle 1.24
# fails to parse struct with access modifiers. It just hangs instead.
# I also use a tmp file in order to avoid annoying Xcode message, that
# source file was changed outside of Xcode.

# Important: there must be always a new line at the end of the source file.
# Next time I provide a fix for that.


TMP=`mktemp -t xcode.XXXXXXXXXX` || exit 1

cat << 'EOFEOFEOF' > "$TMP"
%%%{PBXAllText}%%%EOFEOFEOF

astyle --options=<***PATH_TO_YOUR_ASTYLE_RC_FILE***> $TMP &>/dev/null

echo -n "%%%{PBXSelection}%%%"
cat $TMP
echo -n "%%%{PBXSelection}%%%"

rm $TMP

Restriction: Be advised, there must be always a new line at the end of the source file!

BTW, don't forget to change that <***PATH_TO_YOUR_ASTYLE_RC_FILE***> to a real path to your astyle resource file ;)

The script above is actually a second version of my script. The first one was much simpler:

#!/bin/sh

echo -n "%%%{PBXSelection}%%%"
/usr/bin/astyle --options=<***PATH_TO_YOUR_ASTYLE_RC_FILE***> <&0 echo -n "%%%{PBXSelection}%%%"
But this version didn't work for me with astyle 1.24. This is why in the second version of the script:
I pass selected file instead of a selection, because astyle 1.24 fails to parse struct with access modifiers. It just hangs instead. I also use a tmp file in order to avoid annoying Xcode message, that source file was changed outside of Xcode.
Finally, just assign some shortcuts (I prefer Options + Command + L) to you script and voilĂ ...

Sep 16, 2010

BASH: pipe command output and track the error codes

Anar here...

I've just came across a problem in on of the projects I work on.
I have a bunch of commands in a "pipe line"... something like the following.

command 2>&1 | command2 | command3

Now, what I want is to check the exit code of the first command. If I would use the "$?" than it will return the exit code of the last command, which is not what I need.

The solution is to use bash's PIPESTATUS, which will return an array of exit codes of each command in a line ;)
See what man bash says:
PIPESTATUS
An array variable (see Arrays below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain
only a single command).
So, if I apply the solution to my example above I get something like that:

command 2>&1 | command2 | command3

if (( ${PIPESTATUS[0]} != 0 )); then
echo "something is wrong..."
fi
"In UNIX there is always a workaround" ;)