⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scriplib.c

📁 An interactive water fountain. A realistic water source in your pocket with full control. Contro
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (!filename) return;    if (!SC(scripthandle)) return;    fp = fopen(filename, "w");    if (!fp) return;    numsect = SCRIPT_NumberSections(scripthandle);    for (sec=0; sec<numsect; sec++)    {        section = SCRIPT_Section(scripthandle, sec);        if (sec>0) fprintf(fp, "\n");        if (section[0] != 0)            fprintf(fp, "[%s]\n", section);        nument = SCRIPT_NumberEntries(scripthandle,section);        for (ent=0; ent<nument; ent++)        {            entry = SCRIPT_Entry(scripthandle,section,ent);            value = SCRIPT_GetRaw(scripthandle,section,entry);            fprintf(fp, "%s = %s\n", entry, value);        }    }    fclose(fp);}int32 SCRIPT_NumberSections(int32 scripthandle){    int32 c=0;    ScriptSectionType *s,*ls=NULL;    if (!SC(scripthandle)) return 0;    if (!SCRIPT(scripthandle,script)) return 0;    for (s = SCRIPT(scripthandle,script); ls != s; ls=s,s=s->nextsection) c++;    return c;}char * SCRIPT_Section(int32 scripthandle, int32 which){    ScriptSectionType *s,*ls=NULL;    if (!SC(scripthandle)) return "";    if (!SCRIPT(scripthandle,script)) return "";    for (s = SCRIPT(scripthandle,script); which>0 && ls != s; ls=s, s=s->nextsection, which--) ;    return s->name;}int32 SCRIPT_NumberEntries(int32 scripthandle, 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;}char * SCRIPT_Entry(int32 scripthandle, 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;}char * SCRIPT_GetRaw(int32 scripthandle, char * sectionname, 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;}boolean SCRIPT_GetString(int32 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;}boolean SCRIPT_GetDoubleString(int32 scripthandle, char * sectionname, char * entryname, char * dest1, char * dest2){    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);    //dest1[0] = 0;    //dest2[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': dest1[c++] = '\n'; break;                case 'r': dest1[c++] = '\r'; break;                case 't': dest1[c++] = '\t'; break;                default:  dest1[c++] = ch; break;                }                break;            case '\"':                dest1[c] = 0;                goto breakme;            default:                dest1[c++] = ch;                break;            }        }        if (ch == 0) return 0;    }    else    {        while ((ch = *(p++)))        {            if (ch == ' ' || ch == '\t') { dest1[c] = 0; break; }            else dest1[c++] = ch;        }    }breakme:    while (*p == ' ' || *p == '\t') p++;    if (*p == 0) return 0;    c = 0;    if (*p == '\"')    {        // quoted string        p++;        while ((ch = *(p++)))        {            switch (ch)            {            case '\\':                ch = *(p++);                switch (ch)                {                case 0:   return 0;                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 '\"':                dest2[c] = 0;                return 0;            default:                dest2[c++] = ch;                break;            }        }    }    else    {        while ((ch = *(p++)))        {            if (ch == ' ' || ch == '\t') { dest2[c] = 0; break; }            else dest2[c++] = ch;        }    }    return 0;}boolean SCRIPT_GetNumber(int32 scripthandle, char * sectionname, 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;}boolean SCRIPT_GetBoolean(int32 scripthandle, char * sectionname, 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;}void SCRIPT_PutSection(int32 scripthandle, char * sectionname){    SCRIPT_AddSection(scripthandle, sectionname);}void SCRIPT_PutRaw(    int32 scripthandle,    char * sectionname,    char * entryname,    char * raw){    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);}void SCRIPT_PutString(    int32 scripthandle,    char * sectionname,    char * entryname,    char * string){    char *raw,*q,*p;    int32_t len = 3;    if (!string) string = "";    for (q=string; *q; q++)    {        if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;        else if (*q >= ' ') len++;    }    p = raw = Bmalloc(len);    *(p++) = '"';    for (q=string; *q; q++)    {        if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }        else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }        else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }        else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; }        else if (*q >= ' ') *(p++) = *q;    }    *(p++) = '"';    *p=0;    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);    Bfree(raw);}void SCRIPT_PutDoubleString(    int32 scripthandle,    char * sectionname,    char * entryname,    char * string1,    char * string2){    char *raw,*q,*p;    int32_t len = 6;    if (!string1) string1 = "";    if (!string2) string2 = "";    for (q=string1; *q; q++)    {        if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;        else if (*q >= ' ') len++;    }    for (q=string2; *q; q++)    {        if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;        else if (*q >= ' ') len++;    }    p = raw = Bmalloc(len);    *(p++) = '"';    for (q=string1; *q; q++)    {        if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }        else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }        else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }        else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; }        else if (*q >= ' ') *(p++) = *q;    }    *(p++) = '"';    *(p++) = ' ';    *(p++) = '"';    for (q=string2; *q; q++)    {        if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }        else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }        else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }        else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; }        else if (*q >= ' ') *(p++) = *q;    }    *(p++) = '"';    *p=0;    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);    Bfree(raw);}void SCRIPT_PutNumber(    int32 scripthandle,    char * sectionname,    char * entryname,    int32 number,    boolean hexadecimal,    boolean defaultvalue){    char raw[64];    UNREFERENCED_PARAMETER(defaultvalue);    if (hexadecimal) Bsprintf(raw, "0x%X", number);    else Bsprintf(raw, "%d", number);    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);}void SCRIPT_PutBoolean(    int32 scripthandle,    char * sectionname,    char * entryname,    boolean boole){    char raw[2] = "0";    if (boole) raw[0] = '1';    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);}void SCRIPT_PutDouble(    int32 scripthandle,    char * sectionname,    char * entryname,    double number,    boolean defaultvalue){    char raw[64];    UNREFERENCED_PARAMETER(defaultvalue);    Bsprintf(raw, "%g", number);    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -