mama_status mamaDictionary_populateFromFile ( mamaDictionary dictionary, const char* fileName) { char lineBuffer[256]; FILE* infile = NULL; mamaDictionaryImpl* impl = (mamaDictionaryImpl*)dictionary; if (!impl) return MAMA_STATUS_NULL_ARG; if (MAMA_STATUS_OK!=openWombatFile (fileName, "r", &infile)) { mama_log (MAMA_LOG_LEVEL_FINE, "Could not open file for reading [%s]", fileName); return MAMA_STATUS_IO_ERROR; } while (fgets (lineBuffer, 255, infile) != NULL) { mama_status status = MAMA_STATUS_OK; char* c = lineBuffer; char* fidStr = NULL; char* fieldName = NULL; char* typeStr = NULL; /*Get rid of any newline characters*/ stripTrailingWhiteSpace (lineBuffer); /*Validate the line - continue if invalid*/ if (MAMA_STATUS_OK!=validateDelimLine (c)) continue; /*First field is the fid*/ fidStr = c; /*Second field is the field name*/ fieldName = getNextDelimStr (c); /*Third field is the field type*/ typeStr = getNextDelimStr (c); /*Add the descriptor to the dictionary*/ if (MAMA_STATUS_OK!=(status=mamaDictionary_createFieldDescriptor (dictionary, atoi (fidStr), fieldName, atoi (typeStr), NULL))) { mama_log (MAMA_LOG_LEVEL_FINE, "Could not create field descriptor" "from file. [%s] [%s]",fileName, lineBuffer); return status; } } fclose (infile); return MAMA_STATUS_OK; }
/** * Collapses all white space in a string. * All occurances of tab, line feed and carriage return are replaced with * space, after which all sequences of spaces are collapsed to a single space. * * @param value The string to have all white space collapsed * @return AxisString The string with all white space collapsed. */ const AxisString& WhiteSpace::collapseWhiteSpace(AxisString& value) { #ifdef ENABLE_AXISTRACE if (axiscpp::AxisTrace::isTraceOn()) axiscpp::AxisTrace::traceEntry("WhiteSpace", "collapseWhiteSpace", this, 1, TRACETYPE_STLSTRING, 0, ((void*)&value)); /* AUTOINSERTED TRACE */ #endif if (value.empty ()) { { #ifdef ENABLE_AXISTRACE const AxisString& traceRet = (value); if (axiscpp::AxisTrace::isTraceOn()) axiscpp::AxisTrace::traceExit("WhiteSpace", "collapseWhiteSpace", this, 1, TRACETYPE_STLSTRING, 0, ((void*)&traceRet)); /* AUTOINSERTED TRACE */ return traceRet; #else return value; #endif } } AxisString replacedValue = replaceWhiteSpace(value); /* * Strip leading and trailing space */ AxisString leadingStripped = stripLeadingWhiteSpace(replacedValue); replacedValue = stripTrailingWhiteSpace(leadingStripped); // Initialize return value to empty string m_strReturnVal = ""; /* * Find space character and returns the first any of chars find * position */ unsigned long nPos = replacedValue.find_first_of (' '); /* Check for position validity */ if (AxisString::npos == nPos) { m_strReturnVal.assign (replacedValue); { #ifdef ENABLE_AXISTRACE const AxisString& traceRet = (m_strReturnVal); if (axiscpp::AxisTrace::isTraceOn()) axiscpp::AxisTrace::traceExit("WhiteSpace", "collapseWhiteSpace", this, 2, TRACETYPE_STLSTRING, 0, ((void*)&traceRet)); /* AUTOINSERTED TRACE */ return traceRet; #else return m_strReturnVal; #endif } } unsigned long nOldIdx = 0; // Counter value while (AxisString::npos != nPos) { m_strReturnVal.append (replacedValue.substr (nOldIdx, nPos - nOldIdx)); /** * Only copy space character across if it's NOT followed by * another space character */ if ( replacedValue.at(nPos+1) != ' ') { m_strReturnVal.append (" "); } nOldIdx = ++nPos; // Get old position /* * Find the next entity reference characters from previous found * position, */ nPos = replacedValue.find_first_of (' ', nPos); } unsigned long nDataLen = replacedValue.length (); // Get the length of the field value unsigned long nLen = nDataLen - nOldIdx; // Get remaining number of characters if (nLen > 0) { /* * Append the remaining data */ m_strReturnVal += replacedValue.substr (nOldIdx, nLen); } { #ifdef ENABLE_AXISTRACE const AxisString& traceRet = (m_strReturnVal); if (axiscpp::AxisTrace::isTraceOn()) axiscpp::AxisTrace::traceExit("WhiteSpace", "collapseWhiteSpace", this, 3, TRACETYPE_STLSTRING, 0, ((void*)&traceRet)); /* AUTOINSERTED TRACE */ return traceRet; #else return m_strReturnVal; #endif } }