J'avais une fonction qui skippait les "dummy lines" dans un sources (lignes vides, lignes de commentaires) :
SkipDummyLines simple
;=============================================================================== ; ; pdtlib::SkipDummyLines ; ; in a0 char* Cursor ; a1 short* LineCount ; d1.b Comment char ; ; out a0 char* cursor ; (a1).w updated if a1 != NULL ; ; destroy ; ; Advance Cursor until the next relevant char, skipping empty lines or ; comment lines. ; Update LineCount if a1 != NULL ; ;=============================================================================== SkipL: bsr SkipLine DEFINE pdtlib@000B SkipDummyLines: bsr SkipSpaces move.b (a0),d0 beq.s \End cmpi.b #EOL,d0 beq.s SkipL cmp.b d0,d1 beq.s SkipL \End: rts
J'ai voulu ajouter le fait de pouvoir skipper des commentaires façon /* commentaire */, donc avec un marqueur de début et de fin sur plusieurs caractères, pouvant inclure EOL. Ca donne ça :
SkipDummyLines un peu plus compliqué
;=============================================================================== ; ; pdtlib::SkipDummyLines ; ; in a0 char* Cursor ; a1 short* LineCount ; a2 char* CommentChars ; ; out a0 char* cursor ; (a1).w updated if a1 != NULL ; ; destroy ; ; Advance Cursor until the next relevant char, skipping empty lines or ; comment lines. ; Update LineCount if a1 != NULL ; ; CommentChars format: ; dc.b "<chars that begin a comment>",0,"<char that terminates a comment>",0 ; ;=============================================================================== DEFINE pdtlib@000B SkipDummyLines: pea (a2) \Loop: bsr SkipSpaces ; Skip spaces, quit if EOF move.b (a0),d0 beq.s \End cmpi.b #EOL,d0 ; Check EOL bne.s \CheckCommentBeginning bsr SkipLine bra.s \Loop \CheckCommentBeginning: ; Check if a comment begins pea (a0) ; We restore it if this is not a comment moveq.l #0,d1 ; Counter added to *LineCount if 1 or multiple EOL ; are part of the beginning of a comment >< \BeginningLoop: move.b (a2)+,d0 beq.s \SkipComment ; Ok, this is a comment, we have to skip it cmpi.b #EOL,d0 bne.s \NoEOL addq.w #1,d1 \NoEOL: cmp.b (a0)+,d0 beq.s \BeginningLoop movea.l (sp)+,a0 ; Ok, this is not a comment bra.s \End \SkipComment: ; Beginning of a comment found, skip it addq.l #4,sp ; Remove saved a0 move.l a1,d0 ; Update *LineCount if needed bne.s \SkipCommentLoop add.w d1,(a1) \SkipCommentLoop: move.b (a0)+,d0 beq.s \End ; Comment terminates with EOF cmpi.b #EOL,d0 beq.s \NoEOL2 move.l a1,d1 ; Update *LineCount if needed bne.s \NoEOL2 addq.w #1,(a1) \NoEOL2: movem.l a0/a2,-(sp) ; Save that if comment and source do not match \CheckCommentLoop: move.b (a2)+,d0 bne.s \NotEnd addq.l #8,sp ; Comment found ! Trash regs bra.s \Loop ; And go further \NotEnd: cmp.b (a0)+,d0 ; CommentChars and source match at the moment, continue beq.s \CheckCommentLoop movem.l (sp)+,a0/a2 ; CommentChars and source dismatch bra.s \SkipCommentLoop ; Continue to look for the end of the comment \End: movea.l (sp)+,a2 rts
Je pensais pas faire un dinosaure de ce genre

Les deux fonctions sont aussi capables de mettre à joue un compteur de lignes, dans le cadre du parsing d'un fichier source.









