Tools to convert NFD-type UTF-8 represented strings (such as file/path names represented in Mac OS) to the Synology UTF-8 representation (for filenames). Note that this relies on enabling the mac-compatibility option in the Synology Samba service. The syn2mac and mac2syn scripts are auto-generated by the script gen_mac2lin_lin2mac_scripts found in the linux-nas-scripts repo.
Q: Why need this if there's iconv? Well, ...:
- iconv is not available on every system and sed usually is.
- iconv does not always have the -t UTF-8-MAC option - many unix/linux distribs don't include this option in iconv, at least Synology doesn't.
- iconv behaves pretty erratic when passing large amounts of text (at least in my experience): the conversion misses a mapped character every now and then, and this is not reproducible but depends on the text preceding the erroneous mapping.
- iconv is not bijective, i.e. when converting the string back to it's original representation, it may be different. These scripts are bijective, i.e. cat file | syn2mac | mac2syn reproduces file indentically. In fact, running a text through these scripts always produces the same result, no matter how many times you do this (running syn2mac once, twice or 100 times, like cat file | syn2mac | syn2mac | syn2mac). This is handy if you're not sure which reprensentation the text is in, or if you have a directory with files with mixed representations.
If you look at the script source, you'll see a large array of charater mappings that look like -e 's/A/A/g'. At first sight, this looks rediculous, but the two characters in the substitute command are in fact the same glyph in two different representations (normal UTF-8 and NFD UTF-8, or vice versa depending on which script you're looking at).