*** EXPLORE.CMD - ROOT PROGRAM FOR THE EXPLORATION ON THE GENEOLOGICAL DATA BASE.
***  version 1.0

*** change the following line to suit your installation ***
SET DEFAULT TO B:

*** GETTING STARTED ***
RELEASE ALL
USE PERSONS INDEX REF,FATHER,MOTHER,NAME
SET TALK OFF
SET BELL OFF
erase
store '0000' to curper
store '1111' to m1
store t to cont
store "N" to command
store f to didhelp
@ 12,0 say "type (H)elp to see what the commands listed below"
@ 14,11 say "allow you do."
@ 4,10 say "G E N E A L O G Y "
@ 6,0 SAY "copyright 1984 by S. Washburn"
@ 7,0 say "for public domain use only"

*** main loop ***

do while cont
set intensity on
If .not. didhelp
   *** see what he wants to do. ***
   @ 22,0
   @ 22,0 say 'ENTER A COMMAND ->NRGBFMSCAELQ 8426<- H = Help ?' GET COMMAND PICTURE '!'
   read
endif
store F to didhelp

do case

Case command ="A"
	set carry on
	append
	store ref:no to m1
	store ref:no to curper
	if val(curper)
		do explore1
	endif
	set carry off   	

case command = "R"
   set intensity on
   if val(curper)<>0
      store curper to M1
   endif
   @ 22,0
   @ 22,0 say "enter a person's reference number?" get M1 picture "9999"
   read
   store M1 to curper
   if val(m1)<>0
      do explore1
   endif

case command ="N"
   DO NS

case command ="C"
   if val(m7)>0 .and. childcount>0
	store M7 to curper
	store M7 to M1
	do explore1
   endif

case command ="Q"
   store f to cont

case command ="G"
   if val(curper)<>0
      store curper to m1
      do explore1
   endif

case command ="E"
	find &curper
	if #
		store str(#,4) to line
		edit &line
		store ref:no to m1
		store ref:no to curper
	endif
	if val(curper)
		do explore1
	endif	

case command ="F"
   if val(m2)
      store m2 to curper
      store m2 to M1
      do explore1
   endif

case command = "L"
	store " "to command
	set format to list
	read
	set format to screen
	if command $ "Nn"
		erase
		set print on
		set index to name
		list last:name, first:name,"B:",$(str(birth:date,8),1,4),"ref=",ref:no off
		set print off
	endif
	if command $ "Rr"
		erase
		set print on
		set index to ref
		list ref:no, trim(last:name), trim(first:name),"B:",$(str(birth:date,8),1,4) off
		set print off
	endif
	set index to ref,father,mother,name
	if val(curper)
		do explore1
	endif	

case command ="M"
   if val(m3)
      store m3 to curper
      store M3 to m1
      do explore1
   endif

case command ="S"
   if val(m4)
      store m4 to curper
      store m4 to M1
      do explore1
   endif

case command ="B"
   if val(curper)
	do story   	
   endif

case command $ "H?,"
   set intensity off
   do while command $ "Hh?,"
   	store " " to command
   	set format to helpexp
   	read
	if command $ "?," 
		store " "to command
		set format to helpexp2
		read
		if command $ "?,"
			store " " to command
			set format to helpexp3
			read
			if command $ "?,"
				store " " to command
				set format to helpexp4
				read
			endif
		endif
	endif
   enddo	
   set format to screen
   if val(curper)
   	do explore1
   endif
   if command <> " "
	store T to didhelp
   endif
   store !(command) to command

case command = "I"
	do newindex
	if val(curper)
		do explore1
	endif

case  command $ "8426!'{]"
   store row to nrow
   store col to ncol

*** calculate new row and collumn ***

   if command $ "8!"
     store row-1 to nrow
   else
      if command $ "2{"
         store row+1 to nrow
      else
         if command $ "4'"
            store col-1 to ncol
         else
            if command $ "6]"
               store col+1 to ncol
            endif
         endif
      endif
    endif

*** continue only if new position is on screen ***

if ncol>0 .and. Nrow>0 .and. ncol<5 .and. nrow<7
if .not. (nrow=1 .and. Ncol>2)

*** figure out the memory variable in the new cell ***

      if nrow=1
         if ncol=1
            store M2 to nref
         else
            store m3 to nref
         endif
      else
      if nrow=2
            if ncol=1
              store M1 to nref
            else
               if ncol=2
                  store m4 to nref
               else
                  if ncol=3
                     store m5 to nref
                  else
                     if ncol=4
                        store m6 to nref
                     endif
                  endif
               endif
            endif
        else
        if nrow>2
*set echo on
*set step on
           store (ncol-1)*4+nrow-2 to child1
           if child1>childcount
              store "0" to nref
           else
              store str(child1+6,2) to child
              if val(child)<10
                 store $(child,2,1) to child
              endif
              store m&child to nref
           endif
         endif
       endif
     endif
		**** DEBUG LINES	
		*set echo off
		*set step off

*** continue only if cell is occupied ***

if val(nref)<>0

*** display marker at new position ***

   @ &prow, &pcol say " "
   store str((ncol-1)*26,2) to pcol

      if nrow=1
         store "2" to prow
      else
         if nrow=2
            store "6" to prow
         else
            if nrow>2
               store str(10+(nrow-3)*3,2) to prow
            endif
         endif
       endif

   set intensity off
   @ &prow,&pcol say '*'

   store nrow to row
   store ncol to col
   store nref to curper

endif
endif
endif

	***** DEBUG LINES
	** @ 23,0 say 'nref='+nref+' curper='+curper+' chcnt=';
	** +str(childcount,2)+' '+str(row,2)+' '+str(col,2)

case command="Z"
	set format to ghost
	read
	set format to screen
	if val(curper)
		do explore1
	endif

otherwise
   @ 22,0
   @ 22,0 say command+" command unknown. Type any key"
   wait

endcase

if .not. didhelp
	store " " to command
endif

enddo

return

