Thursday, June 20, 2013

Короткое замыкание в С++

Инициализация ссылки
Как известно, в С++ ссылки, являющиеся переменными класса, нужно инициализировать в списке инициализации конструктора:
class A() {
   std::vector<int> & m_refData; // ссылка на массив
}
См. короткое замыкание...

Трассировка лёгкая как printf


Разобрался наконец как работать с переменным количеством аргументов, а точнее конструкцией ... в Си-шных функциях. Заодно написал полезняшку для отладки с помощью WinAPI-шной функции OutputDebugString, которая неудобна, т.к. принимает только строки, что заставляло меня писать громоздские конструкции для отладки.

Исходники void TraceString(const char *msg, ...) см. ниже


Непроходимые горы, Dependency Walker, sxstrace.exe и другие

Иногда перед программистом во время отладки, а особенно 64-битных приложений, на ровном месте вырастают непроходимые горы, как например эти:


(нарисовано в thisissand.com)

"...И горы встают перед ним на пути,
И он по горам начинает ползти,
А горы всё выше, а горы всё круче,
А горы уходят под самые тучи!...

И сейчас же с высокой скалы к Айболиту спустились орлы..." (с)

Monday, June 17, 2013

Welcome, gettext, this is VBasic script

Task description
There is a project containing thousands of CPP sources that have to be localized into Chinese ASAP. We're using gettext technique for localization and strings to be translated have to be wrapped with _(), for example:
::MessageBox( _("Translate me please"), _("Warning"), MB_OK)
We can run Visual Studio Find In Files->Current File for each file with the following regexp:
\".*\" 
in order to search all strings, а then insert _('s and )'s.
But this is dull and boring, so let's switch on the brains and write a VisualBasic script in VBasic IDE (Alt-F11) which can be invoked by pressing F5 (or whatever you like, use Tools->Customize-Keyboard to setup hotkey).
Now just you have to traverse "Find Results" window by pressing F4 and optionally pressing F5 on each string that should be wrapped with _(). You can even avoid watching into .cpp source in simple cases with MessageBoxes (90% of strings). This way you reduce summary time  of processing all the .cpp sources for at least thrice, and even five times.

Here is VBasic Script. Note that it even handles multiline strings!