Deutsch   English   Français   Italiano  
<cd465c66efca71557414235266b368ed@www.novabbs.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth
Subject: Re: Managing custom words [Re: "Back & Forth" is back!]
Date: Mon, 2 Dec 2024 20:40:25 +0000
Organization: novaBBS
Message-ID: <cd465c66efca71557414235266b368ed@www.novabbs.com>
References: <nnd$0729bd17$4f184982@a8d623d456fa3140> <vhij1o$1uuek$1@dont-email.me> <vhq912$17shb$1@dont-email.me> <dfcc6e20ea84a306917427e430df2060d66ff648@i2pn2.org> <2b5b872a1b22c79c145835221089ab24@www.novabbs.com> <nnd$549643c7$6fbb6e4e@1b875ad64c871ecb>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="976557"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="J+nubxJRM7ncpF4l6KLO+OONWmFAYJHVJegfwQXJ8vc";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$LQfvVpYN7PT1T0b2M6AULOhNtvavP8tl6.Vwia4hMm.qXMCPuNtD2
X-Rslight-Posting-User: 4e0dc1fdad1ead10b39e7eb5db19bf73d73e3ab3
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 3833
Lines: 79

On Mon, 2 Dec 2024 18:14:14 +0000, Hans Bezemer wrote:
[..]
> I'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~ ;