Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6668a6

Browse files
Add test_libblobstamper executable, move Blob Dump function to Bolb methods
1 parent3adadc7 commite6668a6

File tree

5 files changed

+86
-26
lines changed

5 files changed

+86
-26
lines changed

‎Makefile‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ ifeq ($(origin CC),default)
77
endif
88

99
.PHONY: all
10-
all: testcpp_test
10+
all: testtest_pg_op_wrappers test_libblobstamper
1111
@echo All done!
1212

1313

1414
test:$(LIB_OBJS) test.o
1515
$(CC)$(LDFLAGS)$^ -o$@$(LDLIBS)
1616

17-
cpp_test:$(LIB_OBJS)cpp_test.o libblobstamper.o pg_op_wrappers.o
17+
test_pg_op_wrappers:$(LIB_OBJS)test_pg_op_wrappers.o libblobstamper.o pg_op_wrappers.o
1818
$(CXX)$(LDFLAGS)$^ -o$@$(LDLIBS)
1919

20+
test_libblobstamper:$(LIB_OBJS) libblobstamper.o test_libblobstamper.o
21+
$(CXX)$(LDFLAGS)$^ -o$@$(LDLIBS)
22+
23+
24+
2025
%.o:%.cpp$(DEPS)
2126
$(CXX) -c -g$(CFLAGS)$<
2227

@@ -25,5 +30,5 @@ cpp_test: $(LIB_OBJS) cpp_test.o libblobstamper.o pg_op_wrappers.o
2530

2631
.PHONY: clean
2732
clean:
28-
rm -f*.otestcpp_test
33+
rm -f*.otesttest_pg_op_wrappers test_libblobstamper
2934
@echo Clean done!

‎libblobstamper.cpp‎

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Blob::Blob (char * data_in, int size_in)
1212
data = data_in;
1313
size = size_in;
1414
begin =0;
15-
end = size;
15+
end = size -1;/* i.e. size=1 means begin=0 && end=0*/
1616
}
1717

1818
bool
@@ -22,18 +22,68 @@ Blob::isEmpty ()
2222
returnfalse;
2323
}
2424

25-
void
26-
wflBlobDump(Blob blob)
25+
/* Borrowed from http://www.stahlworks.com/dev/index.php?tool=csc01*/
26+
/* Code is not nice for support, better rewrite it*/
27+
28+
voidhexdump(void *pAddressIn,long lSize)
2729
{
28-
int length = blob.end - blob.begin +1 ;
29-
char * str =(char *)malloc(length +1);// second +1 is for \0
30-
// FIXME проверка null
31-
str[0]='\0';
30+
char szBuf[100];
31+
long lIndent =1;
32+
long lOutLen, lIndex, lIndex2, lOutLen2;
33+
long lRelPos;
34+
struct {char *pData;unsignedlong lSize; } buf;
35+
unsignedchar *pTmp,ucTmp;
36+
unsignedchar *pAddress = (unsignedchar *)pAddressIn;
37+
38+
buf.pData = (char *)pAddress;
39+
buf.lSize = lSize;
40+
41+
while (buf.lSize >0)
42+
{
43+
pTmp = (unsignedchar *)buf.pData;
44+
lOutLen = (int)buf.lSize;
45+
if (lOutLen >16)
46+
lOutLen =16;
47+
48+
// create a 64-character formatted output line:
49+
sprintf(szBuf," >"
50+
""
51+
" %08lX", pTmp-pAddress);
52+
lOutLen2 = lOutLen;
53+
54+
for(lIndex =1+lIndent, lIndex2 =53-15+lIndent, lRelPos =0;
55+
lOutLen2;
56+
lOutLen2--, lIndex +=2, lIndex2++
57+
)
58+
{
59+
ucTmp = *pTmp++;
60+
61+
sprintf(szBuf + lIndex,"%02X", (unsignedshort)ucTmp);
62+
if(!isprint(ucTmp)) ucTmp ='.';// nonprintable char
63+
szBuf[lIndex2] = ucTmp;
64+
65+
if (!(++lRelPos &3))// extra blank after 4 bytes
66+
{ lIndex++; szBuf[lIndex+2] =''; }
67+
}
68+
69+
if (!(lRelPos &3)) lIndex--;
70+
71+
szBuf[lIndex ] ='\t';
72+
szBuf[lIndex+1] ='\t';
73+
74+
printf("%s\n", szBuf);
75+
76+
buf.pData += lOutLen;
77+
buf.lSize -= lOutLen;
78+
}
79+
}
3280

33-
strncat(str, blob.data + blob.begin, length);
3481

35-
printf("%s\n",str);
36-
free(str);
82+
void
83+
Blob::Dump()
84+
{
85+
int length = end - begin +1 ;
86+
hexdump(data + begin, length);
3787
}
3888

3989
Blob

‎libblobstamper.h‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11

2-
2+
#include<string>
33
classBlob
44
{
55
private:
66
public:
77
Blob(char * data,int size);
88
boolisEmpty ();
9+
voidDump();
910

10-
char * data;/*FIZME потом сделать private*/
11+
char * data;/*FIXME потом сделать private*/
1112
int size;
1213
int begin;
1314
int end;
1415

1516
};
1617

17-
typedefstructwflBlobDsc
18-
{
19-
structwflMemCtx * mctx;
20-
char * data;
21-
int begin;
22-
int end;
23-
}wflBlobDsc;
24-
25-
26-
voidwflBlobDump(wflBlobDsc* blob);
27-
2818
BlobwflShiftN(Blob &blob,size_t n);
2919
std::stringwflShiftDouble(Blob &blob);
3020
std::stringwflShiftPgPoint(Blob &blob);

‎test_libblobstamper.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<string.h>
2+
3+
#include"libblobstamper.h"
4+
5+
char my_data[]="1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyzАБВГДитд.___";
6+
7+
int
8+
main(void)
9+
{
10+
Blobbl(my_data,strlen(my_data));
11+
bl.Dump();
12+
13+
14+
return0;
15+
}
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp