( Title: Count AAma assembly language source comments, lines, and ops File: AAma-count.fs Author: David N. Williams License: Public Domain Version: 0.5.0 Revised: April 26, 2009 Version 0.5.0 6Apr09 * Started. * Worked. 7Apr09 * Refined to ignore "|" in trailing comments. 8Apr09 * Deleted superfluous EMPTY-LFPARSE-AREA from AAMACOUNT. 26Apr09 * Changed file name from AAMAcount.fs to AAma-count.fs This quick and dirty utility was inspired by Albert van der Horst. It counts the basic kinds of lines in text source files for Martinus Veltman's Ann Arbor macro assembler, AAma, and accumulates totals for successive files. See the example at the end. The point of the #OP-SUBLINES count is that Veltman assembly language supports multiple ops on the same line, separated by "|". There is a rough assumption that any line which is not empty or a comment contains pseudo-ops or ops. This is not true, for example, for lines in literal text blocks. Lines with single ops/pseudo-ops are included in #OP-SUBLINES. Comments in a line are introduced by "*", when it's the first nonwhitespace character, or by ";". A "|" embedded in a trailing comment is ignored. If the rest of a line following the last nonignored "|" is all whitespace or a comment, that technically counts as a subline, but shouldn't occur. Whitespace also gets counted if it's the only thing before the first "|" or between successive "|"'s. This file is mostly ANS Forth compatible up to case dependence, and the use of [UNDEFINED] and REQUIRED in the libraries it calls. ) 1 constant MAX-FILE-DEPTH s" lfinput.fs" included \ loads parsing.fs s" mstrings-store.fs" included \ loads mstrings-srep.fs, mstrings-cat.fs 128 constant /file-name create file-name /file-name allot \ mstring buffer : 0! ( addr -- ) 0 swap ! ; : 1+! ( addr -- ) 1 swap +! ; variable #lines variable #empty-lines \ includes all-white lines variable #comment-lines variable #op-sublines : 0file-counts ( -- ) #lines 0! #empty-lines 0! #comment-lines 0! #op-sublines 0! ; 0file-counts : .file-counts ( -- ) cr ." file " file-name mcount type cr ." #lines " #lines @ . cr ." #empty-lines " #empty-lines @ . cr ." #comment-lines " #comment-lines @ . cr ." #op-sublines " #op-sublines @ . ; variable #files #files 0! variable tot#lines tot#lines 0! variable tot#empty-lines tot#empty-lines 0! variable tot#comment-lines tot#comment-lines 0! variable tot#op-sublines tot#op-sublines 0! : .totals ( -- ) cr ." TOTAL cr ." #files " #files @ . cr ." #lines " tot#lines @ . cr ." #empty-lines " tot#empty-lines @ . cr ." #comment-lines " tot#comment-lines @ . cr ." #op-sublines " tot#op-sublines @ . ; : open-linestream ( name.s -- ) r/o open-file throw to lfid ; : close-linestream ( -- ) lfid close-file throw ; : lfpa-empty? ( -- flag ) lfparse-area@ nip 0= ; : lfpa-skip ( char -- ) lfparse-area@ rot skip lfparse-area! ; create {*;} char * c, char ; c, 0 c, create {|;} char | c, char ; c, 0 c, : lfpa-{}starts ( &chars -- char|0 ) lfparse-area@ rot {}starts -rot lfparse-area! ; : lfpa-{}seek ( &chars -- char|0 ) lfparse-area@ rot {}seek -rot lfparse-area! ; : count-sublines ( -- ) BEGIN #op-sublines 1+! {|;} lfpa-{}seek [char] | <> UNTIL ; : accumulate ( -- ) #lines @ tot#lines +! #empty-lines @ tot#empty-lines +! #comment-lines @ tot#comment-lines +! #op-sublines @ tot#op-sublines +! #files 1+! ; : AAMAcount ( name.s -- ) 2dup file-name /file-name m! 0= ABORT" ***FILE NAME TOO LONG" open-linestream 0file-counts BEGIN lfrefill WHILE #lines 1+! bl lfpa-skip lfpa-empty? IF #empty-lines 1+! ELSE {*;} lfpa-{}starts IF #comment-lines 1+! ELSE count-sublines THEN THEN REPEAT close-linestream accumulate .file-counts ; false [IF] \ count Schoonschip lines s" Anneke.a" AAMAcount s" Athead.a" AAMAcount s" Code.e" AAMAcount s" Exec.a" AAMAcount s" Gammas.a" AAMAcount s" Helene.a" AAMAcount s" Hugo.a" AAMAcount s" Inlay.a" AAMAcount s" Inp.a" AAMAcount s" Intask.a" AAMAcount s" Lees.a" AAMAcount s" Lovbug.a" AAMAcount s" Martijn.a" AAMAcount s" Messa.a" AAMAcount s" Number.a" AAMAcount s" Outask.a" AAMAcount s" Outlay.a" AAMAcount s" Readin.a" AAMAcount s" Schoon.a" AAMAcount s" Schoonschip.a" AAMAcount s" Schrijf.a" AAMAcount s" Schuif.a" AAMAcount s" Setz.a" AAMAcount s" Smacro.e" AAMAcount s" Statis.a" AAMAcount s" Tafman.a" AAMAcount s" Test.e" AAMAcount s" Wrong.a" AAMAcount cr .totals [THEN]