コード例 #1
0
ファイル: scriplib.c プロジェクト: Rockbox/rockbox
/*
==============
=
= SCRIPT_PutNumber
=
==============
*/
void SCRIPT_PutNumber
   (
   int32 scripthandle,
   char  * sectionname,
   char  * entryname,
   int32 number,
   boolean hexadecimal,
   boolean defaultvalue
   )
{
	/* DDOI - I don't know what "defaultvalue" is for so it's ignored */
	scriptnode_t *head;
	scriptnode_t *section;
	scriptnode_t *node;

	if(scripthandle >= MAX_SCRIPTS || scripthandle < 0)
		return;

	head = script_headnode[scripthandle];

	/* We're screwed if there's no head */
	if (head == NULL) return;

	section = SCRIPT_findinchildren (head, sectionname);
	if (section == NULL)
	{
		/* Add the section if it does not exist */
		section = SCRIPT_constructnode ();
		section->type = SCRIPTFLAG_CATEGORY;
		section->key = SCRIPT_copystring (sectionname);
		SCRIPT_addchild (head, section);
	}

	node = SCRIPT_findinchildren (section, entryname);
	if (node == NULL)
	{
		/* Add the section if it does not exist */
		node = SCRIPT_constructnode ();
		node->key = SCRIPT_copystring (entryname);
		SCRIPT_addchild (section, node);
	}

	if (hexadecimal)
		node->type = SCRIPTFLAG_HEX;
	else
		node->type = SCRIPTFLAG_DECIMAL;
	node->data.number = number;
}
コード例 #2
0
ファイル: scriplib.c プロジェクト: Rockbox/rockbox
/*
==============
=
= SCRIPT_PutDoubleString
=
==============
*/
void SCRIPT_PutDoubleString
   (
   int32 scripthandle,
   char  * sectionname,
   char  * entryname,
   char  * string1,
   char  * string2
   )
{
	scriptnode_t *head;
	scriptnode_t *section;
	scriptnode_t *node;

	if(scripthandle >= MAX_SCRIPTS || scripthandle < 0)
		return;

	head = script_headnode[scripthandle];

	/* We're screwed if there's no head */
	if (head == NULL) return;

	section = SCRIPT_findinchildren (head, sectionname);
	if (section == NULL)
	{
		/* Add the section if it does not exist */
		section = SCRIPT_constructnode ();
		section->type = SCRIPTFLAG_CATEGORY;
		section->key = SCRIPT_copystring (sectionname);
		SCRIPT_addchild (head, section);
	}

	node = SCRIPT_findinchildren (section, entryname);
	if (node == NULL)
	{
		/* Add the section if it does not exist */
		node = SCRIPT_constructnode ();
		node->type = SCRIPTFLAG_TWOSTRING;
		node->key = SCRIPT_copystring (entryname);
		SCRIPT_addchild (section, node);
	} else {
		free (node->data.string[0]);
		free (node->data.string[1]);
	}

	node->data.string[0] = SCRIPT_copystring (string1);
	node->data.string[1] = SCRIPT_copystring (string2);
}
コード例 #3
0
ファイル: scriplib.c プロジェクト: Ellorah/chocolate_duke3D
int32 SCRIPT_Load ( char  * filename )
{
	FILE *fp;
	char  curline[128];
	scriptnode_t *headnode = NULL;
	scriptnode_t *cur_subsection = NULL;

	if (script_numscriptsopen == MAX_SCRIPTS) return -1;

	/* The main program does not check for any sort of */
	/* error in loading, so each SCRIPT_ function needs */
	/* to check if the handle is -1 before doing anything */
	fp = fopen (filename, "r");

	if (fp == NULL) return -1;

	/* Start loading the script */
	/* Loads and parse the entire file into a tree */
	script_numscriptsopen++;

	/* script_nexthandle is the current handle until we increment it */
	script_headnode[script_nexthandle] = SCRIPT_constructnode ();
	headnode = script_headnode[script_nexthandle];

	memset (curline, 0, 128);
	while (fgets (curline, 128, fp))
	{
		/* Skip comments */
		if (curline[0] == ';') continue;

		/* Parse line */
		/* We have two options... it starts with a [, making it */
		/* a new subsection (child of headnode) or it starts with */
		/* a letter, making it a child of a subsection. */
		if (curline[0] == '[')
		{
			scriptnode_t *node;
			int i;
			
			/* Remove [] manually */
			for (i = 0; i < 127; i++)
				curline[i] = curline[i+1];
			for (i = 127; i >= 0; i--)
			{
				if (curline[i] == ']') {
					curline[i] = '\0';
					break;
				} else {
					curline[i] = '\0';
				}
			}

			/* Insert into head */
			node = SCRIPT_constructnode ();
			node->type = SCRIPTFLAG_CATEGORY;
			node->key = SCRIPT_copystring (curline);
			SCRIPT_addchild (headnode, node);
			cur_subsection = node;
			/* printf ("Working in section \"%s\"\n", node->key); */
		} else if (isalpha (curline[0])) {
			scriptnode_t *node;

			/* Ignore if not under a subsection */
			if (cur_subsection == NULL)
				continue;

			node = SCRIPT_constructnode ();
			
			/* TODO: Parse line here */
			SCRIPT_parseline (curline, node);
			if (node != NULL)
			{
				/* printf ("Adding node with key \"%s\"\n", node->key); */
				SCRIPT_addchild (cur_subsection, node);
			}
		}
		memset (curline, 0, 128);
	}

	fclose (fp);

	return script_nexthandle++;	/* postincrement is important here */
}