TerraME / terrame

TerraME is a programming environment for spatial dynamical modelling
www.terrame.org
GNU Lesser General Public License v3.0
36 stars 13 forks source link

folder with special characters #659

Closed pedro-andrade-inpe closed 6 years ago

pedro-andrade-inpe commented 9 years ago

TerraME cannot install packages that belong to folders with special characters. This error was verified in Windows. Check it in Mac as well.

pedro-andrade-inpe commented 8 years ago

Investigate os.setlocale.

http://www.lua.org/pil/22.2.html

The os.setlocale function sets the current locale used by a Lua program. Locales define behavior that is sensitive to cultural or linguistic differences. The setlocale function has two string parameters: the locale name and a category, which specifies what features the locale will affect. There are six categories of locales: "collate" controls the alphabetic order of strings; "ctype" controls the types of individual characters (e.g., what is a letter) and the conversion between lower and upper cases; "monetary" has no influence in Lua programs; "numeric" controls how numbers are formatted; "time" controls how date and time are formatted (i.e., function os.date); and "all" controls all the above functions. The default category is "all", so that if you call setlocale with only the locale name it will set all categories. The setlocale function returns the locale name or nil if it fails (usually because the system does not support the given locale).

    print(os.setlocale("ISO-8859-1", "collate"))   --> ISO-8859-1
pedro-andrade-inpe commented 8 years ago

There is a windows command called chcp that returns a code related to the encoding. The available codes are available at http://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac00408_.htm.

avancinirodrigo commented 6 years ago

@pedro-andrade-inpe, this error is not associated with chcp and os.setlocale()

chcp sets the prompt locale, but there is a lot of problem associated with its use. os.setlocale() sets how Lua handle its categories formats like ("collate", "ctype", "monetary", "numeric", or "time")

As example that nothing change with special characters if changes the locale:

print(os.setlocale())
print("ç" == "ç")
print("á" == "á")
print("ççdjçfaáó5")

print(os.setlocale("en-US"))
print("ç" == "ç")
print("á" == "á")
print("ççdjçfaáó5")

print(os.setlocale("pt-BR"))
print("ç" == "ç")
print("á" == "á")
print("ççdjçfaáó5")

print(os.setlocale(""))
print("ç" == "ç")
print("á" == "á")
print("ççdjçfaáó5")
C
true
true
ççdjçfaáó5
en-US
true
true
ççdjçfaáó5
pt-BR
true
true
ççdjçfaáó5
Portuguese_Brazil.1252
true
true
ççdjçfaáó5

Some notes: chcp doesn't work properly with Lua: A possible cause can be seen here: https://superuser.com/questions/239810/setting-utf8-as-default-character-encoding-in-windows-7

To test, print some special characters in Lua script and change the code page chcp: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx https://technet.microsoft.com/pt-br/library/cc733037(v=ws.10).aspx