Index: mttroot/mtt/bin/trans/awk/rbg_fig2m.awk ================================================================== --- mttroot/mtt/bin/trans/awk/rbg_fig2m.awk +++ mttroot/mtt/bin/trans/awk/rbg_fig2m.awk @@ -10,10 +10,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.20 1997/03/19 12:02:01 peterg +## Now writes an error message if a lable is used twice in the fig file. +## # Revision 1.19 1997/03/19 09:49:39 peterg # Ports now written in cmp file. # # Revision 1.18 1997/03/19 09:42:08 peterg # Now writes out the following additional fig files: @@ -169,20 +172,21 @@ } # The depth is field 4 depth = $4; -# It is terminated by /001 - so delete this termination +# It is terminated by \001 - so delete this termination str = substr(str,1,length(str)-4); # A component string contains only alphanumeric _ and : isa_plain_component = match(str, component_regexp)==0; # It must also be specified at depth 0 isa_plain_component = isa_plain_component && (depth==0); -# A port is an integer within [] and no alpha characters - isa_port = (match(str, port_regexp)>0)&&(match(str, nonport_regexp)==0); +# A port is a string within [] + isa_port = (match(str, port_regexp)>0) + # It must also be specified at depth 0 isa_port = isa_port && (depth==0); # A port component is SS followed by : followed by a port string isa_port_component = 0; @@ -202,22 +206,23 @@ y_coord = $13; # Do the ports if (isa_port) { i_port++; - port_index = substr(str,2,length(str)-2); - ports[i_port] = sprintf("%s %s %s", x_coord, y_coord, port_index); + port_name = str; + ports[i_port] = sprintf("%s %s %s", x_coord, y_coord, port_name); } # Do the port components if (isa_port_component) { i_port_component++; # Port number is the bit between the [] - port_number = substr(a[2],2,length(a[2])-2); - x_port[port_number] = x_coord; - y_port[port_number] = y_coord; - info_port[port_number] = fig_info(); + port_label = substr(a[2],2,length(a[2])-2); + x_port[i_port_component] = x_coord; + y_port[i_port_component] = y_coord; + info_port[i_port_component] = fig_info(); + port_labels[i_port_component] = port_label; } # Do the plain components if (isa_plain_component) { i_text++; @@ -471,11 +476,11 @@ repetition_delimiter = "*"; repetition_regexp = "\\*"; q = "\047"; terminator = "\\001"; component_regexp = "[^0-9a-zA-Z_:\*-]"; - port_regexp = "\[[0-9]*\]"; + port_regexp = "^\[[a-zA-Z0-9]*\]"; nonport_regexp = "[a-zA-Z]"; isa_fig_file = 0; min_line_length = 10; object = 0; @@ -511,12 +516,12 @@ } } END { #Print out the matlab functions - printf("function [rbonds, rstrokes,rcomponents,rports,n_ports] = %s_rbg\n", sys_name) > b_file; - printf("%% [rbonds,rstrokes,rcomponents,rports,n_ports] = %s_rbg\n", sys_name) > b_file; + printf("function [rbonds, rstrokes,rcomponents,port_coord,port_name,port_list] = %s_rbg\n", sys_name) > b_file; + printf("%% [rbonds,rstrokes,rcomponents,port_coord,port_name,port_list] = %s_rbg\n", sys_name) > b_file; printf("%% Generated by MTT\n\n") > b_file; printf("function [comp_type, name, cr, arg, repetitions] = %s_cmp(i)\n",\ sys_name) > c_file; printf("%% [comp_type, name, cr, arg, repetitions] = %s_cmp\n", sys_name) > c_file; @@ -536,14 +541,14 @@ printf("rcomponents = [") >> b_file; j = 0; -# Do the port components, in order, first +# Do the port components, in order of appearance, first for (i = 1; i <= i_port_component; i++) { port_type = "SS"; - name = sprintf("[%1.0f]", i); + name = sprintf("[%s]", port_labels[i]); cr = "MTT_port"; arg = i; if (length(x_port[i])==0) printf(warning_p); @@ -581,19 +586,30 @@ print "end" >> c_file } } printf("];\n") >> b_file; -# Print the ports list - printf("rports = [\n") >> b_file; - for (i = 1; i <= i_port; i++) - print ports[i] >> b_file; +# Print the (internal) ports list + printf("port_coord = [\n") >> b_file; + for (i = 1; i <= i_port; i++) { + split(ports[i],a, " "); + printf("%s %s\n", a[1], a[2]) >> b_file; + } + printf("];\n\n") >> b_file; + + printf("port_name = [\n") >> b_file; + for (i = 1; i <= i_port; i++) { + split(ports[i],a, " "); + printf("'%s'\n", a[3]) >> b_file; + } printf("];\n\n") >> b_file; -# Print the number of ports - printf("n_ports = %1.0f;\n", i_port_component) >> b_file; - +# Print the (external) port list +# printf("n_ports = %1.0f;\n", i_port_component) >> b_file; + printf("port_list = [\n") >> b_file; + for (i = 1; i <= i_port_component; i++) + printf("'[%s]'\n", port_labels[i]) >> b_file; + printf("];\n\n") >> b_file; - }