blackbox.tcl 2.96 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
package provide blackbox 0.1 
# C code editor (using Kate)
lappend auto_path .
namespace eval blackbox {
    
    # Graphical name of the operation
    proc getLabel {} {
        return "Edit source code"
    }
    
    # Name of the application this script can be used with
    # shall be either InterfaceView or DeploymentView
    proc getApplication {} {
        return "InterfaceView"
    }
    
    # Names of  the object this script can be used on
    proc getApplyTo {} {
        return [list { "Function" {"Source_Language" "Blackbox_device"} }  ]
    }
    
    # List of way to manage output in the Framework
    # Could be an empty list or one or both of 'dialogBox' and 'statusBar'
    proc getOutputManagement {} {
25 26
		## Ticket mantis 0000625
        return [list statusBar dialogBoxOnError]
Maxime Perrotin's avatar
Maxime Perrotin committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40
    }
    
    proc blackbox { args } {
        set params [lindex $args 0]
        set aadlFilePath [Parameter::getParameter $params aadlFilePath]
        set aadlId [Parameter::getParameter $params id]
        return [bb_internal $aadlFilePath $aadlId]
    }
    
    #  the line "exec {*}[auto_execok $::installationPath/config/externalTools/test.bat]"
    #  ask the current OS which software is to be used to open the file test.bat
    #  to launch using the absolute path, read the template2.tcl_
    
    # synchronous call
41 42
    proc bb_internal { aadlFilePath aadlId } {  
		## Ticket mantis 0000625  
Maxime Perrotin's avatar
Maxime Perrotin committed
43 44 45 46
        set initialPath [pwd]
        cd [file dirname $aadlFilePath]
        set msg ""
        
47 48 49 50 51 52 53
        set scriptPath [auto_execok "taste-generate-skeletons"]
        if { $scriptPath != "" } {
			set errNumb [catch { exec -ignorestderr {*}$scriptPath 2>@1 } errMsg]
		} else {
			set errNumb -1
			set errMsg "Unknown command taste-generate-skeletons."
		}
Maxime Perrotin's avatar
Maxime Perrotin committed
54 55 56 57 58
        
        set aadlId [string tolower $aadlId 0 end]
        
        if { $errNumb == 0 && [file exists [file normalize "[pwd]/$aadlId" ] ] } {
            cd [file normalize "[pwd]/$aadlId" ]
59
            set errNumb [catch { exec -ignorestderr {*}[auto_execok kate] ${aadlId}.h ${aadlId}.c 2>@1 & } errMsg]
Maxime Perrotin's avatar
Maxime Perrotin committed
60 61 62 63 64 65 66
            if { $errNumb == 0 } {
             # TODO: check code - but we need to have C_ASN1_Types.h
             #   set errNumb [catch { exec -ignorestderr {*}[auto_execok gcc] -fsyntax-only -c ${aadlId}.c } ]
             #   if { $errNumb != 0 } {
             #       set msg "Note: There are syntax errors in your code - check it before you build"
             #   }
            } else {
67
                set msg [list "Error in execution of \"kate ${aadlId}.c ${aadlId}.h\": $errMsg" ]
Maxime Perrotin's avatar
Maxime Perrotin committed
68 69
            }
        } else {
70
            set msg [list "Error in execution of \"taste-generate-skeletons $aadlFilePath\": $errMsg" ]
Maxime Perrotin's avatar
Maxime Perrotin committed
71 72 73 74 75 76 77 78 79 80 81 82 83
        }
        
        cd $initialPath
        return [list $errNumb $msg]
    } 
    
    # asynchronous call
    #proc template_internal { aadlFilePath aadlId } {        
    #    exec {*}[auto_execok $::installationPath/config/externalTools/test.bat] $aadlFilePath $aadlId &
    #    return ""
    #} 
    
}