package dfixer;

import java.util.ArrayList;

public class Instruction {
	
	private char type;
	private String filename;
	private String path;
	private int  line = 0;
	private int  col  = 0; 
	private String text; 
	

	public Instruction(String s,String path){
		char[] tmp = s.toCharArray();
		int l = s.length();
		if(tmp.length==0)
			return;
		else
			type = tmp[0];
		ArrayList<Character> filename = new ArrayList<Character>();
		int i = 2;
		char c1 = tmp[i];
		char c2 = tmp[i+1];
		if(type!='A' && type!='D' && type!='P')
			return;

		while(!(c1==' ' && Character.isDigit(c2))){
			filename.add(c1);
			i++;
			c1 = tmp[i];
			c2 = tmp[i+1];
		}
		if(filename.get(0)=='.' && filename.get(1)=='/')
		{
			filename.remove(1);
			filename.remove(0);
		}
			
		StringBuilder sb1 = new StringBuilder();
		for(int j=0;j<filename.size();j++)
			sb1.append(filename.get(j));
		this.filename = sb1.toString();
		this.path = path;
		/*if(!path.equals("./"))
			name = path + name;  //name ???????????????????????????????????????*/
		//line & column
		i++;
		while(tmp[i]!=':'){
			line = line*10 + tmp[i] - '0';
			i++;
		}
		i++;
		while(tmp[i]!=' '){
			col = col*10 + tmp[i] - '0';
			i++;
		}
		i+=2;
		ArrayList<Character> ca = new ArrayList<Character>();
		for(;i<l;i++)
			ca.add(tmp[i]);
		StringBuilder sb = new StringBuilder();
		for(int j=0;j<ca.size();j++)
			sb.append(ca.get(j));
		text = sb.toString();
	}
	
	public char gettype(){
		return type;
	}
	
	public String getname(){
		return filename;
	}
	
	public String getpath(){
		return path;
	}
	
	public int getline(){
		return line;
	}
	
	public int getcol(){
		return col;
	}
	
	public String gettext(){
		return text;
	}
}
