/****************************************************************************** * public メソッド *****************************************************************************/ void PostDataChecker::validate_uitem(apr_pool_t *pool, apr_uint64_t file_size, apr_time_t mtime, const char **file_name, const char **file_mime, const char *file_digest, const char *remove_pass, const char *download_pass, const char **comment, const char *code_pat) { const char *file_ext; validate_file_name(pool, file_name, code_pat); validate_file_mime(pool, *file_mime); validate_comment(pool, comment, code_pat); file_ext = get_file_ext(*file_name); validate_file_ext(file_ext); if (strlen(*file_name) == 0) { THROW(MESSAGE_POST_FILE_NAME_EMPTY); } else if (strlen(*file_name) > (ITM_MAX_FILE_NAME_SIZE-1)) { THROW(MESSAGE_POST_FILE_NAME_TOO_LONG); } if (file_size == 0) { THROW(MESSAGE_POST_FILE_SIZE_ZERO); } if (strlen(*file_mime) == 0) { THROW(MESSAGE_POST_FILE_MIME_EMPTY); } else if (strlen(*file_mime) > (ITM_MAX_FILE_MIME_SIZE-1)) { THROW(MESSAGE_POST_FILE_MIME_TOO_LONG); } if (strlen(file_ext) == 0) { THROW(MESSAGE_POST_FILE_EXT_EMPTY); } else if (strlen(file_ext) > (ITM_MAX_FILE_EXT_SIZE-1)) { THROW(MESSAGE_POST_FILE_EXT_TOO_LONG); } if (strlen(file_digest) == 0) { THROW(MESSAGE_POST_FILE_DIGEST_EMPTY); } else if (strlen(file_digest) > (ITM_MAX_FILE_DIGEST_SIZE-1)) { THROW(MESSAGE_POST_FILE_DIGEST_TOO_LONG); } if (strlen(remove_pass) > (ITM_MAX_REMOVE_PASS_SIZE-1)) { THROW(MESSAGE_POST_REMOVE_PASS_TOO_LONG); } if (strlen(download_pass) > (ITM_MAX_DOWNLOAD_PASS_SIZE-1)) { THROW(MESSAGE_POST_DOWNLOAD_PASS_TOO_LONG); } if (strlen(*comment) == 0) { #ifndef EMPTY_COMMENT THROW(MESSAGE_POST_COMMENT_EMPTY); #endif } else if (strlen(*comment) > (ITM_MAX_COMMENT_SIZE-1)) { THROW(MESSAGE_POST_COMMENT_TOO_LONG); } }
void GLEZData::read(const string& fname) throw(ParserError) { string expanded(GLEExpandEnvironmentVariables(fname)); validate_file_name(expanded, false); TokenizerLanguage lang; std::auto_ptr<Tokenizer> tokens; std::vector<GLEBYTE> contents; if (str_i_ends_with(expanded, ".gz")) { if (GLEReadFileBinaryGZIP(expanded, &contents)) { contents.push_back(0); tokens.reset(new StringTokenizer((const char*)&contents[0], &lang)); } else { g_throw_parser_error("can't open: '", expanded.c_str(), "'"); } } else { StreamTokenizer* streamTokens = new StreamTokenizer(&lang); tokens.reset(streamTokens); streamTokens->open_tokens(expanded.c_str()); } lang.setSpaceTokens(" \t\r,"); lang.setSingleCharTokens("\n!"); // Read the header of the z file GLERectangle* bounds = getBounds(); tokens->ensure_next_token("!"); while (tokens->has_more_tokens()) { string& token = tokens->next_token(); if (token == "\n") { break; } else if (str_i_equals(token, "NX")) { m_NX = tokens->next_integer(); } else if (str_i_equals(token, "NY")) { m_NY = tokens->next_integer(); } else if (str_i_equals(token, "XMIN")) { bounds->setXMin(tokens->next_double()); } else if (str_i_equals(token, "XMAX")) { bounds->setXMax(tokens->next_double()); } else if (str_i_equals(token, "YMIN")) { bounds->setYMin(tokens->next_double()); } else if (str_i_equals(token, "YMAX")) { bounds->setYMax(tokens->next_double()); } else { stringstream str; str << "unknown .z header token '" << token << "'"; throw tokens->error(str.str()); } } lang.setLineCommentTokens("!"); lang.setSingleCharTokens(""); lang.setSpaceTokens(" \t\n\r,"); // Allocate data if (m_NX == 0 || m_NY == 0) { throw tokens->error("data file header should contain valid NX and NY parameters"); } m_Data = new double[m_NX * m_NY]; for (int y = 0; y < m_NY; y++) { for (int x = 0; x < m_NX; x++) { double v = tokens->next_double(); if (v < m_ZMin) m_ZMin = v; if (v > m_ZMax) m_ZMax = v; m_Data[x + y * m_NX] = v; } } }