<commit_before>/*
sopc2dts - Devicetree generation for Altera systems

Copyright (C) 2011 <NAME> <<EMAIL>>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import sopc2dts.Logger;
import sopc2dts.Logger.LogLevel;
import sopc2dts.generators.DTSGenerator;
import sopc2dts.generators.KernelHeadersGenerator;
import sopc2dts.generators.SopcCreateHeaderFilesImitator;
import sopc2dts.gui.Sopc2DTSGui;
import sopc2dts.lib.AvalonSystem;
import sopc2dts.lib.BoardInfo;
import sopc2dts.lib.components.BasicComponent;
import sopc2dts.parsers.BasicSystemLoader;


public class Sopc2DTS {
	protected Vector<CommandLineOption> vOptions = new Vector<CommandLineOption>();
	protected CLParameter showHelp = new CLParameter(""+false);
	protected CLParameter showVersion = new CLParameter("" + false);
	protected CLParameter verbose = new CLParameter("" + false);
	protected CLParameter mimicAlteraTools = new CLParameter("" + false);
	protected CLParameter inputFileName = new CLParameter("");
	protected CLParameter boardFileName = new CLParameter("");
	protected CLParameter outputFileName = new CLParameter("");
	protected CLParameter outputType = new CLParameter("dts");
	protected CLParameter pov = new CLParameter("");
	protected CLParameter bootargs = new CLParameter("");
	protected CLParameter sopcParameters = new CLParameter("none");
	protected CLParameter gui = new CLParameter("" + false);
	BasicComponent.parameter_action dumpParameters = BasicComponent.parameter_action.NONE;

	protected static final String programName = "sopc2dts";
	protected static final String programVersion = "0.2";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Sopc2DTS s2d = new Sopc2DTS();
		try {
			if(s2d.parseCmdLine(args))
			{
				s2d.go();
			}
		} catch(Exception e) {
			e.printStackTrace();
			s2d.printUsage();
		}
	}
	
	public Sopc2DTS() {
		vOptions.add(new CommandLineOption("board", 	"b", boardFileName, 	true, false,"The board description file", "boardinfo file"));
		vOptions.add(new CommandLineOption("help",		"h", showHelp,			false,false,"Show this usage info and exit",null));
		vOptions.add(new CommandLineOption("verbose",	"v", verbose,			false,false,"Show Lots of debugging info", null));
		vOptions.add(new CommandLineOption("gui",		"g", gui,				false,false,"Run in gui mode (beta)", null));
		vOptions.add(new CommandLineOption("version",	null,showVersion,		false,false,"Show version information and exit", null));
		vOptions.add(new CommandLineOption("mimic-sopc-create-header-files"	,"m", mimicAlteraTools,		false,false,"Try to (mis)behave like sopc-create-header-files does", null));
		vOptions.add(new CommandLineOption("input", 	"i", inputFileName, 	true, true, "The sopcinfo file (if not supplied the current dir is scanned for one)", "sopcinfo file"));
		vOptions.add(new CommandLineOption("output",	"o", outputFileName,	true, false,"The output filename","filename"));
		vOptions.add(new CommandLineOption("pov", 		"p", pov,		 		true, false,"The point of view to generate from. Defaults to the first cpu found", "component name"));
		vOptions.add(new CommandLineOption("type", 		"t", outputType, 		true, false,"The type of output to generate", "{dts,uboot,kernel,kernel-full}"));
		vOptions.add(new CommandLineOption("bootargs", 	null,bootargs,	 		true, false,"Default kernel arguments for the \"chosen\" section of the DTS", "kernel-args"));
		vOptions.add(new CommandLineOption("sopc-parameters", 	null,sopcParameters, true, false,"What sopc-parameters to include in DTS: none, cmacro or all.", "choice"));
	}
	protected void go()
	{
		BoardInfo bInfo = null;
		File f;
		if(inputFileName.value.length()==0)
		{
			System.out.println("No input file specified!");
			printUsage();
		}
		if(boardFileName.value.length()>0)
		{
			f = new File(boardFileName.value);
			if(f.exists())
			{
				try {
					bInfo = new BoardInfo(new InputSource(new BufferedReader(new FileReader(f))));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				} catch (SAXException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			f = null;
		}
		if(bInfo==null)
		{
			bInfo = new BoardInfo();
		}
		if(pov.value.length()>0)
		{
			bInfo.setPov(pov.value);
		}
		if(Boolean.parseBoolean(gui.value))
		{
			if(outputType.value.equalsIgnoreCase("dts"))
			{
				Sopc2DTSGui s2dgui = new Sopc2DTSGui(inputFileName.value);
				s2dgui.setVisible(true);
			} else {
				Logger.logln("GUI-Mode is only supported for dts output", 
						LogLevel.ERROR);
			}
		} else {
			f = new File(inputFileName.value);
			if(f.exists())
			{
				try {<commit_msg>sopc2dts: close app when gui closes<commit_after>/*
sopc2dts - Devicetree generation for Altera systems

Copyright (C) 2011 <NAME> <<EMAIL>>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JFrame;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import sopc2dts.Logger;
import sopc2dts.Logger.LogLevel;
import sopc2dts.generators.DTSGenerator;
import sopc2dts.generators.KernelHeadersGenerator;
import sopc2dts.generators.SopcCreateHeaderFilesImitator;
import sopc2dts.gui.Sopc2DTSGui;
import sopc2dts.lib.AvalonSystem;
import sopc2dts.lib.BoardInfo;
import sopc2dts.lib.components.BasicComponent;
import sopc2dts.parsers.BasicSystemLoader;


public class Sopc2DTS {
	protected Vector<CommandLineOption> vOptions = new Vector<CommandLineOption>();
	protected CLParameter showHelp = new CLParameter(""+false);
	protected CLParameter showVersion = new CLParameter("" + false);
	protected CLParameter verbose = new CLParameter("" + false);
	protected CLParameter mimicAlteraTools = new CLParameter("" + false);
	protected CLParameter inputFileName = new CLParameter("");
	protected CLParameter boardFileName = new CLParameter("");
	protected CLParameter outputFileName = new CLParameter("");
	protected CLParameter outputType = new CLParameter("dts");
	protected CLParameter pov = new CLParameter("");
	protected CLParameter bootargs = new CLParameter("");
	protected CLParameter sopcParameters = new CLParameter("none");
	protected CLParameter gui = new CLParameter("" + false);
	BasicComponent.parameter_action dumpParameters = BasicComponent.parameter_action.NONE;

	protected static final String programName = "sopc2dts";
	protected static final String programVersion = "0.2";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Sopc2DTS s2d = new Sopc2DTS();
		try {
			if(s2d.parseCmdLine(args))
			{
				s2d.go();
			}
		} catch(Exception e) {
			e.printStackTrace();
			s2d.printUsage();
		}
	}
	
	public Sopc2DTS() {
		vOptions.add(new CommandLineOption("board", 	"b", boardFileName, 	true, false,"The board description file", "boardinfo file"));
		vOptions.add(new CommandLineOption("help",		"h", showHelp,			false,false,"Show this usage info and exit",null));
		vOptions.add(new CommandLineOption("verbose",	"v", verbose,			false,false,"Show Lots of debugging info", null));
		vOptions.add(new CommandLineOption("gui",		"g", gui,				false,false,"Run in gui mode (beta)", null));
		vOptions.add(new CommandLineOption("version",	null,showVersion,		false,false,"Show version information and exit", null));
		vOptions.add(new CommandLineOption("mimic-sopc-create-header-files"	,"m", mimicAlteraTools,		false,false,"Try to (mis)behave like sopc-create-header-files does", null));
		vOptions.add(new CommandLineOption("input", 	"i", inputFileName, 	true, true, "The sopcinfo file (if not supplied the current dir is scanned for one)", "sopcinfo file"));
		vOptions.add(new CommandLineOption("output",	"o", outputFileName,	true, false,"The output filename","filename"));
		vOptions.add(new CommandLineOption("pov", 		"p", pov,		 		true, false,"The point of view to generate from. Defaults to the first cpu found", "component name"));
		vOptions.add(new CommandLineOption("type", 		"t", outputType, 		true, false,"The type of output to generate", "{dts,uboot,kernel,kernel-full}"));
		vOptions.add(new CommandLineOption("bootargs", 	null,bootargs,	 		true, false,"Default kernel arguments for the \"chosen\" section of the DTS", "kernel-args"));
		vOptions.add(new CommandLineOption("sopc-parameters", 	null,sopcParameters, true, false,"What sopc-parameters to include in DTS: none, cmacro or all.", "choice"));
	}
	protected void go()
	{
		BoardInfo bInfo = null;
		File f;
		if(inputFileName.value.length()==0)
		{
			System.out.println("No input file specified!");
			printUsage();
		}
		if(Boolean.parseBoolean(gui.value))
		{
			if(outputType.value.equalsIgnoreCase("dts"))
			{
				Sopc2DTSGui s2dgui = new Sopc2DTSGui(inputFileName.value, boardFileName.value);
				s2dgui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				s2dgui.setVisible(true);
			} else {
				Logger.logln("GUI-Mode is only supported for dts output", 
						LogLevel.ERROR);
			}
		} else {
			if(boardFileName.value.length()>0)
			{
				f = new File(boardFileName.value);
				if(f.exists())
				{
					try {
						bInfo = new BoardInfo(new InputSource(new BufferedReader(new FileReader(f))));
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					} catch (SAXException e) {
						e.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				f = null;
			}
			if(bInfo==null)
			{
				bInfo = new BoardInfo();
			}
			if(pov.value.length()>0)
			{
				bInfo.setPov(pov.value);
			}
			f = new File(inputFileName.value);
			if(f.exists())
			{
				try {
{'fraction_non_alphanumeric': 0.11773551525873507, 'fraction_numerical': 0.008491817779743477, 'mean_word_length': 4.818836850231601, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5249680', 'n_tokens_mistral': 3885, 'n_tokens_neox': 3542, 'n_words': 999}