473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

my getline is better than yours

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
Nov 12 '07 #1
13 1980
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
Nov 12 '07 #2
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 type
int 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]
Nov 12 '07 #3

"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, k
ret 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

Nov 13 '07 #4
In data Mon, 12 Nov 2007 22:04:02 +0100, Rosario scrisse:
>#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
an error: here should be something like:

..8: a=i; a+=4; _realloc_m<(b, a); a==0#.9;
b=a; a=^20; *a=b;
..9: a=k; clc;
..f:
b, i, j, k
ret 12

Nov 13 '07 #5
In data Mon, 12 Nov 2007 20:04:07 -0500, Rod Pemberton scrisse:
>"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 ?????
#define FILE_m FILE
#define fopen_m fopen
#define free_m free
#define fclose_m fclose

int __stdcall GetLine_m( char** s, uns* len, FILE_m* f);
various includes

Should one assume that the _m functions are custom or just redefined ANSI C
functions?
yes they would be an implementation of C standard 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.
all variables and arguments are in the start of routine: so all we
know where we can find them
>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.
there is some different if i write "s=NULL;" or "s=0;"?
in GetLine_m(&s, &len, f) the first time "s" has to be "0"
(or has to point memory returned from malloc)
>My personal preference is to see arguments written as such, "return(0);",
not "return 0;".
this can be good
>/* 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

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.
so you can understand well the assembly paths of that routine?
(i read the code thru the "2"nd point above)
you are very good in assembly programming if yes (i can't read easily
the assembly version)
>Why do you post code nobody can use? Neither a.l.a. or c.l.c. is likely to
use this ever...
1) because i think it is a good thing to see what a cpu does
2) and because i think 'my' language is better
than your assembly and C
3) Because this show that all theories that say goto and jumps are
not for structured programming are all wrong
>Rod Pemberton
Nov 13 '07 #6
Rosario wrote:
there is some different if i write "s=NULL;" or "s=0;"?
cf. http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=null

In pointer contexts, NULL and 0 are equivalent.
Nov 13 '07 #7
Rosario wrote:
3) Because this show that all theories that say goto and jumps are
not for structured programming are all wrong
That clears that one up then. I'm glad you came along.

(sarcasm-o-meter asplodes)

Incedentally, I have read a paper by Knuth called, I think, "Structured
programming with gotos" which was interesting reading; he gave examples
of constructs which are more efficiently implemented using gotos than
"traditional" structured constructs. This was in the mid-70s, though,
and I don't think such efficiency savings are worthwhile today given how
few programmers are at all familiar with gotos.

--
Philip Potter pgp <atdoc.ic.ac.uk
Nov 13 '07 #8
Philip Potter wrote:
Rosario wrote:
>3) Because this show that all theories that say goto and jumps are
not for structured programming are all wrong

That clears that one up then. I'm glad you came along.

(sarcasm-o-meter asplodes)

Incedentally, I have read a paper by Knuth called, I think, "Structured
programming with gotos" which was interesting reading; he gave examples
of constructs which are more efficiently implemented using gotos than
"traditional" structured constructs. This was in the mid-70s, though,
and I don't think such efficiency savings are worthwhile today given how
few programmers are at all familiar with gotos.
The official style of the Linux kernel encourages the judicious use of
gotos for a programming construct sometimes known as a posit/admit
structure. Languages which have explicit support for it often implement
it with a construct called try/catch, but there is no such construct in C.

-hpa
Nov 13 '07 #9
In data Tue, 13 Nov 2007 07:28:10 +0100, Rosario scrisse:

this is my last version but i have not debug well it...
(today i were out all the day)

/* 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_f
GetLine_m:
< b, i, j, k
a=^20; k=^28; i=0; a==0#.e2; k==0#.e2;
b=*a; j=4; / era j=64
a=^24; D*a==0#.0; D*a==1#.e2; --D*a; / 0..(len-1),
..0: b#.1; a=j; a+=4; _malloc_m<(a);
/ thre are problems if i change one arg?
a==0#.e0; b=a; a=^20; *a=b; #.1;
..e0: a=3; stc; ##.c;
/ errori iniziale di memoria [non settati "s" e "len"]
..e2: a=2; stc; ##.c;
/ errori di parametro [non settati "s" e "len"]
..e3: k=3; ##.8; / errori di memoria
..e4: k=4; ##.8; / errori di overflow indice
..e5: k=5; ##.8; / errori di lettura file
..1: j&i!#.2 | j+=i; jc .e4; a=j; a+=4; jc .e4;
| _realloc_m<(b, a); a==0#.e3;
| b=a; a= ^20; *a=b;
..2: _fgetc_m<(k); a==-1!#.3| D [k+12]& 16 #.e5 // ferror(k)? (ext)
| k=1; #.8; // EOF (ext)
..3: i==-1#.e4; [b+i]=al; r=^24; ++i;
r==0#.4; D*r==0#.1; i>=*r#.e4; // ceck if i>max_index
..4: al!=10#.1;
..7: k=0; / here "\n" is found
..8: a=i; a+=4; _realloc_m<(b, a); a==0#.9;
b=a; a=^20; *a=b;
..9: a=k;
B[b+i]=0; r=^24; r==0#.a; *r=i; // save len
..a: a<=1#.b| stc; #.c; / error
..b: | clc; / ok
..c:
b, i, j, k
ret 12

; 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 errori di overflow indice CF==1
; 5 errori di lettura file CF==1
;
; 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_f
GetLine_m:
push ebx
push esi
push edi
push ebp
mov eax, [ esp + 20 ]
mov ebp, [ esp + 28 ]
mov esi, 0
cmp eax, 0
je .e2
cmp ebp, 0
je .e2
mov ebx, [eax] ; era j=64
mov edi, 4
mov eax, [ esp + 24 ] ; 0..(len-1),
cmp dword[eax], 0
je .0
cmp dword[eax], 1
je .e2
dec dword[eax]
..0: ; thre are problems if i change one arg?
cmp ebx, 0
jne .1
mov eax, edi
add eax, 4
push eax
call _malloc_m
add esp, 4
cmp eax, 0
je .e0
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
jmp short .1
..e0: ; errori iniziale di memoria [non settati "s" e "len"]
mov eax, 3
stc
jmp .c
..e2: ; errori di parametro [non settati "s" e "len"]
mov eax, 2
stc
jmp .c
..e3: ; errori di memoria
mov ebp, 3
jmp .8
..e4: ; errori di overflow indice
mov ebp, 4
jmp .8
..e5: ; errori di lettura file
mov ebp, 5
jmp .8
..1:
test edi, esi
jz .2
add edi, esi
jc .e4
mov eax, edi
add eax, 4
jc .e4

push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e3

mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..2: ;/ ferror(k)? (ext)
push ebp
call _fgetc_m
add esp, 4
cmp eax, -1
jne .3
test dword [ebp+12], 16
jnz .e5
;/ EOF (ext)
mov ebp, 1
jmp short .8
..3:
cmp esi, -1
je .e4
mov [ebx+esi], al
mov edx, [ esp + 24 ]
inc esi
cmp edx, 0
je .4 ;/ ceck if i>max_index
cmp dword[edx], 0
je .1
cmp esi, [edx]
jae .e4
..4:
cmp al, 10
jne .1
..7: ; here "\n" is found
mov ebp, 0
..8:
mov eax, esi
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .9
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..9:
mov eax, ebp
mov byte[ebx+esi], 0
mov edx, [ esp + 24 ]
cmp edx, 0
je .a
mov [edx], esi
..a: ; error
cmp eax, 1
jbe .b
stc
jmp short .c
..b: ; ok

clc
..c:
pop ebp
pop edi
pop esi
pop ebx
ret 12
Nov 13 '07 #10

"Rosario" <Ro*****@not.existwrote in message
news:g7********************************@4ax.com...
3) Because this show that all theories that say goto and jumps are
not for structured programming are all wrong
Structured programming techniques can be applied to unstructured languages
such as Basic or assembly. That's what you've done. This isn't new. It's
many decades old.

Some languages, assembly or BASIC, only have unstructured programming flow
control like goto and jump. This doesn't mean that the gotos and jumps are
the _cause_ of the problem or can't be used in a structured manner. They
were the _effect_ of the language design and programmer choice. The purpose
of structured programming was to _force_ programmers to use structured
methods via language design instead of allowing them to _choose_
unstructured methods.

The use of unstructured programming techniques, where allowed, frequently
results in coding errors. One of the main problems was multiple entry and
exit points to code blocks or loops. This was the plague of line oriented
BASIC. It was difficult to reorganize code once it was on a specific line
or set of lines. So, the solution was to goto somewhere else and goto back
later. But, as the a number of these jump out, jump back patches were
applied, the code became unreadable and unmaintainable, i.e., "spaghetti"
code. And, as a result, difficult to locate and correct programming errors,
such as part of the loop or block not being executed, would arise.

C allows unstructured coding using a) goto's, b) the unstructured form of
the switch statement, c) multiple exit points via returns from procedures or
functions, and d) coroutines (multiple entry points) (See Duff's Device or
Simon Tatham's coroutines) e) multiple exit points from loops using break,
etc., but is usually considered to be a structured programming language like
Pascal because it has many semi-structured forms of control flow that can be
used as structured forms. Those who use multiple returns from procedures or
functions or use goto's to setup error routines within a procedure usually
haven't learned a programming technique called "fall through." The code
falls through to the next section or the programmer sets a flag to skip some
code before falling into another section or return. With structured
programming techniques, one never has to use a goto but may do so for
clarity, speed, size reduction etc. Multiple entry and exit points aren't
needed in new code, but can be very useful when patching two or more pieces
of existing code together.

Unfortunately, structured programming languages have problems too. One of
the most notable is the "cut 'n' paste" problem. It is much easier in a
structured programming language to copy a small section of code than write a
procedure to reuse it. Therefore, the code becomes bloated with large
amounts of small pieces of repeated code like identical if statements. This
tends to affect larger applications.
Rod Pemberton

Nov 13 '07 #11
In data Tue, 13 Nov 2007 18:43:52 +0100, Rosario scrisse:
>In data Tue, 13 Nov 2007 07:28:10 +0100, Rosario scrisse:

this is my last version but i have not debug well it...
(today i were out all the day)
you have to change only the name realloc_m -realloc,
fgetc_m -fgetc,
D [k+12]& 16 #.e5 ->
"push ebp; call _ferror; pop edx; cmp eax, 0; jnz .e5"
How many errors do you see?
but it will be full of errors :)

/* int __stdcall
/* GetLine_m( char** s, uns* len, uns max_len, FILE* f)
/* trash ecx, edx
/* NB: *deve essere* "s"=0 oppure "s" allocato
/* tramite malloc() o realloc().
/* Assegna a "s" un indirizzo a una stringa contenente una
/* linea di "f", o tutto il file puntato da "f" se "max_len"==0;
/* se "max_len!=0" la lunghezza massima della stringa è "max_len"
/* 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 errori di overflow indice CF==1
/* 5 errori di lettura file CF==1
/* usare come in: char *s; uns len; int i; FILE *f;
/* ----------------------
/* s=0; n=GetLine_m(&s, &len, 0, f); ... free(s); // tutto il file
/* ----------------------
/* s=0; n=GetLine_m(&s, &len, -1, f); ... free(s); // la linea
/* ----------------------
/* 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_max_len, 32P_f
GetLine_m:
< b, i, j, k
a=^20; k=^32; i=0; a==0#.e2; k==0#.e2;
b=*a; j=4; D[s+28]==1#.e2
..0: a=j; a+=4; _realloc_m<(b, a); a==0#.e0;
b=a; a=^20; *a=b; #.1;
..e0: b#.e3;
a=3; stc; ##.c; / errori iniziale di memoria
..e2: a=2; stc; ##.c; / errori di parametro
..e3: k=3; ##.8; / errori di memoria
..e4: k=4; ##.8; / errori di overflow indice
..e5: k=5; ##.8; / errori di lettura file
..1: j&i!#.2 | j+=i; jc .e4; a=j; a+=4; jc .e4;
| _realloc_m<(b, a); a==0#.e3;
| b=a; a=^20; *a=b;
..2: _fgetc_m<(k); a==-1!#.3| D [k+12]& 16 #.e5 / ferror(k)? (ext)
| k=1; #.8; / EOF (ext)
..3: i==-1#.e4; [b+i]=al; r=^28; ++i; r==0#.1; i>=r#.e4;
..4: al!=10#.1;
..7: k=0; / here "\n" is found
..8: a=i; a+=4; _realloc_m<(b, a); a==0#.9;
b=a; a=^20; *a=b;
..9: a=k;
B[b+i]=0; r=^24; r==0#.a; *r=i;
..a: a<=1#.b| stc; #.c; / error
..b: | clc; / ok
..c:
b, i, j, k
ret 16

GetLine_m:
push ebx
push esi
push edi
push ebp
mov eax, [ esp + 20 ]
mov ebp, [ esp + 32 ]
mov esi, 0
cmp eax, 0
je .e2
cmp ebp, 0
je .e2
mov ebx, [eax]
mov edi, 4
cmp dword[esp+28], 1
je .e2
..0:
mov eax, edi
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e0
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
jmp short .1
..e0:
cmp ebx, 0
jne .e3
mov eax, 3 ; errori iniziale di memoria
stc
jmp .c
..e2: ; errori di parametro
mov eax, 2
stc
jmp .c
..e3: ; errori di memoria
mov ebp, 3
jmp .8
..e4: ; errori di overflow indice
mov ebp, 4
jmp .8
..e5: ; errori di lettura file
mov ebp, 5
jmp .8
..1:
test edi, esi
jz .2
add edi, esi
jc .e4
mov eax, edi
add eax, 4
jc .e4

push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e3

mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..2: ; ferror(k)? (ext)
push ebp
call _fgetc_m
add esp, 4
cmp eax, -1
jne .3
test dword [ebp+12], 16
jnz .e5
; EOF (ext)
mov ebp, 1
jmp short .8
..3:
cmp esi, -1
je .e4
mov [ebx+esi], al
mov edx, [ esp + 28 ]
inc esi
cmp edx, 0
je .1
cmp esi, edx
jae .e4
..4:
cmp al, 10
jne .1
..7: ; here "\n" is found
mov ebp, 0
..8:
mov eax, esi
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .9
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..9:
mov eax, ebp
mov byte[ebx+esi], 0
mov edx, [ esp + 24 ]
cmp edx, 0
je .a
mov [edx], esi
..a: ; error
cmp eax, 1
jbe .b
stc
jmp short .c
..b: ; ok

clc
..c:
pop ebp
pop edi
pop esi
pop ebx
ret 16
Nov 14 '07 #12
In data Wed, 14 Nov 2007 06:30:32 +0100, Rosario scrisse:

for this there is the need to know how the malloc and realloc have to
save the size of the buffer, and to do some calculation that dipend of
that

/* int __stdcall
/* GetLine_m( char** s, uns* len, uns size_max, FILE* f)
/* trash ecx, edx
/* NB: *deve essere* "s"=0 oppure "s" allocato
/* tramite malloc() o realloc().
/* Assegna a "s" un indirizzo a una stringa contenente una
/* linea di "f", o tutto il file puntato da "f" se "size_max"==0;
/* se "size_max"!=0 la lunghezza massima della stringa è "size_max-1"
/* 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 errori di overflow indice CF==1
/* 5 errori di lettura file CF==1
/* usare come in: char *s; uns len; int i; FILE *f;
/* ----------------------
/* s=0; n=GetLine_m(&s, &len, 0, f); ... free(s); // tutto il file
/* ----------------------
/* s=0; n=GetLine_m(&s, &len, -1, f); ... free(s); // la linea
/* ----------------------
/* s=0; while(!(n=GetLine_m(&s, &len, -1, f))){...}
/* if( n==0|| n==1 ) { tutto ok}
/* free(s)
/* ----------------------
/* 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_max_len, 32P_f
GetLine_m:
< b, i, j, k
a=^20; k=^32; i=0; a==0#.e2; k==0#.e2;
b=*a; j=4; D[s+28]==1#.e2; D[s+24]==0#.e2;
/ e' dword[ebx-4] la dimensione
/ in unità sizeof(header)==8bytes della memoria
/ nunits = (nbytes+8)/8 + (nbytes%8?1:0) + 1
/ 8*nunits = nbytes + 8 + 8*(nbytes%8?1:0) + 8
/ nbytes = 8*(nunits-1) - 8*(nbytes%8?1:0) - 8
/ nbytes <= 8*(nunits-1) -8
b==0#.0; a=[b-4]; a<=1#.ee; --a; a<<=3; jc .e0; a>8#.1;
..0: a=j; a+=4; _realloc_m<(b, a); a==0#.e0;
b=a; a=^20; *a=b; #.1;
..e0: b#.e3;
..ee: a=3; stc; ##.c; / errori iniziale di memoria
..e2: a=2; stc; ##.c; / errori di parametro
..e3: k=3; ##.8; / errori di memoria
..e4: k=4; ##.8; / errori di overflow indice
..e5: k=5; ##.8; / errori di lettura file
..1: j&i!#.2 | j+=i; jc .e4; a=j; a+=8; jc .e4;
| r=[b-4]; r<=1#.ee; --r; r<<=3; jc .e3; r>a#.2;
| _realloc_m<(b, a); a==0#.e3;
| b=a; a=^20; *a=b;
..2: _fgetc_m<(k); a==-1!#.3| D [k+12]& 16 #.e5 / ferror(k)? (ext)
| k=1; #.8; / EOF (ext)
/ i non va in overflow (prima di j)
..3: [b+i]=al; r=^28; ++i; r==0#.1; --r; i>=r#.e4; / 0..size-1
..4: al!=10#.1;
..7: k=0; / here "\n" is found
..8: a=i; r=[b-4]; r<=1#.ee; --r; r<<=3; jc .9; r-=i;
r<16#.9; / in teoria mai in realloc
a+=4; _realloc_m<(b, a); a==0#.9;
b=a; a=^20; *a=b;
..9: a=k;
B[b+i]=0; r=^24; r==0#.a; *r=i;
..a: a<=1#.b| stc; #.c; / error
..b: | clc; / ok
..c:
b, i, j, k
ret 16

; int __stdcall
; GetLine_m( char** s, uns* len, uns size_max, FILE* f)
; trash ecx, edx
; NB: *deve essere* "s"=0 oppure "s"
; allocato tramite malloc() o realloc().
; Assegna a "s" un indirizzo a una stringa contenente una
; linea di "f", o tutto il file puntato da "f" se "size_max"==0;
; se "size_max"!=0 la lunghezza massima della stringa è "size_max-1"
; 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 errori di overflow indice CF==1
; 5 errori di lettura file CF==1
; usare come in: char *s; uns len; int i; FILE *f;
; ----------------------
; s=0; n=GetLine_m(&s, &len, 0, f); ... free(s); // tutto il file
; ----------------------
; s=0; n=GetLine_m(&s, &len, -1, f); ... free(s); // la linea
; ----------------------
; s=0; while(!(n=GetLine_m(&s, &len, -1, f))){...}
; if( n==0|| n==-1 ) { tutto ok}
; free(s)
; ----------------------
; 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_max_len, 32P_f
GetLine_m:
push ebx
push esi
push edi
push ebp
mov eax, [ esp + 20 ]
mov ebp, [ esp + 32 ]
mov esi, 0
cmp eax, 0
je .e2
cmp ebp, 0
je .e2
mov ebx, [eax]
mov edi, 4
cmp dword[esp+28], 1
je .e2
cmp dword[esp+24], 0
je .e2
; e' D b[-4]la dimensione in unità
; sizeof(header)==8bytes della memoria
; nunits = (nbytes+8)/8 + (nbytes%8?1:0) + 1
; 8*nunits = nbytes + 8 + 8*(nbytes%8?1:0) + 8
; nbytes = 8*(nunits-1) - 8*(nbytes%8?1:0) - 8
; nbytes <= 8*(nunits-1) -8
cmp ebx, 0
je .0
mov eax, [ebx-4]
cmp eax, 1
jbe .ee
dec eax
shl eax, 3
jc .e0
cmp eax, 8
ja .1
..0:
mov eax, edi
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e0
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
jmp short .1
..e0:
cmp ebx, 0
jne .e3
..ee: ; errori iniziale di memoria
mov eax, 3
stc
jmp .c
..e2: ; errori di parametro
mov eax, 2
stc
jmp .c
..e3: ; errori di memoria
mov ebp, 3
jmp .8
..e4: ; errori di overflow indice
mov ebp, 4
jmp .8
..e5: ; errori di lettura file
mov ebp, 5
jmp .8
..1:
test edi, esi
jz .2
add edi, esi
jc .e4
mov eax, edi
add eax, 8
jc .e4

mov edx, [ebx-4]
cmp edx, 1
jbe .ee
dec edx
shl edx, 3
jc .e3
cmp edx, eax
ja .2

push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .e3

mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..2: ; ferror(k)? (ext)
push ebp
call _fgetc_m
add esp, 4
cmp eax, -1
jne .3
test dword [ebp+12], 16
jnz .e5
; EOF (ext)
mov ebp, 1
jmp short .8
; i non va in overflow (prima di j)
..3: ; 0..size-1
mov [ebx+esi], al
mov edx, [ esp + 28 ]
inc esi
cmp edx, 0
je .1
dec edx
cmp esi, edx
jae .e4
..4:
cmp al, 10
jne .1
..7: ; here "\n" is found
mov ebp, 0
..8:
mov eax, esi
mov edx, [ebx-4]
cmp edx, 1
jbe .ee
dec edx
shl edx, 3
jc .9
sub edx, esi
cmp edx, 16
jb .9 ; in teoria mai in realloc
add eax, 4
push eax
push ebx
call _realloc_m
add esp, 8
cmp eax, 0
je .9
mov ebx, eax
mov eax, [ esp + 20 ]
mov [eax], ebx
..9:
mov eax, ebp
mov byte[ebx+esi], 0
mov edx, [ esp + 24 ]
cmp edx, 0
je .a
mov [edx], esi
..a: ; error
cmp eax, 1
jbe .b
stc
jmp short .c
..b: ; ok

clc
..c:
pop ebp
pop edi
pop esi
pop ebx
ret 16

Nov 14 '07 #13
Rosario wrote:
Rosario scrisse:
>#define P printf
PLONK

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 17 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John | last post by:
Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I...
1
by: ma740988 | last post by:
Consider: ifstrem MyFile("extractMe.txt"); string Str; getline(MyFile, Str); getline above extracts the contents of MyFile and place into the string object. Deduced using FROM/TO logic I...
3
by: algorithm | last post by:
Hi, I've a simplified program snippet in which getline behaves in a way, which at least I find odd: // File: getline_example.cpp #include <iostream> #include <string> using namespace std;
14
by: KL | last post by:
I am so lost. I am in a college course for C++, and first off let me state I am not asking for anyone to do my assignment, just clarification on what I seem to not be able to comprehend. I have a...
18
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include...
22
by: bitshadow | last post by:
using the following code, i was able to have my compiler seg fault on me when i gave the argument as anythng greater than 20,832,000bytes. In the case of the struct its 868 instances of said...
5
by: allspamgoeshere3 | last post by:
Hi! I'm having trouble reading text lines from a file describing the levels for a simple game I'm creating. Inside the function that reads the content of the file there is a loop that basically...
4
by: Chen shuSheng | last post by:
I have a code: --------------------------- #include <iostream.h \\ where I assume getline() is inner. #include <stdlib.h> int main() { int max=15; char line; getline(line,max);...
13
by: theronnightstar | last post by:
I seem to be having a problem with getline(). I have tried to find it on google, but I'm not seeing the answer. The goal of this section of code is simply to read in a line from a file to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.