1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 07:35:24 +02:00

bug 299376: Console/Problem view UTF-8 character encoding problem with

Cygwin 1.7
This commit is contained in:
Andrew Gvozdev 2011-11-30 15:32:47 -05:00
parent 726e835448
commit 5a5124dd04

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2010 Intel Corporation and others. * Copyright (c) 2005, 2011 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -23,25 +23,48 @@ import org.eclipse.cdt.managedbuilder.internal.envvar.BuildEnvVar;
public class GnuCygwinConfigurationEnvironmentSupplier implements public class GnuCygwinConfigurationEnvironmentSupplier implements
IConfigurationEnvironmentVariableSupplier { IConfigurationEnvironmentVariableSupplier {
static final String VARNAME = "PATH"; //$NON-NLS-1$ private static final String PATH = "PATH"; //$NON-NLS-1$
static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$ private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
static final String PROPERTY_DELIMITER = "path.separator"; //$NON-NLS-1$ private static final String PROPERTY_DELIMITER = "path.separator"; //$NON-NLS-1$
static final String PROPERTY_OSNAME = "os.name"; //$NON-NLS-1$ private static final String PROPERTY_OSNAME = "os.name"; //$NON-NLS-1$
private static final String LANG = "LANG"; //$NON-NLS-1$
private static final String LC_ALL = "LC_ALL"; //$NON-NLS-1$
private static final String LC_MESSAGES = "LC_MESSAGES"; //$NON-NLS-1$
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier#getVariable(java.lang.String, org.eclipse.cdt.managedbuilder.core.IConfiguration, org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider) * @see org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier#getVariable(java.lang.String, org.eclipse.cdt.managedbuilder.core.IConfiguration, org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider)
*/ */
public IBuildEnvironmentVariable getVariable(String variableName, public IBuildEnvironmentVariable getVariable(String variableName,
IConfiguration configuration, IEnvironmentVariableProvider provider) { IConfiguration configuration, IEnvironmentVariableProvider provider) {
if (variableName == null)
return null;
if (!System.getProperty(PROPERTY_OSNAME).toLowerCase().startsWith("windows ")) //$NON-NLS-1$ if (!System.getProperty(PROPERTY_OSNAME).toLowerCase().startsWith("windows ")) //$NON-NLS-1$
return null; return null;
if (variableName == null) return null; if (variableName.equalsIgnoreCase(PATH)) {
if (!VARNAME.equalsIgnoreCase(variableName)) return null;
String p = CygwinPathResolver.getBinPath(); String p = CygwinPathResolver.getBinPath();
if (p != null) if (p != null)
return new BuildEnvVar(VARNAME, p.replace('/','\\'), IBuildEnvironmentVariable.ENVVAR_PREPEND, System.getProperty(PROPERTY_DELIMITER, DELIMITER_UNIX)); return new BuildEnvVar(PATH, p.replace('/','\\'), IBuildEnvironmentVariable.ENVVAR_PREPEND, System.getProperty(PROPERTY_DELIMITER, DELIMITER_UNIX));
} else if (variableName.equalsIgnoreCase(LANG)) {
// Workaround for not being able to select encoding for CDT console -> change codeset to Latin1
String langValue = System.getenv(LANG);
if (langValue == null || langValue.length() == 0)
langValue = System.getenv(LC_ALL);
if (langValue == null || langValue.length() == 0)
langValue = System.getenv(LC_MESSAGES);
if (langValue != null && langValue.length() > 0)
// langValue is [language[_territory][.codeset][@modifier]], i.e. "en_US.UTF-8@dict"
// we replace codeset with Latin1 as CDT console garbles UTF
// and ignore modifier which is not used by LANG
langValue = langValue.replaceFirst("([^.@]*)(\\..*)?(@.*)?", "$1.ISO-8859-1"); //$NON-NLS-1$ //$NON-NLS-2$
else
langValue = "C.ISO-8859-1"; //$NON-NLS-1$
return new BuildEnvVar(LANG, langValue);
}
return null; return null;
} }
@ -51,9 +74,13 @@ public class GnuCygwinConfigurationEnvironmentSupplier implements
public IBuildEnvironmentVariable[] getVariables( public IBuildEnvironmentVariable[] getVariables(
IConfiguration configuration, IEnvironmentVariableProvider provider) { IConfiguration configuration, IEnvironmentVariableProvider provider) {
IBuildEnvironmentVariable[] tmp = new IBuildEnvironmentVariable[1]; IBuildEnvironmentVariable varLang = getVariable(LANG, configuration, provider);
tmp[0] = getVariable(VARNAME, configuration, provider); IBuildEnvironmentVariable varPath = getVariable(PATH, configuration, provider);
if (tmp[0] != null) return tmp;
return null; if (varPath != null) {
return new IBuildEnvironmentVariable[] {varLang, varPath};
} else {
return new IBuildEnvironmentVariable[] {varLang};
}
} }
} }