#!/bin/csh -f
if ($1 == "help" ) then
 echo "development aid"
 echo " "
 echo "by: maschaub"
 echo ""
 echo "Usage: develop"
 exit
endif
######################################################################
set root = /mit/cdsdev/beta/src
set workdir = /mit/cdsdev/dev/$user/work
set inboxdir = /mit/cdsdev/dev/$user/inbox

while (1)
 cd $workdir
 echo ""
 echo "clean (w)ork	clean up your work directory before betaco"
 echo "betac(o)	check out files"
 echo "(u)make		added dependencies to the makefile"
 echo "(e)macs		editor"
 echo "(q)m		build cds in /usr/tmp/cds"
 echo "(c)ds		run cds"
 echo "g(d)b		debug /usr/tmp/cds"
 echo "betac(i)	check files back in"
 echo "betaci (a)ll files"
 echo ""
 echo "The commands above are in the order that development should be done"
 echo "Enter the letter of the command or a unix command and hit return"
 echo "or just hit return to quit"
 echo ""
 echo -n "$cwd>"
 set input = "$<"
 echo ""
 echo ""

 ################################# clean work
 if ( "$input" == "w" ) then
	ls *~ *.cc *.o *.yacc *.lex *.h
	echo ""
	echo "Are you sure you want to remove these files from your work"
	echo -n "directory ('yes' or anything else to stop) ->"
	set input = "$<"
	if ( "$input" == "yes" ) then
		delete $workdir/*~
		delete $workdir/*.cc
		delete $workdir/*.o
		delete $workdir/*.yacc
		delete $workdir/*.lex
		delete $workdir/*.h
		echo "done"
	endif
 end
 endif

 ############################# betaco
 if ( "$input" == "o" ) then
	cd $root
	clear
        # print directory menu
        set counter = 0
        foreach dir (`ls`)
                echo "$counter.  $dir"
                @ counter = $counter + 1
        end
        echo ""
        echo -n "Select a module (RETURN to abort) ->"
        set input = "$<"
	if ( "$input" == "" ) end

        # find the directory
        set counter = 0
        foreach dir (`ls`)
                if ( $counter == "$input" ) then
                        cd $dir
			set module = $dir
                endif
                @ counter = $counter + 1

        end

        clear
        # print file menu
        set counter = 0
        foreach file (`ls *.h *.cc *.yacc *.lex`)
                echo "$counter.  $file"
                @ counter = $counter + 1
        end
        echo ""
        echo -n "Enter the file to check out (RETURN to abort)->"
        set input = "$<"
	if ( "$input" == "" ) end

        # find the file
        set counter = 0
        foreach file (`ls *.h *.cc *.yacc *.lex`)
                if ( $counter == "$input" ) then
			set locked = `rlog $file | grep "locked"`
			if ( "$locked" == "" ) then
				cd $workdir
				echo ""
				betaco $module $file
				echo ""
				echo "copying $file to work directory"
				cp ../inbox/$file $workdir
			else
				echo ""
				echo ""
				echo "$file is already checked out"
			endif
                endif
                @ counter = $counter + 1
        end
 end
 endif

 ################################# umake
 if ( "$input" == "u" ) then
	umake
 	end
 endif

 ################################# emacs
 if ( "$input" == "e" ) then
	emacs &
 	end
 endif

 ################################# qm
 if ( "$input" == "q" ) then
	qm
 	end
 endif

 ################################# cds
 if ( "$input" == "c" ) then
	echo -n "Enter arguments if any ->"
	set args = "$<"
	qcds $args
 	end
 endif

 ################################# gdb
 if ( "$input" == "d" ) then
	gdb /usr/tmp/cds 
 	end
 endif

 ############################# betaci
 if ( "$input" == "i" ) then
	cd $root
	clear
        # print directory menu
        set counter = 0
        foreach dir (`ls`)
                echo "$counter.  $dir"
                @ counter = $counter + 1
        end
        echo "---------------------------------------------------------------"
	echo "files currently checked out"
	echo ""
	set olddir = $cwd
	cd $inboxdir
	ls *.cc *.h *.yacc *.lex
	cd $olddir
        echo "---------------------------------------------------------------"
	echo ""
        echo -n "Select a module (RETURN to abort) ->"
        set input = "$<"
	if ( "$input" == "" ) end

        # find the directory
        set counter = 0
        foreach dir (`ls`)
                if ( $counter == "$input" ) then
                        cd $dir
			set module = $dir
                endif
                @ counter = $counter + 1

        end

        clear
        # print file menu
        set counter = 0
        foreach file (`ls *.h *.cc *.yacc *.lex`)
                echo "$counter.  $file"
                @ counter = $counter + 1
        end
        echo ""
        echo ""
        echo "---------------------------------------------------------------"
	echo "files currently checked out"
	echo ""
	set olddir = $cwd
	cd $inboxdir
	ls *.cc *.h *.yacc *.lex
	cd $olddir
        echo "---------------------------------------------------------------"
	echo ""
        echo -n "Enter the file to check in (RETURN to abort)->"
        set input = "$<"
	if ( "$input" == "" ) end

        # find the file
        set counter = 0
        foreach file (`ls *.h *.cc *.yacc *.lex`)
                if ( $counter == "$input" ) then
			set locked = `rlog $file | grep "locked"`
			if ( "$locked" != "" ) then
				cd $workdir
				echo ""
				echo "copying $file to outbox"
				cp $file ../outbox
				betaci $module $file
			else
				echo ""
				echo ""
				echo "$file is not checked out"
			endif
                endif
                @ counter = $counter + 1
        end
 end
 endif

 ############################# betaci all files
 if ( "$input" == "a" ) then
	cd $root
	clear
	echo "Please wait while I look up the module names"
	echo ""
	set olddir = $cwd
	cd $inboxdir
	foreach file (`ls *.cc *.h *.yacc *.lex`)
	  cp ../work/$file ../outbox/$file
	  # find the module with the file in it
	  unalias ls
	  foreach module (`ls /mit/cdsdev/beta/src`)
	    if (`ls /mit/cdsdev/beta/src/$module | grep $file ` != "") then
              betaci $module $file
	    endif
	  end
    	end
end
endif


 ############################# quit
 if ( "$input" == "" ) then
	exit
 endif
 
 ############################# unix command
 $input
end
