void CMemBuf::PutStrDQ( char *data ) { // ダブルクォート内専用str // unsigned char *src; unsigned char *p; unsigned char a1; unsigned char a2 = '\0'; int fl; src = (unsigned char *)data; while(1) { a1 = *src++; if ( a1 == 0 ) break; fl = 0; if ( a1 == '\\' ) { // ¥を¥¥に p = (unsigned char *) PreparePtr( 1 ); *p = a1; } if ( a1 == 13 ) { // CRを¥nに fl = 1; a2 = 10; if ( *src == 10 ) src++; } if (a1>=129) { // 全角文字チェック if (a1<=159) { fl = 1; a2 = *src++; } else if (a1>=224) { fl = 1; a2 = *src++; } if ( a2 == 0 ) break; } if ( fl ) { p = (unsigned char *) PreparePtr( 2 ); p[0] = a1; p[1] = a2; continue; } p = (unsigned char *) PreparePtr( 1 ); *p = a1; } }
int CMemBuf::PutFile( char *fname ) { // バッファに指定ファイルの内容を追加 // (return:ファイルサイズ(-1=error)) // char *p; int length; FILE *ff; ff=fopen( fname,"rb" ); if (ff==NULL) return -1; fseek( ff,0,SEEK_END ); length=(int)ftell( ff ); // normal file size fclose(ff); p = PreparePtr( length+1 ); ff=fopen( fname,"rb" ); fread( p, 1, length, ff ); fclose(ff); p[length]=0; strcpy( name,fname ); return length; }
void CMemBuf::PutStrf( char *format, ... ) { va_list args; int c = cur; int space = size - cur; while(1) { char *p = PreparePtr(space - 1); cur = c; space = size - cur; int n; va_start(args, format); n = VSNPRINTF(p, space, format, args); va_end(args); if ( 0 <= n && n < space ) { cur += n; return; } if ( 0 <= n ) { space = n + 1; } else { space *= 2; } } }
void CMemBuf::Put( int data ) { char *p; p = PreparePtr( sizeof(int) ); memcpy( p, &data, sizeof(int) ); }
void CMemBuf::PutData( void *data, int sz ) { char *p; p = PreparePtr( sz ); memcpy( p, (char *)data, sz ); }
void CMemBuf::PutCR( void ) { char *p; p = PreparePtr( 2 ); *p++ = 13; *p++ = 10; }
void CMemBuf::PutStrBlock( char *data ) { char *p; p = PreparePtr( (int)strlen(data)+1 ); strcpy( p, data ); }
void CMemBuf::Put( double data ) { char *p; p = PreparePtr( sizeof(double) ); memcpy( p, &data, sizeof(data) ); }
void CMemBuf::Put( char data ) { char *p; p = PreparePtr( 1 ); *p = data; }
void CMemBuf::Put( unsigned char data ) { unsigned char *p; p = (unsigned char *) PreparePtr( 1 ); *p = data; }
void CMemBuf::Put( int data ) { int *p; p = (int *)PreparePtr( sizeof(int) ); *p = data; }
void CMemBuf::PutStr( char *data ) { char *p; p = PreparePtr( strlen(data) ); strcpy( p, data ); }
void CMemBuf::Put( double data ) { double *p; p = (double *)PreparePtr( sizeof(double) ); *p = data; }
void CMemBuf::Put( float data ) { float *p; p = (float *)PreparePtr( sizeof(float) ); *p = data; }
void CMemBuf::Put( short data ) { short *p; p = (short *)PreparePtr( sizeof(short) ); *p = data; }