Exemplo n.º 1
0
/* Appends characters in str to buf. */
struct Buf *
buf_strappend(struct Buf *buf, const char *str)
{
	return buf_strnappend(buf, str, strlen(str));
}
Exemplo n.º 2
0
void flexinit (int argc, char **argv)
{
	int     i, sawcmpflag, rv, optind;
	char   *arg;
	scanopt_t sopt;

	printstats = syntaxerror = trace = spprdflt = false;
	lex_compat = posix_compat = C_plus_plus = backing_up_report =
		ddebug = fulltbl = false;
	fullspd = long_align = nowarn = yymore_used = continued_action =
		false;
	do_yylineno = yytext_is_array = in_rule = reject = do_stdinit =
		false;
	yymore_really_used = reject_really_used = unspecified;
	interactive = csize = unspecified;
	do_yywrap = gen_line_dirs = usemecs = useecs = true;
	reentrant = bison_bridge_lval = bison_bridge_lloc = false;
	performance_report = 0;
	did_outfilename = 0;
	prefix = "yy";
	yyclass = 0;
	use_read = use_stdout = false;
	tablesext = tablesverify = false;
	gentables = true;
	tablesfilename = tablesname = NULL;

	sawcmpflag = false;

	/* Initialize dynamic array for holding the rule actions. */
	action_size = 2048;	/* default size of action array in bytes */
	action_array = allocate_character_array (action_size);
	defs1_offset = prolog_offset = action_offset = action_index = 0;
	action_array[0] = '\0';

	/* Initialize any buffers. */
	buf_init (&userdef_buf, sizeof (char));	/* one long string */
	buf_init (&defs_buf, sizeof (char *));	/* list of strings */
	buf_init (&yydmap_buf, sizeof (char));	/* one long string */
	buf_init (&top_buf, sizeof (char));	    /* one long string */

    {
        const char * m4defs_init_str[] = {"m4_changequote\n",
                                          "m4_changequote([[, ]])\n"};
        buf_init (&m4defs_buf, sizeof (char *));
        buf_append (&m4defs_buf, &m4defs_init_str, 2);
    }

    sf_init ();

    /* initialize regex lib */
    flex_init_regex();

	/* Enable C++ if program name ends with '+'. */
	program_name = basename (argv[0]);

	if (program_name != NULL &&
	    program_name[strlen (program_name) - 1] == '+')
		C_plus_plus = true;

	/* read flags */
	sopt = scanopt_init (flexopts, argc, argv, 0);
	if (!sopt) {
		/* This will only happen when flexopts array is altered. */
		fprintf (stderr,
			 _("Internal error. flexopts are malformed.\n"));
		FLEX_EXIT (1);
	}

	while ((rv = scanopt (sopt, &arg, &optind)) != 0) {

		if (rv < 0) {
			/* Scanopt has already printed an option-specific error message. */
			fprintf (stderr,
				 _
				 ("Try `%s --help' for more information.\n"),
				 program_name);
			FLEX_EXIT (1);
		}

		switch ((enum flexopt_flag_t) rv) {
		case OPT_CPLUSPLUS:
			C_plus_plus = true;
			break;

		case OPT_BATCH:
			interactive = false;
			break;

		case OPT_BACKUP:
			backing_up_report = true;
			break;

		case OPT_DONOTHING:
			break;

		case OPT_COMPRESSION:
			if (!sawcmpflag) {
				useecs = false;
				usemecs = false;
				fulltbl = false;
				sawcmpflag = true;
			}

			for (i = 0; arg && arg[i] != '\0'; i++)
				switch (arg[i]) {
				case 'a':
					long_align = true;
					break;

				case 'e':
					useecs = true;
					break;

				case 'F':
					fullspd = true;
					break;

				case 'f':
					fulltbl = true;
					break;

				case 'm':
					usemecs = true;
					break;

				case 'r':
					use_read = true;
					break;

				default:
					lerr (_
						("unknown -C option '%c'"),
						arg[i]);
					break;
				}
			break;

		case OPT_DEBUG:
			ddebug = true;
			break;

		case OPT_NO_DEBUG:
			ddebug = false;
			break;

		case OPT_FULL:
			useecs = usemecs = false;
			use_read = fulltbl = true;
			break;

		case OPT_FAST:
			useecs = usemecs = false;
			use_read = fullspd = true;
			break;

		case OPT_HELP:
			usage ();
			FLEX_EXIT (0);

		case OPT_INTERACTIVE:
			interactive = true;
			break;

		case OPT_CASE_INSENSITIVE:
			sf_set_case_ins(true);
			break;

		case OPT_LEX_COMPAT:
			lex_compat = true;
			break;

		case OPT_POSIX_COMPAT:
			posix_compat = true;
			break;

        case OPT_PREPROC_LEVEL:
            preproc_level = (int) strtol(arg,NULL,0);
            break;

		case OPT_MAIN:
			buf_strdefine (&userdef_buf, "YY_MAIN", "1");
			do_yywrap = false;
			break;

		case OPT_NO_MAIN:
			buf_strdefine (&userdef_buf, "YY_MAIN", "0");
			break;

		case OPT_NO_LINE:
			gen_line_dirs = false;
			break;

		case OPT_OUTFILE:
			outfilename = arg;
			did_outfilename = 1;
			break;

		case OPT_PREFIX:
			prefix = arg;
			break;

		case OPT_PERF_REPORT:
			++performance_report;
			break;

		case OPT_BISON_BRIDGE:
			bison_bridge_lval = true;
			break;

		case OPT_BISON_BRIDGE_LOCATIONS:
			bison_bridge_lval = bison_bridge_lloc = true;
			break;

		case OPT_REENTRANT:
			reentrant = true;
			break;

		case OPT_NO_REENTRANT:
			reentrant = false;
			break;

		case OPT_SKEL:
			skelname = arg;
			break;

		case OPT_DEFAULT:
			spprdflt = false;
			break;

		case OPT_NO_DEFAULT:
			spprdflt = true;
			break;

		case OPT_STDOUT:
			use_stdout = true;
			break;

		case OPT_NO_UNISTD_H:
			//buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0);
			break;

		case OPT_TABLES_FILE:
			tablesext = true;
			tablesfilename = arg;
			break;

		case OPT_TABLES_VERIFY:
			tablesverify = true;
			break;

		case OPT_TRACE:
			trace = true;
			break;

		case OPT_VERBOSE:
			printstats = true;
			break;

		case OPT_VERSION:
			printf (_("%s %s\n"), program_name, flex_version);
			FLEX_EXIT (0);

		case OPT_WARN:
			nowarn = false;
			break;

		case OPT_NO_WARN:
			nowarn = true;
			break;

		case OPT_7BIT:
			csize = 128;
			break;

		case OPT_8BIT:
			csize = CSIZE;
			break;

		case OPT_ALIGN:
			long_align = true;
			break;

		case OPT_NO_ALIGN:
			long_align = false;
			break;

		case OPT_ALWAYS_INTERACTIVE:
			buf_m4_define (&m4defs_buf, "M4_YY_ALWAYS_INTERACTIVE", 0);
			break;

		case OPT_NEVER_INTERACTIVE:
            buf_m4_define( &m4defs_buf, "M4_YY_NEVER_INTERACTIVE", 0);
			break;

		case OPT_ARRAY:
			yytext_is_array = true;
			break;

		case OPT_POINTER:
			yytext_is_array = false;
			break;

		case OPT_ECS:
			useecs = true;
			break;

		case OPT_NO_ECS:
			useecs = false;
			break;

		case OPT_HEADER_FILE:
			headerfilename = arg;
			break;

		case OPT_META_ECS:
			usemecs = true;
			break;

		case OPT_NO_META_ECS:
			usemecs = false;
			break;

		case OPT_PREPROCDEFINE:
			{
				/* arg is "symbol" or "symbol=definition". */
				char   *def;

				for (def = arg;
				     *def != '\0' && *def != '='; ++def) ;

				buf_strappend (&userdef_buf, "#define ");
				if (*def == '\0') {
					buf_strappend (&userdef_buf, arg);
					buf_strappend (&userdef_buf,
						       " 1\n");
				}
				else {
					buf_strnappend (&userdef_buf, arg,
							(int) (def - arg));
					buf_strappend (&userdef_buf, " ");
					buf_strappend (&userdef_buf,
						       def + 1);
					buf_strappend (&userdef_buf, "\n");
				}
			}
			break;

		case OPT_READ:
			use_read = true;
			break;

		case OPT_STACK:
			//buf_strdefine (&userdef_buf, "YY_STACK_USED", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0);
			break;

		case OPT_STDINIT:
			do_stdinit = true;
			break;

		case OPT_NO_STDINIT:
			do_stdinit = false;
			break;

		case OPT_YYCLASS:
			yyclass = arg;
			break;

		case OPT_YYLINENO:
			do_yylineno = true;
			break;

		case OPT_NO_YYLINENO:
			do_yylineno = false;
			break;

		case OPT_YYWRAP:
			do_yywrap = true;
			break;

		case OPT_NO_YYWRAP:
			do_yywrap = false;
			break;

		case OPT_YYMORE:
			yymore_really_used = true;
			break;

		case OPT_NO_YYMORE:
			yymore_really_used = false;
			break;

		case OPT_REJECT:
			reject_really_used = true;
			break;

		case OPT_NO_REJECT:
			reject_really_used = false;
			break;

		case OPT_NO_YY_PUSH_STATE:
			//buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0);
			break;
		case OPT_NO_YY_POP_STATE:
			//buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0);
			break;
		case OPT_NO_YY_TOP_STATE:
			//buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0);
			break;
		case OPT_NO_UNPUT:
			//buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0);
			break;
		case OPT_NO_YY_SCAN_BUFFER:
			//buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0);
			break;
		case OPT_NO_YY_SCAN_BYTES:
			//buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0);
			break;
		case OPT_NO_YY_SCAN_STRING:
			//buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0);
			break;
		case OPT_NO_YYGET_EXTRA:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0);
			break;
		case OPT_NO_YYSET_EXTRA:
			//buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0);
			break;
		case OPT_NO_YYGET_LENG:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0);
			break;
		case OPT_NO_YYGET_TEXT:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0);
			break;
		case OPT_NO_YYGET_LINENO:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0);
			break;
		case OPT_NO_YYSET_LINENO:
			//buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0);
			break;
		case OPT_NO_YYGET_IN:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0);
			break;
		case OPT_NO_YYSET_IN:
			//buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0);
			break;
		case OPT_NO_YYGET_OUT:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0);
			break;
		case OPT_NO_YYSET_OUT:
			//buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0);
			break;
		case OPT_NO_YYGET_LVAL:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0);
			break;
		case OPT_NO_YYSET_LVAL:
			//buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0);
			break;
		case OPT_NO_YYGET_LLOC:
			//buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0);
			break;
		case OPT_NO_YYSET_LLOC:
			//buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1");
            buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0);
			break;
		case OPT_HEX:
			trace_hex = 1;
                        break;
                case OPT_NO_SECT3_ESCAPE:
                        no_section3_escape = true;
                        break;
		}		/* switch */
	}			/* while scanopt() */

	scanopt_destroy (sopt);

	num_input_files = argc - optind;
	input_files = argv + optind;
	set_input_file (num_input_files > 0 ? input_files[0] : NULL);

	lastccl = lastsc = lastdfa = lastnfa = 0;
	num_rules = num_eof_rules = default_rule = 0;
	numas = numsnpairs = tmpuses = 0;
	numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst =
		0;
	numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
	num_backing_up = onesp = numprots = 0;
	variable_trailing_context_rules = bol_needed = false;

	linenum = sectnum = 1;
	firstprot = NIL;

	/* Used in mkprot() so that the first proto goes in slot 1
	 * of the proto queue.
	 */
	lastprot = 1;

	set_up_initial_allocations ();
}