/*
 * Created on 2004-08-29
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2004
 */
package pl.zalewski.mikolaj.symbdev.errorparsers;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IErrorParser;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.core.resources.IFile;

/**
 * @author mikolaj
 *
 * Scans the output of the Symbian reource compiler for errors
 */
public class RCCompErrorParser implements IErrorParser {

    /**
     * 
     */
    public RCCompErrorParser() {
        super();
        error=Pattern.compile("(.*)\\(([0-9]+)\\) : (.*)");
    }
    
    Pattern error;

    /* (non-Javadoc)
     * @see org.eclipse.cdt.core.IErrorParser#processLine(java.lang.String, org.eclipse.cdt.core.ErrorParserManager)
     */
    public boolean processLine(String line, ErrorParserManager eoParser) {
        Matcher m=error.matcher(line);
        if (!m.matches())
            return false;
        
        String path=m.group(1);
        String errLine=m.group(2);
        String errMsg=m.group(3);
        int errLineNr=Integer.parseInt(errLine);
                
		IFile file = eoParser.findFilePath(path);
		if (file != null) {
			eoParser.generateMarker(file, errLineNr, "RCOMP: "+errMsg, IMarkerGenerator.SEVERITY_ERROR_RESOURCE, null);
			return true;
		} else
		{
	        String filename=path;
	        
			int i=path.lastIndexOf(File.separatorChar);
			if (i!=-1)
				filename=path.substring(i + 1);
			eoParser.generateMarker(null, -1, filename+": "+errLine+": "+errMsg, IMarkerGenerator.SEVERITY_ERROR_RESOURCE, null);		    
		}
        
        return true;
    }

}
