\ whatis_doc extraction for Risc_OS

decimal

only forth also hidden definitions
: w_doc    p" <Forthmacs$Dir>.risc_os.whatis_doc" ;
: w_ind    p" <Forthmacs$Dir>.risc_os.whatis_ind" ;

128 32 - cells constant  /index
/index buffer: index
260    buffer: linebuf

variable index-read index-read off

: ?read-index	( filename -- )
	index-read @ 0=
	if	w_ind read-open
		index /index erase
		index /index ifd @ fgets
		/index <> abort" Read failure on whatis_ind"
		ifd @ fclose
		index-read on
	then ;
: dropline	( -- )		newline ifd @  fskiptill  ;
: getline	( -- line )	linebuf newline ifd @  fgettill ;
: showit	( str -- )	". space getline ". cr	getline ". cr  ;

: (>index	( str -- adr )	1+ c@  bl - cells index + ;
: >index	( str -- off)	(>index @ ;
: file-search	( str -- str found? )
	begin	pad ifd @ fgetword over "=
		if true exit then  dropline dropline
		eof? if false exit then
	again ;
: no-help	( str -- )
	".  ."  is not described in the glossary file whatis_doc"  cr ;
: (whatis	( str -- )
	?read-index
	w_doc read-open
	dup >index   ( str file-offset) dup 0<
	if	drop no-help
	else	ifd @ fseek   ( str)
		file-search   ( str flag)
		if  showit  else  no-help then
	then
	ifd @ fclose ;

variable tell-index
: indexes	(s -- )
	index /index erase
	w_doc read-open  ifd @ 0= abort" Can't find whatis_doc"
	begin	eof? 0=
	while	ifd @ ftell >r
		getline  dup >index
		if	drop
		else	(>index r@ swap !
		then
		dropline r> drop
	repeat	ifd @ fclose  ifd off
	w_ind new-file
	index /index ofd @  fputs  ofd @ fclose	ofd off ;

only forth hidden also forth definitions

: (cold-hook	(cold-hook index-read off ;  ' (cold-hook is cold-hook 
: whatis  \ word  ( -- )
	blword (whatis ;

only forth also definitions
