view lwasm/pragma.c @ 325:619fd6ad4ab9

Completed command line parsing
author lost
date Sat, 13 Feb 2010 05:20:55 +0000
parents
children f5b77989f675
line wrap: on
line source

/*
pragma.c

Copyright © 2010 William Astle

This file is part of LWTOOLS.

LWTOOLS 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 3 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, see <http://www.gnu.org/licenses/>.
*/

#include <config.h>

#include <lw_string.h>

#include "lwasm.h"

struct pragma_list
{
	const char *str;
	int flag;
};

static const struct pragma_list set_pragmas[] =
{
	{ "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
	{ "noindex0tonone", PRAGMA_NOINDEX0TONONE },
	{ "undefextern", PRAGMA_UNDEFEXTERN },
	{ "cescapes", PRAGMA_CESCAPES },
	{ "importundefexport", PRAGMA_IMPORTUNDEFEXPORT },
	{ 0, 0 }
};

static const struct pragma_list reset_pragmas[] =
{
	{ "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
	{ "index0tonone", PRAGMA_NOINDEX0TONONE },
	{ "noundefextern", PRAGMA_UNDEFEXTERN },
	{ "nocescapes", PRAGMA_CESCAPES },
	{ "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT },
	{ 0, 0 }
};

int parse_pragma_string(asmstate_t *as, char *str)
{
	char *p;
	int i;
	const char *np = str;
	int pragmas = as -> pragmas;

	while (np)
	{
		p = lw_token(np, ',', &np);
		for (i = 0; set_pragmas[i].str; i++)
		{
			if (!strcasecmp(p, set_pragmas[i].str))
			{
				pragmas |= set_pragmas[i].flag;
				goto out;
			}
		}
		for (i = 0; reset_pragmas[i].str; i++)
		{
			if (!strcasecmp(p, reset_pragmas[i].str))
			{
				pragmas &= ~(reset_pragmas[i].flag);
				goto out;
			}
		}
		/* unrecognized pragma here */
		lw_free(p);
		return 0;
		
	out:	
		lw_free(p);
	}
	as -> pragmas = pragmas;
	return 1;
}