void OGRGTMDataSource::WriteWaypointStyles() { if( fpOutput != NULL ) { // We have waypoints, thus we need to write the default // waypoint style as defined by the specification if ( numWaypoints != 0) { void* pBuffer = CPLMalloc(35); void* pBufferAux = pBuffer; for (int i = 0; i < 4; ++i) { // height appendInt(pBufferAux, -11); pBufferAux = ((char*)pBufferAux) + 4; // facename size appendUShort(pBufferAux, 5); pBufferAux = ((char*)pBufferAux) + 2; // facename strncpy((char*)pBufferAux, "Arial", 5); pBufferAux = ((char*)pBufferAux) + 5; // dspl appendUChar(pBufferAux, (unsigned char) i); pBufferAux = ((char*)pBufferAux) + 1; // color appendInt(pBufferAux, 0); pBufferAux = ((char*)pBufferAux) + 4; // weight appendInt(pBufferAux, 400); pBufferAux = ((char*)pBufferAux) + 4; // scale1 appendInt(pBufferAux, 0); pBufferAux = ((char*)pBufferAux) + 4; // border appendUChar(pBufferAux, (i != 3) ? 0 : 139); pBufferAux = ((char*)pBufferAux) + 1; // background appendUShort(pBufferAux, (i != 3) ? 0 : 0xFF); pBufferAux = ((char*)pBufferAux) + 2; // backcolor appendInt(pBufferAux, (i != 3) ? 0 : 0xFFFF); pBufferAux = ((char*)pBufferAux) + 4; // italic, underline, strikeout appendInt(pBufferAux, 0); pBufferAux = ((char*)pBufferAux) + 3; // alignment appendUChar(pBufferAux, (i != 3) ? 0 : 1); pBufferAux = pBuffer; VSIFWriteL(pBuffer, 35, 1, fpOutput); } CPLFree(pBuffer); } } }
inline void GTMTrackLayer::WriteTrackpoint( double lat, double lon, float altitude, bool start ) { void* pBuffer = CPLMalloc(25); void* pBufferAux = pBuffer; //latitude appendDouble(pBufferAux, lat); pBufferAux = (char*)pBufferAux + 8; //longitude appendDouble(pBufferAux, lon); pBufferAux = (char*)pBufferAux + 8; //date appendInt(pBufferAux, 0); pBufferAux = (char*)pBufferAux + 4; //start appendUChar(pBufferAux, start); pBufferAux = (char*)pBufferAux + 1; //altitude appendFloat(pBufferAux, altitude); VSIFWriteL(pBuffer, 25, 1, poDS->getTmpTrackpointsFP()); poDS->incNumTrackpoints(); CPLFree(pBuffer); }
void GTMTrackLayer::WriteFeatureAttributes( OGRFeature *poFeature ) { char* psztrackname = nullptr; int type = 1; unsigned int color = 0; for (int i = 0; i < poFeatureDefn->GetFieldCount(); ++i) { OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( i ); if( poFeature->IsFieldSetAndNotNull( i ) ) { const char* l_pszName = poFieldDefn->GetNameRef(); /* track name */ if (STARTS_WITH(l_pszName, "name")) { CPLFree(psztrackname); psztrackname = CPLStrdup( poFeature->GetFieldAsString( i ) ); } /* track type */ else if (STARTS_WITH(l_pszName, "type")) { type = poFeature->GetFieldAsInteger( i ); // Check if it is a valid type if (type < 1 || type > 30) type = 1; } /* track color */ else if (STARTS_WITH(l_pszName, "color")) { color = (unsigned int) poFeature->GetFieldAsInteger( i ); if (color > 0xFFFFFF) color = 0xFFFFFFF; } } } if (psztrackname == nullptr) psztrackname = CPLStrdup( "" ); const size_t trackNameLength = strlen(psztrackname); const size_t bufferSize = 14 + trackNameLength; void* pBuffer = CPLMalloc(bufferSize); void* pBufferAux = pBuffer; /* Write track string name size to buffer */ appendUShort(pBufferAux, (unsigned short) trackNameLength); pBufferAux = (char*)pBufferAux + 2; /* Write track name */ memcpy((char*)pBufferAux, psztrackname, trackNameLength); pBufferAux = (char*)pBufferAux + trackNameLength; /* Write track type */ appendUChar(pBufferAux, (unsigned char) type); pBufferAux = (char*)pBufferAux + 1; /* Write track color */ appendInt(pBufferAux, color); pBufferAux = (char*)pBufferAux + 4; /* Write track scale */ appendFloat(pBufferAux, 0); pBufferAux = (char*)pBufferAux + 4; /* Write track label */ appendUChar(pBufferAux, 0); pBufferAux = (char*)pBufferAux + 1; /* Write track layer */ appendUShort(pBufferAux, 0); VSIFWriteL(pBuffer, bufferSize, 1, poDS->getTmpTracksFP()); poDS->incNumTracks(); CPLFree(psztrackname); CPLFree(pBuffer); }
void GTMWaypointLayer::WriteFeatureAttributes( OGRFeature *poFeature, float altitude ) { char psNameField[] = " "; // 10 spaces char* pszcomment = nullptr; int icon = 48; int date = 0; for (int i = 0; i < poFeatureDefn->GetFieldCount(); ++i) { OGRFieldDefn *poFieldDefn = poFeatureDefn->GetFieldDefn( i ); if( poFeature->IsFieldSetAndNotNull( i ) ) { const char* l_pszName = poFieldDefn->GetNameRef(); /* Waypoint name */ if (STARTS_WITH(l_pszName, "name")) { strncpy (psNameField, poFeature->GetFieldAsString( i ), 10); CPLStrlcat (psNameField, " ", sizeof(psNameField)); } /* Waypoint comment */ else if (STARTS_WITH(l_pszName, "comment")) { CPLFree(pszcomment); pszcomment = CPLStrdup( poFeature->GetFieldAsString( i ) ); } /* Waypoint icon */ else if (STARTS_WITH(l_pszName, "icon")) { icon = poFeature->GetFieldAsInteger( i ); // Check if it is a valid icon if (icon < 1 || icon > 220) icon = 48; } /* Waypoint date */ else if (EQUAL(l_pszName, "time")) { struct tm brokendowndate; int year, month, day, hour, min, sec, TZFlag; if (poFeature->GetFieldAsDateTime( i, &year, &month, &day, &hour, &min, &sec, &TZFlag)) { brokendowndate.tm_year = year - 1900; brokendowndate.tm_mon = month - 1; brokendowndate.tm_mday = day; brokendowndate.tm_hour = hour; brokendowndate.tm_min = min; brokendowndate.tm_sec = sec; GIntBig unixTime = CPLYMDHMSToUnixTime(&brokendowndate); if (TZFlag != 0) unixTime -= (TZFlag - 100) * 15; if (unixTime <= GTM_EPOCH || (unixTime - GTM_EPOCH) != (int)(unixTime - GTM_EPOCH)) { CPLError(CE_Warning, CPLE_AppDefined, "%04d/%02d/%02d %02d:%02d:%02d is not a valid datetime for GTM", year, month, day, hour, min, sec); } else { date = (int)(unixTime - GTM_EPOCH); } } } } } if (pszcomment == nullptr) pszcomment = CPLStrdup( "" ); const size_t commentLength = strlen(pszcomment); const size_t bufferSize = 27 + commentLength; void* pBuffer = CPLMalloc(bufferSize); void* pBufferAux = pBuffer; /* Write waypoint name to buffer */ memcpy((char*)pBufferAux, psNameField, 10); /* Write waypoint string comment size to buffer */ pBufferAux = (char*)pBuffer+10; appendUShort(pBufferAux, (unsigned short) commentLength); /* Write waypoint string comment to buffer */ memcpy((char*)pBuffer+12, pszcomment, commentLength); /* Write icon to buffer */ pBufferAux = (char*)pBuffer+12+commentLength; appendUShort(pBufferAux, (unsigned short) icon); /* Write dslp to buffer */ pBufferAux = (char*)pBufferAux + 2; appendUChar(pBufferAux, 3); /* Date */ pBufferAux = (char*)pBufferAux + 1; appendInt(pBufferAux, date); /* wrot */ pBufferAux = (char*)pBufferAux + 4; appendUShort(pBufferAux, 0); /* walt */ pBufferAux = (char*)pBufferAux + 2; appendFloat(pBufferAux, altitude); /* wlayer */ pBufferAux = (char*)pBufferAux + 4; appendUShort(pBufferAux, 0); VSIFWriteL(pBuffer, bufferSize, 1, poDS->getOutputFP()); poDS->incNumWaypoints(); CPLFree(pszcomment); CPLFree(pBuffer); }
void BlrFromMessage::buildBlr(IMessageMetadata* metadata) { if (!metadata) return; LocalStatus st; expectedMessageLength = metadata->getMessageLength(&st); checkStatus(&st); getBlrData().clear(); const unsigned count = metadata->getCount(&st); fb_assert(count < MAX_USHORT / 2); if (count == 0) return; // If there isn't an SQLDA, don't bother with anything else. appendVersion(); appendUChar(blr_begin); appendUChar(blr_message); appendUChar(0); appendUShort(count * 2); unsigned msgLen = 0; for (unsigned i = 0; i < count; ++i) { unsigned dtype = metadata->getType(&st, i) & ~1; checkStatus(&st); unsigned len = metadata->getLength(&st, i); checkStatus(&st); unsigned scale = metadata->getScale(&st, i); checkStatus(&st); unsigned charSet = metadata->getCharSet(&st, i); checkStatus(&st); switch (dtype) { case SQL_VARYING: appendUChar(blr_varying2); appendUShort(charSet); appendUShort(len); dtype = dtype_varying; len += sizeof(USHORT); break; case SQL_TEXT: appendUChar(blr_text2); appendUShort(charSet); appendUShort(len); dtype = dtype_text; break; case SQL_DOUBLE: appendUChar(blr_double); dtype = dtype_double; break; case SQL_FLOAT: appendUChar(blr_float); dtype = dtype_real; break; case SQL_D_FLOAT: appendUChar(blr_d_float); dtype = dtype_d_float; break; case SQL_TYPE_DATE: appendUChar(blr_sql_date); dtype = dtype_sql_date; break; case SQL_TYPE_TIME: appendUChar(blr_sql_time); dtype = dtype_sql_time; break; case SQL_TIMESTAMP: appendUChar(blr_timestamp); dtype = dtype_timestamp; break; case SQL_BLOB: appendUChar(blr_blob2); appendUShort(metadata->getSubType(&st, i)); appendUShort(charSet); dtype = dtype_blob; break; case SQL_ARRAY: appendUChar(blr_quad); appendUChar(0); dtype = dtype_array; break; case SQL_LONG: appendUChar(blr_long); appendUChar(scale); dtype = dtype_long; break; case SQL_SHORT: appendUChar(blr_short); appendUChar(scale); dtype = dtype_short; break; case SQL_INT64: appendUChar(blr_int64); appendUChar(scale); dtype = dtype_int64; break; case SQL_QUAD: appendUChar(blr_quad); appendUChar(scale); dtype = dtype_quad; break; case SQL_BOOLEAN: appendUChar(blr_bool); dtype = dtype_boolean; break; case SQL_NULL: appendUChar(blr_text); appendUShort(len); dtype = dtype_text; break; default: Arg::Gds(isc_dsql_sqlda_value_err).raise(); break; } appendUChar(blr_short); appendUChar(0); unsigned align = type_alignments[dtype]; if (align) msgLen = FB_ALIGN(msgLen, align); msgLen += len; align = type_alignments[dtype_short]; if (align) msgLen = FB_ALIGN(msgLen, align); msgLen += sizeof(SSHORT); } appendUChar(blr_end); appendUChar(blr_eoc); if (expectedMessageLength && msgLen && (expectedMessageLength != msgLen)) { Arg::Gds(isc_wrong_message_length).raise(); } }
int OGRGTMDataSource::Create( const char* pszFilename, CPL_UNUSED char** papszOptions ) { CPLAssert( NULL != pszFilename ); if( fpOutput != NULL ) { CPLAssert( FALSE ); return FALSE; } /* -------------------------------------------------------------------- */ /* Do not override exiting file. */ /* -------------------------------------------------------------------- */ VSIStatBufL sStatBuf; if( VSIStatL( pszFilename, &sStatBuf ) == 0 ) { CPLError(CE_Failure, CPLE_NotSupported, "You have to delete %s before being able to create it with the GTM driver", pszFilename); return FALSE; } /* -------------------------------------------------------------------- */ /* Create the output file. */ /* -------------------------------------------------------------------- */ pszName = CPLStrdup( pszFilename ); fpOutput = VSIFOpenL( pszFilename, "w" ); if( fpOutput == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to create GTM file %s.", pszFilename ); return FALSE; } // Generate a temporary file for Trackpoints const char* pszTmpName = CPLGenerateTempFilename(NULL); pszTmpTrackpoints = CPLStrdup( pszTmpName ); fpTmpTrackpoints = VSIFOpenL(pszTmpName , "w" ); if( fpTmpTrackpoints == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to create temporary file %s.", pszTmpName ); return FALSE; } // Generate a temporary file for Tracks pszTmpName = CPLGenerateTempFilename(NULL); pszTmpTracks = CPLStrdup( pszTmpName ); fpTmpTracks = VSIFOpenL(pszTmpName , "w" ); if( fpTmpTracks == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to create temporary file %s.", pszTmpName ); return FALSE; } /* -------------------------------------------------------------------- */ /* Output header of GTM file. */ /* -------------------------------------------------------------------- */ char* pszBaseFileName = CPLStrdup( CPLGetBasename(pszFilename) ); size_t sizeBuffer = 175 + strlen(pszBaseFileName); void* pBuffer = CPLCalloc(1, sizeBuffer); void* pCurrentPos = pBuffer; // Write version number appendUShort(pCurrentPos, 211); pCurrentPos = ((char*)pCurrentPos) + 2; // Write code strcpy((char*)pCurrentPos, "TrackMaker"); // gradnum pCurrentPos = (char*) pBuffer + 14; appendUChar(pCurrentPos, 8); // bcolor pCurrentPos = (char*) pBuffer + 23; appendInt(pCurrentPos, 0xffffff); // nwptstyles -- We just create the defaults, so four pCurrentPos = (char*) pBuffer + 27; appendInt(pCurrentPos, 4); // gradfont, labelfont pCurrentPos = (char*) pBuffer + 99; for (int i = 0; i < 2; i++) { appendUShort(pCurrentPos, 5); pCurrentPos = ((char*)pCurrentPos) + 2; strcpy((char*)pCurrentPos, "Arial"); pCurrentPos = ((char*)pCurrentPos) + 5; } appendUShort(pCurrentPos, (unsigned short) strlen(pszBaseFileName)); pCurrentPos = ((char*)pCurrentPos) + 2; strcpy((char*)pCurrentPos, pszBaseFileName); // Write ndatum. We are implementing just WGS84, so write the // corresponding value for WGS84. pCurrentPos = ((char*) pBuffer) + 151 + strlen(pszBaseFileName); appendInt(pCurrentPos, 217); VSIFWriteL(pBuffer, sizeBuffer, 1, fpOutput); CPLFree(pszBaseFileName); CPLFree(pBuffer); return TRUE; }
/** * Greek string uppercasing with a state machine. * Probably simpler than a stateless function that has to figure out complex context-before * for each character. * TODO: Try to re-consolidate one way or another with the non-Greek function. */ int32_t toUpper(const UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode) { int32_t locCache = UCASE_LOC_GREEK; int32_t destIndex=0; uint32_t state = 0; for (int32_t i = 0; i < srcLength;) { int32_t nextIndex = i; UChar32 c; U16_NEXT(src, nextIndex, srcLength, c); uint32_t nextState = 0; int32_t type = ucase_getTypeOrIgnorable(csm->csp, c); if ((type & UCASE_IGNORABLE) != 0) { // c is case-ignorable nextState |= (state & AFTER_CASED); } else if (type != UCASE_NONE) { // c is cased nextState |= AFTER_CASED; } uint32_t data = getLetterData(c); if (data > 0) { uint32_t upper = data & UPPER_MASK; // Add a dialytika to this iota or ypsilon vowel // if we removed a tonos from the previous vowel, // and that previous vowel did not also have (or gain) a dialytika. // Adding one only to the final vowel in a longer sequence // (which does not occur in normal writing) would require lookahead. // Set the same flag as for preserving an existing dialytika. if ((data & HAS_VOWEL) != 0 && (state & AFTER_VOWEL_WITH_ACCENT) != 0 && (upper == 0x399 || upper == 0x3A5)) { data |= HAS_DIALYTIKA; } int32_t numYpogegrammeni = 0; // Map each one to a trailing, spacing, capital iota. if ((data & HAS_YPOGEGRAMMENI) != 0) { numYpogegrammeni = 1; } // Skip combining diacritics after this Greek letter. while (nextIndex < srcLength) { uint32_t diacriticData = getDiacriticData(src[nextIndex]); if (diacriticData != 0) { data |= diacriticData; if ((diacriticData & HAS_YPOGEGRAMMENI) != 0) { ++numYpogegrammeni; } ++nextIndex; } else { break; // not a Greek diacritic } } if ((data & HAS_VOWEL_AND_ACCENT_AND_DIALYTIKA) == HAS_VOWEL_AND_ACCENT) { nextState |= AFTER_VOWEL_WITH_ACCENT; } // Map according to Greek rules. UBool addTonos = FALSE; if (upper == 0x397 && (data & HAS_ACCENT) != 0 && numYpogegrammeni == 0 && (state & AFTER_CASED) == 0 && !isFollowedByCasedLetter(csm->csp, src, nextIndex, srcLength)) { // Keep disjunctive "or" with (only) a tonos. // We use the same "word boundary" conditions as for the Final_Sigma test. if (i == nextIndex) { upper = 0x389; // Preserve the precomposed form. } else { addTonos = TRUE; } } else if ((data & HAS_DIALYTIKA) != 0) { // Preserve a vowel with dialytika in precomposed form if it exists. if (upper == 0x399) { upper = 0x3AA; data &= ~HAS_EITHER_DIALYTIKA; } else if (upper == 0x3A5) { upper = 0x3AB; data &= ~HAS_EITHER_DIALYTIKA; } } destIndex=appendUChar(dest, destIndex, destCapacity, (UChar)upper); if (destIndex >= 0 && (data & HAS_EITHER_DIALYTIKA) != 0) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x308); // restore or add a dialytika } if (destIndex >= 0 && addTonos) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x301); } while (destIndex >= 0 && numYpogegrammeni > 0) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x399); --numYpogegrammeni; } if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } } else { const UChar *s; UChar32 c2 = 0; c=ucase_toFullUpper(csm->csp, c, NULL, NULL, &s, csm->locale, &locCache); if((destIndex<destCapacity) && (c<0 ? (c2=~c)<=0xffff : UCASE_MAX_STRING_LENGTH<c && (c2=c)<=0xffff)) { /* fast path version of appendResult() for BMP results */ dest[destIndex++]=(UChar)c2; } else { destIndex=appendResult(dest, destIndex, destCapacity, c, s); if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } } } i = nextIndex; state = nextState; } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
U_CFUNC int32_t U_CALLCONV ustrcase_internalToTitle(const UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode) { const UChar *s; UChar32 c; int32_t prev, titleStart, titleLimit, idx, destIndex; UBool isFirstIndex; if(U_FAILURE(*pErrorCode)) { return 0; } // Use the C++ abstract base class to minimize dependencies. // TODO: Change UCaseMap.iter to store a BreakIterator directly. BreakIterator *bi=reinterpret_cast<BreakIterator *>(csm->iter); /* set up local variables */ int32_t locCache=csm->locCache; UCaseContext csc=UCASECONTEXT_INITIALIZER; csc.p=(void *)src; csc.limit=srcLength; destIndex=0; prev=0; isFirstIndex=TRUE; /* titlecasing loop */ while(prev<srcLength) { /* find next index where to titlecase */ if(isFirstIndex) { isFirstIndex=FALSE; idx=bi->first(); } else { idx=bi->next(); } if(idx==UBRK_DONE || idx>srcLength) { idx=srcLength; } /* * Unicode 4 & 5 section 3.13 Default Case Operations: * * R3 toTitlecase(X): Find the word boundaries based on Unicode Standard Annex * #29, "Text Boundaries." Between each pair of word boundaries, find the first * cased character F. If F exists, map F to default_title(F); then map each * subsequent character C to default_lower(C). * * In this implementation, segment [prev..index[ into 3 parts: * a) uncased characters (copy as-is) [prev..titleStart[ * b) first case letter (titlecase) [titleStart..titleLimit[ * c) subsequent characters (lowercase) [titleLimit..index[ */ if(prev<idx) { /* find and copy uncased characters [prev..titleStart[ */ titleStart=titleLimit=prev; U16_NEXT(src, titleLimit, idx, c); if((csm->options&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0 && UCASE_NONE==ucase_getType(csm->csp, c)) { /* Adjust the titlecasing index (titleStart) to the next cased character. */ for(;;) { titleStart=titleLimit; if(titleLimit==idx) { /* * only uncased characters in [prev..index[ * stop with titleStart==titleLimit==index */ break; } U16_NEXT(src, titleLimit, idx, c); if(UCASE_NONE!=ucase_getType(csm->csp, c)) { break; /* cased letter at [titleStart..titleLimit[ */ } } destIndex=appendString(dest, destIndex, destCapacity, src+prev, titleStart-prev); if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } } if(titleStart<titleLimit) { /* titlecase c which is from [titleStart..titleLimit[ */ csc.cpStart=titleStart; csc.cpLimit=titleLimit; c=ucase_toFullTitle(csm->csp, c, utf16_caseContextIterator, &csc, &s, csm->locale, &locCache); destIndex=appendResult(dest, destIndex, destCapacity, c, s); if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } /* Special case Dutch IJ titlecasing */ if (titleStart+1 < idx && ucase_getCaseLocale(csm->locale,&locCache) == UCASE_LOC_DUTCH && (src[titleStart] == 0x0049 || src[titleStart] == 0x0069) && (src[titleStart+1] == 0x004A || src[titleStart+1] == 0x006A)) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x004A); if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } titleLimit++; } /* lowercase [titleLimit..index[ */ if(titleLimit<idx) { if((csm->options&U_TITLECASE_NO_LOWERCASE)==0) { /* Normal operation: Lowercase the rest of the word. */ destIndex+= _caseMap( csm, ucase_toFullLower, dest+destIndex, destCapacity-destIndex, src, &csc, titleLimit, idx, pErrorCode); if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) { *pErrorCode=U_ZERO_ERROR; } if(U_FAILURE(*pErrorCode)) { return destIndex; } } else { /* Optionally just copy the rest of the word unchanged. */ destIndex=appendString(dest, destIndex, destCapacity, src+titleLimit, idx-titleLimit); if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } } } } } prev=idx; } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }