/*
 * Created on 2004-08-10
 *
 */
package pl.zalewski.mikolaj.symbdev;

import java.util.Properties;

/**
 * @author mikolaj
 *
 * A configuration entry for a Win32 compoiler
 */
public class Win32ToolEntry {
	/**
	 * Constructs a new entry
	 * @param setAsDefault if true the entry is filled with default strings.
	 * If not, it is filled with nulls
	 */
	public Win32ToolEntry(boolean setAsDefault)
	{
		if (setAsDefault)
		{
			name="A new tool";
			path="";
			target="wins";
			autodetected=false;
			id=-1;
		}
	}

	/**
	 * Equivalent to Win32ToolEntry(true)
	 *
	 */
	public Win32ToolEntry()
	{
		this(true);
	}

	/**
	 * <p>This items entered by the user will be given ids smaller than that
	 * number.</p>
	 * 
	 * <p>The value of AUTODETECTED_MIN is 0x10000</p>
	 */
	public static final int AUTODETECTED_MIN=0x10000;
	
	/**
	 * Name of the entry
	 */
	public String name;
	
	/**
	 * Semicolon-separated directories to be added at the beginning of the
	 * PATH variable
	 */
	public String path;  
	
	/**
	 * Name of the ABLD target (e.g. wins)
	 */
	public String target;
	
	/**
	 * Each entry has an id to find it in the preferences file
	 */
	public int id;
	
	/**
	 * That item was autodetected, not entered by the user
	 * @author mikolaj
	 */
	public boolean autodetected;

	/**
	 * This function adds the environment variables to setup the tool
	 * @param env the environment to alter
	 */
	public void alterEnvironment(Properties env)
	{
		String envPath=env.getProperty("PATH");
		if (envPath==null) envPath="";
		env.setProperty("PATH", path+';'+envPath);
	}
	
	/**
	 * Returns the name of the ARMI atrget for this toolchain (e.g. ARMI, AMRIB, ARMICW).
	 * This is implemented by changing WINS to ARMI in the target string
	 * @return The name of the ARMI atrget for this toolchain
	 */
	public String getARMITarget()
	{
	    return target.toUpperCase().replaceFirst("WINS", "ARMI");
	}
}
