#!/usr/bin/awk -f # # File: order_labels.awk # # This file is part of XSCHEM, # a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit # simulation. # Copyright (C) 1998-2024 Stefan Frederik Schippers # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #------------------------ BEGIN{ i=0 } NF=2 { i++ pin[i]=$1 # 20111116 dir[$1] = $2 } END{ pin["n"]=i hsort(pin, pin["n"]) compact_pinlist(pin) for(i=1;i<=pin_ret["n"];i++){ a=pin_ret[i] # gsub(/\[/,"<",a) # gsub(/\]/,">",a) printf "%s %s\n", a, dir_ret[i] } } function compact_pinlist(pin ,i,ii,base,curr,curr_n,np) { delete pin_ret delete dir_ret np=pin["n"] if(np) { ii=1 for(i=1;i<=np;i++) { base =lab_name( pin[i] ) if(i==1) {curr=base; curr_n=i} else { if(base != curr) { pin_ret[ii] = compact_label(pin,curr_n,i-1) dir_ret[ii] = dir[pin[i-1]] # 20111116 ii++ curr=base;curr_n=i } } } pin_ret[ii] = compact_label(pin,curr_n,np) dir_ret[ii] = dir[pin[np]] # 20111116 pin_ret["n"] = ii } } # 1 2 3 4 5 6 7 8 9 10 11 12 # PP A[3] A[2] A[1] B C K[10] K[9] K[5] K[4] K[3] K[1] function compact_label(ar,a,b, ret,start,i) { ret="" for(i=a;i<=b;i++) { if(i==a) {start=a} else { if(ar[i-1] !~ /\[/) { if(ar[i-1] != ar[i]) { if(start < i-1) { ret = ret (i-start) "*" ar[i-1] ","; start=i } else {ret = ret ar[i-1] ","; start=i } } } else if(lab_name(ar[i])!=lab_name(ar[i-1]) || ( lab_index(ar[i]) != lab_index(ar[i-1])-1 && lab_index(ar[i]) != lab_index(ar[i-1])+1) ) { if(start1) { rarray=array[--l] } else { rarray=array[ir] array[ir]=array[1] if(--ir==1) { array[1]=rarray return } } i=l j=l*2 while(j<=ir) { if(j lab_index(b) else return lab_name(a) > lab_name(b) }