# Autogenerated with DRAKON Editor 1.15

proc check_index_fields { index state } {
    #item 30
    unpack $state indexed fields name
    #item 6
    set iname       [ get_value $index "name" ]
    set fields_cell [ get_value $index "fields" ]
    #item 7
    set ifields [ make_list $fields_cell ]
    #item 8
    if {$ifields == {}} {
        #item 11
        set msg \
        "Index $iname of table $name does not have fields."
        #item 37
        error $msg
    } else {
        #item 12
        if {[ is_unique $ifields ]} {
            #item 160001
            set _col16 $ifields
            set _len16 [ llength $_col16 ]
            set _ind16 0
            while { 1 } {
                #item 160002
                if {$_ind16 < $_len16} {
                    #item 160004
                    set ifield [ lindex $_col16 $_ind16 ]
                    #item 15
                    set field_key [ find_key $fields $ifield ]
                    #item 18
                    if {$field_key == -1} {
                        #item 20
                        set msg \
                        "Index $iname of table $name: field $ifield not found."
                    } else {
                        #item 21
                        incr field_key
                        set field [ lindex $fields $field_key ]
                        set type [ get_value $field "type" ]
                        #item 330001
                        if {($type == "value") || ($type == "own")} {
                            #item 160003
                            incr _ind16
                        } else {
                            #item 28
                            set msg [ concat \
                            "Index $iname of table $name: " \
                            "fields of type $type cannot be indexed." ]
                        }
                    }
                    #item 37
                    error $msg
                    break
                } else {
                    break
                }
            }
        } else {
            #item 14
            set msg \
            "Index $iname of table $name has repeating fields."
            #item 37
            error $msg
        }
    }
    #item 35
    set indexed2 [ concat $indexed $ifields ]
    #item 36
    return [ list $indexed2 $fields $name ]
}

proc check_index_fields2 { index state } {
    #item 530001
    set _col53 $ifields
    set _len53 [ llength $_col53 ]
    set _ind53 0
    while { 1 } {
        #item 530002
        if {$_ind53 < $_len53} {
            #item 530004
            set ifield [ lindex $_col53 $_ind53 ]
            #item 45
            if {$ifields == {}} {
                #item 48
                A
            } else {
                #item 52
                U
                #item 700001
                if {$type == "value"} {
                    #item 97
                    Y
                    #item 530003
                    incr _ind53
                } else {
                    #item 65
                    B
                }
            }
            #item 74
            C
            break
        } else {
            break
        }
    }
    #item 73
    foo
}

proc check_index_fields3 { index state } {
    set _col85 $ifields
    set _len85 [ llength $_col85 ]
    set _ind85 0
    
    set _next_item_ 850002
    while { 1 } {
        if {$_next_item_ == 850002} {
            if {$_ind85 < $_len85} {
                #item 850004
                set ifield [ lindex $_col85 $_ind85 ]
                set _next_item_ 80
            } else {
                set _next_item_ 94
            }
    
        } elseif {$_next_item_ == 80} {
            if {$ifields == {}} {
                #item 83
                A
                set _next_item_ 95
            } else {
                #item 84
                U
                set _next_item_ 96
            }
    
        } elseif {$_next_item_ == 96} {
            if {X} {
                #item 90
                B
                set _next_item_ 95
            } else {
                #item 850003
                incr _ind85
                set _next_item_ 850002
            }
    
        } elseif {$_next_item_ == 95} {
            C
            set _next_item_ 94
    
        } elseif {$_next_item_ == 94} {
            foo
            return {}
    
        }
    }
}


