How to auto-format WinCC OA ctl
WinCC-OA control language has a similar to C/C++ syntax and its beautify/auto-format tools can be used to reformat ctrl libraries and scripts.
I'm using astyle tool for automatic formatting of ctrl scripts. With this command all *.ctl files repulsively will be formatted:
astyle --style=google --indent=spaces=4 --pad-oper --pad-header --add-brackets --keep-one-line-blocks --indent-switches --suffix=none -r *ctl
It's more tricky to format the code inside .pnl files. If you have a big piece of control script that for some reason you want to keep inside the panel, you still can pretty-format it. For that, manually extract to code to he tmp.ctl file, then re-format if as following and put it back to the panel.
sed -i '' -e 's/\\"/\"/g' tmp.ctl astyle --style=google --indent=spaces=4 --pad-oper --pad-header --add-brackets --keep-one-line-blocks --indent-switches --suffix=none tmp.ctl sed -i '' -e 's/\"/\\"/g' tmp.ctl
AStyle installation instruction
Download astyle source code from here , then install as following:
~ $ tar zxf astyle_2.05.1_linux.tar.gz ~ $ cd astyle ~/astyle $ cd build/gcc/ ~/astyle/.../gcc $ make g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/astyle_main.o ../../src/astyle_main.cpp g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASBeautifier.o ../../src/ASBeautifier.cpp g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASFormatter.o ../../src/ASFormatter.cpp g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASEnhancer.o ../../src/ASEnhancer.cpp g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASLocalizer.o ../../src/ASLocalizer.cpp g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASResource.o ../../src/ASResource.cpp g++ -s -o bin/astyle obj/astyle_main.o obj/ASBeautifier.o obj/ASFormatter.o obj/ASEnhancer.o obj/ASLocalizer.o obj/ASResource.o ~/astyle/.../gcc $ sudo make install install -o root -g root -m 755 -d /usr/bin install -o root -g root -m 755 -d /usr/share/doc/astyle