<commit_before>/*
 * Anarres C Preprocessor
 * Copyright (C) 2007 Shevek
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.anarres.cpp;

import java.io.File;
import java.io.IOException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

import gnu.getopt.Getopt;
import gnu.getopt.LongOpt;

import static org.anarres.cpp.Token.*;

/**
 * (Currently a simple test class).
 */
public class Main {

    protected static class Option extends LongOpt {
        private String  eg;
        private String  help;
        public Option(String word, int arg, int ch,
                        String eg, String help) {
            super(word, arg, null, ch);
            this.eg = eg;
            this.help = help;
        }
    }

	private List<String>		i_default;
	private List<String>		i_system;
	private List<String>		i_user;
	private List<String>		i_quote;
	private Map<String,String>	d_default;
	private Map<String,String>	d_user;
	private Set<Warning>		warnings;
	private List<String>		f_include;

	private static final Option[]	OPTS = new Option[] {
		new Option("help",   LongOpt.NO_ARGUMENT,       'h', null,
			"Displays help and usage information."),
		new Option("define", LongOpt.REQUIRED_ARGUMENT, 'D', "name=definition",
			"Defines the given macro."),
		new Option("undefine", LongOpt.REQUIRED_ARGUMENT, 'U', "name",
			"Undefines the given macro, previously either builtin or defined using -D."),
		new Option("include", LongOpt.REQUIRED_ARGUMENT, 'i', "file",
			"Process file as if \"#" + "include \"file\"\" appeared as the first line of the primary source file."),
		new Option("incdir", LongOpt.REQUIRED_ARGUMENT, 'I', "dir",
			"Adds the directory dir to the list of directories to be searched for header files."),
		new Option("warning", LongOpt.REQUIRED_ARGUMENT, 'W', "type",
			"Enables the named warning class ("  + getWarnings() + ")."),
		new Option("no-warnings", LongOpt.NO_ARGUMENT, 'w', null,
			"Disables ALL warnings."),
		new Option("version", LongOpt.NO_ARGUMENT, 'V', null,
			"Prints jcpp's version number (" + Version.getVersion() + ")"),
	};

	private static CharSequence getWarnings() {
		StringBuilder	buf = new StringBuilder();
		for (Warning w : Warning.values()) {
			if (buf.length() > 0)
				buf.append(", ");
			String	name = w.name().toLowerCase();
			buf.append(name.replace('_', '-'));
		}
		return buf;
	}

	public static void main(String[] args) throws Exception {
		(new Main()).run(OPTS, args);
	}

	public Main() {
		i_default = new ArrayList<String>();
		i_system = new ArrayList<String>();
		i_user = new ArrayList<String>();
		i_quote = new ArrayList<String>();
		d_default = new HashMap<String,String>();
		d_user = new HashMap<String,String>();
	}

	public void run(Option[] opts, String[] args) throws Exception {
        String	sopts = getShortOpts(opts);
        Getopt	g = new Getopt("jcpp", args, sopts, opts);
		int		c;
		String	arg;
		int		idx;

		Preprocessor	pp = new Preprocessor();
		pp.addFeature(Feature.LINEMARKERS);

        GETOPT: while ((c = g.getopt()) != -1) {
            switch (c) {
				case 'D':
					arg = g.getOptarg();
					idx = arg.indexOf('=');
					if (idx == -1)
						d_user.put(arg, "1");
					else
						d_user.put(arg.substring(0, idx),
									arg.substring(idx + 1));
					break;
				case 'U':
					d_default.remove(g.getOptarg());
					d_user.remove(g.getOptarg());
					break;
				case 'I':
					i_user.add(g.getOptarg());
					break;
				case 'W':
					arg = g.getOptarg().toUpperCase();
					arg = arg.replace('-', '_');
					if (arg.equals("all"))
						pp.addWarnings(EnumSet.allOf(Warning.class));
					else
						pp.addWarning(Enum.valueOf(Warning.class, arg));
					break;
                case 'w':
					pp.getWarnings().clear();
					break;
				case 'i':
					// pp.addInput(new File(g.getOptarg()));
					// Comply exactly with spec.
					pp.addInput(new StringLexerSource(
						"#" + "include \"" + g.getOptarg() + "\"\n"
					));
					break;
				case 'V':
					System.out.println("Anarres Java C Preprocessor version " + Version.getVersion());
					return;
                case 'h':
                    usage(getClass().getName(), opts);
					return;
                default:
                case '?':
                    throw new Exception("Illegal option " + c);
			}
		}

		/* XXX include-path, include-files. */<commit_msg>extend version info<commit_after>/*
 * Anarres C Preprocessor
 * Copyright (C) 2007 Shevek
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.anarres.cpp;

import java.io.File;
import java.io.IOException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

import gnu.getopt.Getopt;
import gnu.getopt.LongOpt;

import static org.anarres.cpp.Token.*;

/**
 * (Currently a simple test class).
 */
public class Main {

    protected static class Option extends LongOpt {
        private String  eg;
        private String  help;
        public Option(String word, int arg, int ch,
                        String eg, String help) {
            super(word, arg, null, ch);
            this.eg = eg;
            this.help = help;
        }
    }

	private List<String>		i_default;
	private List<String>		i_system;
	private List<String>		i_user;
	private List<String>		i_quote;
	private Map<String,String>	d_default;
	private Map<String,String>	d_user;
	private Set<Warning>		warnings;
	private List<String>		f_include;

	private static final Option[]	OPTS = new Option[] {
		new Option("help",   LongOpt.NO_ARGUMENT,       'h', null,
			"Displays help and usage information."),
		new Option("define", LongOpt.REQUIRED_ARGUMENT, 'D', "name=definition",
			"Defines the given macro."),
		new Option("undefine", LongOpt.REQUIRED_ARGUMENT, 'U', "name",
			"Undefines the given macro, previously either builtin or defined using -D."),
		new Option("include", LongOpt.REQUIRED_ARGUMENT, 'i', "file",
			"Process file as if \"#" + "include \"file\"\" appeared as the first line of the primary source file."),
		new Option("incdir", LongOpt.REQUIRED_ARGUMENT, 'I', "dir",
			"Adds the directory dir to the list of directories to be searched for header files."),
		new Option("warning", LongOpt.REQUIRED_ARGUMENT, 'W', "type",
			"Enables the named warning class ("  + getWarnings() + ")."),
		new Option("no-warnings", LongOpt.NO_ARGUMENT, 'w', null,
			"Disables ALL warnings."),
		new Option("version", LongOpt.NO_ARGUMENT, 'V', null,
			"Prints jcpp's version number (" + Version.getVersion() + ")"),
	};

	private static CharSequence getWarnings() {
		StringBuilder	buf = new StringBuilder();
		for (Warning w : Warning.values()) {
			if (buf.length() > 0)
				buf.append(", ");
			String	name = w.name().toLowerCase();
			buf.append(name.replace('_', '-'));
		}
		return buf;
	}

	public static void main(String[] args) throws Exception {
		(new Main()).run(OPTS, args);
	}

	public Main() {
		i_default = new ArrayList<String>();
		i_system = new ArrayList<String>();
		i_user = new ArrayList<String>();
		i_quote = new ArrayList<String>();
		d_default = new HashMap<String,String>();
		d_user = new HashMap<String,String>();
	}

	public void run(Option[] opts, String[] args) throws Exception {
        String	sopts = getShortOpts(opts);
        Getopt	g = new Getopt("jcpp", args, sopts, opts);
		int		c;
		String	arg;
		int		idx;

		Preprocessor	pp = new Preprocessor();
		pp.addFeature(Feature.LINEMARKERS);

        GETOPT: while ((c = g.getopt()) != -1) {
            switch (c) {
				case 'D':
					arg = g.getOptarg();
					idx = arg.indexOf('=');
					if (idx == -1)
						d_user.put(arg, "1");
					else
						d_user.put(arg.substring(0, idx),
									arg.substring(idx + 1));
					break;
				case 'U':
					d_default.remove(g.getOptarg());
					d_user.remove(g.getOptarg());
					break;
				case 'I':
					i_user.add(g.getOptarg());
					break;
				case 'W':
					arg = g.getOptarg().toUpperCase();
					arg = arg.replace('-', '_');
					if (arg.equals("all"))
						pp.addWarnings(EnumSet.allOf(Warning.class));
					else
						pp.addWarning(Enum.valueOf(Warning.class, arg));
					break;
                case 'w':
					pp.getWarnings().clear();
					break;
				case 'i':
					// pp.addInput(new File(g.getOptarg()));
					// Comply exactly with spec.
					pp.addInput(new StringLexerSource(
						"#" + "include \"" + g.getOptarg() + "\"\n"
					));
					break;
				case 'V':
					System.out.println("Anarres Java C Preprocessor version " + Version.getVersion());
					System.out.println("Copyright (C) 2008 Shevek (http://www.anarres.org/).");
					System.out.println("This is free software; see the source for copying conditions.  There is NO");
					System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
					return;
                case 'h':
                    usage(getClass().getName(), opts);
					return;
                default:
                case '?':
                    throw new Exception("Illegal option " + c);
			}
		}

		/* XXX include-path, include-files. */
{'fraction_non_alphanumeric': 0.13446792593977933, 'fraction_numerical': 0.0044884982233027865, 'mean_word_length': 2.9847242921013413, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, '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': '7640466', 'n_tokens_mistral': 3804, 'n_tokens_neox': 3326, 'n_words': 1023}