Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package tests;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.apache.commons.codec.DecoderException;
- import org.apache.commons.codec.binary.Hex;
- /**
- *
- * @author Makerimages
- */
- public class Compilertest3
- {
- String S;
- String SClean;
- public Compilertest3(File f) throws IOException
- {
- // intNames=new String[256];
- // ints=new String[256];
- StringBuffer fileData = new StringBuffer();
- BufferedReader reader = new BufferedReader(
- new FileReader(f));
- char[] buf = new char[1024];
- int numRead=0;
- while((numRead=reader.read(buf)) != -1){
- String readData = String.valueOf(buf, 0, numRead);
- fileData.append(readData);
- }
- reader.close();
- S=fileData.toString();
- }
- public void cleanFile(String input)
- {
- String split[]=input.split("\n");
- input="\n"+input;
- split[0]=" "+split[0];
- int count = 0;
- int intCount = 0;//change this for starting vX value (default: 0)
- int funcCount=0;
- while (count < split.length) {
- if (split[count].startsWith(" define")) {
- split[count] = split[count].substring(8);//remove define and space
- input = input.replaceAll(split[count].split(" ")[0], split[count].substring(split[count].split(" ")[0].length()));
- //the above replaces the first argument with all the last arguments in the define function, in the input string
- // System.err.print(input);
- } if (split[count].startsWith(" int")) {
- //System.out.println("int debug:");
- split[count] = split[count].substring(4);//remove "int" and space
- input = input.replaceAll(split[count], " v" + intCount + " ");
- input= input.replaceAll(split[count], " v" + intCount + " ");//just in case
- intCount++;
- }
- if (split[count].startsWith("func "))
- {
- split[count] = split[count].substring(0);
- input = input.replaceAll(split[count], "~" + funcCount + " ");
- // input = input.replaceAll(split[count], " ~" + funcCount + " ");//just in case
- funcCount++;
- }
- count++;
- }
- input = input.replaceAll("\n int.*.\n", "\n");//this is where the added \n at start is
- input = input.replaceAll("\n func.*.\n", "\n");
- input = input.replaceAll(" #.*.", "");
- input = input.replaceAll("\\{", "");
- while(input.contains(" int ")==true)
- {
- input = input.replaceAll("\n int.*.\n", "\n");
- }
- while(input.contains(" func ")==true)
- {
- input = input.replaceAll("\n func.*.\n", "\n");
- }
- input=input.replaceAll("(?m)^[ \t]*\r?\n", "");//clear all empty lines
- input=input.substring(0);//gets rid of the problem caused by the adding \n thing
- // input = cleanInput(input);//cleans the input for the last time
- //System.err.print(input);
- SClean=input;
- System.err.println(SClean);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement