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

Commit987cf19

Browse files
The very begining
1 parentf66a1c6 commit987cf19

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

‎Makefile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#DEPS = function.h
2+
#LIB_OBJS = function.o
3+
4+
# https://stackoverflow.com/questions/18007326/how-to-change-default-values-of-variables-like-cc-in-makefile
5+
ifeq ($(originCC),default)
6+
CC = gcc
7+
endif
8+
9+
.PHONY: all
10+
all: test
11+
@echo All done!
12+
13+
14+
test:$(LIB_OBJS) test.o
15+
$(CC)$(LDFLAGS)$^ -o$@$(LDLIBS)
16+
17+
%.o:%.cpp$(DEPS)
18+
$(CC)$(CFLAGS)$<
19+
20+
.PHONY: clean
21+
clean:
22+
rm -f*.otest
23+
@echo Clean done!

‎test.c‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include<string.h>
2+
#include<stdio.h>
3+
#include<stdlib.h>
4+
5+
6+
7+
typedefstructwflMemCtx
8+
{
9+
//Nothing for now;
10+
}wflMemCtx ;
11+
12+
13+
wflMemCtxstatic_ctx;
14+
15+
wflMemCtx*
16+
wflCreateMemCtx()
17+
{
18+
return&static_ctx;
19+
}
20+
21+
22+
void
23+
wflDestroyMemCtx(wflMemCtx*mctx)
24+
{
25+
}
26+
27+
typedefstructwflBlobDsc
28+
{
29+
structwflMemCtx*mctx;
30+
char*data;
31+
intbegin;
32+
intend;
33+
}wflBlobDsc;
34+
35+
36+
void
37+
wflBlobDump(wflBlobDsc*blob)
38+
{
39+
intlength=blob->end-blob->begin+1 ;
40+
char*str=malloc(length+1 );// second +1 is for \0
41+
// FIXME проверка null
42+
str[0]='\0';
43+
44+
45+
46+
strncat(str,blob->data+blob->begin,length);// second +1 is for \0
47+
48+
printf("%s\n",str);
49+
free(str);
50+
}
51+
52+
void*
53+
wflMalloc(size_tsize )
54+
{
55+
/*just that simple for now*/
56+
returnmalloc(size );
57+
}
58+
59+
60+
wflBlobDsc*
61+
wflShiftN(wflBlobDsc*blob,size_tn)
62+
{
63+
wflBlobDsc*new_blob;
64+
// FIXME null check here;
65+
if (blob->begin+n>blob->end)
66+
returnNULL;/*not enough data*/
67+
68+
new_blob=wflMalloc(sizeof(wflBlobDsc));
69+
70+
new_blob->data=blob->data;
71+
new_blob->begin=blob->begin;
72+
new_blob->end=blob->begin+n-1;
73+
74+
blob->begin+=n;
75+
76+
returnnew_blob;
77+
}
78+
79+
80+
81+
charblob_data[]="aaalkjdhfs89345yu3ifhjew;lkhf4;lt;o34ithp;eriuwtgp;etup568p34tuewritwe;rtgj;ewoty;4w85tyeihwritgzzz";
82+
83+
intmain()
84+
{
85+
wflMemCtx*mctx;
86+
wflBlobDscblob;
87+
wflBlobDsc*b2;
88+
89+
mctx=wflCreateMemCtx();
90+
91+
blob.mctx=mctx;
92+
blob.data=blob_data;
93+
blob.begin=0;
94+
blob.end=strlen(blob_data)-1;
95+
96+
97+
98+
wflBlobDump(&blob);
99+
printf("-----\n");
100+
b2=wflShiftN(&blob,9993);
101+
102+
103+
wflBlobDump(&blob);
104+
wflBlobDump(b2);
105+
106+
wflDestroyMemCtx(mctx);
107+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp