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] } # Here is the place to open the file: jtools_src:relation.sddl # and create a new file called: relation.shtml puts [format "Converting %s..." $sddl_file_name] set end_record 0 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 "END_RECORD" $SDDLLine] == 1 } {
                   set end_record 1
                   puts $HTMLFileId [format "%s" $SDDLLine]
               } elseif { [ 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 "TYPE  " $SDDLLine] == 1 && \
                          [string first "zspss_user_types" $relation_name] == -1 } {

                   # This line of SDDL specifies the data type of the fiels.
                   # If the data type is defined by SPSS users,
                   # build a link to the file it is defined
                   
                   if { $end_record == 1 } {
                       puts $HTMLFileId [format "%s" $SDDLLine] 
                   } elseif {[string first "_" $SDDLLine] != -1} {
                       set pos [string first "E" $SDDLLine]
                       set type [string range $SDDLLine 0 $pos]
                       incr pos 1
                       set user_type [string range $SDDLLine $pos end]
                       set user_type [string trimleft $user_type]

                       puts $HTMLFileId \
                            [format "%s %s" \
                            $type $user_type $user_type]
                   } else {
                       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]
                   set second_part [string trimleft $second_part]

                   # 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
                       get_relation_field_name $second_part

                       if { [string first "*" $related_field_name]  != -1 } {
                           puts -nonewline $HTMLFileId \
                                [format "" \
                                $related_relation_name $related_relation_name] 
                       } else {         
                           puts -nonewline $HTMLFileId \
                                [format "" \
                                $related_relation_name $related_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.

                       
                       set start_pos 0 
                       set end_pointer [expr [string length $second_part]-1]

                       

                       set temp $second_part


                       while { $start_pos != -1 } {
#puts "start of loop"
#puts [format "temp is:%s." $temp]
                           set end_pos [string first "," $temp]
#puts [format "start pos is:%d." $start_pos]                              

			   if { $end_pos == -1 } {
                               # This is the last related relation/field area
                            
                               set relation_field_name [string range $temp $start_pos end]
#puts [format "relation field name is:%s." $relation_field_name]
                               set relation_field_name [string trimleft $relation_field_name]
                               get_relation_field_name $relation_field_name
#puts "aaaaaa"

                               if { [string first "*" $related_field_name]  != -1 } {
                                   puts -nonewline $HTMLFileId \
                                        [format "" \
                                        $related_relation_name $related_relation_name] 
                               } else {         
                                   puts -nonewline $HTMLFileId \
                                        [format "" \
                                        $related_relation_name $related_relation_name \
                                        $related_field_name]
                               }    
                               # Write this last line of RELATED_FIELDS area                     
                               puts $HTMLFileId [format "%s" $relation_field_name]
                               puts $HTMLFileId ""   
                               set start_pos -1  
 
                           } else {
                                        
                               incr end_pos -1   
#puts [format "temp is:%s." $temp]
                               set relation_field [string range $temp $start_pos $end_pos]
                               set relation_field [string trimleft $relation_field]
#puts [format "relation field name is:%s." $relation_field]
                               get_relation_field_name $relation_field
         
        
                               if { [string first "*" $related_field_name]  != -1 } {
    
                                   puts -nonewline $HTMLFileId \
                                        [format "" \
                                        $related_relation_name $related_relation_name] 
                               } else {         
                                   puts -nonewline $HTMLFileId \
                                        [format "" \
                                        $related_relation_name $related_relation_name \
                                        $related_field_name]
                               }

                               # Write this part to the HTML file
                               puts -nonewline $HTMLFileId [format "%s" $relation_field]
                               puts -nonewline $HTMLFileId "" 
                               puts -nonewline $HTMLFileId " "  
                       
                               # stay at the position of a ','
                               incr end_pos 1

                               # check to see whether this is the end of the line or not
                               if { $end_pos == [expr [string length $temp]-1] } {

                                   # Write this line to the HTML file
                                   #puts -nonewline $HTMLFileId [format "%s" $relation_field]
                                   #puts $HTMLFileId ""

                                   # Get the next line. Here the file pointer is changed
                                   gets $SDDLFileId second_part
                                   set temp $second_part
                                   set start_pos 0 
                                   set end_pointer [expr [string length $second_part]-1]
                                    
                               } else {         


#puts [format "temp is:%s." $temp]
#puts [format "end pos is:%d." $end_pos]                              
                                   set temp [string range $temp $end_pos end]
#puts [format "temp is:%s." $temp]
                                   set start_pos [string first "\"" $temp]
                                 
                                   set temp [string range $temp $start_pos end]
                                   set start_pos [string first "\"" $temp]
#puts [format "temp is:%s." $temp]
#puts "end of loop"
                               }
                           }
		       }
                       
                           
                   }
              
                   # come back to the current position
                  # seek $SDDLFileId $current_position
                   
               } elseif { [ regexp "USER_TYPE " $SDDLLine] == 1 && \
                          [ string first "_USER_TYPE " $SDDLLine] == -1 } {
                   set pos [string last " " $SDDLLine] 
                   incr pos 1
                   set user_type [string range $SDDLLine $pos end]
                   puts $HTMLFileId [format "" $user_type]
                   puts $HTMLFileId [format "%s" $SDDLLine]

               } else {
                   # This is just a normal sddl line
                   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 $relation_name] puts $HelpHTMLId \ [format " Bottom" \ $html_file_name $relation_name] puts $HelpHTMLId \ " Help" puts $HelpHTMLId ""