Do you like my Fopen_m function?
Is in it some error? I forget something?
Why open a file with "FILE_SHARE_WRITE"?
; u32* Fopen_m(u8* nome, u8* mode)
; nome: Stringa del nome del file da aprire
; mode: ["r" read, sola lettura inizio file, apre se esiste],
; ["w" write, sola scrittura inizio file, apre sempre e
; scarta eventuale vecchio file]
; ["a" append, sola scrittura alla fine file,
; apre se esiste altrimenti crea il file]
; ["rw" lettura e scrittura all'inizio file,
; apre il file, se il file non esiste lo crea]
; ["ra" lettura e scrittura alla fine del file
; apre il file, se il file non esiste lo crea]
; ["wa" sola scrittura fine file, apre sempre e
; scarta eventuale vecchio file]
; [ "sr" share read, sola lettura inizio file, apre se esiste]
; [ "sw" share write, sola scrittura inizio file, apre sempre e
; scarta eventuale vecchio file]
; [ "r+" lettura e scrittura all'inizio del file,
; apre il file se esiste]
; [ "w+" lettura e scrittura all'inizio del file, apre sempre e
; scarta eventuale vecchio file]
; [ "a+" lettura e scrittura alla fine del file,
; apre se esiste altrimenti crea il file]
; (0k,4j,8i,12b,16ra,20P_name,24P_mode) + 16
; 36 40
align 4
Fopen_m:
<b,i,j,k
s-=16
j=[s+36]|i=[s+40]|j==0#.e|B*j==0#.e|a^=a|k^=k|i#.1
.e: a^=a|stc|##.f
.0: ++i
.1: al=*i
a=='r'!#.2|k|= 1|#.0
.2: a=='w'!#.3|k|= 2|#.0
.3: a=='a'!#.4|k|= 4|#.0
.4: a=='s'!#.5|k|= 8|#.0
.5: a=='+'!#.6|k|=16|#.0
.6: a==0#.8|##.0
.eee: CloseHandle(j)
.ee: a^=a |stc |##.f
.8: Strcmp_m(j, "stdin_m")|a#.c0|k!=1#.ee
D[_stdin_m+16]!=IVA_#.ee
D[_stdin_m]=0|D[_stdin_m+4]=_std_mezzo
D[_stdin_m+8]=_std_mezzo|D[_stdin_m+12]= 1 ; _READ=1
GetStdHandle(STD_INPUT_HANDLE)|a==IVA_#.ee
D[_stdin_m+16]=a|a=_stdin_m|clc|##.f
.c0: Strcmp_m(j, "stdout_m")|a#.c1|k!=2#.ee
D[_stdout_m+16]!=IVA_#.ee ; WRITE|_UNBUF=6
D[_stdout_m]=0|D[_stdout_m+4]=_variab_w
D[_stdout_m+8]=_variab_w|D[_stdout_m+12]= 6
GetStdHandle(STD_OUTPUT_HANDLE)|a==IVA_#.ee
D[_stdout_m+16]=a|a=_stdout_m|clc|##.f
.c1: Strcmp_m(j, "stderr_m")|a#.c2|k!=2#.ee
D[_stderr_m+16]!=IVA_#.ee ; WRITE|_UNBUF=6
D[_stderr_m]=0| D[_stderr_m+4]=_variab_e
D[_stderr_m+8]=_variab_e|D[_stderr_m+12]= 6
GetStdHandle(STD_ERROR_HANDLE)|a==IVA_#.ee
D[_stderr_m+16]=a|a=_stderr_m|clc|##.f
.c2: c=625|r=_iobS|c<<=2|a=_iobS|r+=c|a+=12
.9: c=[a]|c&3!#.a|a+=20|a<r#.9|##.ee ; 3==011 significa leggi o scrivi
.a: a-=12|[s+12]=a ; in ^12 la posizione libera
b^=b|r^=r
k==1!#.b0 ; "r"
c=GENERIC_READ |b=OPEN_EXISTING|##.a0
.b0: k==2!#.b1 ; "w"
.b00: c=GENERIC_WRITE|b=CREATE_ALWAYS|##.a0
.b1: k==4!#.b2 ; "a"
c=GENERIC_WRITE|b=OPEN_ALWAYS |##.a0
.b2: k==3 #.b3 ; "rw"
k==5!#.b4 ; "ar"
.b3: c=(GENERIC_READ|GENERIC_WRITE)
k|=2 ; aggiungo write mi serve alla fine
b=OPEN_ALWAYS |##.a0
.b4: k==20!#.x0 ; "a+"
k|=1 ; aggiungo read
#.b3
.x0: k==7!#.c3 ; "arw" 7=111
.b44: c=(GENERIC_READ|GENERIC_WRITE)
b=CREATE_ALWAYS|##.a0
.c3: k==18!#.c4 ; "w+"
k|=1 ; aggiungo read
#.b44
.c4: k==17!#.c5 ; "r+"
c=(GENERIC_READ|GENERIC_WRITE)
k|=2 ; aggiungo il write
b=OPEN_EXISTING|##.a0
.c5: k==6 #.b00 ; "aw"
k==9 !#.b5 ; "sr"
c=GENERIC_READ|b=OPEN_EXISTING
r=FILE_SHARE_READ|##.a0
.b5: k==10!#.b7 ; "sw"
.b6: c=GENERIC_WRITE|b=CREATE_ALWAYS
k|=2 ; aggiungo write mi serve alla fine
r=FILE_SHARE_WRITE|##.a0
.b7: k==12#.b6 ; "sa"
##.ee
.e3: ##.eee
.a0: CreateFileA(j,c,r,0,b, FILE_ATTRIBUTE_NORMAL , 0)
a==IVA_#.ee|j=a
k&4!#.a1
SetFilePointer(j, 0, 0, FILE_END)|a==-1#.e3
.a1: i=[s+12]|r=k|r&=3
.d0: ; r==2!#.d1 |r|= _UNBUF ; legge scrive unbuf
.d1:
; 0 4 8 12 16
; File dd 0, _std_mezzo, _std_mezzo, _READ|_WRITE, IVA_
D[i]=0|D[i+4]=0|D[i+8]=0|D[i+12]=r |D[i+16] =j
GetFileType(j)|a==FILE_TYPE_DISK!#.d2|D[i+12]|= _DISKF
.d2: a=i|clc
.f:
s=&[s+16]
>b,i,j,k
ret 8
; u32* Fopen_m(u8* nome, u8* mode)
; nome: Stringa del nome del file da aprire
; mode: ["r" read, sola lettura inizio file, apre se esiste],
; ["w" write, sola scrittura inizio file, apre sempre e
; scarta eventuale vecchio file]
; ["a" append, sola scrittura alla fine file,
; apre se esiste altrimenti crea il file]
; ["rw" lettura e scrittura all'inizio file,
; apre il file, se il file non esiste lo crea]
; ["ra" lettura e scrittura alla fine del file
; apre il file, se il file non esiste lo crea]
; ["wa" sola scrittura fine file, apre sempre e
; scarta eventuale vecchio file]
; [ "sr" share read, sola lettura inizio file, apre se esiste]
; [ "sw" share write, sola scrittura inizio file, apre sempre e
; scarta eventuale vecchio file]
; [ "r+" lettura e scrittura all'inizio del file,
; apre il file se esiste]
; [ "w+" lettura e scrittura all'inizio del file, apre sempre e
; scarta eventuale vecchio file]
; [ "a+" lettura e scrittura alla fine del file,
; apre se esiste altrimenti crea il file]
; (0k,4j,8i,12b,16ra,20P_name,24P_mode) + 16
; 36 40
align 4
Fopen_m:
push ebx
push esi
push edi
push ebp
sub esp, 16
mov edi, [esp+36]
mov esi, [esp+40]
cmp edi, 0
je .e
cmp byte [edi], 0
je .e
xor eax, eax
xor ebp, ebp
cmp esi, 0
jne .1
.e: xor eax, eax
stc
jmp .f
.0: inc esi
.1: mov al, [esi]
cmp eax, 'r'
jne .2
or ebp, 1
jmp short .0
.2: cmp eax, 'w'
jne .3
or ebp, 2
jmp short .0
.3: cmp eax, 'a'
jne .4
or ebp, 4
jmp short .0
.4: cmp eax, 's'
jne .5
or ebp, 8
jmp short .0
.5: cmp eax, '+'
jne .6
or ebp, 16
jmp short .0
.6: cmp eax, 0
je .8
jmp .0
.eee: push edi
call CloseHandle
.ee: xor eax, eax
stc
jmp .f
.8: push Istdin_m
push edi
call Strcmp_m
cmp eax, 0
jne .c0
cmp ebp, 1
jne .ee
cmp dword[_stdin_m+16], IVA_
jne .ee
mov dword[_stdin_m], 0
mov dword[_stdin_m+4], _std_mezzo
mov dword[_stdin_m+8], _std_mezzo
mov dword[_stdin_m+12], 1 ; _READ=1
push STD_INPUT_HANDLE
call GetStdHandle
cmp eax, IVA_
je .ee
mov dword[_stdin_m+16], eax
mov eax, _stdin_m
clc
jmp .f
.c0: push Istdout_m
push edi
call Strcmp_m
cmp eax, 0
jne .c1
cmp ebp, 2
jne .ee
cmp dword[_stdout_m+16], IVA_
jne .ee ; WRITE|_UNBUF=6
mov dword[_stdout_m], 0
mov dword[_stdout_m+4], _variab_w
mov dword[_stdout_m+8], _variab_w
mov dword[_stdout_m+12], 6
push STD_OUTPUT_HANDLE
call GetStdHandle
cmp eax, IVA_
je .ee
mov dword[_stdout_m+16], eax
mov eax, _stdout_m
clc
jmp .f
.c1: push Istderr_m
push edi
call Strcmp_m
cmp eax, 0
jne .c2
cmp ebp, 2
jne .ee
cmp dword[_stderr_m+16], IVA_
jne .ee ; WRITE|_UNBUF=6
mov dword[_stderr_m], 0
mov dword[_stderr_m+4], _variab_e
mov dword[_stderr_m+8], _variab_e
mov dword[_stderr_m+12], 6
push STD_ERROR_HANDLE
call GetStdHandle
cmp eax, IVA_
je .ee
mov dword[_stderr_m+16], eax
mov eax, _stderr_m
clc
jmp .f
.c2: mov ecx, 625
mov edx, _iobS
shl ecx, 2
mov eax, _iobS
add edx, ecx
add eax, 12
.9: mov ecx, [eax]
test ecx, 3
jz .a
add eax, 20
cmp eax, edx
jb .9
jmp .ee ; 3==011 significa leggi o scrivi
.a: sub eax, 12
mov [esp+12], eax ; in ^12 la posizione libera
xor ebx, ebx
xor edx, edx
cmp ebp, 1
jne .b0 ; "r"
mov ecx, GENERIC_READ
mov ebx, OPEN_EXISTING
jmp .a0
.b0: cmp ebp, 2
jne .b1 ; "w"
.b00: mov ecx, GENERIC_WRITE
mov ebx, CREATE_ALWAYS
jmp .a0
.b1: cmp ebp, 4
jne .b2 ; "a"
mov ecx, GENERIC_WRITE
mov ebx, OPEN_ALWAYS
jmp .a0
.b2: cmp ebp, 3
je .b3 ; "rw"
cmp ebp, 5
jne .b4 ; "ar"
.b3: mov ecx, (GENERIC_READ|GENERIC_WRITE)
or ebp, 2 ; aggiungo write mi serve alla fine
mov ebx, OPEN_ALWAYS
jmp .a0
.b4: cmp ebp, 20
jne .x0 ; "a+"
or ebp, 1 ; aggiungo read
jmp short .b3
.x0: cmp ebp, 7
jne .c3 ; "arw" 7=111
.b44: mov ecx, (GENERIC_READ|GENERIC_WRITE)
mov ebx, CREATE_ALWAYS
jmp .a0
.c3: cmp ebp, 18
jne .c4 ; "w+"
or ebp, 1 ; aggiungo read
jmp short .b44
.c4: cmp ebp, 17
jne .c5 ; "r+"
mov ecx, (GENERIC_READ|GENERIC_WRITE)
or ebp, 2 ; aggiungo il write
mov ebx, OPEN_EXISTING
jmp .a0
.c5: cmp ebp, 6
je .b00 ; "aw"
cmp ebp, 9
jne .b5 ; "sr"
mov ecx, GENERIC_READ
mov ebx, OPEN_EXISTING
mov edx, FILE_SHARE_READ
jmp .a0
.b5: cmp ebp, 10
jne .b7 ; "sw"
.b6: mov ecx, GENERIC_WRITE
mov ebx, CREATE_ALWAYS
or ebp, 2 ; aggiungo write mi serve alla fine
mov edx, FILE_SHARE_WRITE
jmp .a0
.b7: cmp ebp, 12
je .b6 ; "sa"
jmp .ee
.e3: jmp .eee
.a0: push 0
push FILE_ATTRIBUTE_NORMAL
push ebx
push 0
push edx
push ecx
push edi
call CreateFileA
cmp eax, IVA_
je .ee
mov edi, eax
test ebp, 4
jz .a1
push FILE_END
push 0
push 0
push edi
call SetFilePointer
cmp eax, -1
je .e3
.a1: mov esi, [esp+12]
mov edx, ebp
and edx, 3
.d0: ; r==2!#.d1 |r|= _UNBUF ; legge scrive unbuf
.d1:
; 0 4 8 12 16
; File dd 0, _std_mezzo, _std_mezzo, _READ|_WRITE, IVA_
mov dword[esi], 0
mov dword[esi+4], 0
mov dword[esi+8], 0
mov dword[esi+12], edx
mov dword[esi+16], edi
push edi
call GetFileType
cmp eax, FILE_TYPE_DISK
jne .d2
or dword[esi+12], _DISKF
.d2: mov eax, esi
clc
.f:
lea esp, [esp+16]
pop ebp
pop edi
pop esi
pop ebx
ret 8
what about if the argument "mode" string
has some char not in "rwa+sb"?
it is better return NULL?
.0: ++i
.1: al=*i
a=='r'!#.2|k|= 1|#.0
.2: a=='w'!#.3|k|= 2|#.0
.3: a=='a'!#.4|k|= 4|#.0
.4: a=='s'!#.5|k|= 8|#.0
.5: a=='+'!#.6|k|=16|#.0
.6: a=='b' #.0 ; 'b' means nothing: it is all binary
a==0#.8|#.ee
could be one limit for mode argument string len too
r=i| r+=10
>> B*j==0#.e|a^=a|k^=k|i#.1
>> .e: a^=a|stc|##.f
...
> what about if the argument "mode" string
> has some char not in "rwa+sb"?
> it is better return NULL?
>
> .0: ++i
> .1: al=*i
> a=='r'!#.2|k|= 1|#.0
> .2: a=='w'!#.3|k|= 2|#.0
> .3: a=='a'!#.4|k|= 4|#.0
> .4: a=='s'!#.5|k|= 8|#.0
> .5: a=='+'!#.6|k|=16|#.0
> .6: a=='b' #.0 ; 'b' means nothing: it is all binary
i>= r #.ee
Rio,
I'd help if I could. As I've stated in quite a few past posts, your syntax
is too cryptic to be readable. Also, I think I mentioned previously that it
seems you're having difficutly with your own syntax. You keep posting
corrections, additions, and modifications. But, you still shouldn't be
experiencing these as frequently as you seem to be if your syntax is
suitable. They should be quite apparent, almost obvious. That's one of the
measures of a long lasting language. Have you considered making changes to
help you identify these situations the first time around?
Rod Pemberton
PS. Is the clax server down again? Anyone?
> Rio,
>
> I'd help if I could. As I've stated in quite a few past posts, your syntax
> is too cryptic to be readable. Also, I think I mentioned previously that it
> seems you're having difficutly with your own syntax.
it seems i remember that i answer for that that i have
no problem with my assembly language;
the only problem could be that i'm a slow lerner
and a slow writer (expecially in code
generation) and possibily i'm not much smart
> You keep posting
> corrections, additions, and modifications.
i, in code generation, never right the first time;
you are right the first time?
> But, you still shouldn't be
> experiencing these as frequently as you seem to be if your syntax is
> suitable.
yes it is suitable
> They should be quite apparent, almost obvious. That's one of the
> measures of a long lasting language. Have you considered making changes to
> help you identify these situations the first time around?
what does it mean?
anyway this NG is free, i'm free to post anyting only too for my
pleacer of see something that seems OK