Пример #1
0
boolean SCRIPT_GetNumber( int32 scripthandle, const char * sectionname, const char * entryname, int32 * number )
{
	ScriptSectionType *s;
	ScriptEntryType *e;
	char *p;

	if (!SC(scripthandle)) return 1;
	if (!SCRIPT(scripthandle,script)) return 1;

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	e = SCRIPT_EntryExists(s, entryname);
	
	if (!e) return 1;// *number = 0;
	else {
		if (e->value[0] == '0' && e->value[1] == 'x') {
			// hex
			*number = strtol(e->value+2, &p, 16);
			if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1;
		} else {
			// decimal
			*number = strtol(e->value, &p, 10);
			if (p == e->value || *p != 0 || *p != ' ' || *p != '\t') return 1;
		}
	}

	return 0;
}
Пример #2
0
void SCRIPT_AddEntry ( int32 scripthandle, const char * sectionname, const char * entryname, const char * entryvalue )
{
	ScriptSectionType *s;
	ScriptEntryType *e,*e2;

	if (scripthandle < 0 || scripthandle >= MAXSCRIPTFILES) return;
	if (!sectionname || !entryname || !entryvalue) return;
	if (!SC(scripthandle)) return;

//	s = SCRIPT_SectionExists(scripthandle, sectionname);
//	if (!s) {
		s = SCRIPT_AddSection(scripthandle, sectionname);
		if (!s) return;
//	}

	e = SCRIPT_EntryExists(s, entryname);
	if (!e) {
		AllocEntry(e);
		e->name = strdup(entryname);
		if (!s->entries) {
			s->entries = e;
		} else {
			e2 = s->entries;
			while (e2->nextentry != e2) e2=e2->nextentry;
			e2->nextentry = e;
			e->preventry = e2;
		}
	}

	if (e->value) free(e->value);
	e->value = strdup(entryvalue);
}
Пример #3
0
int32_t SCRIPT_GetString(int32_t scripthandle, char * sectionname, char * entryname, char * dest)
{
    ScriptSectionType *s;
    ScriptEntryType *e;
    char *p, ch;
    int32_t c;

    if (!SC(scripthandle)) return 1;
    if (!SCRIPT(scripthandle,script)) return 1;

    s = SCRIPT_SectionExists(scripthandle, sectionname);
    e = SCRIPT_EntryExists(s, entryname);

    //dest[0] = 0;
    if (!e) return 1;

    p = e->value;
    c = 0;

    if (*p == '\"')
    {
        // quoted string
        p++;
        while ((ch = *(p++)))
        {
            switch (ch)
            {
            case '\\':
                ch = *(p++);
                switch (ch)
                {
                case 0:   return 0;
                case 'n': dest[c++] = '\n'; break;
                case 'r': dest[c++] = '\r'; break;
                case 't': dest[c++] = '\t'; break;
                default:  dest[c++] = ch; break;
                }
                break;
            case '\"':
                dest[c] = 0;
                return 0;
            default:
                dest[c++] = ch;
                break;
            }
        }
    }
    else
    {
        while ((ch = *(p++)))
        {
            if (ch == ' ' || ch == '\t') { dest[c] = 0; break; }
            else dest[c++] = ch;
        }
    }

    return 0;
}
Пример #4
0
const char * SCRIPT_GetRaw(int32 scripthandle, const char * sectionname, const char * entryname)
{
	ScriptSectionType *s;
	ScriptEntryType *e;

	if (!SC(scripthandle)) return 0;
	if (!SCRIPT(scripthandle,script)) return 0;

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	e = SCRIPT_EntryExists(s, entryname);

	if (!e) return "";
	return e->value;
}
Пример #5
0
boolean SCRIPT_GetDouble( int32 scripthandle, const char * sectionname, const char * entryname, double * UNUSED(number) )
{
	ScriptSectionType *s;
	ScriptEntryType *e;

	if (!SC(scripthandle)) return 1;
	if (!SCRIPT(scripthandle,script)) return 1;

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	e = SCRIPT_EntryExists(s, entryname);
	
	if (!e) return 1;// *number = 0.0;
	else {
        //XXX
	}

	return 0;
}
Пример #6
0
boolean SCRIPT_GetBoolean( int32 scripthandle, const char * sectionname, const char * entryname, boolean * boole )
{
	ScriptSectionType *s;
	ScriptEntryType *e;

	if (!SC(scripthandle)) return 1;
	if (!SCRIPT(scripthandle,script)) return 1;

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	e = SCRIPT_EntryExists(s, entryname);
	
	if (!e) return 1;// *boole = 0;
	else {
		if (!Bstrncasecmp(e->value, "true", 4)) *boole = 1;
		else if (!Bstrncasecmp(e->value, "false", 5)) *boole = 0;
		else if (e->value[0] == '1' && (e->value[1] == ' ' || e->value[1] == '\t' || e->value[1] == 0)) *boole = 1;
		else if (e->value[0] == '0' && (e->value[1] == ' ' || e->value[1] == '\t' || e->value[1] == 0)) *boole = 0;
	}

	return 0;
}
Пример #7
0
boolean SCRIPT_GetDoubleString( int32 scripthandle, const char * sectionname, const char * entryname, char * dest1, char * dest2, size_t dest1len, size_t dest2len )
{
	ScriptSectionType *s;
	ScriptEntryType *e;
	const char *p;
    char ch, done;
	size_t c;

	if (!SC(scripthandle)) return 1;
	if (!SCRIPT(scripthandle,script)) return 1;

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	e = SCRIPT_EntryExists(s, entryname);
	
	if (!e) return 1;
	if (dest1len < 1) return 1;
	if (dest2len < 1) return 1;

	// Deduct the terminating nulls.
	dest1len--;
	dest2len--;

	p = e->value;
	c = 0;
	done = 0;
		
	if (*p == '\"') {
		// quoted string
		p++;
		while (!done && (ch = *(p++))) {
			switch (ch) {
				case '\\':
					ch = *(p++);
					if (ch == 0) {
						done = 1;
					} else if (c < dest1len) {
						switch (ch) {
							case 'n': dest1[c++] = '\n'; break;
							case 'r': dest1[c++] = '\r'; break;
							case 't': dest1[c++] = '\t'; break;
							default:  dest1[c++] = ch; break;
						}
					}
					break;
				case '\"':
					done = 1;
					break;
				default:
					if (c < dest1len) {
						dest1[c++] = ch;
					}
					break;
			}
		}
	} else {
		while ((ch = *(p++))) {
			if (ch == ' ' || ch == '\t') {
				break;
			} else if (c < dest1len) {
				dest1[c++] = ch;
			}
		}
	}

	dest1[c] = 0;

	while (*p == ' ' || *p == '\t') p++;
	if (*p == 0) return 0;

	c = 0;
	done = 0;
		
	if (*p == '\"') {
		// quoted string
		p++;
		while (!done && (ch = *(p++))) {
			switch (ch) {
				case '\\':
					ch = *(p++);
					if (ch == 0) {
						done = 1;
					} else if (c < dest2len) {
						switch (ch) {
							case 'n': dest2[c++] = '\n'; break;
							case 'r': dest2[c++] = '\r'; break;
							case 't': dest2[c++] = '\t'; break;
							default:  dest2[c++] = ch; break;
						}
					}
					break;
				case '\"':
					done = 1;
					break;
				default:
					if (c < dest2len) {
						dest2[c++] = ch;
					}
					break;
			}
		}
	} else {
		while ((ch = *(p++))) {
			if (ch == ' ' || ch == '\t') {
				break;
			} else if (c < dest2len) {
				dest2[c++] = ch;
			}
		}
	}

	dest2[c] = 0;

	return 0;
}