On Mon, 2 Dec 2024 18:14:14 +0000, Hans Bezemer wrote:
[..]
Post by Hans BezemerI've ported a couple of members from the FFL, but they're HUGE!
Over 600 lines for an XML library. For comparison: my 4tH preprocessor
is a 100 lines LESS!
Who cares. My program using the lib is only 60 lines long.
-marcel
(*
* LANGUAGE : ANS Forth with extensions
* PROJECT : Forth Environments
* DESCRIPTION : Mag_Tool utility
* CATEGORY : Example
* AUTHOR : Marcel Hendrix
* LAST CHANGE : May 28, 2019, Marcel Hendrix
*)
NEEDS -miscutil
[UNDEFINED] -ffl [IF] S" ffl/xis.fs" INCLUDED [THEN]
REVISION -readxml "--- XML reader Version 0.00 ---"
PRIVATES
DOC
(*
Mag_Tool output files contain useful data between the tag
<inductance> and the tag <Windings>.
*)
ENDDOC
-- Setup the reader callback word for reading from file
-- We know the Mag_Tool output files are > 100kbytes in size (no spaces)
:NONAME ( fileid -- c-addr u | 0 )
PAD #1024000 ROT READ-FILE ?FILE
DUP IF PAD SWAP ENDIF ; =: file-reader PRIVATE
: DISPLAY-XML ( c-addr u -- )
0 LOCAL start?
0 LOCAL finished?
R/O OPEN-FILE ?FILE LOCAL handle \ Open the file
XIS-NEW LOCAL xis \ Create a XML input
\ stream on the heap
handle file-reader xis XIS-SET-READER \ Use the xml reader
\ with a file
TRUE xis XIS-STRIP! \ Strip leading and
\ trailing whitespace
\ in the text
\ parse the file
BEGIN
xis XIS-READ \ Read the next token
DUP XIS.ERROR <> OVER XIS.DONE <> AND \ Done when ready/error
WHILE
DUP XIS.START-TAG
= IF 2 PICK 2 PICK S" inductance" COMPARE-NC
0= IF TRUE TO start? CLEAR finished? ENDIF
2 PICK 2 PICK S" L_row" COMPARE-NC
0= IF TRUE TO start? CLEAR finished? ENDIF
2 PICK 2 PICK S" Windings" COMPARE-NC
0= IF CLEAR start? TRUE TO finished? ENDIF
2 PICK 2 PICK S" Layouts" COMPARE-NC
0= IF CLEAR start? TRUE TO finished? ENDIF
start? IF >S CR 2DUP TYPE S> ENDIF
ELSE DUP XIS.TEXT = finished? 0= AND ( print all text )
IF ." = " >S 2DUP TYPE S> ENDIF
ENDIF
XIS+REMOVE-READ-PARAMETERS \ remove the tokens
REPEAT
XIS.ERROR = IF CR ." Error parsing the file." ENDIF
handle CLOSE-FILE ?FILE
xis XIS-FREE ;
: do-job ( -- )
S~ MagApplication "Output.xml" out.xml~ SYSTEM
S" out.xml" DISPLAY-XML ;
:ABOUT CR .~ Try: S" out.xml" DISPLAY-XML~ ;