我的getline比你的好 [英] my getline is better than yours
问题描述
你喜欢GetLine_m吗?我今天写的功能?
你看到多少错误?
i只尝试将所有[text]文件加载到一个字符串中
不能加载一行\ n结束所以它应该充满
错误
[但因为我有len我可以使用该函数加载二进制
文件]
#define P printf
int main(int c,char ** a)
{char * s;
uns len;
int i,n;
FILE_m * f;
/ * ....打开文件* /
if(c< = 1)返回0;
f = fopen_m(a [1] ,rb;;
if(f == 0){P(Errore apertura \ n); R 0;}
len = 0; s = 0;
n = GetLine_m(& s,& len,f); //每个严格的文件
if(n == 1)P(Tutto ok ilfileè=%s \ n,s);
else if(n == 2)P(Errore di parametro\ n);
P(len =%un =%i \ n,len, n);
free_m(s); // alla fine s deve essere liberato
fclose_m(f);
返回0;
}
/ * int __stdcall GetLine_m(char ** s,uns * len,FILE * f)
/ * trash ecx,edx
/ * Assegna a" S" un indirizzo a una stringa contenente una
/ * linea di" f",(o tutto il file puntato da f se len == 0)
/ * ritorna un codice di errore e assegna(se len!= 0)ad len
/ * la lunghezza di tale stringa
/ * usare进来
/ * char * s;
/ * uns len;
/ * int i;
/ * FILE * f;
/ * ....打开文件
/ * ----------------------
/ * len = 0; s = 0;
/ * n = GetLine_m(& s,& len,f); //每个严格的文件
/ * if(n == 1)// tutto ok ilfileèinse nessun errore
/ * else if( n == 2)// errore di parametro等
/ * free(s); // alla fine s deve essere liberato
/ * ----------------------
/ * LEN = 12345678; S = 0; n = GetLine_m(& s,& len,f); ...免费;
/ * ----------------------
/ * S = 0; n = GetLine_m(& s,& len,f); ...免费;
/ * ----------------------
/ * ritorna 0 se tutto ok e EOF non raggiunto CF == 0
/ * 1 Eof raggiunto e nessun errore trovato CF == 0
/ * 2 errore parametro CF == 1
/ * 3 errore memoria CF == 1
/ * 4 errore lettura file CF == 1
/ * 5 errore file troppo grande per la memoria CF == 1
/ *
/ * 0k,4j,8i,12b,16Ra,20P_s,24P_len,28P_f
GetLine_m:
< b,i,j,k
a = ^ 20; K = ^ 28;一个== 0#.e2; k == 0#.e2;
i = 0; B = * A; J = 2; //时代j = 64
b#.1;一个= j的;一个+ = 8; _malloc_m<(a);
a == 0#.e3; B = A; A = ^ 20; * A = B; #。1;
..e2:a = 2; #.E; / errori di parametro
..e3:a = 3; #.E; / errori di memoria
..e4:a = 4; #.E; / errori di overflow indice
..e5:a = 5; / errori di lettura文件
..e:stc; ##。f /在循环下面
..1:j& i!#。2 | J + = I; jc .e4;一个= j的;一个+ = 8; jc .e4;
| _realloc_m<(b,a);
| a#.2b | R = ^ 24; ř== 0#.2a; * r = i;
.2a:| #.e3;
..2b:| B = A; a = ^ 20; * a = b;
..2:_fgetc_m<(k);一== - 1#3!| R = ^ 24; B [B + I] = 0; [R == 0#.2d | * r = i;
.2d:| D [k + 12]& 16#.e5 // ferror(k)?
| K = 1; #0.8; // EOF
..3:[b + i] = al; ++ I; jz .e4; R = ^ 24; ř== 0#0.4; d * R == 0#0.1; i> = * r#.5;
..4:al!= 10#.1; #。6;
..5:r = ^ 24; B [B + I] = 0; ř== 0#.e4; * R = I; ##。e4;
..6:r = ^ 24; B [B + I] = 0; ř== 0#0.7; * r = i;
..7:k = 0;
..8:a = i;一个+ = 4; _realloc_m<(b,a); a == 0#.e4;
b = a; A = ^ 20; * a = b;
a = k; clc;
..f:
b,i,j,k
ret 12
GetLine_m:
push ebx
push esi
push edi
push ebp
mov eax,[esp + 20]
mov ebp,[esp + 28]
cmp eax ,0
je .e2
cmp ebp,0
je .e2
mov esi,0; /时代j = 64
mov ebx,[eax]
mov edi,2
cmp ebx,0
jne .1
mov eax,edi
add eax,8
push eax
call _malloc_m >
add esp,4
cmp eax,0
je .e3
mov ebx,eax
mov eax,[esp + 20]
mov [eax],ebx
jmp short .1
..e2 :; errori di parametro
mov eax,2
jmp short .e
..e3 :; errori di memoria
mov eax,3
jmp short .e
..e4 :; errori di overflow indice
mov eax,4
jmp short .e
..e5 :; errori di lettura文件
mov eax,5
..e:
stc
jmp .f
..1:
test edi,esi
jz .2
add edi,esi
jc .e4
mov eax,edi
add eax,8
jc .e4
推eax
推ebx
打电话_realloc_m
添加esp,8
cmp eax,0
jne .2b
mov edx,[esp + 24]
cmp edx,0
je .2a
mov [edx],esi
.2a:
jmp short .e3
..2b:
mov ebx,eax
mov eax,[esp + 20]
mov [eax ],ebx
..2:
push ebp
call _fgetc_m
add esp,4
cmp eax,-1
jne .3
mov edx,[esp + 24]
mov byte [ebx + esi],0
cmp edx,0
je .2d
mov [edx],esi
。 .2d: ; / ferror(k)?
测试dword [ebp + 12],16
jnz .e5
; / EOF
mov ebp,1
jmp short .8
..3:
mov [ebx + esi] ,al
inc esi
jz .e4
mov edx,[esp + 24]
cmp edx, 0
je .4
cmp dword [edx],0
je .1
cmp esi,[ edx]
jae .5
..4:
cmp al,10
jne .1
jmp短.6
..5:
mov edx,[esp + 24]
mov byte [ebx + esi],0
cmp edx,0
je .e4
mov [edx],esi
jmp .e4
..6:
mov edx,[esp + 24]
mov byte [ebx + esi],0
cmp edx,0
je .7
mov [edx],esi
..7:
mov ebp,0
..8:
mov eax,esi
add eax,4
push eax
push ebx
来电_realloc_m
加esp,8
cmp eax,0
je .e4
mov ebx,eax
mov eax,[esp + 20]
mov [eax],ebx
mov eax,ebp
clc
..f:
pop ebp
pop edi
pop esi
pop ebx
ret 12
罗萨里奥写于11/12/07 16:04,:
你喜欢GetLine_m吗?我今天写的功能?
你看到多少错误?
Rosario写道:
< blockquote class =post_quotes>
你喜欢GetLine_m吗?我今天写的功能?
你看到多少错误?
i只尝试将所有[text]文件加载到一个字符串中
不能加载一行\ n结束所以它应该充满
错误
[但因为我有len我可以使用该函数加载二进制
文件]
#define P printf
^^^^^^^^^^^^^^^^
哦,狗屎,他回来了。
>
int main(int c,char ** a)
{ char * s;
uns len;
^^^
undefined type
int i,n;
FILE_m * f;
^^^^^^
未定义类型
[未缩进C-的剩余部分喜欢但不是很C的代码和大量的
没有类似C代码剪断了]
Rosario < Ro ***** @ not.existwrote in message
news:lt ************************* ******* @ 4ax.com ...
你喜欢GetLine_m吗?我今天写的功能?
你看到多少错误?
i只尝试将所有[text]文件加载到一个字符串中
不能加载一行\ n结束所以它应该充满
错误
[但因为我有len我可以加载该函数二进制
文件]
跟进此帖子设置为ala
>
#define P printf
int main(int c,char ** a)
{char * s;
uns len;
int i,n;
FILE_m * f;
/ * ....打开文件* /
如果(c <= 1)返回0;
f = fopen_m(a [1],rb ;);
if(f == 0){P(Errore apertura \ n); R 0;}
len = 0; s = 0;
n = GetLine_m(& s,& len,f); //每个严格的文件
if(n == 1)P(Tutto ok ilfileè=%s \ n,s);
else if(n == 2)P(Errore di parametro\ n);
P(len =%un =%i \ n,len, n);
free_m(s); // alla fine s deve essere liberato
fclose_m(f);
返回0;
}
我不喜欢你的C编码风格。
#define P printf
int main(int c,char ** a)
{
char * s;
uns len;
int i, n;
FILE_m * f;
/ * ....打开文件* /
if(c< = 1)
return(0);
f = fopen_m(a [1]," rb");
if(f == 0)
{
P(Errore apertura \ n);
R(0);
}
len = 0;
s = 0;
n = GetLine_m(& s,& len,f); //每个文件中的每个文件
if(n == 1)
{
P(&tutto ok ilfileè =%s \ n",s);
}
else
{
if(n = = 2)
P(Errore di parametro \ n);
}
P(" len =%un = %i \ n",len,n);
free_m(s); // alla fine s deve essere liberato
fclose_m(f);
返回(0);
}
>
显然,有很多缺失,例如:
#define R return
#define uns unsigned int
#define FILE_m ?????
#define fopen_m ?????
#define GetLine_m ?????
#定义free_m ?????
#define fclose_m ?????
各种包括
如果有人认为_m函数是自定义的还是刚重新定义的ANSI C
函数?
我宁愿看主要定义为:
int main(int argc,char ** argv)
所以,我知道什么是[1]而不必追踪
a是的位置定义。
s是一个指向char的指针,但你没有在C源代码中分配空间。
基于a + = 8; _malloc_m≤(一);"在下面的神秘代码部分,我怀疑你可能已经为s分配了空间。
。但是,在可能被分配的唯一位置之前,你仍然将s设置为零,
而不是NULL。
我的个人偏好是查看参数如此写,return(0);,
notreturn 0;
/ * int __stdcall GetLine_m(char ** s,uns * len,FILE * f)
/ * trash ecx,edx
/ * Assegna a" s" un indirizzo a una stringa contenente una
/ * linea di" f",(o tutto il file puntato da f se len == 0)
/ * ritorna un codice di errore e assegna(se len!= 0)ad len
/ * la lunghezza di tale stringa
/ * usare进来
/ * char * s;
/ * uns len;
/ * int i;
/ * FILE * f;
/ * ....打开文件
/ * ----------------------
/ * len = 0; s = 0;
/ * n = GetLine_m(& s,& len,f); //每个严格的文件
/ * if(n == 1)// tutto ok ilfileèinse nessun errore
/ * else if( n == 2)// errore di parametro等
/ * free(s); // alla fine s deve essere liberato
/ * ----------------------
/ * LEN = 12345678; S = 0; n = GetLine_m(& s,& len,f); ...免费;
/ * ----------------------
/ * S = 0; n = GetLine_m(& s,& len,f); ...免费;
/ * ----------------------
/ * ritorna 0 se tutto ok e EOF non raggiunto CF == 0
/ * 1 Eof raggiunto e nessun errore trovato CF == 0
/ * 2 errore parametro CF == 1
/ * 3 errore memoria CF == 1
/ * 4 errore lettura file CF == 1
/ * 5 errore file troppo grande per la memoria CF == 1
/ *
/ * 0k,4j,8i,12b,16Ra,20P_s,24P_len,28P_f
GetLine_m:
< b,i,j,k
a = ^ 20; K = ^ 28;一个== 0#.e2; k == 0#.e2;
i = 0; B = * A; J = 2; //时代j = 64
b#.1;一个= j的;一个+ = 8; _malloc_m<(a);
a == 0#.e3; B = A; A = ^ 20; * A = B; #。1;
.e2:a = 2; #.E; / errori di parametro
.e3:a = 3; #.E; / errori di memoria
.e4:a = 4; #.E; / errori di overflow indice
.e5:a = 5; / errori di lettura文件
.e:stc; ##。f /在循环下面
.1:j& i!#。2 | J + = I; jc .e4;一个= j的;一个+ = 8; jc .e4;
| _realloc_m<(b,a);
| a#.2b | R = ^ 24; ř== 0#.2a; * r = i;
.2a:| #.e3;
.2b:| B = A; a = ^ 20; * a = b;
.2:_fgetc_m<(k);一== - 1#3!| R = ^ 24; B [B + I] = 0; [R == 0#.2d | * r = i;
.2d:| D [k + 12]& 16#.e5 // ferror(k)?
| K = 1; #0.8; // EOF
.3:[b + i] = al; ++ I; jz .e4; R = ^ 24; ř== 0#0.4; d * R == 0#0.1; i> = * r#.5;
.4:al!= 10#.1; #。6;
.5:r = ^ 24; B [B + I] = 0; ř== 0#.e4; * R = I; ##。e4;
.6:r = ^ 24; B [B + I] = 0; ř== 0#0.7; * r = i;
.7:k = 0;
.8:a = i;一个+ = 4; _realloc_m<(b,a); a == 0#.e4;
b = a; A = ^ 20; * a = b;
a = k; clc;
.f:
b,i,j,k
ret 12
我不明白这个神秘的代码部分。你得到了程序集clc,
程序集标签.4,C运算符a + = 8,C-ish stuff_fgetc_m<(k),
评论带有单个和双正斜杠,还有一堆垃圾
带#和##。关于唯一可以全部工作的现有语言
一起是FORTH或者广泛的C预处理器滥用...
GetLine_m :
push ebx
push esi
push edi
push ebp
mov eax,[esp + 20]
mov ebp,[esp + 28]
cmp eax,0
je .e2
cmp ebp,0
je .e2
mov esi,0; / era j = 64
mov ebx,[eax ]
mov edi,2
cmp ebx,0
jne .1
mov eax,edi
添加eax,8
推eax
调用_malloc_m
添加esp,4
cmp eax,0
je .e3
mov ebx,eax
mov eax,[esp + 20]
mov [eax],ebx
jmp short .1
.e2 :; errori di parametro
mov eax,2
jmp short .e
.e3 :; errori di memoria
mov eax,3
jmp short .e
.e4 :; errori di overflow indice
mov eax,4
jmp short .e
.e5 :; errori di lettura文件
mov eax,5
.e:
stc
jmp .f
.1:
test edi,esi
jz .2
add edi,esi
jc .e4
mov eax,edi
add eax,8
jc .e4
推eax
推ebx
打电话_realloc_m
添加esp,8
cmp eax, 0
jne .2b
mov edx,[esp + 24]
cmp edx,0
je。 2a
mov [edx],esi
.2a:
jmp short .e3
.2b:
mov ebx,eax
mov eax,[esp + 20]
mov [eax],ebx
.2:
推ebp
调用_fgetc_m
添加esp,4
cmp eax,-1
jne .3
mov edx,[esp + 24]
mov byte [ebx + esi],0
cmp edx,0
je .2d
mov [edx],esi
.2d:; / ferror(k)?
测试dword [ebp + 12],16
jnz .e5
; / EOF
mov ebp,1
jmp short .8
.3:
mov [ebx + esi],al
inc esi
jz .e4
mov edx,[esp + 24]
cmp edx,0
je .4
cmp dword [edx],0
je .1
cmp esi,[edx]
jae .5
.4:
cmp al,10
jne .1
jmp short .6
.5:
mov edx,[esp + 24]
mov byte [ebx + esi],0
cmp edx,0
je .e4
mov [edx],esi
jmp .e4
.6:
mov edx,[esp + 24]
mov byte [ebx + esi], 0
cmp edx,0
je .7
mov [edx],esi
.7:
mov ebp,0
.8:
mov eax,esi
add eax,4
push eax
push ebx
调用_realloc_m
添加esp,8
cmp eax,0
je .e4
mov ebx,eax
mov eax,[esp + 20]
mov [eax],ebx
mov eax,ebp
clc
.f:
pop ebp
pop edi >
pop esi
pop ebx
ret 12
这个我理解作为x86程序集。它可能实际上是用FASM编译的。
你喜欢GetLine_m吗?我今天写的功能?
1)C代码:没有。
2)神秘的伪FORTH-FASM-C-mixup:不。
3)x86汇编:是的。
为什么你发布没有人可以使用的代码?既不是a.l.a.或c.l.c.很可能
使用这个......
Rod Pemberton
do you like the "GetLine_m" function i have written today?
How many errors do you see?
i have try only the option for to load the all [text] file in a string
not the option to load a line "\n" ended so it should be full of
errors
[but because i have the "len" i can load with that function the binary
files too]
#define P printf
int main(int c, char** a)
{ char *s;
uns len;
int i, n;
FILE_m *f;
/* ....open file */
if(c<=1) return 0;
f=fopen_m( a[1], "rb");
if(f==0) {P("Errore apertura\n"); R 0;}
len=0; s=0;
n=GetLine_m(&s, &len, f); // per avere in s tutto il file
if(n==1) P("Tutto ok il file è = %s\n", s);
else if(n==2) P("Errore di parametro\n");
P("len=%u n=%i\n ", len, n);
free_m(s); // alla fine s deve essere liberato
fclose_m(f);
return 0;
}
/* int __stdcall GetLine_m( char** s, uns* len, FILE* f)
/* trash ecx, edx
/* Assegna a "s" un indirizzo a una stringa contenente una
/* linea di "f", (o tutto il file puntato da f se len==0)
/* ritorna un codice di errore e assegna (se len!=0) ad len
/* la lunghezza di tale stringa
/* usare come in
/* char *s;
/* uns len;
/* int i;
/* FILE *f;
/* ....open file
/* ----------------------
/* len=0; s=0;
/* n=GetLine_m(&s, &len, f); // per avere in s tutto il file
/* if(n==1) // tutto ok il file è in s e nessun errore
/* else if(n==2) // errore di parametro etc
/* free(s); // alla fine s deve essere liberato
/* ----------------------
/* len=12345678; s=0; n=GetLine_m(&s, &len, f); ... free(s);
/* ----------------------
/* s=0; n=GetLine_m(&s, &len, f); ... free(s);
/* ----------------------
/* ritorna 0 se tutto ok e EOF non raggiunto CF==0
/* 1 Eof raggiunto e nessun errore trovato CF==0
/* 2 errore parametro CF==1
/* 3 errore memoria CF==1
/* 4 errore lettura file CF==1
/* 5 errore file troppo grande per la memoria CF==1
/*
/* 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_f
GetLine_m:
< b, i, j, k
a=^20; k=^28; a==0#.e2; k==0#.e2;
i=0; b=*a; j=2; // era j=64
b#.1; a=j; a+=8; _malloc_m<(a);
a==0#.e3; b=a; a=^20; *a=b; #.1;
..e2: a=2; #.e; / errori di parametro
..e3: a=3; #.e; / errori di memoria
..e4: a=4; #.e; / errori di overflow indice
..e5: a=5; / errori di lettura file
..e: stc; ##.f / below the loop
..1: j&i!#.2 | j+=i; jc .e4; a=j; a+=8; jc .e4;
| _realloc_m<(b, a);
| a#.2b | r=^24; r==0#.2a; *r=i;
..2a: | #.e3;
..2b: | b=a; a= ^20; *a=b;
..2: _fgetc_m<(k); a==-1!#.3| r=^24; B[b+i]=0; r==0#.2d| *r=i;
..2d: | D [k+12]& 16 #.e5 // ferror(k)?
| k=1; #.8; // EOF
..3: [b+i]=al; ++i; jz .e4; r=^24; r==0#.4; D*r==0#.1; i>=*r#.5;
..4: al!=10#.1; #.6;
..5: r=^24; B[b+i]=0; r==0#.e4; *r=i; ##.e4;
..6: r=^24; B[b+i]=0; r==0#.7; *r=i;
..7: k=0;
..8: a=i; a+=4; _realloc_m<(b, a); a==0#.e4;
b=a; a=^20; *a=b;
a=k; clc;
..f:
b, i, j, k
ret 12
GetLine_m:
push ebx
push esi
push edi
push ebp
mov eax, [ esp + 20 ]
mov ebp, [ esp + 28 ]
cmp eax, 0
je .e2
cmp ebp, 0
je .e2
mov esi, 0 ;/ era j=64
mov ebx, [eax]
mov edi, 2
cmp ebx, 0
jne .1
mov eax, edi
add eax, 8
push eax
call _malloc_m
add esp, 4
cmp eax, 0
je .e3
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
jmp short .1
..e2: ; errori di parametro
mov eax, 2
jmp short .e
..e3: ; errori di memoria
mov eax, 3
jmp short .e
..e4: ; errori di overflow indice
mov eax, 4
jmp short .e
..e5: ; errori di lettura file
mov eax, 5
..e:
stc
jmp .f
..1:
test edi, esi
jz .2
add edi, esi
jc .e4
mov eax, edi
add eax, 8
jc .e4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
jne .2b
mov edx, [ esp + 24 ]
cmp edx, 0
je .2a
mov [edx], esi
..2a:
jmp short .e3
..2b:
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..2:
push ebp
call _fgetc_m
add esp, 4
cmp eax, -1
jne .3
mov edx, [ esp + 24 ]
mov byte[ebx+esi], 0
cmp edx, 0
je .2d
mov [edx], esi
..2d: ;/ ferror(k)?
test dword [ebp+12], 16
jnz .e5
;/ EOF
mov ebp, 1
jmp short .8
..3:
mov [ebx+esi], al
inc esi
jz .e4
mov edx, [ esp + 24 ]
cmp edx, 0
je .4
cmp dword[edx], 0
je .1
cmp esi, [edx]
jae .5
..4:
cmp al, 10
jne .1
jmp short .6
..5:
mov edx, [ esp + 24 ]
mov byte[ebx+esi], 0
cmp edx, 0
je .e4
mov [edx], esi
jmp .e4
..6:
mov edx, [ esp + 24 ]
mov byte[ebx+esi], 0
cmp edx, 0
je .7
mov [edx], esi
..7:
mov ebp, 0
..8:
mov eax, esi
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e4
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
mov eax, ebp
clc
..f:
pop ebp
pop edi
pop esi
pop ebx
ret 12
Rosario wrote On 11/12/07 16:04,:do you like the "GetLine_m" function i have written today?
How many errors do you see?Nine.
--
Er*********@sun.com
Rosario wrote:do you like the "GetLine_m" function i have written today?
How many errors do you see?
i have try only the option for to load the all [text] file in a string
not the option to load a line "\n" ended so it should be full of
errors
[but because i have the "len" i can load with that function the binary
files too]
#define P printf^^^^^^^^^^^^^^^^
Oh shit, he''s back.>
int main(int c, char** a)
{ char *s;
uns len;^^^
undefined typeint i, n;
FILE_m *f;^^^^^^
undefined type
[remaineder of unindented C-like-but-not-quite-C code and large amounts
of nothing-like-C code snipped]
"Rosario" <Ro*****@not.existwrote in message
news:lt********************************@4ax.com...do you like the "GetLine_m" function i have written today?
How many errors do you see?
i have try only the option for to load the all [text] file in a string
not the option to load a line "\n" ended so it should be full of
errors
[but because i have the "len" i can load with that function the binary
files too]
Follow ups to this post set to a.l.a.
>
#define P printf
int main(int c, char** a)
{ char *s;
uns len;
int i, n;
FILE_m *f;
/* ....open file */
if(c<=1) return 0;
f=fopen_m( a[1], "rb");
if(f==0) {P("Errore apertura\n"); R 0;}
len=0; s=0;
n=GetLine_m(&s, &len, f); // per avere in s tutto il file
if(n==1) P("Tutto ok il file è = %s\n", s);
else if(n==2) P("Errore di parametro\n");
P("len=%u n=%i\n ", len, n);
free_m(s); // alla fine s deve essere liberato
fclose_m(f);
return 0;
}
I don''t like your C coding style.
#define P printf
int main(int c,char **a)
{
char *s;
uns len;
int i, n;
FILE_m *f;
/* ....open file */
if(c<=1)
return(0);
f=fopen_m(a[1],"rb");
if(f==0)
{
P("Errore apertura\n");
R(0);
}
len=0;
s=0;
n=GetLine_m(&s,&len,f); // per avere in s tutto il file
if(n==1)
{
P("Tutto ok il file è = %s\n",s);
}
else
{
if(n==2)
P("Errore di parametro\n");
}
P("len=%u n=%i\n ",len,n);
free_m(s); // alla fine s deve essere liberato
fclose_m(f);
return(0);
}
Obviously, there is much missing, like:
#define R return
#define uns unsigned int
#define FILE_m ?????
#define fopen_m ?????
#define GetLine_m ?????
#define free_m ?????
#define fclose_m ?????
various includes
Should one assume that the _m functions are custom or just redefined ANSI C
functions?
I''d rather see main defined as:
int main(int argc,char **argv)
So, that I know what a[1] is without having to track down the location where
a is defined.
s is a pointer to char, but you didn''t allocate space in the C source.
Based on "a+=8; _malloc_m<(a);" in the cryptic code section below, I suspect
that you may have allocated space for s. However, you still set s to zero,
instead of NULL, before the only place where it might be allocated.
My personal preference is to see arguments written as such, "return(0);",
not "return 0;".
/* int __stdcall GetLine_m( char** s, uns* len, FILE* f)
/* trash ecx, edx
/* Assegna a "s" un indirizzo a una stringa contenente una
/* linea di "f", (o tutto il file puntato da f se len==0)
/* ritorna un codice di errore e assegna (se len!=0) ad len
/* la lunghezza di tale stringa
/* usare come in
/* char *s;
/* uns len;
/* int i;
/* FILE *f;
/* ....open file
/* ----------------------
/* len=0; s=0;
/* n=GetLine_m(&s, &len, f); // per avere in s tutto il file
/* if(n==1) // tutto ok il file è in s e nessun errore
/* else if(n==2) // errore di parametro etc
/* free(s); // alla fine s deve essere liberato
/* ----------------------
/* len=12345678; s=0; n=GetLine_m(&s, &len, f); ... free(s);
/* ----------------------
/* s=0; n=GetLine_m(&s, &len, f); ... free(s);
/* ----------------------
/* ritorna 0 se tutto ok e EOF non raggiunto CF==0
/* 1 Eof raggiunto e nessun errore trovato CF==0
/* 2 errore parametro CF==1
/* 3 errore memoria CF==1
/* 4 errore lettura file CF==1
/* 5 errore file troppo grande per la memoria CF==1
/*
/* 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_f
GetLine_m:
< b, i, j, k
a=^20; k=^28; a==0#.e2; k==0#.e2;
i=0; b=*a; j=2; // era j=64
b#.1; a=j; a+=8; _malloc_m<(a);
a==0#.e3; b=a; a=^20; *a=b; #.1;
.e2: a=2; #.e; / errori di parametro
.e3: a=3; #.e; / errori di memoria
.e4: a=4; #.e; / errori di overflow indice
.e5: a=5; / errori di lettura file
.e: stc; ##.f / below the loop
.1: j&i!#.2 | j+=i; jc .e4; a=j; a+=8; jc .e4;
| _realloc_m<(b, a);
| a#.2b | r=^24; r==0#.2a; *r=i;
.2a: | #.e3;
.2b: | b=a; a= ^20; *a=b;
.2: _fgetc_m<(k); a==-1!#.3| r=^24; B[b+i]=0; r==0#.2d| *r=i;
.2d: | D [k+12]& 16 #.e5 // ferror(k)?
| k=1; #.8; // EOF
.3: [b+i]=al; ++i; jz .e4; r=^24; r==0#.4; D*r==0#.1; i>=*r#.5;
.4: al!=10#.1; #.6;
.5: r=^24; B[b+i]=0; r==0#.e4; *r=i; ##.e4;
.6: r=^24; B[b+i]=0; r==0#.7; *r=i;
.7: k=0;
.8: a=i; a+=4; _realloc_m<(b, a); a==0#.e4;
b=a; a=^20; *a=b;
a=k; clc;
.f:b, i, j, kret 12
I don''t understand this cryptic code section. You got assembly "clc",
assembly labels ".4", C operators "a+=8", C-ish stuff "_fgetc_m<(k)",
comments with both a single and double forward slash, and a bunch of junk
with # and ##. About the only existing language that could that all to work
together is FORTH or perhaps extensive C pre-processor abuse...
GetLine_m:
push ebx
push esi
push edi
push ebp
mov eax, [ esp + 20 ]
mov ebp, [ esp + 28 ]
cmp eax, 0
je .e2
cmp ebp, 0
je .e2
mov esi, 0 ;/ era j=64
mov ebx, [eax]
mov edi, 2
cmp ebx, 0
jne .1
mov eax, edi
add eax, 8
push eax
call _malloc_m
add esp, 4
cmp eax, 0
je .e3
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
jmp short .1
.e2: ; errori di parametro
mov eax, 2
jmp short .e
.e3: ; errori di memoria
mov eax, 3
jmp short .e
.e4: ; errori di overflow indice
mov eax, 4
jmp short .e
.e5: ; errori di lettura file
mov eax, 5
.e:
stc
jmp .f
.1:
test edi, esi
jz .2
add edi, esi
jc .e4
mov eax, edi
add eax, 8
jc .e4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
jne .2b
mov edx, [ esp + 24 ]
cmp edx, 0
je .2a
mov [edx], esi
.2a:
jmp short .e3
.2b:
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
.2:
push ebp
call _fgetc_m
add esp, 4
cmp eax, -1
jne .3
mov edx, [ esp + 24 ]
mov byte[ebx+esi], 0
cmp edx, 0
je .2d
mov [edx], esi
.2d: ;/ ferror(k)?
test dword [ebp+12], 16
jnz .e5
;/ EOF
mov ebp, 1
jmp short .8
.3:
mov [ebx+esi], al
inc esi
jz .e4
mov edx, [ esp + 24 ]
cmp edx, 0
je .4
cmp dword[edx], 0
je .1
cmp esi, [edx]
jae .5
.4:
cmp al, 10
jne .1
jmp short .6
.5:
mov edx, [ esp + 24 ]
mov byte[ebx+esi], 0
cmp edx, 0
je .e4
mov [edx], esi
jmp .e4
.6:
mov edx, [ esp + 24 ]
mov byte[ebx+esi], 0
cmp edx, 0
je .7
mov [edx], esi
.7:
mov ebp, 0
.8:
mov eax, esi
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e4
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
mov eax, ebp
clc
.f:
pop ebp
pop edi
pop esi
pop ebx
ret 12
This I understand as x86 assembly. It might actually compile with FASM.
do you like the "GetLine_m" function i have written today?1) C code: No.
2) cryptic pseudo-FORTH-FASM-C-mixup: No.
3) x86 assembly: Yes.
Why do you post code nobody can use? Neither a.l.a. or c.l.c. is likely to
use this ever...
Rod Pemberton
这篇关于我的getline比你的好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!