📄 resource.cpp
字号:
} // Escaped characters else if (ch == '\\') { int newCh = getc(fd); if (newCh == '"') actualCh = '"'; else if (newCh == 10) actualCh = 10; else { ungetc(newCh, fd); } } if (wxResourceBufferCount >= wxResourceBufferSize-1) wxReallocateResourceBuffer(); wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; wxResourceBufferCount ++; ch = getc(fd); } wxResourceBuffer[wxResourceBufferCount] = 0; } else { wxResourceBufferCount = 0; // Any other token while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) { if (wxResourceBufferCount >= wxResourceBufferSize-1) wxReallocateResourceBuffer(); wxResourceBuffer[wxResourceBufferCount] = (char)ch; wxResourceBufferCount ++; ch = getc(fd); } wxResourceBuffer[wxResourceBufferCount] = 0; if (ch == EOF) return false; } return true;}bool wxGetResourceToken(wxInputStream *is){ if (!wxResourceBuffer) wxReallocateResourceBuffer(); wxResourceBuffer[0] = 0; wxEatWhiteSpace(is); int ch = is->GetC() ; if (ch == '"') { // Get string wxResourceBufferCount = 0; ch = is->GetC(); while (ch != '"') { int actualCh = ch; if (ch == EOF) { wxResourceBuffer[wxResourceBufferCount] = 0; return false; } // Escaped characters else if (ch == '\\') { char newCh = is->GetC(); if (newCh == '"') actualCh = '"'; else if (newCh == 10) actualCh = 10; else if (newCh == 13) // mac actualCh = 10; else { is->Ungetch(newCh); } } if (wxResourceBufferCount >= wxResourceBufferSize-1) wxReallocateResourceBuffer(); wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; wxResourceBufferCount ++; ch = is->GetC(); } wxResourceBuffer[wxResourceBufferCount] = 0; } else { wxResourceBufferCount = 0; // Any other token while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) { if (wxResourceBufferCount >= wxResourceBufferSize-1) wxReallocateResourceBuffer(); wxResourceBuffer[wxResourceBufferCount] = (char)ch; wxResourceBufferCount ++; ch = is->GetC(); } wxResourceBuffer[wxResourceBufferCount] = 0; if (ch == EOF) return false; } return true;}/** Files are in form:static char *name = "....";with possible comments.*/bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table){ if (!table) table = wxDefaultResourceTable; // static or #define if (!wxGetResourceToken(fd)) { *eof = true; return false; } if (strcmp(wxResourceBuffer, "#define") == 0) { wxGetResourceToken(fd); wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); wxGetResourceToken(fd); wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); if (wxIsdigit(value[0])) { int val = (int)wxAtol(value); wxResourceAddIdentifier(name, val, table); } else { wxLogWarning(_("#define %s must be an integer."), name); delete[] name; delete[] value; return false; } delete[] name; delete[] value; return true; } else if (strcmp(wxResourceBuffer, "#include") == 0) { wxGetResourceToken(fd); wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); wxChar *actualName = name; if (name[0] == wxT('"')) actualName = name + 1; int len = wxStrlen(name); if ((len > 0) && (name[len-1] == wxT('"'))) name[len-1] = 0; if (!wxResourceParseIncludeFile(actualName, table)) { wxLogWarning(_("Could not find resource include file %s."), actualName); } delete[] name; return true; } else if (strcmp(wxResourceBuffer, "static") != 0) { wxChar buf[300]; wxStrcpy(buf, _("Found ")); wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); wxStrcat(buf, _(", expected static, #include or #define\nwhile parsing resource.")); wxLogWarning(buf); return false; } // char if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } if (strcmp(wxResourceBuffer, "char") != 0) { wxLogWarning(_("Expected 'char' while parsing resource.")); return false; } // *name if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } if (wxResourceBuffer[0] != '*') { wxLogWarning(_("Expected '*' while parsing resource.")); return false; } wxChar nameBuf[100]; wxMB2WX(nameBuf, wxResourceBuffer+1, 99); nameBuf[99] = 0; // = if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } if (strcmp(wxResourceBuffer, "=") != 0) { wxLogWarning(_("Expected '=' while parsing resource.")); return false; } // String if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } else { if (!db.ReadPrologFromString(wxResourceBuffer)) { wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); return false; } } // Semicolon if (!wxGetResourceToken(fd)) { *eof = true; } return true;}bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table){ if (!table) table = wxDefaultResourceTable; // static or #define if (!wxGetResourceToken(fd)) { *eof = true; return false; } if (strcmp(wxResourceBuffer, "#define") == 0) { wxGetResourceToken(fd); wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); wxGetResourceToken(fd); wxChar *value = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); if (wxIsalpha(value[0])) { int val = (int)wxAtol(value); wxResourceAddIdentifier(name, val, table); } else { wxLogWarning(_("#define %s must be an integer."), name); delete[] name; delete[] value; return false; } delete[] name; delete[] value; return true; } else if (strcmp(wxResourceBuffer, "#include") == 0) { wxGetResourceToken(fd); wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); wxChar *actualName = name; if (name[0] == wxT('"')) actualName = name + 1; int len = wxStrlen(name); if ((len > 0) && (name[len-1] == wxT('"'))) name[len-1] = 0; if (!wxResourceParseIncludeFile(actualName, table)) { wxLogWarning(_("Could not find resource include file %s."), actualName); } delete[] name; return true; } else if (strcmp(wxResourceBuffer, "static") != 0) { wxChar buf[300]; wxStrcpy(buf, _("Found ")); wxStrncat(buf, wxConvLibc.cMB2WX(wxResourceBuffer), 30); wxStrcat(buf, _(", expected static, #include or #define\nwhile parsing resource.")); wxLogWarning(buf); return false; } // char if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } if (strcmp(wxResourceBuffer, "char") != 0) { wxLogWarning(_("Expected 'char' while parsing resource.")); return false; } // *name if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } if (wxResourceBuffer[0] != '*') { wxLogWarning(_("Expected '*' while parsing resource.")); return false; } char nameBuf[100]; strncpy(nameBuf, wxResourceBuffer+1, 99); // = if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } if (strcmp(wxResourceBuffer, "=") != 0) { wxLogWarning(_("Expected '=' while parsing resource.")); return false; } // String if (!wxGetResourceToken(fd)) { wxLogWarning(_("Unexpected end of file while parsing resource.")); *eof = true; return false; } else { if (!db.ReadPrologFromString(wxResourceBuffer)) { wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); return false; } } // Semicolon if (!wxGetResourceToken(fd)) { *eof = true; } return true;}/** Parses string window style into integer window style*//** Style flag parsing, e.g.* "wxSYSTEM_MENU | wxBORDER" -> integer*/wxChar* wxResourceParseWord(wxChar*s, int *i){ if (!s) return (wxChar*) NULL; static wxChar buf[150]; int len = wxStrlen(s); int j = 0; int ii = *i; while ((ii < len) && (wxIsalpha(s[ii]) || (s[ii] == wxT('_')))) { buf[j] = s[ii]; j ++; ii ++; } buf[j] = 0; // Eat whitespace and conjunction characters while ((ii < len) && ((s[ii] == wxT(' ')) || (s[ii] == wxT('|')) || (s[ii] == wxT(',')))) { ii ++; } *i = ii; if (j == 0) return (wxChar*) NULL; else return buf;}struct
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -