Accueil > > > UN EDITEUR DE FICHIER UNIX DEPUIS WINDOWS
UN EDITEUR DE FICHIER UNIX DEPUIS WINDOWS
Information sur la source
Description
Voici un petit programme, qui a l'heure d'aujourd'hui m'est fort utile.
Dans mon entreprise on possède un serveur AIX, ce dernier lance différent traitements tout les soirs.
De temps a autre, il fallait contrôler certains de ces traitements.
2 solutions s'offraient, soit par l'éditeur VI, soit par un utilitaire de style "Ultra édit".
La première solution était assez fastidieuse, quand a la seconde, c'était une solution payante et de plus les dates des fichiers ne correspondait pas a la réalité.
J'ai donc développé un petit utilitaire pour pouvoir visualiser ces fichiers de log.
Mon premier jet fut dans une solution en DHTML. Pourquoi le "DHTML", uniquement par rapport à la politique de l'entreprise.
Cette application marchait très bien jusqu'a ce que les répertoires contenant les logs, soit trop volumineux.
J'ai donc rajouté un petit prog en assembleur afin d'augmenter la vitesse.
Source
- ; compil me with MASM32
-
- .486
- .model flat, stdcall
- option casemap :none ; case sensitive
-
- ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
-
- include \masm32\include\windows.inc
- include \masm32\include\masm32.inc
- include \masm32\include\user32.inc
- include \masm32\include\kernel32.inc
- include \masm32\macros\macros.asm
-
- includelib \masm32\lib\masm32.lib
- includelib \masm32\lib\user32.lib
- includelib \masm32\lib\kernel32.lib
-
-
- .data
- File_Input db "C:\rep.tmp",0
- h_Input dd 0
- File_Output db "C:\dir.htm", 0
- h_Output dd 0
- Buffer_In db 128 dup (0)
- File_struct OFSTRUCT <>
- BW dd 0
- Temp db 10 dup (0)
- dir db 260 dup (0)
-
-
- Txt00 db "<table>",13,10,0
- Txt01 db "<TR><TD><IMG SRC='images\paper.gif'></TD><TD><font color=green style='cursor:hand' OnMouseDown = 'parent.edit(",34,0
- Txt11 db "<TR><TD><IMG SRC='images\close.gif'></TD><TD><font color=blue style='cursor:hand' OnMouseDown = 'parent.dir( ",34,0
- Txt02 db 34,");'>",0
- Txt03 db "</Font></TD><TD>",0
- Txt04 db "</TD></TR>",13,10,0
- Txt05 db "</b></TD><td width='15'></td><TD>",0
- Txt06 db "</TD><TD align=right><B>",0
- Txt07 db " oKoMoGo"
- Txt08 db "</TD><TD>",0
- Txt09 db "</TD><td width='15'></td><TD>",0
- DSize dd 0
- Txt99 db 13,10,"</table>",0
-
- .code
-
- start:
-
- invoke GetCL,1,ADDR dir ; dir is the first param of call this programme
-
- ;create the file to write
- invoke OpenFile, offset File_Output, offset File_struct, OF_CREATE ; create new file
- mov h_Output, eax ; save its handle
- invoke WriteFile, h_Output, offset Txt00, 9, offset BW, NULL
- ;read
- invoke OpenFile, offset File_Input, offset File_struct, GENERIC_READ ; open file
- mov h_Input, eax ; save its handle
-
- mov ebx, offset Buffer_In ; point to tempory string
- debut: ; read the first line
- invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read open file char by char
- mov al,[ebx] ; push it in the tempory string
- cmp BW,0 ; end of read ?
- je fin ; yes leave programm
- cmp al,13 ; loop until is carriage return
- jne debut
- invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read again for chr(10) last chr(13)
-
- loop00: ; read a line
- mov ebx,offset Buffer_In
- invoke ReadFile,h_Input,ebx,57,offset BW,NULL ; read the 57 first char
- cmp BW,0 ; end of the file ?
- je fin ; yes quit
- add ebx,57
- loop01:
- invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read open file char by char
- mov al,[ebx] ; push it in the tempory string
- cmp al,13 ; compare the char by return carrige
- je fin_ligne ; chr(13)=yes -> end of line
- inc ebx ; else inc position in the tempory string
- jmp loop01
-
- fin_ligne:
- Xor al,al
- mov [ebx],al ; terminate the string by chr(0)
- mov ebx,offset Buffer_In ; go to the begining of tempory string
- mov al,[ebx] ; read the first char
- cmp al,"d" ; char is "d" ?
- je directory ; yes -> is directory go to directory
- cmp al,"l" ; char is "l" ?
- je loop00 ; yes -> virtual dir do nothing
-
-
- ;fichier
- file:
- invoke WriteFile, h_Output, offset Txt01, 111, offset BW, NULL ; write Txt01
- suite:
- invoke lstrlen, offset dir ; get len of param dir
- invoke WriteFile, h_Output,offset dir, eax, offset BW, NULL ; write dir
- mov ebx,offset Buffer_In
- add ebx,57 ; begin the tempory buffer at then char 57
- invoke lstrlen, ebx ; get len of the tempory buffer
- invoke WriteFile, h_Output, ebx, eax, offset BW, NULL ; write the tempory buffer
- invoke WriteFile, h_Output, offset Txt02, 5, offset BW, NULL ; write Txt02
- invoke lstrlen, ebx
- invoke WriteFile, h_Output, ebx, eax, offset BW, NULL ; write the tempory buffer
- invoke WriteFile, h_Output, offset Txt03,16, offset BW, NULL ; write Txt03
- mov ebx,offset Buffer_In
- invoke WriteFile, h_Output, ebx, 10, offset BW, NULL ; write right(txt,10)
- invoke WriteFile, h_Output, offset Txt09, 29, offset BW, NULL ; write Txt09
- invoke WriteFile, h_Output, offset Txt06, 24, offset BW, NULL ; write Txt06
- add ebx,43 ; position char 43 of tempory string
- loop03:
- dec ebx ; write the size of file
- mov al,[ebx] ; found the first number after space
- cmp al,32
- jne loop03
- xor ecx,ecx
- mov edx,ebx
- loop04:
- inc edx ; found the last number before space
- inc ecx
- mov al,[edx]
- cmp al,32
- jne loop04
-
- mov eax,ebx
- mov ebx,edx
- xor edx,edx
- mov [ebx],dl
- inc ebx
-
- mov DSize,offset Txt07 ; convert in ko, mo or go
- mov eax,sval (eax)
- cmp eax,1024
- jl suite2
- shr eax,10
- add DSize,2
- cmp eax,1024
- jl suite2
- shr eax,10
- add DSize,2
- cmp eax,1024
- jl suite2
- shr eax,10
- add DSize,2
-
- suite2:
- mov edx,ustr$(eax)
- invoke lstrlen , edx
- invoke WriteFile, h_Output, edx, eax, offset BW, NULL ; write the number
- invoke WriteFile, h_Output, offset Txt08, 9, offset BW, NULL ; write Txt08
- invoke WriteFile, h_Output, DSize, 2, offset BW, NULL ; write type of size o ko mo go
- invoke WriteFile, h_Output, offset Txt05, 33, offset BW, NULL ; write Txt05
- invoke WriteFile, h_Output, ebx, 12, offset BW, NULL ; write the date
- invoke WriteFile, h_Output, offset Txt04, 12, offset BW, NULL ; write Txt04
- invoke ReadFile , h_Input, ebx,1,offset BW,NULL ; read one char
- cmp BW,0 ; error -> end of file
- je fin
- jmp loop00
-
- directory:
- invoke WriteFile, h_Output, offset Txt11, 111, offset BW, NULL ; write Txt11
- jmp suite
-
- fin:
- invoke WriteFile, h_Output, offset Txt99, 10, offset BW, NULL ; write Txt99
- invoke CloseHandle, h_Output ; close the file
- invoke ExitProcess, 0
- end start
; compil me with MASM32
.486
.model flat, stdcall
option casemap :none ; case sensitive
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\macros.asm
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
File_Input db "C:\rep.tmp",0
h_Input dd 0
File_Output db "C:\dir.htm", 0
h_Output dd 0
Buffer_In db 128 dup (0)
File_struct OFSTRUCT <>
BW dd 0
Temp db 10 dup (0)
dir db 260 dup (0)
Txt00 db "<table>",13,10,0
Txt01 db "<TR><TD><IMG SRC='images\paper.gif'></TD><TD><font color=green style='cursor:hand' OnMouseDown = 'parent.edit(",34,0
Txt11 db "<TR><TD><IMG SRC='images\close.gif'></TD><TD><font color=blue style='cursor:hand' OnMouseDown = 'parent.dir( ",34,0
Txt02 db 34,");'>",0
Txt03 db "</Font></TD><TD>",0
Txt04 db "</TD></TR>",13,10,0
Txt05 db "</b></TD><td width='15'></td><TD>",0
Txt06 db "</TD><TD align=right><B>",0
Txt07 db " oKoMoGo"
Txt08 db "</TD><TD>",0
Txt09 db "</TD><td width='15'></td><TD>",0
DSize dd 0
Txt99 db 13,10,"</table>",0
.code
start:
invoke GetCL,1,ADDR dir ; dir is the first param of call this programme
;create the file to write
invoke OpenFile, offset File_Output, offset File_struct, OF_CREATE ; create new file
mov h_Output, eax ; save its handle
invoke WriteFile, h_Output, offset Txt00, 9, offset BW, NULL
;read
invoke OpenFile, offset File_Input, offset File_struct, GENERIC_READ ; open file
mov h_Input, eax ; save its handle
mov ebx, offset Buffer_In ; point to tempory string
debut: ; read the first line
invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read open file char by char
mov al,[ebx] ; push it in the tempory string
cmp BW,0 ; end of read ?
je fin ; yes leave programm
cmp al,13 ; loop until is carriage return
jne debut
invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read again for chr(10) last chr(13)
loop00: ; read a line
mov ebx,offset Buffer_In
invoke ReadFile,h_Input,ebx,57,offset BW,NULL ; read the 57 first char
cmp BW,0 ; end of the file ?
je fin ; yes quit
add ebx,57
loop01:
invoke ReadFile,h_Input,ebx,1,offset BW,NULL ; read open file char by char
mov al,[ebx] ; push it in the tempory string
cmp al,13 ; compare the char by return carrige
je fin_ligne ; chr(13)=yes -> end of line
inc ebx ; else inc position in the tempory string
jmp loop01
fin_ligne:
Xor al,al
mov [ebx],al ; terminate the string by chr(0)
mov ebx,offset Buffer_In ; go to the begining of tempory string
mov al,[ebx] ; read the first char
cmp al,"d" ; char is "d" ?
je directory ; yes -> is directory go to directory
cmp al,"l" ; char is "l" ?
je loop00 ; yes -> virtual dir do nothing
;fichier
file:
invoke WriteFile, h_Output, offset Txt01, 111, offset BW, NULL ; write Txt01
suite:
invoke lstrlen, offset dir ; get len of param dir
invoke WriteFile, h_Output,offset dir, eax, offset BW, NULL ; write dir
mov ebx,offset Buffer_In
add ebx,57 ; begin the tempory buffer at then char 57
invoke lstrlen, ebx ; get len of the tempory buffer
invoke WriteFile, h_Output, ebx, eax, offset BW, NULL ; write the tempory buffer
invoke WriteFile, h_Output, offset Txt02, 5, offset BW, NULL ; write Txt02
invoke lstrlen, ebx
invoke WriteFile, h_Output, ebx, eax, offset BW, NULL ; write the tempory buffer
invoke WriteFile, h_Output, offset Txt03,16, offset BW, NULL ; write Txt03
mov ebx,offset Buffer_In
invoke WriteFile, h_Output, ebx, 10, offset BW, NULL ; write right(txt,10)
invoke WriteFile, h_Output, offset Txt09, 29, offset BW, NULL ; write Txt09
invoke WriteFile, h_Output, offset Txt06, 24, offset BW, NULL ; write Txt06
add ebx,43 ; position char 43 of tempory string
loop03:
dec ebx ; write the size of file
mov al,[ebx] ; found the first number after space
cmp al,32
jne loop03
xor ecx,ecx
mov edx,ebx
loop04:
inc edx ; found the last number before space
inc ecx
mov al,[edx]
cmp al,32
jne loop04
mov eax,ebx
mov ebx,edx
xor edx,edx
mov [ebx],dl
inc ebx
mov DSize,offset Txt07 ; convert in ko, mo or go
mov eax,sval (eax)
cmp eax,1024
jl suite2
shr eax,10
add DSize,2
cmp eax,1024
jl suite2
shr eax,10
add DSize,2
cmp eax,1024
jl suite2
shr eax,10
add DSize,2
suite2:
mov edx,ustr$(eax)
invoke lstrlen , edx
invoke WriteFile, h_Output, edx, eax, offset BW, NULL ; write the number
invoke WriteFile, h_Output, offset Txt08, 9, offset BW, NULL ; write Txt08
invoke WriteFile, h_Output, DSize, 2, offset BW, NULL ; write type of size o ko mo go
invoke WriteFile, h_Output, offset Txt05, 33, offset BW, NULL ; write Txt05
invoke WriteFile, h_Output, ebx, 12, offset BW, NULL ; write the date
invoke WriteFile, h_Output, offset Txt04, 12, offset BW, NULL ; write Txt04
invoke ReadFile , h_Input, ebx,1,offset BW,NULL ; read one char
cmp BW,0 ; error -> end of file
je fin
jmp loop00
directory:
invoke WriteFile, h_Output, offset Txt11, 111, offset BW, NULL ; write Txt11
jmp suite
fin:
invoke WriteFile, h_Output, offset Txt99, 10, offset BW, NULL ; write Txt99
invoke CloseHandle, h_Output ; close the file
invoke ExitProcess, 0
end start
Conclusion
Ce prog n'est pas 100 % en assembleur, mais le code assembleur ci joint peut etre une bonne base pour la manipulation de chaine et de fichier.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE?COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE? par Matthieu MEZIL
Avec EF, les vues doivent être mappées sur des entity types. Le problème c'est que les entity types doivent avoir une clé. Avec EF, nous avons les complex type qui n'ont pas de clé mais les vues ne peuvent pas être mappées dessus. Avec EF4, il est possibl...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL?[WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL? par JeremyJeanson
Certain d'entre vous on peut être vécu cette situation embarrassante après quelques temps passer avec WF4 : Au début avec mon " ActivityDesigner" , tout allait bien. Et puis un jour j'ai au des problèmes de " Binding" . Alors nous sommes allé sur le site ...
Cliquez pour lire la suite de l'article par JeremyJeanson MYTIC - SHAREPOINT 2010 : DéJà UN MYTHE MICROSOFT ?MYTIC - SHAREPOINT 2010 : DéJà UN MYTHE MICROSOFT ? par junarnoalg
La prochaine session de MyTIC aura lieu à Namur, le 23 mars prochain. Pendant presque une heure, nous parlerons de SharePoint 2010. Voici un aperçu du programme.
Accueil : 17h30 Début de la session : 18h00 - Les nouvelles int...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : ASSEMBLEURRE : ASSEMBLEUR par solleil
Cliquez pour lire la suite par solleil RE : ASSEMBLEURRE : ASSEMBLEUR par ghuysmans99
Cliquez pour lire la suite par ghuysmans99 RE : ASSEMBLEURRE : ASSEMBLEUR par ghuysmans99
Cliquez pour lire la suite par ghuysmans99 ASSEMBLEURASSEMBLEUR par solleil
Cliquez pour lire la suite par solleil
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
|