set System UNIX set jtools_src $env(jtools_src) set pos [string first " " $jtools_src] set jtools_src [string range $jtools_src $pos end] source procedures.tcl # If the relation_name is NULL, put out messages and exit if { $argc !=1 } { puts "Usage: sddl_to_html sddl_name" puts " " return } elseif { $argc == 1 } { set relation_name $argv } # change the input to lower case set relation_name [ string tolower $relation_name ] # user can input a relation name with or without .sddl suffix. set pos [string first "." $relation_name] if { $pos != -1 } { # if the suffix is not .sddl, output a message and exit if { [string first ".sddl" $relation_name] == -1 } { puts "This tool only works for sddl files." return } else { set sddl_file_name $relation_name incr pos -1 set relation_name [string range $relation_name 0 $pos } } else { # add the .sddl surffix set temp ".sddl" set sddl_file_name [concat $relation_name$temp] } puts [format "The sddl file name is:%s" $sddl_file_name] # Here is the place to open the file: jtools_src:relation.sddl # and create a new file called: relation.shtml set SDDLFileId [open_file $System $sddl_file_name $jtools_src] if { $SDDLFileId != "NULL" } { # generate the name of the output html file regsub ".sddl" $sddl_file_name ".shtml" html_file_name # open the output file if [ catch {open $html_file_name w+} HTMLFileId ] { puts "Cannot Open Output File" exit } puts $HTMLFileId "" puts $HTMLFileId "
"
       puts $HTMLFileId ""
       puts $HTMLFileId ""
       puts $HTMLFileId [format "" $relation_name]

       while { [gets $SDDLFileId SDDLLine] >= 0 } {
 
           # when this line is not a comment
           if { [string first "!" $SDDLLine] == -1 } {  
     
               # search for the token for a field name
               if { [ regexp "FIELD " $SDDLLine] == 1 } {
                   # get the field name
                   set pos [string last " " $SDDLLine]
                   incr pos 1
                   set field_name [string range $SDDLLine $pos end]
                   puts $HTMLFileId [format "" $relation_name $field_name]
                   puts $HTMLFileId [format "%s" $SDDLLine]
           
 
               } elseif { [ regexp "RELATED_FIELDS " $SDDLLine] == 1 } {   

                   # this is a related fields area
                   # the file access position may be changed, so save the current
                   # access position first
                   set current_position [tell $SDDLFileId]
                    
                   # save this line as two parts: first_part and second_part
                   set pos [string first "RELATED_FIELDS " $SDDLLine]
                   incr pos 15
                   set first_part [string range $SDDLLine 0 $pos]
              
                   # write the first part to the HTML file
                   puts -nonewline $HTMLFileId [format "%s" $first_part]

                   incr pos 1
                   set second_part [string range $SDDLLine $pos end]
         
                   # next we need to check whether there are several related fields 
                   # in this same line
                   set pos [string first "," $SDDLLine]
                
                   if { $pos == -1 } {
                       # only one related relation/field in this line
                       
                       # get the related relation and field names
                       set pos [string first "." $second_part]

                       set star_pos [string first "*" $SDDLLine]
		       if { $star_pos != -1 } {
                           # get the related relation name
                           incr star_pos -2
                           set related_relation_name [string range $SDDLLine 0 $star_pos]
                           puts -nonewline $HTMLFileId [format "" $related_relation_name $related_relation_name 
                       } else {
                           # get the related relation and related field names
                           incr pos -1
                           set related_relation_name [string range $second_part 1 $pos]
                           incr pos 2
                           set end_pos [expr [string length $second_part]-1]
                           set related_field_name [string range $second_part $pos $end_pos] 
                           puts -nonewline $HTMLFileId [format "" $relation_name $relation_name $related_field_name]
                           puts -nonewline $HTMLFileId [format "%s" $second_part]
                           puts $HTMLFileId ""
                       }                        

                   } else {
                       # There are several related relations/fields. 
                       # They may be specified in the same line or in different lines.
                       # If "," is the end of this line, only one related relation/field 
                       # is specified in this line.
                       # First get the relation and field name
                   



                           
                   }
              


                   # come back to the current position
                   seek $SDDLFileId $current_position
                   
                 

               } else {
                   puts $HTMLFileId [format "%s" $SDDLLine]
               }
               
	   } else {
               # write this comment line into the HTML file
               puts $HTMLFileId [format "%s" $SDDLLine]
           }
       }

       puts $HTMLFileId [format "" $relation_name]
       puts $HTMLFileId ""
       puts $HTMLFileId "
" puts $HTMLFileId "" } else { puts [format "Cannot open file: %s%s" $jtools_src $relation_name] } # create file: relation_frame.shtml set temp "_frame.shtml" set frame_html [concat $relation_name$temp] # create file: relation_help.shtml set temp "_help.shtml" set help_html [concat $relation_name$temp] # open if [ catch {open $frame_html w+} FrameHTMLId ] { puts "Cannot Open Output File" exit } puts $FrameHTMLId "" puts $FrameHTMLId "" puts $FrameHTMLId " " puts $FrameHTMLId " " puts $FrameHTMLId [format "" $html_file_name] puts $FrameHTMLId [format "" $help_html] puts $FrameHTMLId " " puts $FrameHTMLId "" puts $FrameHTMLId "" if [ catch {open $help_html w+} HelpHTMLId ] { puts "Cannot Open Output File" exit } puts $HelpHTMLId "" puts $HelpHTMLId "" puts $HelpHTMLId [format "

Relation %s

" $relation_name] puts $HelpHTMLId [format "
Top" $html_file_name] puts $HelpHTMLId [format " Bottom" $html_file_name] puts $HelpHTMLId " Help" puts $HelpHTMLId ""