예제 #1
0
ScriptSectionType * SCRIPT_AddSection(int32_t scripthandle, char * sectionname)
{
    ScriptSectionType *s,*s2;

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

    s = SCRIPT_SectionExists(scripthandle, sectionname);
    if (s) return s;

    AllocSection(s);
    s->name = Bstrdup(sectionname);
    if (!SCRIPT(scripthandle,script))
    {
        SCRIPT(scripthandle,script) = s;
    }
    else
    {
        s2 = SCRIPT(scripthandle,script);
        while (s2->nextsection != s2) s2=s2->nextsection;
        s2->nextsection = s;
        s->prevsection = s2;
    }

    return s;
}
예제 #2
0
파일: scriplib.c 프로젝트: jonof/jfmact
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;
}
예제 #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
파일: scriplib.c 프로젝트: jonof/jfmact
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
파일: scriplib.c 프로젝트: jonof/jfmact
const char * SCRIPT_Entry( int32 scripthandle, const char * sectionname, int32 which )
{
	ScriptSectionType *s;
	ScriptEntryType *e,*le=NULL;

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

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	if (!s) return "";

	for (e = s->entries; which>0 && le != e; le=e, e=e->nextentry, which--) ;
	return e->name;
}
예제 #6
0
파일: scriplib.c 프로젝트: jonof/jfmact
int32 SCRIPT_NumberEntries( int32 scripthandle, const char * sectionname )
{
	ScriptSectionType *s;
	ScriptEntryType *e,*le=NULL;
	int32 c=0;

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

	s = SCRIPT_SectionExists(scripthandle, sectionname);
	if (!s) return 0;

	for (e = s->entries; le != e; le=e,e=e->nextentry) c++;
	return c;
}
예제 #7
0
파일: scriplib.c 프로젝트: jonof/jfmact
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;
}
예제 #8
0
파일: scriplib.c 프로젝트: jonof/jfmact
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;
}
예제 #9
0
파일: scriplib.c 프로젝트: jonof/jfmact
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;
}