#!/usr/bin
set lib [list -I/usr/include -L/usr/lib ]
# Some global variables
set ht [winfo vrootheight .];
set wd [winfo vrootwidth .];

#set this_host [exec /usr/bin/uname ]
set mesg1 "/* The bulk of the code is omitted in this window */"
set mesg2 "/* Only the relevant portions are shown here */"
set newline \n
set PI 3.142857
set tcl_precision 8
set killcmd "kill -USR2"

# set size and position of concept windows and main window and chapters
if { $ht <= 1000 } {
     if { $wd <= 1200} {
  set wingeometry [format "%sx%s+%s+%s" 500 500 575 25]
  # set main window and chapter positions
  set winX -30
  set winY -40
  set wingeometry_lightmodule 500x550+525+2
    } 
 } else {
  set winX -30
  set winY -15
  set wingeometry [format "%sx%s+%s+%s" 600 500 575 25 ]
  set wingeometry_lightmodule 600x675+625+10
    }

#set wingeometry 700x640+525+0
#define font for each concept widget
set Cfont "*times-medium-r-*-*-12*"
#****************************************************************************
# Setup tags to control display of text in the display

proc backtag {name start finish} {

# Sets the background color for the selection to white in the file
# called with the name of the text widget, the start and finish points

  $name tag add backcolor \
     $start $finish
  $name tag configure \
  backcolor -background white

    }

proc redtag {name start finish} {
# Sets the foreground color to red for the selection in the file
# called with the name of the text widget, the start and finish points

  $name tag add redcolor \
     $start $finish
  $name tag configure \
   redcolor -foreground red

    }
proc greentag {name start finish} {
# Sets the foreground color to green for the selection in the file
# called with the name of the text widget, the start and finish points

  $name tag add greencolor \
     $start $finish
  $name tag configure \
   greencolor -foreground darkgreen

    }
proc bluetag {name start finish} {
# Sets the foreground color to blue for the selection in the file
# called with the name of the text widget, the start and finish points

  $name tag add bluecolor \
     $start $finish
  $name tag configure \
   bluecolor -foreground blue

    }
proc underlinetag {name start finish} {
# Underlines from character start to character finish in the file 
# specified in the variable name
  $name tag add underline1 \
     $start $finish
  $name tag configure \
  underline1 -underline 1
    }
proc functag {name start finish} {
# Sets the foreground color to red for the selecition in the file
# It also italicizes the text.
# Called with the name of the text widget, the start and finish points
 
 $name tag add ogltag \
     $start $finish
  $name tag configure \
  ogltag -font "-*-*-medium-i-normal--14-140-*-*-*-*" -foreground Red
    }
#*****************************************************************************
#set up library linkages based on the operting system i.e. miller or SGI
#switch $this_host {
#IRIX { set lib [list -lglut -lGL -lGLU -lm -lX11 -lXext -lXmu]}
  
 #default { set lib [list -I/users/proj/guha/mesa/Mesa-2.3/include -L/users/pro
#j/guha/mesa/Mesa-2.3/lib -lglut -lMesaGLU -lMesaGL -lm -lX11 -lXext -lXmu] }
#}

#****************************************************************************
# The following procedure creates label widgets associates them with a name
# the text to display, font, foreground color, background color, x, and y
# padding distances and anchorpoints with regards to the frame, the wrap
# length, and the type of justification

proc createlabel {name text font colorf colorb xpad ypad anchpoint length just} {
    global .main
 
# declare the .main window as global and call it.

    label $name -text $text -font $font -foreground $colorf \
	-background $colorb -wraplength $length -justify $just 

    pack $name -pady $ypad -padx $xpad -anchor $anchpoint
}

#**************************************************************************
# The following procedure takes a list which contains all the processes forked
# out and then goes through the list deleting the processes

proc killprocess1 {listname} {
    foreach i $listname  { 
        exec kill -9 $i }
}
	
#***************************************************************************
# The following procedure takes as input a string 'name' and an integer value
# width. it then creates a frame with the name and required width. Finally
# we pack the frame to the top of the window, fill it along the x direction
# and anchor it to the west
 
proc createframe {name width} {
     frame $name -relief raised -borderwidth $width

     pack $name -side top -fill x -anchor w 
}

#****************************************************************************
# The following procedure is called to setup a global text widget by the name
# of .textdisplay.  Once this is setup with the right scroll bars, and fonts
# and spacing and width etc, we can keep writing text to this screen from
# files 

proc createtextwidget {font colorf colorb xpad ypad anchpoint} {
text .textdisplay -font "-*-*-medium-r-normal--14-140-*-*-*-*"\
                   -foreground black -background white -wrap word -width 55\
                 -yscrollcommand ".scroll set"

#text .textdisplay -foreground black -background white -wrap word -width 55\
#                 -yscrollcommand ".scroll set"
#text .textdisplay -font $font -foreground $colorf -background $colorb\
#        -wrap word -width 55  -yscrollcommand ".scroll set"
   scrollbar .scroll -command ".textdisplay yview"
# a wrap width of 55 characters is set up.

   pack .scroll -side right -fill y
   pack .textdisplay  -anchor $anchpoint -side left -fill both -expand true -pady $ypad -padx $xpad 
}

#****************************************************************************
# The following procedure is called to display text The windowname where
# the text is to be displayed, the font name, the foreground and background
# colors, and the padding and anchorpoints are provided.
# Also ability to scroll down in the y direction is provided. 

proc displaytext {fname} {
  
  .textdisplay config -state normal
  .textdisplay delete 1.0 end  
   
   
#*****************************************************************************
# The following lines of code, actually open the text file to be read from
# this is provided by $fname. its opened for read only access and then
# the contents are inserted into the text window which is adressed using the
# variable $windowname. note we insert starting at character 1.0
# Also we disable editing of this text window so the user can only read from
# this window.

   set ftemp [eval open $fname r]
   set a [eval read -nonewline $ftemp]
   close $ftemp
  
    .textdisplay insert 1.0 "$a"
    .textdisplay config -state disabled
}

#******************************************************************************
#The following procedure takes as input a filename (user supplied) and
#then copies data from a text widget into this file. i.e. this procedure
# is used to write data from a text widget to disk.

proc write_file {filename data } {
  set fileid [open $filename "w"]
  puts $fileid $data
  close $fileid
    }

#******************************************************************************
#The following procedure takes as input a text widget and the filename to
#write to, copies the data in the textwidget to a variable 'data' and then
#calls thee above procedure i.e. write_file to write from the variable
#data to the filename

proc save_text { textwidget filename } {
  
  set data [$textwidget get 1.0 end]
  write_file $filename $data
}

#****************************************************************************
#The following procedure takes as input a file name which would normally
#contain process id's, one per line.  Then it goes through the file
#killing the processes and finally deletes the file

proc killprocess { filename } {
  if { [ file readable $filename] } {
    set fileid [open $filename "r"]
# are we at the end of file 
  while { [ eof $fileid] != 1 } {
     gets $fileid process
     set cmd "kill $process"
     catch { eval exec $cmd } 
     
  }
  close $fileid
}
  
  catch { exec rm -f $filename }  
}

#*****************************************************************************
# The following procedure takes as input the pid and the file name and
# creates a new file by the filename if one doesnt already exist and stores
# the pid in it.  If the file exists this procedure will just append
# to the file
proc procfile { proc filename} {
  set fileid [ open $filename "a"]
  puts $fileid $proc
  close $fileid

}
# Do some preliminary clean up . remove linking files if any are present
# in the directory.
catch { exec rm -f "link" }  
catch { exec rm -f "link1" }   
catch { exec rm -f "link2" }
catch { exec rm -f "link3" }











































