Mixture of windows newlines and non-windows newlines

4 posts / 0 new
Last post
oren
Offline
Last seen:1 year 7 months ago
Expert
加入:2014-06-28 22:03
Mixture of windows newlines and non-windows newlines

我们是upgrading (rewriting) our code for SDK5.
Like in SDK3, I have noticed that some c\h files use the "windows" new-lines (i.e. two chars: '\r\n') and most files use the non-windows new-lines (just a '\n' char).
Some files even use both styles:

.\projects\target_apps\peripheral_examples\shared\startup\system_ARMCM0.c
.\projects\target_apps\prod_test\prod_test\src\custom_lld_data.c
.\projects\target_apps\prod_test\prod_test\src\custom_lld_evt.c
.\projects\target_apps\template\empty_peripheral_template\src\platform\user_periph_setup.c
.\sdk\ble_stack\profiles\spota\spotar\spotar.h
.\sdk\ble_stack\profiles\streamdata\streamdatad\streamdatad_task.c
.\sdk\platform\core_modules\crypto\aes_task.h
.\sdk\platform\core_modules\crypto\os_port.h
.\sdk\platform\core_modules\crypto\sw_aes.h
.\utilities\flash_programmer\src\otpc.c
.\utilities\mkimage\os_port.h
.\utilities\prod_test\prod_test_cmds\prodtest\host_hci.h
.\utilities\secondary_bootloader\includes\os_port.h
.\utilities\secondary_bootloader\includes\uart.h

The windows new-lines is preferable on Keil4 - for example, I noticed that if you click F12 on a preprocessor macro in order to find its definition, the editor will jump to the exact definition line only if the .h file uses windows newlines (\r\n).

If you want my python script that fixes all these files, please contact me.

Oren Zomer

Device:
ciano
Offline
Last seen:2 weeks 4 days ago
加入:2014-10-03 08:13
Dear Dialog.

Dear Dialog.

I have noticed the same mixture of new lines as Oren Zomer.

Are you planning on changing the new lines to a common format?
I would also suggest windows new lines, while using Kiel.

Best Regards,
Ciano霜
Denmark

MT_dialog
Offline
Last seen:2 months 2 weeks ago
工作人员
加入:2015-06-08 11:34
Hi ciano,

Hi ciano,

I am not aware if the SDK team has plans about that for the next SDK release, i will pass your request though.

Thanks MT_dialog

oren
Offline
Last seen:1 year 7 months ago
Expert
加入:2014-06-28 22:03
I noticed that SDK 5.0.4 also

I noticed that SDK 5.0.4 also contains "unix newlines" - i.e. "\n" without a "\r" before.

Here is a simple python script that I wrote to fix the newlines (from "\n" to "\r\n") in all .c and .h files:


import os
import os.path
import fnmatch
def fix_newlines(main_dir):
for root, dirnames, filenames in os.walk(main_dir):
for filename in fnmatch.filter(filenames, '*.[ch]'):
filepath = os.path.join(root, filename)
f = open(filepath, 'rb')
txt = f.read()
f.close()
new_txt = txt.replace('\r\n','\n').replace('\n','\r\n')
if new_txt != txt:
print "fixing %s" % (filepath,)
open(filepath, 'wb').write(new_txt)
if __name__ == '__main__':
import sys
fix_newlines(sys.argv[1])
print "done"