Пример #1
0
void OutputStream::writeText (const String& text, const bool asUTF16,
                              const bool writeUTF16ByteOrderMark)
{
    if (asUTF16)
    {
        if (writeUTF16ByteOrderMark)
            write ("\x0ff\x0fe", 2);

        String::CharPointerType src (text.getCharPointer());
        bool lastCharWasReturn = false;

        for (;;)
        {
            const juce_wchar c = src.getAndAdvance();

            if (c == 0)
                break;

            if (c == '\n' && ! lastCharWasReturn)
                writeShort ((short) '\r');

            lastCharWasReturn = (c == L'\r');
            writeShort ((short) c);
        }
    }
    else
    {
        const char* src = text.toUTF8();
        const char* t = src;

        for (;;)
        {
            if (*t == '\n')
            {
                if (t > src)
                    write (src, (int) (t - src));

                write ("\r\n", 2);
                src = t + 1;
            }
            else if (*t == '\r')
            {
                if (t[1] == '\n')
                    ++t;
            }
            else if (*t == 0)
            {
                if (t > src)
                    write (src, (int) (t - src));

                break;
            }

            ++t;
        }
    }
}
void DataOutputStream::writeVec2sArray(const osg::Vec2sArray* a)
{
    int size = a->getNumElements();
    writeInt(size);
    for(int i =0; i<size ;i++){
        writeShort((*a)[i].x());
        writeShort((*a)[i].y());
    }

    if (_verboseOutput) std::cout<<"read/writeVec2sArray() ["<<size<<"]"<<std::endl;
}
void OutputStream::writeText (const String& text,
                              const bool asUnicode,
                              const bool writeUnicodeHeaderBytes)
{
    if (asUnicode)
    {
        if (writeUnicodeHeaderBytes)
            write ("\x0ff\x0fe", 2);

        const juce_wchar* src = (const juce_wchar*) text;
        bool lastCharWasReturn = false;

        while (*src != 0)
        {
            if (*src == L'\n' && ! lastCharWasReturn)
                writeShort ((short) L'\r');

            lastCharWasReturn = (*src == L'\r');
            writeShort ((short) *src++);
        }
    }
    else
    {
        const char* src = (const char*) text;
        const char* t = src;

        for (;;)
        {
            if (*t == '\n')
            {
                if (t > src)
                    write (src, (int) (t - src));

                write ("\r\n", 2);
                src = t + 1;
            }
            else if (*t == '\r')
            {
                if (t[1] == '\n')
                    ++t;
            }
            else if (*t == 0)
            {
                if (t > src)
                    write (src, (int) (t - src));

                break;
            }

            ++t;
        }
    }
}
Пример #4
0
void writeMultiCodeShort(GRAPH graph, ADJACENCY adj, int order, FILE *f){
    int i, j;
    
    //write the number of vertices
    fputc(0, f);
    writeShort(order, f);
    
    for(i=1; i<order; i++){
        for(j=0; j<adj[i]; j++){
            if(i==graph[i][j]->smallest){
                writeShort(graph[i][j]->largest, f);
            }
        }
        writeShort(0, f);
    }
}
Пример #5
0
void writeCubicMultiCodeShort(GRAPH graph, int vertexCount, FILE *f){
    int i, j;
    
    //write the number of vertices
    fputc(0, f);
    writeShort(vertexCount, f);
    
    for(i=0; i<vertexCount-1; i++){
        for(j=0; j<3; j++){
            if(i<graph[i][j]){
                writeShort(graph[i][j]+1, f);
            }
        }
        writeShort(0, f);
    }
}
Пример #6
0
//This does not adhere strictly to the UTF8 encoding standard
//this is more like pascal style 16-bit length + content strings
bool Buffer::writeUTF8(const char *data) {
    unsigned short len = (unsigned short)(data ? strlen(data) : 0);
    if (writeShort(len)) {
        return write(data, len);
    }
    return false;
}
Пример #7
0
void writeTypedListElement( TAThread thread, const TypedListElement * value ) {
    const int * start;
    switch ( value->type ) {
        case IntTObjCode    : writeString( thread, "IntTObj"     ); writeInt   ( thread, value->data.IntTObj     ); break;
        case CharTObjCode   : writeString( thread, "CharTObj"    ); writeChar  ( thread, value->data.CharTObj    ); break;
        case ShortTObjCode  : writeString( thread, "ShortTObj"   ); writeShort ( thread, value->data.ShortTObj   ); break;
        case LongTObjCode   : writeString( thread, "LongTObj"    ); writeLong  ( thread, value->data.LongTObj    ); break;
        case LLongTObjCode  : writeString( thread, "LLongTObj"   ); writeLLong ( thread, value->data.LLongTObj   ); break;
        case IntMaxTObjCode : writeString( thread, "IntMaxTObj"  ); writeIntMax( thread, value->data.IntMaxTObj  ); break;
        case SizeTObjCode   : writeString( thread, "SizeTObj"    ); writeSize  ( thread, value->data.SizeTObj    ); break;
        case PtrDiffTObjCode: writeString( thread, "PtrDiffTObj" ); writeLong  ( thread, value->data.PtrDiffTObj ); break;
        case WIntTObjCode   : writeString( thread, "WIntTObj"    ); writeWChar ( thread, value->data.WIntTObj    ); break;
        case FloatTObjCode:
            start = (int *)& value->data.FloatTObj;
            writeString( thread, "FloatTObj" );
            writeIntArray( thread, start, sizeof( float ) / sizeof( int ) );
            break;
        case DoubleTObjCode:
            start = (int *)& value->data.DoubleTObj;
            writeString( thread, "DoubleTObj" );
            writeIntArray( thread, start, sizeof( double ) / sizeof( int ) );
            break;
        case LongDoubleTObjCode:
            start = (int *)& value->data.LongDoubleTObj;
            writeString( thread, "LongDoubleTObj" );
            writeIntArray( thread, start, sizeof( long double ) / sizeof( int ) );
            break;
        case CStringCode    : writeString( thread, "CString"     ); writeString ( thread, value->data.CString     ); break;
        case WStringCode    : writeString( thread, "WString"     ); writeWString( thread, value->data.WString     ); break;
        case VoidTPtrObjCode: writeString( thread, "VoidTPtrObj" ); writePointer( thread, value->data.VoidTPtrObj ); break;
        default: assertion( 0, "writeTypedListElement : unsupported type" ); break;
    }
} // writeTypedListElement
Пример #8
0
int SarReader::writeHeaderSub( ArchiveInfo *ai, FILE *fp, int archive_type, int nsa_offset )
{
    unsigned int i, j;

    fseek( fp, 0L, SEEK_SET );
    for (int k=0 ; k<nsa_offset ; k++)
        fputc( 0, fp );
    writeShort( fp, ai->num_of_files  );
    writeLong( fp, ai->base_offset-nsa_offset );
    
    for ( i=0 ; i<ai->num_of_files ; i++ ){

        for ( j=0 ; ai->fi_list[i].name[j] ; j++ )
            fputc( ai->fi_list[i].name[j], fp );
        fputc( ai->fi_list[i].name[j], fp );
        
        if ( archive_type >= ARCHIVE_TYPE_NSA )
            writeChar( fp, ai->fi_list[i].compression_type );

        writeLong( fp, ai->fi_list[i].offset  - ai->base_offset );
        writeLong( fp, ai->fi_list[i].length );

        if ( archive_type >= ARCHIVE_TYPE_NSA ){
            writeLong( fp, ai->fi_list[i].original_length );
        }
    }

    return 0;
}
Пример #9
0
void SE_BufferOutput::writeShortArray(short* sa, int count)
{
    for(int i = 0 ; i < count ; i++)
    {
        writeShort(sa[i]);
    }
}
void 
GfxFeatureMapReplyPacket::setCopyright( const char* copyright ) {
   int pos = COPYRIGHT_POS;
   incWriteString( pos, copyright );
   writeShort( LENGTH_COPYRIGHT_POS, pos - COPYRIGHT_POS );
   setLength( pos );
}
void
GfxFeatureMapRequestPacket::setStartOffset(uint16 offset)
{
   int pos = startOffset_POS;

   writeShort( pos, offset );
}
Пример #12
0
/**
 * 带消息ID的构造函数
 *
 * @param id 消息ID
 */
CMolMessageOut::CMolMessageOut(int id):
    mPos(0)
{
    mData = (char*) malloc(INITIAL_DATA_CAPACITY);
    mDataSize = INITIAL_DATA_CAPACITY;

    writeShort(id);
}
Пример #13
0
//-----------------------------------------------------------------
// write set indent to buffer
void mgTextBuffer::writeIndent(
  short margin)
{
  if (m_indent == margin)
    return;
  m_indent = margin;
  writeShort(mgIndentCmd, margin);
}
Пример #14
0
//-----------------------------------------------------------------
// write set left margin to buffer
void mgTextBuffer::writeLeftMargin(
  short margin)                   // margin, -1 for current position
{
  if (m_leftMargin == margin)
    return;
  m_leftMargin = margin;
  writeShort(mgLeftMarginCmd, margin);
}
Пример #15
0
//-----------------------------------------------------------------
// set font bold
void mgTextBuffer::writeFontBold(
  mgBooleanAttr bold)
{
  if (m_fontBold == bold)
    return;
  m_fontBold = bold;
  writeShort(mgFontBoldCmd, (short) m_fontBold);
}
Пример #16
0
//-----------------------------------------------------------------
// set font italic
void mgTextBuffer::writeFontItalic(
  mgBooleanAttr italic)
{ 
  if (m_fontItalic == italic)
    return;
  m_fontItalic = italic;
  writeShort(mgFontItalicCmd, (short) m_fontItalic);
}
Пример #17
0
//-----------------------------------------------------------------
// set font size
void mgTextBuffer::writeFontSize(
  short size)                    // pointsize
{
  if (m_fontSize == size)
    return;
  m_fontSize = size;
  writeShort(mgFontSizeCmd, m_fontSize);
}
Пример #18
0
//-----------------------------------------------------------------
// write set justification to buffer
void mgTextBuffer::writeJustify(
  mgTextAlign justify)
{
  if (m_justify == justify)
    return;
  m_justify = justify;
  writeShort(mgJustifyCmd, justify);
}
Пример #19
0
//-----------------------------------------------------------------
// write set right margin to buffer
void mgTextBuffer::writeRightMargin(
  short margin)
{                     
  if (m_rightMargin == margin)
    return;
  m_rightMargin = margin;
  writeShort(mgRightMarginCmd, margin);
}
Пример #20
0
void chunkArchive::newChunk(unsigned short id)
{
	if (TEST_BIT(status_bits, bCHUNK))
		closeChunk();
	current_chunk_id = id;
	writeShort(id);
	writeLong(0);
	current_chunk_start = F->pos();
	SET_BIT(status_bits, bCHUNK);
}
Пример #21
0
void writeBMP24Header(struct bmp24_writer_t *bw) {
	setWriterByteOrder(bw->w, BYTEORDER_LE);

	writeShort(bw->w, 0x4d42); /* "BM" */
	writeLong(bw->w, 54 + byteWidth(bw)*bw->height);
	writeShort(bw->w, 0);
	writeShort(bw->w, 0);
	writeLong(bw->w, 54);

	writeLong(bw->w, 40); /* Header size */
	writeLong(bw->w, bw->width); /* Image width */
	writeLong(bw->w, bw->height); /* Image height */
	writeShort(bw->w, 1); /* Bit-planes */
	writeShort(bw->w, 24); /* Colour depth */
	writeLong(bw->w, 0); /* Uncompressed RGB mode */
	writeLong(bw->w, byteWidth(bw)*bw->height); /* Bitmap size */
	writeLong(bw->w, 0); /* Horizontal resolution */
	writeLong(bw->w, 0); /* Vertical resolution */
	writeLong(bw->w, 0); /* Number of colours in palette */
	writeLong(bw->w, 0); /* Ignored */
}
Пример #22
0
void writeVertexDeletedPlanarCodeShort(){
    int i;
    EDGE *e, *elast;
    
    //write the number of vertices
    fputc(0, stdout);
    writeShort(newNv);
    
    
    for(i=0; i<nv; i++){
        if(!deleted[i]){
            e = elast = firstedge[i];
            do {
                if(!deleted[e->end]){
                    writeShort(newLabels[e->end] + 1);
                }
                e = e->next;
            } while (e != elast);
            writeShort(0);
        }
    }
}
Пример #23
0
void writeSuppressedPlanarCodeShort(){
    int i;
    EDGE *e, *elast;
    
    //write the number of vertices
    fputc(0, stdout);
    writeShort(newNv);
    
    
    for(i=0; i<nv; i++){
        if(degree[i]!=2){
            e = elast = firstedge[i];
            do {
                if(degree[e->end]==2){
                    writeShort(newLabels[e->inverse->next->end] + 1);
                } else {
                    writeShort(newLabels[e->end] + 1);
                }
                e = e->next;
            } while (e != elast);
            writeShort(0);
        }
    }
}
Пример #24
0
void rfidInit() {
    gpioOutputType(RFID_SCL, gpioOutputType_openDrain);
    gpioOutputType(RFID_SDA, gpioOutputType_openDrain);
    gpioPinMode(RFID_SCL, gpioMode_alternate);
    gpioPinMode(RFID_SDA, gpioMode_alternate);
    gpioAlternate(RFID_SCL, 1);
    gpioAlternate(RFID_SDA, 1);


    uint8_t buff[32] = {0};
    i2cInit(rfidi2c, i2cSpeed_std);
    
    readRegister(0x2040, buff, 2);

    readRegister(0x2004, buff, 0x14);
    
    if ((buff[6] == 0x00 &&
        buff[7] == 0x00 &&
        buff[8] == 0x00 &&
        buff[9] == 0x00) ||
        buff[10] != 0x00 ||
        buff[11] != 0x00 ||
        buff[12] != 0x00 ||
        buff[13] != 0x00) {
        writeShort(0x2008, 0xCAFE);
        delay(10);
        writeShort(0x200A, 0xD00D);
        delay(10);

        uint16_t i = 0x200C;
        for (; i < 0x2018; i+=2) {
            writeShort(i, 0x0000);
            delay(10);
        }
    }
}
Пример #25
0
/**
 * 写一个字符串进去
 *
 * @param string 要写入的字符串
 * @param length 字符串长度
 */
void CMolMessageOut::writeString(const std::string &str, int length)
{
    int stringLength = (int)str.length();
    if (length < 0)
    {
        writeShort(stringLength);
        length = stringLength;
    }
    else if (length < stringLength)
    {
        stringLength = length;
    }
    expand(mPos + length);

    memcpy(mData + mPos, str.c_str(), stringLength);

    if (length > stringLength)
    {
        memset(mData + mPos + stringLength, '\0', length - stringLength);
    }
    mPos += length;
}
Пример #26
0
static Boln writeHeader (tkimg_MFile *handle, TGAHEADER *th)
{
    if (!writeUByte (handle, th->numid) ||
	!writeUByte (handle, th->maptyp) ||
	!writeUByte (handle, th->imgtyp) ||
	!writeShort (handle, th->maporig) ||
	!writeShort (handle, th->mapsize) ||
	!writeUByte (handle, th->mapbits) ||
	!writeShort (handle, th->xorig) ||
	!writeShort (handle, th->yorig) ||
	!writeShort (handle, th->xsize) ||
	!writeShort (handle, th->ysize) ||
	!writeUByte (handle, th->pixsize) ||
	!writeUByte (handle, th->imgdes))
	return FALSE;
    return TRUE;
}
Пример #27
0
void SMSSendRequestPacket::fillPacket(int conversion,
                                      const char* senderPhone,
                                      const char* recipientPhone,
                                      int dataLength,
                                      const byte* data,
                                      smsType_t smsType,
                                      int smsNumber,
                                      int nbrParts,
                                      int partNbr)
{
   int position = REQUEST_HEADER_SIZE;
   incWriteShort(position, dataLength); // May be rewritten later.
   incWriteByte(position, smsType);
   incWriteString(position, senderPhone);
   incWriteString(position, recipientPhone);
   // Check if this SMS should be converted
   if ( conversion == CONVERSION_TEXT ) {
      byte* tempBuf = new byte[dataLength*6];
      int outlen = SMSConvUtil::mc2ToGsm((char*)tempBuf, 
                                         (const char*)data, dataLength);
      for(int i=0; i < outlen; i++) {
         incWriteByte(position, tempBuf[i]);
      }
      // Rewrite data size.
      writeShort( REQUEST_HEADER_SIZE, outlen );
      delete [] tempBuf;
   } else {
      // No conversion - just write the data.
      for(int i=0; i < dataLength; i++)
         incWriteByte(position, data[i]);
   }
   if ( smsNumber != -1 ) {
      incWriteByte(position, smsNumber);
      incWriteByte(position, nbrParts);
      incWriteByte(position, partNbr);
   }
   setLength(position);
}
Пример #28
0
uint16_t rfidWriteDownloadReg(uint16_t data) {
    return writeShort(0x203E, data);
}
Пример #29
0
void Message::writeUnsignedShort(unsigned short value)
{
	writeShort(value);
}
//virtual 
void 
ASCIIDataWriter::writeUcChar(ucchar b)
{
  writeShort((short)b);
}