Warning: this is a htmlized version!
The original is across this link.
#######
#
# E-scripts on PForth, TinyScript/Minotaur, PFE and GForth.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/a/e/forth.e>
#           or at <http://angg.twu.net/e/forth.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/a/.emacs[.html]>,
#                 <http://angg.twu.net/a/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######





######
#
# GForth 0.4.0 (potato, on hamm)
# 99dec03
#
######

# (find-vldifile "gforth.list")
# (find-fline "/usr/doc/gforth/")

# (code-c-d "gfshare" "/usr/share/gforth/0.4.0/")
# (find-gfsharefile "")

# (find-es "zsh" "heredoc")
# (find-gfsharefile "kernel/comp.fs" "Defers")

heredoc /tmp/teste.fs -m 766 <<'---'
#! /usr/bin/gforth
: teste 40 11 at-xy ." Oi" ;
teste
bye
---

/tmp/teste.fs


gforth <<'---'
: teste 40 11 at-xy ." Oi" ;
:noname   defers 'cold
  teste  bye ;  is 'cold
savesystem /tmp/teste.fi
bye
---

gforth -i /tmp/teste.fi






########
#
# x3j14 (pdf)
#
########

# (find-fline "/snarf/ftp/ftp.uu.net/vendor/minerva/x3j14/")
gv /snarf/ftp/ftp.uu.net/vendor/minerva/x3j14/drafts/dpans99a.pdf &




########
#
# gforth 0.3.0 hamm
#
########

pdsc /debian/main/source/interpreters/gforth_0.3.0-3.dsc
cd /usr/src/gforth-0.3.0/

dpkg -i ~/HASH/gforth
# (code-c-d "g4" "/usr/share/gforth/0.3.0/" "gforth")

# (find-g4node "Top")
# (find-g4file "")
# (find-g4tag "words")

words cr


context @ @ name>string
.s
nip 2 + +
.s
.name
cr

0 context @ .s name>string .s

: vords ( -- ) \ tools
    cr 0 context @
    BEGIN
	@ dup
    WHILE
	2dup name>string ~~ nip 2 + dup >r + 
	drop
	dup ~~ .name cr r> rot + swap
    REPEAT
    2drop ;
vords

# (find-g4node "Concept Index" "debug tracer")
# (find-g4node "Emacs and Gforth")
# (find-fline "/etc/emacs/site-start.d/50gforth.el")
# (find-fline "/usr/share/emacs/site-lisp/gforth.el")

: foo
    cr 0 context @
    @
    2dup name>string nip 2 + dup >r + 
    dup .name cr r> rot + swap ;
foo cr

# (forth-mode)
cd /usr/src/gforth-0.3.0/
cd /usr/share/gforth/0.3.0/

# (find-g4file "debug.fs")
# (find-g4file "debugging.fs")




#############
#
# GForth 0.3.0
#
#############

cd /usr/src/
rm -Rv gforth-0.3.0/
tar -xvzf /snarf/ftp/prep.ai.mit.edu/pub/gnu/gforth-0.3.0.tar.gz
cd /usr/src/gforth-0.3.0/
./configure |& tee oc
# segfault loop at:
# (find-gffile "om" "-o gforth-ditc")
# (find-gffile "gforth-makeimage")
# (find-gffile "Makefile" "GFORTHD=")
# (find-gffile "om" "-o engine-ditc.o")
# (find-gffile "om" "-o main-ditc.o")
# (find-gffile "om" "-o io.o")
# (find-gffile "om" "-o memcasecmp.o")
# (find-gffile "engine.c")
# (find-gffile "main.c")
# (find-gffile "io.c")
# (find-gffile "memcasecmp.c")

cd /usr/src/gforth-0.3.0/
rm -v engine-ditc.o main-ditc.o io.o memcasecmp.o
make DEBUGFLAG=-g gforth-ditc |& tee omgd
make DEBUGFLAG=-g gforth.fi |& tee omgf

make |& tee om

make install |& tee omi


: foo dup * ;
: fee dup foo * ;
4 variable qa

' foo xt-see
' qa seevar
' foo S" bar" .defname
' foo S" bar" .defname drop drop drop drop drop drop drop

\ (find-g4file "debug.fs" ": dbg")

# (find-esfile "forth.e")
# (find-g4tag ".s")

# (find-g4tag ".name")
# (find-g4tag "bounce")





######
#
# GForth 0.4
#
######

dpkg -i $SDEBIAN/dists/potato/main/binary-i386/interpreters/gforth_0.4.0-2.deb
cd /usr/share/gforth/0.4.0/
cp TAGS TAGS.0
# (find-gffile "TAGS.0")
# (find-gffile "TAGS")

cd /usr/share/gforth/0.4.0/
perl -nle 's:debian/tmp/usr/share/gforth/0.4.0/::; print $_' < TAGS.0 > TAGS

# (find-gftag "(type)")
# (find-gftag "count")

mkdir -p /usr/share/gforth/0.4.0/debian/
ln -s /  /usr/share/gforth/0.4.0/debian/tmp

pdsc $SDEBIAN/dists/potato/main/source/interpreters/gforth_0.4.0-2.dsc
find * -type f | sort > .files
grep '\.fs$' .files   > .files.fs


debian/rules binary |& tee odrb
# (find-fline "$SDEBIAN/dists/potato/main/source/interpreters/gforth_0.4.0-2.diff.gz")
# (find-gffile "odrb")
# (find-gffile "odrb" "gforth.fi")
# (find-gffile "gforthmi" "savesystem")
# (find-gffile "gforthmi2" "savesystem")

# (find-gffile "Makefile" "\ngforth-ditc")

# (find-gfstag "savesystem")

cat > /tmp/x <<'---'
#!/bin/bash
cd /usr/src/gforth-0.4.0/
GFORTHD="./gforth-ditc -p .:." GFORTH="./gforth-ditc -p .:. -i kernl32l.fi startup.fs" ./gforthmi2 gforth.fi  --die-on-signal -p ".:~+:." -i kernl32l.fi startup.fs
---
chmod 777 /tmp/x
/tmp/x > ~/o

# (find-gfnode "Top")
# (find-gfnode "Threading Words")
# (find-gfnode "Threading")
# (find-gfnode "Tokens for Words")
# (find-gfstag "(type)")

# (find-vldifile "gforth.list")
# (find-fline "/usr/share/gforth/0.4.0/")
# (find-fline "/etc/emacs/site-start.d/50gforth.el")
# (find-fline "/usr/share/emacs/site-lisp/gforth.el")

# (find-gffile "prim" "dlopen")
# (find-gffile "prim" "SYSCALL")
# (find-gfsrcfile "prim.b" "SYSCALL")
# (find-gfsrcfile "Makefile" "engine/prim.i:")
# (find-gfsrcfile "engine/prim.i")
# (find-gfsrcfile "engine/engine.c")

lynx /snarf/http/www.complang.tuwien.ac.at/forth/index.html
lynx /snarf/http/www.complang.tuwien.ac.at/forth/dpans-html/dpansf.htm




#####
#
# gforth_rr
#
#####

#  «gforth_rr»

# (find-gfnode "Top")
# (find-gfnode "Word Index")
# (find-gfnode "Words for Including")
# (find-fline "~/FORTH/emacs.rr")

cd ~/bin/
gforth <<'---'
: rr s" ~/FORTH/emacs.rr" included ;
savesystem gforth_rr
bye
---
chmod 755 gforth_rr



# (find-gffile "")
# (find-gfsrcfile "")
# (find-fline "~/FORTH/tcl.fs")

# (find-node "(gforth)Automatic Generation")





#####
#
# TinyScript2 (pforth+Tcl+Perl+Python+...)
# 99sep??
#
#####

# (code-c-d "ts2" "/usr/src/ts2/")

rm -Rv /usr/src/ts2/
cd /usr/src/
tar -xvzf $S/http/mini.net/pub/ts2-19990704.tar.gz
cd /usr/src/ts2/

# Remove some misterious binary files
rm -v $(find * | grep 'mcp$')

cd /usr/src/ts2/forth/csrc/
diff -b -c -rs . /usr/src/pforth/csrc/ | tee ~/o
# diff -b -c -rs . /usr/src/pforth-21/csrc/ | tee ~/o

cd /usr/src/ts2/forth/csrc/
for i in *; do
  if [[ -e /usr/src/pforth/csrc/$i ]] then
    # tkdiff $i /usr/src/pforth/csrc/$i
  else
    echo Only in ts2: $i
  fi
done


# lynx /usr/src/ts2/minotaur.html
# (find-ts2file "minotaur.html" "ShLib")
agrep -l ShLib $(find *)

# (find-ts2file "forth/csrc/pfcustom.c")


psner -nc -np http://mini.net/pub/ts2/
# (find-fline "$S/http/mini.net/pub/ts2/")


forTcl
forPl

lynx http://www.dcs.gla.ac.uk/~meurig/TclHaskell/





#####
#
# Minotaur/tinyscript
# 99nov17
#
#####

# (find-fline "$S/http/mini.net/pub/")
# (find-fline "$S/http/mini.net/pub/ts2-19990704.tar.gz")
# (find-fline "$S/http/mini.net/pub/ts2/")
# (find-fline "$S/http/mini.net/pub/ts2/index.html" "Tcl (Windows):")

# (find-fline "/usr/src/ts2/")
# (find-fline "/usr/src/ts2/forth/")
# (find-fline "/usr/src/ts2/forth/csrc/")

# (find-node "(make)Selective Search")
# (find-fline "/usr/src/ts2/forth/gnuc/Makefile")

#  «ts2»

rm -Rv /usr/src/ts2/
cd /usr/src/
tar -xvzf $S/http/mini.net/pub/ts2-19990704.tar.gz
cd /usr/src/ts2/
find * -type f | sort > .files

cd /usr/src/ts2/forth/gnuc/
make -f ../gnuc/Makefile pforth		|& tee omp
make -f ../gnuc/Makefile dict		|& tee omd

cd /usr/src/ts2/forTcl/gnuc/
./configure --with-tcl=/usr/lib		|& tee oc
sed 's/gluetcl.o/pfcustom.o common.o/' < Makefile > Makefile-
diff Makefile{,-}

cd /usr/src/ts2/forTcl/gnuc/
make -f Makefile-			|& tee om

cd /usr/src/ts2/forTcl/gnuc/
strace-to ~/s expect -c '
  load ./forTcl.so
  forTcl::init
  puts [forTcl::eval {123 456 +}]
  puts [forTcl::eval {123 456 + .}]
'

cd /usr/src/ts2/forTcl/gnuc/
expect -c ' load ./forTcl.so; forTcl::init
  set a [forTcl::eval {2 . 3 . 4 5}]
  puts b
  puts $a
  puts c
'

# (find-ts2file "forth/csrc/")
# (find-ts2file "forTcl/")
# (find-ts2file "forTcl/initTcl.c" "int Fortcl_Init(")
# (find-ts2file "forTcl/gnuc/")
# (find-ts2file "forTcl/gnuc/om" "forTcl.so")
# (find-ts2file "minotaur/")
# (find-ts2file "minotaur/gnuc/")




# How I discovered which files to include in forTcl/gnuc/Makefile:
# (find-ts2file "forTcl/gnuc/om")

cd /usr/src/ts2/
agrep CustomFunctionTable $(<.files)

cd /usr/src/ts2/
agrep initForth $(<.files)



cd /usr/src/ts2/
# (find-ts2file ".files")
# (find-ts2file "forTcl/gnuc/")

# (find-fline "/usr/src/ts2/forTcl/")
# (find-fline "/usr/src/ts2/forTcl/gnuc/")

# (find-fline "/usr/src/ts2/minotaur/")

# (find-ts2file "forth/csrc/pfcustom.c")
# (find-ts2file "forth/csrc/pfcustom.c" "CreateGlueToC( \"ShLibOpen\",   0")

# (find-ts2file "forTcl/initTcl.c" "Fortcl_Init")
# (find-ts2file "forTcl/initTcl.c" "&init_forTcl")






#####
#
# Minotaur/tinyscript: gdb'ing
# 99nov30
#
#####

#  «ts2b»
# (find-es "forth" "ts2")
# (find-ts2file "forTcl/gnuc/")
# (find-ts2file "forTcl/gnuc/Makefile")

rm -Rv /usr/src/ts2/
cd /usr/src/
tar -xvzf $S/http/mini.net/pub/ts2-19990704.tar.gz
cd /usr/src/ts2/
find * -type f | sort > .files

cd /usr/src/ts2/forTcl/gnuc/
./configure --with-tcl=/usr/lib		|& tee oc
sed 's/gluetcl.o/pfcustom.o common.o/' < Makefile > Makefile-
diff Makefile{,-}

cd /usr/src/ts2/forTcl/gnuc/
echo -n > .before-make; sleep 2
make CC='gcc -g -DPF_USER_CUSTOM' -f Makefile-		|& tee om
find ../.. -name '*.[ch]' -and -anewer .before-make > .files.ch
etags $(<.files.ch)

cd /usr/src/ts2/forTcl/gnuc/
expect -c '
  # exec $env(HOME)/TCL/attachgdb expect
  # load ./forTcl.so
  load $env(PWD)/forTcl.so
  exec $env(HOME)/TCL/attachgdb expect
  forTcl::init
  puts [forTcl::eval {123 456 +}]
  puts [forTcl::eval {123 456 + .}]
'



# (find-ts2file "forTcl/")
# (find-ts2file "forTcl/initTcl.c" "forTcl::init")

# (code-c-d "4tcl" "/usr/src/ts2/forTcl/gnuc/")
# (find-4tcltag "eval_forTcl")
# (find-4tclfile "../initTcl.c" 77)

    if (EDRXOBJ_FLAG) {
      Tcl_SetObjResult(interp, Tcl_NewStringObj(EDRXOBJ_PTR, EDRXOBJ_LEN));
      EDRXOBJ_FLAG = 0;
      return 0;
    }

# (find-4tclfile "../../forth/csrc/")
# (find-4tclfile "../../forth/csrc/common.h" 38)

extern int EDRXOBJ_FLAG, EDRXOBJ_LEN;
extern char *EDRXOBJ_PTR;

# (find-4tclfile "../../forth/csrc/pfcustom.c")



# (find-angg ".emacs" "f3")

%*
br TclLoadFile
c
info share
%*

# (find-tclfile "unix/" "tclLoadDl.c")
# (find-node "(gdb)Files" "`load FILENAME'")
# (find-node "(gdb)Files" "`info share'")

strace-to ~/s






#####
#
# Minotaur/tinyscript: returning strings
# 99nov30
#
#####

rm -Rv /usr/src/ts2/
cd /usr/src/
tar -xvzf $S/http/mini.net/pub/ts2-19990704.tar.gz
cd /usr/src/ts2/
find * -type f | sort > .files

cd /usr/src/ts2/forTcl/gnuc/
./configure --with-tcl=/usr/lib		|& tee oc
sed 's/gluetcl.o/pfcustom.o common.o/' < Makefile > Makefile-
diff Makefile{,-}

cd /usr/src/ts2/forTcl/gnuc/
cp -v ~/PFORTH/initTcl.c ..
cp -v ~/PFORTH/{common.h,pfcustom.c} ../../forth/csrc/

cd /usr/src/ts2/forTcl/gnuc/
echo -n > .before-make; sleep 2
make CC='gcc -g -DPF_USER_CUSTOM' -f Makefile-		|& tee om
find ../.. -name '*.[ch]' -and -anewer .before-make > .files.ch
etags $(<.files.ch)

cd /usr/src/ts2/forTcl/gnuc/
# strace-to ~/s \
expect -c '
  load $env(PWD)/forTcl.so
  forTcl::init
  # forTcl::eval {words}
  forTcl::eval {: shlibcall2 33 ;}
  # forTcl::eval {: mmm s" mmm -- aaah." ; mmm SetObjPtr}
' |& tee ~/o



# (find-fline "~/PFORTH/")
# (find-ts2file "forTcl/gnuc/")
# (find-ts2file "forTcl/gnuc/om")
# (find-ts2file "forth/csrc/")



cd /usr/src/ts2/forTcl/gnuc/
expect -c '
  # exec $env(HOME)/TCL/attachgdb expect
  # load ./forTcl.so
  load $env(PWD)/forTcl.so
  exec $env(HOME)/TCL/attachgdb expect
  forTcl::init
  puts [forTcl::eval {123 456 +}]
  puts [forTcl::eval {123 456 + .}]
'






#####
#
# pforth 21 (potato, on slink)
# 99nov19
#
#####

#  «pforth»
# (find-es "forth" "pforth-edrx")

rm -Rv /usr/src/pforth-21/
pdsc $SDEBIAN/dists/potato/main/source/interpreters/pforth_21-2.dsc

cd /usr/src/pforth-21/
for i in docs/* README.txt; do
  tr -d \\r < $i > tmpdoc
  mv -v tmpdoc $i
done
cd /usr/src/pforth-21/docs/
for i in *.htm; do
  unhtml < $i | sed -e 's/&nbsp;/ /g' -e 's/&lt;/</g' > $(basename $i .htm)
done
cd /usr/src/pforth-21/
cat >> debian/docs <<'---'
docs/pf_ref
docs/pf_tut
---
etags csrc/*.[ch]

debian/rules binary	|& tee odrb

# (find-pffile "odrb" "pforth -i")

mv -v /usr/src/pforth*.deb /usr/src/.debs/
apt-update
apti pforth

# (find-vldifile "pforth.list")
# (find-fline "/usr/doc/pforth/")



echo words		| pforth	| tee ~/o
echo see koo cr see foo | pforth	| tee ~/o

# (find-fline "~/o")
# (find-pffile "trace.fth" "KOO")

cd /usr/src/pforth/docs/
lynx 'pf_ref.htm#Single Step Trace'


# (code-c-d "pf" "/usr/src/pforth-21/")
# (find-pffile "")
# (find-pffile "csrc/")
# (find-pffile "docs/")
# (find-pffile "utils/")

# (find-pffile "see.fth")
# (find-pffile "csrc/")
# (find-pffile "csrc/pf_guts.h" 82)
# (find-pffile "system.fth" ": >CODE")
# (find-pffile "misc1.fth" ": >NAME")

(defun eepf-bounded () (interactive)
  (ee-strbounded 'write-ee "%*" "%*" "" "" "/usr/src/pforth/ee.fth"))
(global-set-key [f3] 'eepf-bounded)

cd /usr/src/pforth/
pforth ee.fth

%*
hex
cr see foo
cr ' foo .xt
cr ' foo .
cr ' foo >code .
cr ' foo >code 10 - 30 dump
%*

# (find-pffile "csrc/pf_words.c" "Stack<")



'(s e pre post &optional other-ee-file fmode)
(debug-on-entry 'eepf-bounded)
# (find-elinode "Debugging")





#####
#
# pforth-21 with my own extensions
# 99dec11
#
#####

#  «pforth-custom0»
# (find-es "forth" "pforth")

###
### Part 1: understanding pfcustom.c
###

rm -Rv /usr/src/pforth-21/
pdsc $SDEBIAN/dists/potato/main/source/interpreters/pforth_21-2.dsc
cd /usr/src/pforth-21/
for i in $(find * -name '*.[ch]' -or -name '*.fth'); do
  tr -d \\r < $i > $i.lf; mv $i.lf $i
done
etags csrc/*.[ch]
cp -v csrc/pfcustom.c csrc/pfcustom.c.orig
debian/rules build	|& tee odrbu

laf csrc/*.c objects/* 

# (find-pffile "README.txt" "PF_USER_CUSTOM")
# (find-pffile "csrc/pfcustom.c" "PF_USER_CUSTOM")
# (find-pffile "csrc/pf_cglue.c")
# (find-pffile "odrbu")

g++ -DPF_SUPPORT_FP -E csrc/pfcustom.c > csrc/pfcustom.E
grep -v '^[ 	]*$' csrc/pfcustom.E \
  | awk '{
      if ($1=="#") { verbose = ($3 ~ /csrc/); print }
      else if (verbose) { print }
    }' \
  > csrc/pfcustom.E-
agrep '"C"' $(getstrings < csrc/pfcustom.E- | sort | uniq | grep usr)


###
### Part 2: printing and inspecting pfcustom.{c,E-}
###

cd /usr/src/pforth-21/csrc/
a2ps850dj -o /tmp/o.ps pfcustom.c pfcustom.E-
cd /tmp/
make -f ~/LATEX/Makefile o.p01

cd /usr/src/pforth-21/
find * -name '*.[ch]' -or -name '*.fth' > .files.chfth
agrep LoadCustom $(<.files.chfth)

# (find-pffile "csrc/pfcustom.c")
# (find-pffile "csrc/pfcustom.E")
# (find-pffile "csrc/pfcustom.E-")

# (find-node "(gawk)Using Constant Regexps")
# grep -v '^[ 	]*$' csrc/pfcustom.E | l -S


###
### Part 3: writing my first pfcustom.c
###

cd /usr/src/pforth-21/
cat > csrc/pfcustom.c <<'--%%--'
#include "pf_all.h"
/***/
static int32 CTest0( int32 Val );
static void CTest1( int32 Val1, cell Val2 );
static int32 CTest0(int32 Val) {
  MSG_NUM_D("CTest0 (!!!): Val = ", Val);
  return Val+1;
}
static void CTest1(int32 Val1, cell Val2) {
  MSG("CTest1 (!!!): Val1 = "); ffDot(Val1);
  MSG_NUM_D(", Val2 = ", Val2);
}
/***/
void *CustomFunctionTable[]={
  (void *)CTest0,
  (void *)CTest1
};	
Err CompileCustomFunctions(void) {
/* Params are: Name in UPPER CASE, Function, Index, #rets (0/1), NumParams */
  CreateGlueToC( "CTEST0", 0, C_RETURNS_VALUE, 1 );
  CreateGlueToC( "CTAST1", 1, C_RETURNS_VOID, 2 );
  return 0;
}
--%%--
make	|& tee om

./pforth <<'---'
22 55
ctest0
ctast1
---


###
### Part 4: writing my own pf_main
###

cd /usr/src/pforth-21/
for i in csrc/*.c; do
  echo $i '->' csrc/$(basename $i .c).E-
  g++ -DPF_SUPPORT_FP -E $i \
  | grep -v '^[[:space:]]*$' \
  | awk '{
      if ($1=="#") { verbose = !($3 ~ /^..usr/); print }
      else if (verbose) { print }
    }' \
  > csrc/$(basename $i .c).E-
done

# (find-pffile "csrc/pf_main.E-" "Result = pfDoForth(")
# (find-pffile "csrc/pf_core.E-" "int32 pfDoForth(")
# (find-pffile "csrc/pf_main.c")
# (find-node "(libc)Table of Output Conversions")
# (find-pffile "om")
# (find-pffile "Makefile")

cd /usr/src/pforth-21/csrc/
cat > mypfmain.c <<'---'
#include "pforth.h"
#include <stdio.h>
#define S(ptr) (*(ptr)?ptr:0)
/* */
int main(int argc, char **argv) {
  printf("pfDoForth result: %ld\n",
	 pfDoForth(S(argv[1]), S(argv[2]), *(argv[3])&1));
}
---
g++ -DPF_SUPPORT_FP -Wall -c -o mypfmain.o mypfmain.c
g++ -o mypfmain mypfmain.o ../objects/pf{_{cglue,clib,core,inner,io,mem,save,text,words},compil,custom}.o

cd /usr/src/pforth-21/csrc/
./mypfmain ../pforth.dic '' 0
./mypfmain '' '' 1

# All standard ".o"s: in ../objects/,
# pf{_{cglue,clib,core,inner,io,main,mem,save,text,words},compil,custom}.o



###
### Part 5: replacing pfDoForth
###

# (find-pffile "csrc/pf_core.E-" "int32 pfDoForth(")
# (find-pffile "csrc/pf_core.c" "int32 pfDoForth(")

cd /usr/src/pforth-21/csrc/
cat > mydoforth.c <<'---'
#include "pf_all.h"
#include <stdio.h>
#define S(ptr) (*(ptr)?ptr:0)
/* */
int main(int argc, char **argv) {
  char *DicName = argv[1];
  cfTaskData *cftd;
  cfDictionary *dic;
  int32 Result = 0;
  ExecToken EntryPoint = 0;
  pfInitGlobals();
  cftd = pfCreateTask( (512), (512) );
  pfSetCurrentTask( cftd );
  dic = pfLoadDictionary( DicName, &EntryPoint );
  pfExecByName("AUTO.INIT");
  Result = pfRunForth();
  pfExecByName("AUTO.TERM");
  pfDeleteDictionary( dic );
  pfDeleteTask( cftd );
  return 0;
}
---
g++ -DPF_SUPPORT_FP -Wall -c -o mydoforth.o mydoforth.c
g++ -o mydoforth mydoforth.o ../objects/pf{_{cglue,clib,core,inner,io,mem,save,text,words},compil,custom}.o

cd /usr/src/pforth-21/csrc/
./mydoforth ../pforth.dic


cd /usr/src/pforth-21/csrc/
./mypfmain ../pforth.dic '' 0
./mypfmain '' '' 1




# Almost the original pfDoForth:

int32 pfDoForth(const char *DicName, const char *SourceName, int32 IfInit) {
  cfTaskData *cftd;
  cfDictionary *dic;
  int32 Result = 0;
  ExecToken EntryPoint = 0;
  pfInitGlobals();
  cftd = pfCreateTask( (512), (512) );
  if(cftd) {
    pfSetCurrentTask( cftd );
    if( IfInit ) {
      dic = pfBuildDictionary( (120000), (300000) );
    } else {
      dic = pfLoadDictionary( DicName, &EntryPoint );
    }
    pfExecByName("AUTO.INIT");
    if( EntryPoint != 0 ) {
      pfExecuteToken( EntryPoint );
    } else {
      if( SourceName == __null  ) {
	Result = pfRunForth();
      } else {
	Result = pfIncludeFile( SourceName );
      }
    }
    pfExecByName("AUTO.TERM");
    pfDeleteDictionary( dic );
    pfDeleteTask( cftd );
  }
  return Result;
}



###
### Part ??: calling Tcl from a pfcustom.c
###





#######
#
# Crim1 on PFE
# 00jan24
#
#######

#  «crim1_on_pfe»

# (code-c-d "pfe" "/usr/src/pfe-0.9.14/")
# (find-pfefile "")
# (find-pfefile "INSTALL" "of Linux, FreeBSD,")
# (find-pfefile "src/config/Linux/")

# (find-pfefile "src/config/Linux/options.mk" "ncurses")
# cd /usr/src/pfe-0.9.14/src/
# diff config/Linux/options.mk{~,}	|& tee ~/o

# (find-fline "~/crim/patchpfe.txt")
# (find-pfefile "src/config/default/depend.mk" "ENVOBJ")
# diff config/default/depend.mk{~,}	|& tee ~/o
#
# (find-fline "~/crim/patchpfe.txt" "At src/vocs.c")
# (find-pfefile "src/vocs.c" "extern const Words")
# diff vocs.c{~,}	|& tee ~/o


rm -Rv /usr/src/pfe-0.9.14/
cd /usr/src/
tar -xvzf $S/ftp/ftp.taygeta.com/Taygeta/Forth/Linux/pfe-0.9.14.tar.gz
cd /usr/src/pfe-0.9.14/src/

(
patch config/Linux/options.mk <<'%%'
20,21c20,21
< OPTIONS	=
< LIBS	= -ltermcap -lm
---
> #OPTIONS	=
> #LIBS	= -ltermcap -lm
25,26c25,26
< #OPTIONS = -I/usr/include/ncurses
< #LIBS	= -lncurses -lm
---
> OPTIONS = -I/usr/include/ncurses
> LIBS	= -lncurses -lm
%%

cp -iv ~/crim/crim.c.txt crim.c
#
patch config/default/depend.mk <<'%%'
24c24
< 		yours$o
---
> 		yours$o crim$o
%%
#
patch vocs.c <<'%%'
47c47
<   your_words;
---
>   your_words,		crim_words;
55a56
>   &crim_words,
%%
)	|& tee op

./config.sh	|& tee oc
make		|& tee om

rm -Rv /tmp/crim/
mkdir /tmp/crim/
cd ~/crim/
for i in *.txt; do cp -iv $i /tmp/crim/$(basename $i .txt); done

cd /tmp/crim/
echo "INCLUDE 1.4th BYE" > 1q.4th
echo "INCLUDE 2.4th BYE" > 2q.4th

cd /tmp/crim/
/usr/src/pfe-0.9.14/src/pfe -q 1q.4th
/usr/src/pfe-0.9.14/src/pfe -q 1-autod.4th
/usr/src/pfe-0.9.14/src/pfe -q 2q.4th
/usr/src/pfe-0.9.14/src/pfe -q 2-autod.4th





######
#
# Debugging pforth
# 00jan23
#
######

rm -Rv /usr/src/pforth-21/
pdsc $SDEBIAN/dists/potato/main/source/interpreters/pforth_21-2.dsc
cd /usr/src/pforth-21/
for i in $(find * -name '*.[ch]' -or -name '*.fth'); do
  tr -d \\r < $i > $i.lf; mv $i.lf $i
done
etags csrc/*.[ch]
cp -v csrc/pfcustom.c csrc/pfcustom.c.orig
# (find-pffile "Makefile" "$(COMPILE)")
debian/rules CDEFS=-g build	|& tee odrbu

cd /usr/src/pforth-21/
for i in csrc/*.c; do
  echo $i '->' csrc/$(basename $i .c).E-
  g++ -DPF_SUPPORT_FP -E $i \
  | grep -v '^[[:space:]]*$' \
  | awk '{
      if ($1=="#") { verbose = !($3 ~ /^..usr/); print }
      else if (verbose) { print }
    }' \
  > csrc/$(basename $i .c).E-
done

# (find-pffile "csrc/pfcustom.c" "CustomFunctionTable[] =")
cat > /tmp/4 <<'---'
: square dup * ;
20 ctest0 square .
bye
---

/usr/src/pforth-21/pforth -q /tmp/4

%*
set args -q /tmp/4
br CTest0
run
bt
%*

# (gdb "gdb /usr/src/pforth-21/pforth")





#####
#
# Linking pforth and Tcl
# 00jan30
#
#####

#  «pforth_and_tcl»

# (find-fline "~/PFORTH/")
# (find-fline "~/PFORTH/Makefile")
# (find-fline "~/PFORTH/tclpforth.c")

# The "pf_runforth" in the script below enters pforth's interactive
# mode. Use "bye" to return to Tcl.

cd ~/PFORTH/
make
cat > /tmp/test.4th <<'---'
1 2 + . cr
---
expect -c '
  load ./tclpforth.so
  init_pforth pforth.dic
  # pf_includefile /tmp/test.4th
  pf_includefile $env(HOME)/crim.fth
  # pf_runforth
  finish_pforth
  puts "bye from Tcl!"
'




# (find-pffile "docs/")
# (find-pffile "docs/pf_ref" " pf_main.c")
# (find-pffile "csrc/pf_main.c")
# (find-pffile "csrc/pf_main.c" "module from 'C' based application")
# (find-pffile "csrc/pfcustom.c")
# (find-pffile "csrc/")
# (find-pffile "")
# (find-pffile "Makefile")
# (find-pffile "odrb")
# (find-pftag "pfDoForth")

cd /usr/src/pforth-21/
cat > testmain.c <<'---'
/*
 */
#include <stdio.h>
#include "pforth.h"
int main(int argc, char **argv) {
  const char *DicName = "pforth.dic";
  const char *SourceName = NULL;
  char IfInit = 0;
  char *s;
  int32 i;
  int Result;
  pfSetQuiet(1);
  Result = pfDoForth(DicName, SourceName, IfInit);
  printf("%d\n", Result);
}
---
g++ -c -I csrc -o testmain.o testmain.c
g++ -o testmain $(ls objects/* | grep -v main) testmain.o -lm














# (find-fline "/usr/doc/mktclapp/examples/")
# (find-fline "/usr/doc/mktclapp/examples/README")
# (find-fline "/usr/doc/mktclapp/examples/Makefile")