Exemplo n.º 1
0
std::string ReplayBuilder::textDataString() {
  std::stringstream out;
  out << std::hex << numTexts_;

  int i = 0;
  char *rgbString = new char[8]; // "#RRGGBB\0"
  for (int x = 0; x < numTexts_; x++) {
    appendInt(out, textData_->getInt(i++));
    appendColonString(out, textData_, i);
    for (int y = 0; y < 3; y++) {
      appendInt(out, textData_->getInt(i++));
    }

    int r = textData_->getInt(i++);
    int g = textData_->getInt(i++);
    int b = textData_->getInt(i++);
    sprintf(rgbString, "#%02x%02x%02x", r, g, b);
    out << ':' << rgbString;

    for (int y = 0; y < 2; y++) {
      appendInt(out, textData_->getInt(i++));
    }
  }
  delete rgbString;

  return out.str();
}
Exemplo n.º 2
0
ekBool ekCompilerFormatErrors(ekCompiler *compiler, ekString *output)
{
    struct ekContext *E = compiler->E;
    ekS32 i;
    for(i = 0; i < ekArraySize(E, &compiler->errors); i++)
    {
        ekError *error = compiler->errors[i];
        ekStringConcat(E, output, ekStringSafePtr(&error->filename));
        ekStringConcat(E, output, ":");
        appendInt(E, output, error->lineNo);
        ekStringConcat(E, output, ":");
        appendInt(E, output, error->col + 1); // "column" in an error is 1-indexed
        ekStringConcat(E, output, ": error: ");
        ekStringConcat(E, output, ekStringSafePtr(&error->explanation));
        ekStringConcat(E, output, "\n");

        if(error->line.len > 0)
        {
            ekS32 caratPos = error->col;

            ekStringConcat(E, output, ekStringSafePtr(&error->line));
            ekStringConcat(E, output, "\n");

            // draw the carat!
            for(; caratPos > 0; --caratPos)
            {
                ekStringConcat(E, output, " "); // how about that efficiency! /s
            }
            ekStringConcat(E, output, "^\n");
        }
    }
    return (ekArraySize(E, &compiler->errors) > 0) ? ekTrue : ekFalse;
}
Exemplo n.º 3
0
static sk_sp<SkPDFArray> make_indexed_color_space(const SkColorTable* table) {
    auto result = sk_make_sp<SkPDFArray>();
    result->reserve(4);
    result->appendName("Indexed");
    result->appendName("DeviceRGB");
    SkASSERT(table);
    if (table->count() < 1) {
        result->appendInt(0);
        char shortTableArray[3] = {0, 0, 0};
        SkString tableString(shortTableArray, SK_ARRAY_COUNT(shortTableArray));
        result->appendString(tableString);
        return result;
    }
    result->appendInt(table->count() - 1);  // maximum color index.

    // Potentially, this could be represented in fewer bytes with a stream.
    // Max size as a string is 1.5k.
    char tableArray[256 * 3];
    SkASSERT(3u * table->count() <= SK_ARRAY_COUNT(tableArray));
    uint8_t* tablePtr = reinterpret_cast<uint8_t*>(tableArray);
    const SkPMColor* colors = table->readColors();
    for (int i = 0; i < table->count(); i++) {
        pmcolor_to_rgb24(colors[i], tablePtr, kN32_SkColorType);
        tablePtr += 3;
    }
    SkString tableString(tableArray, 3 * table->count());
    result->appendString(tableString);
    return result;
}
Exemplo n.º 4
0
void OutboundPkt::initConnection() {
    appendInt(CoreTypes::typeInvokeWithLayer);
    appendInt(CoreTypes::typeLayerVersion);
    appendInt(CoreTypes::typeInitConnection);
    appendInt(mSettings->appId());
    appendQString(Utils::getDeviceModel());
    appendQString(Utils::getSystemVersion());
    appendQString(Utils::getAppVersion());
    appendQString(mSettings->langCode());
}
Exemplo n.º 5
0
bool UmbrellaSerializedMessage::prepare(const McReply& reply, mc_op_t op,
                                        uint64_t reqid, struct iovec*& iovOut,
                                        size_t& niovOut) {
  niovOut = 0;

  appendInt(I32, msg_op, umbrella_op_from_mc[op]);
  appendInt(U64, msg_reqid, reqid);
  appendInt(I32, msg_result, umbrella_res_from_mc[reply.result()]);

  if (reply.appSpecificErrorCode()) {
    appendInt(I32, msg_err_code, reply.appSpecificErrorCode());
  }
  if (reply.flags()) {
    appendInt(U64, msg_flags, reply.flags());
  }
  if (reply.exptime()) {
    appendInt(U64, msg_exptime, reply.exptime());
  }
  if (reply.delta()) {
    appendInt(U64, msg_delta, reply.delta());
  }
  if (reply.leaseToken()) {
    appendInt(U64, msg_lease_id, reply.leaseToken());
  }
  if (reply.cas()) {
    appendInt(U64, msg_cas, reply.cas());
  }
  if (reply.number()) {
    appendInt(U64, msg_number, reply.number());
  }

  /* TODO: if we intend to pass chained IOBufs as values,
     we can optimize this to write multiple iovs directly */
  if (reply.hasValue()) {
    auto valueRange = reply.valueRangeSlow();
    appendString(msg_value,
                 reinterpret_cast<const uint8_t*>(valueRange.begin()),
                 valueRange.size());
  }

  /* NOTE: this check must come after all append*() calls */
  if (error_) {
    return false;
  }

  niovOut = finalizeMessage();
  iovOut = iovs_;
  return true;
}
Exemplo n.º 6
0
void utilitySavedataLog(char *buffer, const SyscallInfo *syscallInfo, u32 param) {
	char *s = buffer;

	if (syscallInfo->nid == 0x50C4CD57) {
		utilitySavedataParams = (void *) param;
	}

	int mode = _lw((int) utilitySavedataParams + 48);
	s = append(s, "mode=");
	s = appendInt(s, mode, 0);
	s = append(s, ", gameName=");
	s = append(s, utilitySavedataParams + 60);
	s = append(s, ", saveName=");
	s = append(s, utilitySavedataParams + 76);
	s = append(s, ", fileName=");
	s = append(s, utilitySavedataParams + 100);
	if (syscallInfo->nid == 0x9790B33C) {
		s = append(s, ", result=");
		s = appendHex(s, _lw((int) utilitySavedataParams + 28), 8);
	}
	s = append(s, "\n");
	writeLog(buffer, s - buffer);
	s = buffer;

	printLogMem("Data ", _lw((int) utilitySavedataParams + 116), 16);

	printLogMem("Params ", (int) utilitySavedataParams, _lw((int) utilitySavedataParams + 0));
}
Exemplo n.º 7
0
int	evalNodeSet_ce (cachedExpr *ce,VTDNav *vn){
			int i=-1;
		if (ce->cached){
			if (ce->count<ce->ens->size){
				i=intAt(ce->ens,ce->count);
				recoverNode(vn,i);
				ce->count++;
				return i;
			}else
				return -1;

		}else{
			ce->cached = TRUE;
			
			if (ce->ens==NULL){
				ce->ens = createFastIntBuffer2(8);//page size 64
			}
			//record node set
			while((i=ce->e->evalNodeSet(ce->e,vn))!=-1){
				appendInt(ce->ens,i);
			}
			ce->e->reset(ce->e,vn);
			if(ce->ens->size>0){
				i=intAt(ce->ens,ce->count);//count should be zero
				recoverNode(vn,i);
				vn->count++;
				return i;
			}else
				return -1;
		}
	
}
Exemplo n.º 8
0
Arquivo: wasap.c Projeto: 070499/xbmc
static void SetSongsMenu(int n)
{
	int i;
	for (i = 1; i <= n; i++) {
		char str[16];
		*appendInt(str, i) = '\0';
		AppendMenu(hSongMenu, MF_ENABLED | MF_STRING, IDM_SONG1 + i - 1, str);
	}
}
Exemplo n.º 9
0
static Boolean compNodeSetNodeSet(binaryExpr *be, expr* left, expr* right, VTDNav *vn, opType op){
	exception e;
	int i,i1,k,s1,stackSize;
	Try {
		if (be->fib1 == NULL)
			be->fib1 = createFastIntBuffer2(BUF_SZ_EXP);

	          push2(vn);
	          stackSize = vn->contextBuf2->size;
	          while ((i = be->left->evalNodeSet(be->left,vn)) != -1) {
	              i1 = getStringVal(vn,i);
	              if (i1 != -1)
	              appendInt(be->fib1,i1);
	          }
			  be->left->reset(be->left,vn);
	          vn->contextBuf2->size = stackSize;
	          pop2(vn);
	          push2(vn);
	          stackSize = vn->contextBuf2->size;
	          while ((i = be->right->evalNodeSet(be->right,vn)) != -1) {
	              i1 = getStringVal(vn,i);
	              if (i1 != -1){
	                  s1 = be->fib1->size;
	                  for (k = 0; k < s1; k++) {
		                  Boolean b = compareVV(be,intAt(be->fib1,k),vn,i1,op);
		                  if (b){
		                      clearFastIntBuffer(be->fib1);
		                      vn->contextBuf2->size = stackSize;
		        	          pop2(vn);
		        	          be->right->reset(be->right,vn);
		                      return TRUE;
		                  }
		              }
	              }
	          }
	          vn->contextBuf2->size = stackSize;
	          pop2(vn);
	          be->right->reset(be->right,vn);
	          clearFastIntBuffer(be->fib1);
	          return FALSE;

	} Catch (e) {
		if (e.et == out_of_mem){
			Throw e;
		}
		if(be->fib1!=NULL)
			clearFastIntBuffer(be->fib1);

		e.et = other_exception;
		e.msg = "undefined run time behavior in computerEQNE";
		Throw e;
	}
	return FALSE;
}
Exemplo n.º 10
0
std::string ReplayBuilder::stagePropertiesDataString() {
  std::stringstream out;
  int i = 0;

  appendString(out, stagePropertiesData_, i);
  for (int x = 0; x < 2; x++) {
    appendInt(out, stagePropertiesData_->getInt(i++));
  }
  
  return out.str();
}
Exemplo n.º 11
0
std::string ReplayBuilder::teamPropertiesDataString() {
  std::stringstream out;
  out << std::hex << numTeams_;

  int i = 0;
  for (int x = 0; x < numTeams_; x++) {
    appendInt(out, teamPropertiesData_->getInt(i++));
    appendColonString(out, teamPropertiesData_, i);
  }

  return out.str();
}
Exemplo n.º 12
0
// Expanded results format:
// num results | <results>
//   Team result: team index | rank | score * 100 | num stats | stats
//     Stat: key length | key | value * 100
//
// Encoded to hex format:
// num results : <results>
//   Team result: team index : rank : score * 100 : num stats : stats
//     Stat: key : value * 100
std::string ReplayBuilder::resultsDataString() {
  std::stringstream out;
  int i = 0;
  int numResults =
      (resultsData_->getSize() > 0) ? resultsData_->getInt(i++) : 0;
  out << std::hex << numResults;
  
  for (int x = 0; x < numResults; x++) {
    for (int y = 0; y < 3; y++) {
      appendInt(out, resultsData_->getInt(i++));
    }

    int numStats = resultsData_->getInt(i++);
    appendInt(out, numStats);
    for (int y = 0; y < numStats; y++) {
      appendColonString(out, resultsData_, i);
      appendInt(out, resultsData_->getInt(i++));
    }
  }
  
  return out.str();
}
Exemplo n.º 13
0
Arquivo: wasap.c Projeto: 070499/xbmc
static void Tray_Modify(HICON hIcon)
{
	char *p;
	nid.hIcon = hIcon;
	/* we need to be careful because szTip is only 64 characters */
	/* 5 */
	p = appendString(nid.szTip, APP_TITLE);
	if (songs > 0) {
		const char *pb;
		const char *pe;
		for (pe = current_filename; *pe != '\0'; pe++);
		for (pb = pe; pb > current_filename && pb[-1] != '\\' && pb[-1] != '/'; pb--);
		/* 2 */
		*p++ = ':';
		*p++ = ' ';
		/* max 33 */
		if (pe - pb <= 33)
			p = appendString(p, pb);
		else {
			memcpy(p, pb, 30);
			p = appendString(p + 30, "...");
		}
		if (songs > 1) {
			/* 7 */
			p = appendString(p, " (song ");
			/* max 3 */
			p = appendInt(p, current_song + 1);
			/* 4 */
			p = appendString(p, " of ");
			/* max 3 */
			p = appendInt(p, songs);
			/* 1 */
			*p++ = ')';
		}
	}
	/* 1 */
	*p = '\0';
	Shell_NotifyIcon(NIM_MODIFY, &nid);
}
Exemplo n.º 14
0
SftpOutgoingPacket &SftpOutgoingPacket::init(SftpPacketType type,
    quint32 requestId)
{
    m_data.resize(TypeOffset + 1);
    m_data[TypeOffset] = type;
    if (type != SSH_FXP_INIT) {
        appendInt(requestId);
#ifdef CREATOR_SSH_DEBUG
        qDebug("Generating SFTP packet of type %d with request id %u", type,
            requestId);
#endif
    }
    return *this;
}
Exemplo n.º 15
0
std::string ReplayBuilder::logDataString() {
  std::stringstream out;
  out << std::hex << numLogEntries_;
  
  int i = 0;
  for (int x = 0; x < numLogEntries_; x++) {
    for (int y = 0; y < 2; y++) {
      appendInt(out, logData_->getInt(i++));
    }

    appendColonString(out, logData_, i);
  }
  
  return out.str();
}
Exemplo n.º 16
0
MM::VOID MM::String::appendInt(MM::INT32 val)
{
  MM::UINT32 ulDigits = digits(val);
  
  if(this->used + ulDigits < this->size)
  {
    snprintf(this->buf + this->used, this->size - this->used, "%ld", val);
    this->used += ulDigits;
  }
  else
  {
    resize(this->size * MM::String::RESIZE_FACTOR);
    appendInt(val);
  }
}
Exemplo n.º 17
0
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);
        }
    }
}
Exemplo n.º 18
0
static sk_sp<SkPDFStream> make_invert_function() {
    // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
    // a type 2 function, so we use a type 4 function.
    auto domainAndRange = sk_make_sp<SkPDFArray>();
    domainAndRange->reserve(2);
    domainAndRange->appendInt(0);
    domainAndRange->appendInt(1);

    static const char psInvert[] = "{1 exch sub}";
    // Do not copy the trailing '\0' into the SkData.
    auto invertFunction = sk_make_sp<SkPDFStream>(
            SkData::MakeWithoutCopy(psInvert, strlen(psInvert)));
    invertFunction->dict()->insertInt("FunctionType", 4);
    invertFunction->dict()->insertObject("Domain", domainAndRange);
    invertFunction->dict()->insertObject("Range", std::move(domainAndRange));
    return invertFunction;
}
Exemplo n.º 19
0
static int write_samples_data(const LoggerMessage *msg)
{
        ChannelSample *sample = msg->channelSamples;
        size_t channelCount = msg->sampleCount;

        if (NULL == sample) {
                pr_warning("Logger: null sample record\r\n");
                return WRITE_FAIL;
        }

        int i;
        for (i = 0; 0 < channelCount; channelCount--, sample++, i++) {
                appendFileBuffer(0 == i ? "" : ",");

                if (!sample->populated)
                        continue;

                const int precision = sample->cfg->precision;

                switch(sample->sampleData) {
                case SampleData_Float:
                case SampleData_Float_Noarg:
                        appendFloat(sample->valueFloat, precision);
                        break;
                case SampleData_Int:
                case SampleData_Int_Noarg:
                        appendInt(sample->valueInt);
                        break;
                case SampleData_LongLong:
                case SampleData_LongLong_Noarg:
                        appendLongLong(sample->valueLongLong);
                        break;
                case SampleData_Double:
                case SampleData_Double_Noarg:
                        appendDouble(sample->valueDouble, precision);
                        break;
                default:
                        pr_warning("file: Unknown channel sample type\n");
                }
        }

        appendFileBuffer("\n");
        return writeFileBuffer();
}
Exemplo n.º 20
0
static void populate_type_1_font(SkPDFDict* font,
                                 const SkAdvancedTypefaceMetrics& info,
                                 const std::vector<SkString>& glyphNames,
                                 SkTypeface* typeface,
                                 SkGlyphID firstGlyphID,
                                 SkGlyphID lastGlyphID) {
    font->insertName("Subtype", "Type1");
    font->insertName("BaseFont", info.fPostScriptName);

    // glyphCount not including glyph 0
    unsigned glyphCount = 1 + lastGlyphID - firstGlyphID;
    SkASSERT(glyphCount > 0 && glyphCount <= 255);
    font->insertInt("FirstChar", (size_t)0);
    font->insertInt("LastChar", (size_t)glyphCount);
    {
        int emSize;
        auto glyphCache = SkPDFFont::MakeVectorCache(typeface, &emSize);
        auto widths = sk_make_sp<SkPDFArray>();
        SkScalar advance = glyphCache->getGlyphIDAdvance(0).fAdvanceX;
        widths->appendScalar(from_font_units(advance, SkToU16(emSize)));
        for (unsigned gID = firstGlyphID; gID <= lastGlyphID; gID++) {
            advance = glyphCache->getGlyphIDAdvance(gID).fAdvanceX;
            widths->appendScalar(from_font_units(advance, SkToU16(emSize)));
        }
        font->insertObject("Widths", std::move(widths));
    }
    auto encDiffs = sk_make_sp<SkPDFArray>();
    encDiffs->reserve(lastGlyphID - firstGlyphID + 3);
    encDiffs->appendInt(0);

    SkASSERT(glyphNames.size() > lastGlyphID);
    const SkString unknown("UNKNOWN");
    encDiffs->appendName(glyphNames[0].isEmpty() ? unknown : glyphNames[0]);
    for (int gID = firstGlyphID; gID <= lastGlyphID; gID++) {
        encDiffs->appendName(glyphNames[gID].isEmpty() ? unknown : glyphNames[gID]);
    }

    auto encoding = sk_make_sp<SkPDFDict>("Encoding");
    encoding->insertObject("Differences", std::move(encDiffs));
    font->insertObject("Encoding", std::move(encoding));
}
Exemplo n.º 21
0
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);
}
Exemplo n.º 22
0
std::string ReplayBuilder::shipPropertiesDataString() {
  std::stringstream out;
  out << std::hex << numShips_;

  int i = 0;
  char *rgbString = new char[8]; // "#RRGGBB\0"
  for (int x = 0; x < numShips_; x++) {
    appendInt(out, shipPropertiesData_->getInt(i++));
    for (int y = 0; y < 3; y++) {
      int r = shipPropertiesData_->getInt(i++);
      int g = shipPropertiesData_->getInt(i++);
      int b = shipPropertiesData_->getInt(i++);
      sprintf(rgbString, "#%02x%02x%02x", r, g, b);
      out << ':' << rgbString;
    }

    appendColonString(out, shipPropertiesData_, i);
  }
  delete rgbString;

  return out.str();
}
Exemplo n.º 23
0
static int write_samples_header(const LoggerMessage *msg)
{
        int i;
        ChannelSample *sample = msg->channelSamples;
        size_t channelCount = msg->sampleCount;

        for (i = 0; 0 < channelCount; channelCount--, sample++, i++) {
                appendFileBuffer(0 == i ? "" : ",");

                uint8_t precision = sample->cfg->precision;
                appendQuotedString(sample->cfg->label);
                appendFileBuffer("|");
                appendQuotedString(sample->cfg->units);
                appendFileBuffer("|");
                appendFloat(decodeSampleRate(sample->cfg->min), precision);
                appendFileBuffer("|");
                appendFloat(decodeSampleRate(sample->cfg->max), precision);
                appendFileBuffer("|");
                appendInt(decodeSampleRate(sample->cfg->sampleRate));
        }

        appendFileBuffer("\n");
        return writeFileBuffer();
}
Exemplo n.º 24
0
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);
}
Exemplo n.º 25
0
// http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
static void finishStr(QString &str, const WeekDate &week_date, const QDate &date, const QTime &time, QChar c, int length)
{
    if (length <= 0)
        return;

    switch (c.unicode())
    {
    case L'G':
    {
        bool ad = date.year() > 0;
        if (length < 4)
            str += ad ? "AD" : "BC";
        else if (length == 4)
            str += ad ? "Anno Domini" : "Before Christ";
        else
            str += ad ? "A" : "B";
        break;
    }
    case L'y':
        if (length == 2)
            appendInt(str, date.year() % 100, 2);
        else
            appendInt(str, date.year(), length);
        break;
    case L'Y':
        appendInt(str, week_date.year(), length);
        break;
    case L'u':
    {
        int year = date.year();
        if (year < 0)
            year++;
        appendInt(str, date.year(), length);
        break;
    }
    case L'q':
    case L'Q':
    {
        int q = (date.month() + 2) / 3;
        if (length < 3)
            appendInt(str, q, length);
        else if (length == 3)
        {
            str += 'Q';
            str += QString::number(q);
        }
        else
        {
            switch (q)
            {
            case 1:
                str += qApp->translate("AdiumTimeFormatter", "1st quarter");
                break;
            case 2:
                str += qApp->translate("AdiumTimeFormatter", "2nd quarter");
                break;
            case 3:
                str += qApp->translate("AdiumTimeFormatter", "3rd quarter");
                break;
            case 4:
                str += qApp->translate("AdiumTimeFormatter", "4th quarter");
                break;
            default:
                break;
            }
        }
        break;
    }
    case L'M':
    case L'L':
        if (length < 3)
            appendInt(str, date.month(), length);
        else if (length == 3)
            str += QDate::shortMonthName(date.month());
        else if (length == 4)
            str += QDate::longMonthName(date.month());
        else
            str += QDate::shortMonthName(date.month()).at(0);
        break;
    case L'w':
        TRIM_LENGTH(2);
        appendInt(str, length, week_date.week());
        break;
    case L'W':
        while (length-- > 0)
            str += QString::number((date.day() + 6) / 7);
        break;
    case L'd':
        TRIM_LENGTH(2);
        appendInt(str, date.day(), length);
        break;
    case L'D':
        TRIM_LENGTH(3);
        appendInt(str, date.dayOfYear(), length);
        break;
    case L'F':
        while (length-- > 0)
            str += QString::number(1);
        break;
    case L'g':
        appendInt(str, date.toJulianDay(), length);
        break;
    case L'c':
    case L'e':
        if (length < 3)
        {
            appendInt(str, date.dayOfWeek(), length);
            break;
        }
    case L'E':
        if (length < 4)
            str += QDate::shortDayName(date.dayOfWeek());
        else if (length == 4)
            str += QDate::longDayName(date.dayOfWeek());
        else
            str += QDate::shortDayName(date.dayOfWeek()).at(0);
        break;
    case L'a':
        str += time.hour() < 12 ? "AM" : "PM";
        break;
    case L'H':
        TRIM_LENGTH(2);
        appendInt(str, time.hour(), length);
        break;
    case L'h':
        TRIM_LENGTH(2);
        appendInt(str, time.hour() % 12, length);
        break;
    case L'K':
        TRIM_LENGTH(2);
        appendInt(str, time.hour() - 1, length);
        break;
    case L'k':
        TRIM_LENGTH(2);
        appendInt(str, time.hour() % 12 - 1, length);
        break;
    case L'm':
        TRIM_LENGTH(2);
        appendInt(str, time.minute(), length);
        break;
    case L's':
        TRIM_LENGTH(2);
        appendInt(str, time.second(), length);
        break;
    case L'S':
        str += QString::number(time.msec() / 1000.0, 'f', length).section('.', 1);
        break;
    case L'A':
        appendInt(str, QTime(0,0).msecsTo(time), length);
        break;
    case L'v':
    // I don't understand the difference
    case L'z':
        if (length < 4)
            str += SystemInfo::instance()->timezone();
        else
            // There should be localized name, but I don't know how get it
            str += SystemInfo::instance()->timezone();
        break;
    case L'Z':
    {
        if (length == 4)
            str += "GMT";
        int offset = SystemInfo::instance()->timezoneOffset();
        if (offset < 0)
            str += '+';
        else
            str += '-';
        appendInt(str, qAbs((offset/60)*100 + offset%60), 4);
        break;
    }
    default:
        while (length-- > 0)
            str += c;
        break;
    }
}
Exemplo n.º 26
0
QString convertTimeDate(const QString &mac_format, const QDateTime &datetime)
{
    QDate date = datetime.date();
    QTime time = datetime.time();
    QString str;
    if (mac_format.contains('%'))
    {
        const QChar *chars = mac_format.constData();
        bool is_percent = false;
        int length = 0;
        bool error = false;
        while ((*chars).unicode() && !error)
        {
            if (is_percent)
            {
                is_percent = false;
                switch ((*chars).unicode())
                {
                case L'%':
                    str += *chars;
                    break;
                case L'a':
                    appendStr(str, QDate::shortDayName(date.dayOfWeek()), length);
                    break;
                case L'A':
                    appendStr(str, QDate::longDayName(date.dayOfWeek()), length);
                    break;
                case L'b':
                    appendStr(str, QDate::shortMonthName(date.day()), length);
                    break;
                case L'B':
                    appendStr(str, QDate::longMonthName(date.day()), length);
                    break;
                case L'c':
                    appendStr(str, QLocale::system().toString(datetime), length);
                    break;
                case L'd':
                    appendInt(str, date.day(), length > 0 ? length : 2);
                    break;
                case L'e':
                    appendInt(str, date.day(), length);
                    break;
                case L'F':
                    appendInt(str, time.msec(), length > 0 ? length : 3);
                    break;
                case L'H':
                    appendInt(str, time.hour(), length > 0 ? length : 2);
                    break;
                case L'I':
                    appendInt(str, time.hour() % 12, length > 0 ? length : 2);
                    break;
                case L'j':
                    appendInt(str, date.dayOfYear(), length > 0 ? length : 3);
                    break;
                case L'm':
                    appendInt(str, date.month(), length > 0 ? length : 2);
                    break;
                case L'M':
                    appendInt(str, time.minute(), length > 0 ? length : 2);
                    break;
                case L'p':
                    appendStr(str, time.hour() < 12 ? "AM" : "PM", length);
                    break;
                case L'S':
                    appendInt(str, time.second(), length > 0 ? length : 2);
                    break;
                case L'w':
                    appendInt(str, date.dayOfWeek(), length);
                    break;
                case L'x':
                    appendStr(str, QLocale::system().toString(date), length);
                    break;
                case L'X':
                    appendStr(str, QLocale::system().toString(time), length);
                    break;
                case L'y':
                    appendInt(str, date.year() % 100, length > 0 ? length : 2);
                    break;
                case L'Y':
                    appendInt(str, date.year(), length > 0 ? length : 4);
                    break;
                case L'Z':
                    // It should be localized, isn't it?..
                    appendStr(str, SystemInfo::instance()->timezone(), length);
                    break;
                case L'z':
                {
                    int offset = SystemInfo::instance()->timezoneOffset();
                    appendInt(str, (offset/60)*100 + offset%60, length > 0 ? length : 4);
                    break;
                }
                default:
                    if ((*chars).isDigit())
                    {
                        is_percent = true;
                        length *= 10;
                        length += (*chars).digitValue();
                    }
                    else
                        error = true;
                }
            }
            else if (*chars == '%')
            {
                length = 0;
                is_percent = true;
            }
            else
                str += *chars;
            chars++;
        }
        if (!error)
            return str;

        str.clear();
    }

    WeekDate week_date(date);
    QChar last;
    QChar cur;
    int length = 0;
    bool quote = false;
    const QChar *chars = mac_format.constData();
    forever
    {
        cur = *chars;
        if (cur == '\'')
        {
            if (*(chars+1) == '\'')
            {
                chars++;
                str += cur;
            }
            else
            {
                if (!quote)
                    finishStr(str, week_date, date, time, last, length);
                quote = !quote;
            }
            length = 0;
        }
        else if (quote)
            str += cur;
        else
        {
            if (cur == last)
                length++;
            else
            {
                finishStr(str, week_date, date, time, last, length);
                length = 1;
            }
        }
        if (!chars->unicode())
            break;

        last = cur;
        chars++;
    }
    return str;
}
Exemplo n.º 27
0
void OutboundPkt::appendBool(bool b) {
    qCDebug(TG_CORE_OUTBOUNDPKT) << "appendBool()" << b;
    b ? appendInt(CoreTypes::typeBoolTrue) : appendInt(CoreTypes::typeBoolFalse);
}
Exemplo n.º 28
0
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);
}
Exemplo n.º 29
0
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;
}
Exemplo n.º 30
0
void syscallLog(const SyscallInfo *syscallInfo, const u32 *parameters, u64 result, u32 ra, const char *prefix) {
	char buffer[300];
	char *s = buffer;
	int i, j, k;
	int length;
	int lineStart;

	// Don't log out own sceIoWrites.
	if (syscallInfo->nid == 0x42EC03AC && parameters[0] == commonInfo->logFd) {
		return;
	}

	if (logTimestamp) {
		pspTime time;
		if (sceRtcGetCurrentClockLocalTime(&time) == 0) {
			s = appendInt(s, time.hour, 2);
			*s++ = ':';
			s = appendInt(s, time.minutes, 2);
			*s++ = ':';
			s = appendInt(s, time.seconds, 2);
			*s++ = '.';
			s = appendInt(s, time.microseconds, 6);
			*s++ = ' ';
		}
	}

	if (logThreadName) {
		SceKernelThreadInfo currentThreadInfo;
		currentThreadInfo.size = sizeof(currentThreadInfo);
		currentThreadInfo.name[0] = '\0';
		sceKernelReferThreadStatus(0, &currentThreadInfo);

		s = append(s, currentThreadInfo.name);
		*s++ = ' ';
		*s++ = '-';
		*s++ = ' ';
	}

	if (logRa) {
		s = appendHex(s, ra, 0);
		*s++ = ' ';
	}

	s = append(s, prefix);
	s = append(s, syscallInfo->name);
	int types = syscallInfo->paramTypes;
	for (i = 0; i < syscallInfo->numParams; i++, types >>= 4) {
		if (i > 0) {
			*s++ = ',';
		}
		*s++ = ' ';
		int parameter = parameters[i];
		switch (types & 0xF) {
			case TYPE_HEX32:
				s = appendHex(s, parameter, 0);
				break;
			case TYPE_INT32:
				s = appendInt(s, parameter, 0);
				break;
			case TYPE_STRING:
				s = appendHex(s, parameter, 8);
				if (parameter != 0) {
					*s++ = '(';
					*s++ = '\'';
					s = append(s, (char *) parameter);
					*s++ = '\'';
					*s++ = ')';
				}
				break;
			case TYPE_POINTER32:
				s = appendHex(s, parameter, 8);
				if (parameter != 0) {
					*s++ = '(';
					s = appendHex(s, _lw(parameter), 0);
					*s++ = ')';
				}
				break;
			case TYPE_POINTER64:
				s = appendHex(s, parameter, 8);
				if (parameter != 0) {
					*s++ = '(';
					s = appendHex(s, _lw(parameter), 8);
					*s++ = ' ';
					s = appendHex(s, _lw(parameter + 4), 8);
					*s++ = ')';
				}
				break;
			case TYPE_VARSTRUCT:
				s = appendHex(s, parameter, 8);
				if (parameter != 0) {
					*s++ = ':';
					*s++ = '\n';
					writeLog(buffer, s - buffer);
					s = buffer;
					length = _lw(parameter);
					lineStart = 0;
					for (j = 0; j < length; j += 4) {
						if (j > 0) {
							if ((j % 16) == 0) {
								s = append(s, "  >");
								for (k = lineStart; k < j; k++) {
									char c = _lb(parameter + k);
									if (c < ' ' || c > '~') {
										c = '.';
									}
									*s++ = c;
								}
								s = append(s, "<\n");
								writeLog(buffer, s - buffer);
								s = buffer;
								lineStart = j;
							} else {
								*s++ = ',';
								*s++ = ' ';
							}
						}
						s = appendHex(s, _lw(parameter + j), 8);
					}
				}
				break;
			case TYPE_FIXSTRUCT:
				s = appendHex(s, parameter, 8);
				if (parameter != 0) {
					*s++ = ':';
					*s++ = '\n';
					writeLog(buffer, s - buffer);
					s = buffer;
					length = FIXSTRUCT_SIZE;
					lineStart = 0;
					for (j = 0; j < length; j += 4) {
						if (j > 0) {
							if ((j % 16) == 0) {
								s = append(s, "  >");
								for (k = lineStart; k < j; k++) {
									char c = _lb(parameter + k);
									if (c < ' ' || c > '~') {
										c = '.';
									}
									*s++ = c;
								}
								s = append(s, "<\n");
								writeLog(buffer, s - buffer);
								s = buffer;
								lineStart = j;
							} else {
								*s++ = ',';
								*s++ = ' ';
							}
						}
						s = appendHex(s, _lw(parameter + j), 8);
					}
				}
				break;
		}
	}
	*s++ = ' ';
	*s++ = '=';
	*s++ = ' ';
	s = appendHex(s, (int) result, 0);

	#if DEBUG_MUTEX
	s = mutexLog(s, syscallInfo, parameters, result);
	#endif

	*s++ = '\n';
	writeLog(buffer, s - buffer);

	#if DEBUG_UTILITY_SAVEDATA
	utilitySavedataLog(buffer, syscallInfo, parameters[0]);
	#endif
}