[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: branch: master updated (1.4.0-20080127-37-g267f6ca)



The branch, master has been updated
       via  267f6cae3b2aa6df5af8edc0bfbea95e72ee03b8 (commit)
       via  324b94f10b4482e61701b4880d15aec52403d774 (commit)
      from  c1b1d3646043f27302b36a4b541bc9b34fbfe6b9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 utils/examples/tragesym/alltest   |    5 +
 utils/examples/tragesym/test1.src |   10 +-
 utils/scripts/tragesym            |  321 +++++++++++++++++++------------------
 3 files changed, 178 insertions(+), 158 deletions(-)


=================
 Commit Messages
=================

commit 267f6cae3b2aa6df5af8edc0bfbea95e72ee03b8
Author: Werner Hoch <werner.ho@xxxxxx>
Date:   Sat Mar 29 20:49:28 2008 +0100

    tragesym: moved pin comparison, cleanup version is now 0.0.13
    
    Use the old rules for sorting pins by it's label. The sorting function
    is in the pin class now (__cmp__). Moved pin tests into pin class and
    reenabled pintype translation.
    Improved some test files.

:100755 100755 2b5183e... a0db777... M	utils/examples/tragesym/alltest
:100644 100644 a4aec01... 87e2478... M	utils/examples/tragesym/test1.src
:100755 100755 4f85d3e... 17063fc... M	utils/scripts/tragesym

commit 324b94f10b4482e61701b4880d15aec52403d774
Author: Werner Hoch <werner.ho@xxxxxx>
Date:   Sat Mar 29 20:40:12 2008 +0100

    refactoring of the tragesym code to use pin objects and getopt
    
    This commit changes the pin dictionary to a pin class and converts the
    pin sort into pin comparisons inside the pin class It adds a nice
    getopt command line interface and adds some more sanity checks. Thanks
    for the patch written by Thomas Hille <thomas.hille@xxxxxx>

:100755 100755 6a592ca... 4f85d3e... M	utils/scripts/tragesym

=========
 Changes
=========

commit 267f6cae3b2aa6df5af8edc0bfbea95e72ee03b8
Author: Werner Hoch <werner.ho@xxxxxx>
Date:   Sat Mar 29 20:49:28 2008 +0100

    tragesym: moved pin comparison, cleanup version is now 0.0.13
    
    Use the old rules for sorting pins by it's label. The sorting function
    is in the pin class now (__cmp__). Moved pin tests into pin class and
    reenabled pintype translation.
    Improved some test files.

diff --git a/utils/examples/tragesym/alltest b/utils/examples/tragesym/alltest
index 2b5183e..a0db777 100755
--- a/utils/examples/tragesym/alltest
+++ b/utils/examples/tragesym/alltest
@@ -1,8 +1,13 @@
 #!/bin/sh
 
 # run tragesym over all test and example files
+echo testing 4099.src
 ../../scripts/tragesym 4099.src 4099.sym
+echo testing test1.src
 ../../scripts/tragesym test1.src test1.sym
+echo testing test2.src
 ../../scripts/tragesym test2.src test2.sym
+echo testing test3.src
 ../../scripts/tragesym test3.src test3.sym
+echo testing AT90S8535_TQFP.src
 ../../scripts/tragesym AT90S8535_TQFP.src AT90S8535_TQFP.sym
diff --git a/utils/examples/tragesym/test1.src b/utils/examples/tragesym/test1.src
index a4aec01..87e2478 100644
--- a/utils/examples/tragesym/test1.src
+++ b/utils/examples/tragesym/test1.src
@@ -21,6 +21,8 @@ description=pin sorting test, pin sequence test
 documentation=http://url_to_the_datasheet.com/datasheet.pdf
 author=Werner Hoch <werner.ho(AT)gmx.de>
 numslots=4
+use-license=unlimited
+dist-license=GPL
 slot=1
 slotdef=1:1,2,3
 slotdef=2:4,5,6
@@ -34,8 +36,8 @@ comment=blablub
 #-----------------------------------------------------
 #pinnr	seq	type	style	posit.	net	label	
 #-----------------------------------------------------
-1	21	io	line	l		hello
-2	20	out	clk	l		\_neg\_
+1	21	i	line	l		hello
+2	20	o	clk	l		\_neg\_
 3	19	out	dot	l		\_n\_0\_n\_
 4		pwr	none		GND
 5	18	IO	line	l		\_ABC\_ (DEF)
@@ -56,7 +58,7 @@ comment=blablub
 20 	6	in	dotclk	b		other
 21	5	in	dot	b		\_Reset\_
 22	4	out	line	t		PD1 (\_SS\_)
-23	3	io	clk	r		PD2 (\_xxx\_hello\_sss\_)
-24	2	io	dot	r		PD3 (x_no_over)
+23	3	pas	clk	r		PD2 (\_xxx\_hello\_sss\_)
+24	2	p	dot	r		PD3 (x_no_over)
 25	1	io	clk	r		PD4 (\\\_strange\\\_)
 
diff --git a/utils/scripts/tragesym b/utils/scripts/tragesym
index 4f85d3e..17063fc 100755
--- a/utils/scripts/tragesym
+++ b/utils/scripts/tragesym
@@ -3,7 +3,7 @@
 ############################################################################
 #    tragesym  - create gEDA symbols out of structured textfiles
 #    begin      : 2001-10-20
-#    copyright  : (C) 2001,2002,2003,2004,2006,2007 by Werner Hoch
+#    copyright  : (C) 2001,2002,2003,2004,2006,2007, 2008 by Werner Hoch
 #    email      : werner.ho@xxxxxx
 ############################################################################
 #                                                                          #
@@ -24,28 +24,10 @@
 #   symbol width based on the greater number of pins at the top or at the
 #   bottom of the symbol
 
-# TODO:
-# - make a nicer comandline interface including stdin /stdout
-# - write cleaner code (variables, constants, structure)
-
-
-# Changes by Thomas Hille:
-# - use getopt for parsing command line
-# - check for existing input file prior trying to open it
-# - section headers are identified (and parsed) by a regular expression instead of line[0]=='['
-# - pins are stored as an object instead of a dictionary
-# - pin comparison is now done in class Pin itself:
-#       - _for now_ only the pin position and the label are taken into account
-#
-# TODO:
-# - sorting and spacer(s) don't go well with each other, tell the user
-#
-
-
 import getopt, os.path, re, string, sys
 
 ##################### GLOBALS ############################################
-VERSION="0.0.12"
+VERSION="0.0.13"
 
 CHARHIGH=26
 preset_options = {"wordswap":"yes",
@@ -66,6 +48,7 @@ multiple_attr = ["slotdef", "comment"]
 stylelist = ["line","dot","clk","dotclk","spacer","none"]
 poslist = ["l","r","t","b",""]
 typelist = ["in","out","io","oc","oe","pas","tp","tri","clk","pwr"]
+translate_pintype = {"i/o":"io", "i":"in", "o":"out", "p":"pas"}
 P_NR, P_SEQ, P_TYPE, P_STYLE, P_POS, P_NET, P_LABEL = 0,1,2,3,4,5,6
 re_section_header = re.compile("^\s*\[(?P<name>.+)]\s*$")
 
@@ -78,66 +61,66 @@ class Pin:
         element.extend(('', '', '', '', '', '', ''))
         self.nr = element[P_NR].strip()
         self.seq = element[P_SEQ].strip()
-        self.type = element[P_TYPE].lower().strip()
+        pintype = element[P_TYPE].lower().strip()
+        self.type = translate_pintype.get(pintype, pintype)
         self.style = element[P_STYLE].lower().strip()
         self.pos = element[P_POS].lower().strip()
         self.net = element[P_NET].strip()
         self.label = element[P_LABEL].strip()
-		
+
     def __str__(self):
         str = "Pin object (nr:" + self.nr + " seq:" + self.seq + " type:" + self.type
         str += " style:" + self.style + " pos:" + self.pos + " net:" + self.net
         str += " label:" + self.label + ")"
         return str
 
-# rules: nets, positions, labels
-    def __lt__(self, other):
+    def __cmp__(self, other):
+        """
+        Comparison function for the pin.
+        * The sorting rule is to place the nets first.
+        * The pin position is the second sorting key
+        * The pin label is the third sorting key
+        """
         if not isinstance(other, Pin):
             return NotImplemented
-        if self.pos != other.pos:
-            return self.pos < other.pos
-        return self.label < other.label
-
-      
-    def __le__(self, other):
-        if not isinstance(other, Pin):
-            return NotImplemented
-        if self.pos != other.pos:
-            return self.pos < other.pos
-        return self.label <= other.label
-
-      
-    def __eq__(self, other):
-        if not isinstance(other, Pin):
-            return NotImplemented
-        if self.pos != other.pos:
-            return False
-        return self.label == other.label
-
-
-    def __ne__(self, other):
-        if not isinstance(other, Pin):
-            return NotImplemented
-        if self.pos != other.pos:
-            return True
-        return self.label != other.label
-
-
-    def __gt__(self, other):
-        if not isinstance(other, Pin):
-            return NotImplemented
-        if self.pos != other.pos:
-            return self.pos > other.pos
-        return self.label > other.label
-        
+        ret = cmp(self.net, other.net)
+        if ret != 0:
+            return ret
+        ret = cmp(other.pos, self.pos)
+        if ret != 0:
+            return ret
+        return cmp(splitspecial(parselabel(self.label)),
+                   splitspecial(parselabel(other.label)))
+
+
+    def check(self):
+    	if self.style=="spacer":
+	    if self.pos == "":
+		print "Error: there must be a position with a spacer.\n"
+		sys.exit()
+	    if self.pos not in poslist:
+		print "Error: position is not allowed: \n", self
+		sys.exit()
+            return
+        if self.style != "none":
+            if self.seq.isdigit():
+                string.atoi(self.seq)
+            else:
+                print "pinseq needs to be a number: \n", self
+                sys.exit()
+        if self.type not in typelist:
+            print "Pintype not allowed: \n", self
+            sys.exit()
+        if self.style not in stylelist:
+            print "Style is not allowed: \n", self
+            sys.exit()
+        if self.pos not in poslist:
+            print "Position is not allowed: \n", self
+            sys.exit()
+        if self.pos == "" and self.net == "":
+            print "There must be either position or a netlabel: \n", self
+            sys.exit()
         
-
-    def __ge__(self, other):
-        if not isinstance(other, Pin):
-            return NotImplemented
-        if self.pos != other.pos:
-            return self.pos > other.pos
-        return self.label >= other.label
         
 ################################# FUNCTIONS ##############################
 
@@ -184,18 +167,6 @@ def swapwords(str):
         back=i+" "+back
     return back
 
-## make the parser more tolerant to the input file
-def type_translate(str):
-    if str == "i/o":
-        str="io"
-    elif str == "i":
-        str="in"
-    elif str == "o":
-        str="out"
-    elif str == "p":
-        str="pas"
-    return str
-
 ## split a string at the first tab or equal char
 def split_tab_equal(str,n=1):
     list_tab=string.split(str,'\t',n)
@@ -245,35 +216,6 @@ def readsrc(filename):
             sys.exit()
     return options, geda_attr, pins
 
-def checkpins(pinlist):
-    for pin in pinlist:
-    	if (pin.style=="spacer"):
-	    if (pin.pos == ""):
-		print "There must be a position with a spacer.\n"
-		sys.exit()
-	    if pin.pos not in poslist:
-		print "Position is not allowed: \n", pin
-		sys.exit()
-    	    continue
-        if pin.style != "none":
-            if pin.seq.isdigit():
-                string.atoi(pin.seq)
-            else:
-                print "pinseq needs to be a number: \n", pin
-                sys.exit()
-        if pin.type not in typelist:
-            print "Pintype not allowed: \n", pin
-            sys.exit()
-        if pin.style not in stylelist:
-            print "Style is not allowed: \n", pin
-            sys.exit()
-        if pin.pos not in poslist:
-            print "Position is not allowed: \n", pin
-            sys.exit()
-        if pin.pos == "" and pin.net == "":
-            print "There must be either position or a netlabel: \n", pin
-            sys.exit()
-
 def checkattr(attr):
     for attr,value in attr.items():
         attr,nr=attr
@@ -281,33 +223,36 @@ def checkattr(attr):
             print "this attribute is not allowed: ", attr, value
             sys.exit()
 
-## makes a list out of a string: "3abc345x?" --> ["","3","abc","345","x?"]
+
 def splitspecial(str):
+    """
+    makes a list out of a string:
+    "3abc345x?" --> ["",3,"abc",345,"x?"]
+    """
     isletter=1
-    list=[""]
+    list=[]
+    current = ""
     for letter in str:
         if letter not in string.digits:
             if isletter == 1:
-                list[-1]=list[-1] + letter
+                current += letter
             else:
-                list.append(letter)
+                list.append(int(current))
+                current = letter
                 isletter=1
         else:
             if isletter == 0:
-                list[-1]=list[-1] + letter
+                current += letter
             else:
-                list.append(letter)
+                list.append(current)
+                current = letter
                 isletter=0
+    if isletter == 0:
+        list.append(int(current))
+    else:
+        list.append(current)
     return list
 
-    
-def sort(item1,item2):
-    if item1 < item2:
-        return -1
-    elif item1 > item2:
-        return 1
-    return 0
-
 def writesym(filename,options,attr,pins):
     o_symwidth=string.atoi(options["sym_width"])
     o_hdist=string.atoi(options["pinwidthhorizontal"])
@@ -400,7 +345,6 @@ def writesym(filename,options,attr,pins):
         sys.exit()
    
     if o_sort == "yes":
-        print "sorting..."
         pins.sort()
 
     for pin in pins:
@@ -419,6 +363,7 @@ def writesym(filename,options,attr,pins):
             elif pin.pos == "t": # top pin
                 ptopx=ptopx + o_hdist
             continue
+        
 ### decide which pindirection to use
         ## TODO: put all constants into a dictionary         
         if pin.pos == "l": #left pin
@@ -428,7 +373,6 @@ def writesym(filename,options,attr,pins):
             pinl=(350,0,0,0)  # """"
             pina=(350,0,2,0)  # """"
             pinq=(200,-50,8,0)  # """"
-            negl=(0, CHARHIGH*4+20,0,0) # dx,dy,vert,rotate (base is label)
             swap=0   # swap words in label ?
             plefty=plefty - o_vdist  #where to draw the _next_ pin
         elif pin.pos == "r": #right pin
@@ -438,7 +382,6 @@ def writesym(filename,options,attr,pins):
             pinl=(-350,0,6,0)
             pina=(-350,0,8,0)
             pinq=(-200,-50,2,0)
-            negl=(0, CHARHIGH*4+20,2,0)
             swap=1
             prighty=prighty - o_vdist
         elif pin.pos == "b": # bottom pin
@@ -449,13 +392,11 @@ def writesym(filename,options,attr,pins):
                 pinl=(0,350,0,90)
                 pina=(0,350,2,90)
                 pinq=(50,200,8,90)
-                negl=(CHARHIGH*4+20,0,0,1)
             else:
                 pint=(50,100,0,0)
                 pinl=(0,350,3,0)
                 pina=(0,500,3,0)
                 pinq=(50,100,2,0)
-                negl=(0,CHARHIGH*4+20,1,0)
             swap=0
             pbottomx=pbottomx + o_hdist
         elif pin.pos == "t": # top pin
@@ -466,14 +407,12 @@ def writesym(filename,options,attr,pins):
                 pinl=(0,-350,6,90)
                 pina=(0,-350,8,90)
                 pinq=(50,-200,2,90)
-                negl=(CHARHIGH*4+20,0,2,1)
                 swap=1
             else:
                 pint=(50,-200,0,0)
                 pinl=(0,-350,5,0)
                 pina=(0,-500,5,0)
                 pinq=(50,-200,2,0)
-                negl=(0,20,1,0)
                 swap=0
             ptopx=ptopx + o_hdist
 ### draw the pin
@@ -662,7 +601,9 @@ options=mergeoptions(opts,preset_options)
 if options["generate_pinseq"] == "yes":
     pins=generate_pinseq(pins)
 
-checkpins(pins)
+for pin in pins:
+    pin.check()
+
 checkattr(attr)
 
 writesym(file_out,options,attr,pins)

commit 324b94f10b4482e61701b4880d15aec52403d774
Author: Werner Hoch <werner.ho@xxxxxx>
Date:   Sat Mar 29 20:40:12 2008 +0100

    refactoring of the tragesym code to use pin objects and getopt
    
    This commit changes the pin dictionary to a pin class and converts the
    pin sort into pin comparisons inside the pin class It adds a nice
    getopt command line interface and adds some more sanity checks. Thanks
    for the patch written by Thomas Hille <thomas.hille@xxxxxx>

diff --git a/utils/scripts/tragesym b/utils/scripts/tragesym
index 6a592ca..4f85d3e 100755
--- a/utils/scripts/tragesym
+++ b/utils/scripts/tragesym
@@ -28,7 +28,21 @@
 # - make a nicer comandline interface including stdin /stdout
 # - write cleaner code (variables, constants, structure)
 
-import sys, string
+
+# Changes by Thomas Hille:
+# - use getopt for parsing command line
+# - check for existing input file prior trying to open it
+# - section headers are identified (and parsed) by a regular expression instead of line[0]=='['
+# - pins are stored as an object instead of a dictionary
+# - pin comparison is now done in class Pin itself:
+#       - _for now_ only the pin position and the label are taken into account
+#
+# TODO:
+# - sorting and spacer(s) don't go well with each other, tell the user
+#
+
+
+import getopt, os.path, re, string, sys
 
 ##################### GLOBALS ############################################
 VERSION="0.0.12"
@@ -53,9 +67,86 @@ stylelist = ["line","dot","clk","dotclk","spacer","none"]
 poslist = ["l","r","t","b",""]
 typelist = ["in","out","io","oc","oe","pas","tp","tri","clk","pwr"]
 P_NR, P_SEQ, P_TYPE, P_STYLE, P_POS, P_NET, P_LABEL = 0,1,2,3,4,5,6
+re_section_header = re.compile("^\s*\[(?P<name>.+)]\s*$")
+
+################################## CLASSES ###############################
+
+class Pin:
+    '''Encapsulation for all data related to a pin.'''
+    def __init__(self, element):
+		
+        element.extend(('', '', '', '', '', '', ''))
+        self.nr = element[P_NR].strip()
+        self.seq = element[P_SEQ].strip()
+        self.type = element[P_TYPE].lower().strip()
+        self.style = element[P_STYLE].lower().strip()
+        self.pos = element[P_POS].lower().strip()
+        self.net = element[P_NET].strip()
+        self.label = element[P_LABEL].strip()
+		
+    def __str__(self):
+        str = "Pin object (nr:" + self.nr + " seq:" + self.seq + " type:" + self.type
+        str += " style:" + self.style + " pos:" + self.pos + " net:" + self.net
+        str += " label:" + self.label + ")"
+        return str
+
+# rules: nets, positions, labels
+    def __lt__(self, other):
+        if not isinstance(other, Pin):
+            return NotImplemented
+        if self.pos != other.pos:
+            return self.pos < other.pos
+        return self.label < other.label
+
+      
+    def __le__(self, other):
+        if not isinstance(other, Pin):
+            return NotImplemented
+        if self.pos != other.pos:
+            return self.pos < other.pos
+        return self.label <= other.label
+
+      
+    def __eq__(self, other):
+        if not isinstance(other, Pin):
+            return NotImplemented
+        if self.pos != other.pos:
+            return False
+        return self.label == other.label
+
+
+    def __ne__(self, other):
+        if not isinstance(other, Pin):
+            return NotImplemented
+        if self.pos != other.pos:
+            return True
+        return self.label != other.label
+
+
+    def __gt__(self, other):
+        if not isinstance(other, Pin):
+            return NotImplemented
+        if self.pos != other.pos:
+            return self.pos > other.pos
+        return self.label > other.label
+        
+        
+
+    def __ge__(self, other):
+        if not isinstance(other, Pin):
+            return NotImplemented
+        if self.pos != other.pos:
+            return self.pos > other.pos
+        return self.label >= other.label
+        
+################################# FUNCTIONS ##############################
 
+def usage():
+    '''Print a usage message.'''
+    print "tragesym version " + VERSION
+    print "(C) 2001,2002,2003,2004,2006,2007 by Werner Hoch <werner.ho@xxxxxx>"
+    print "Usage is: ", sys.argv[0] ,"<infile> <outfile>"
 
-################################# FUNCTIONS ##############################
 
 def parselabel(str):
     '''returns a stripped label without overbar markers "\_"'''
@@ -123,13 +214,17 @@ def readsrc(filename):
     content= f.readlines()
     section=""
     linenr=0
-    for line in content:
+    for lineraw in content:
+    	line = lineraw.rstrip()
         linenr=linenr+1
-        if line[0]=="[":        # find a section 
-            section=string.split(line[1:],"]")[0]
+    	if len(line) == 0:
+    		continue
+        match = re_section_header.match(line)
+        if match:        			# find a section 
+            section=match.group('name')
             continue
         elif section=="" or line[0]=="#" \
-             or len(string.strip(line)) == 0: # comment, empty line or no section
+             or len(string.strip(line)) == 0:	# comment, empty line or no section
             continue
         if section=="options":
             element=split_tab_equal(line,1)
@@ -144,15 +239,7 @@ def readsrc(filename):
         elif section=="pins":
             element=string.split(line,"\t")
             if len(element) > 2:
-                for j in xrange(len(element)):
-                    element[j]=string.strip(element[j])
-                    if j in [P_TYPE,P_POS,P_STYLE]:
-                        element[j]= string.lower(element[j])
-                    if j == P_TYPE:
-                        element[j] = type_translate(element[j])
-                while len(element) < 7:
-                    element.append("")
-                pins.append(element)
+                pins.append(Pin(element))
         else:
             print linenr, ": illegal section name: ", section
             sys.exit()
@@ -160,30 +247,30 @@ def readsrc(filename):
 
 def checkpins(pinlist):
     for pin in pinlist:
-    	if pin[P_STYLE] == "spacer":
-	    if pin[P_POS] == "":
-		print "Error: There must be a position with a spacer.\n"
+    	if (pin.style=="spacer"):
+	    if (pin.pos == ""):
+		print "There must be a position with a spacer.\n"
 		sys.exit()
-	    if pin[P_POS] not in poslist:
-		print "Error: position is not allowed: \n", pin
+	    if pin.pos not in poslist:
+		print "Position is not allowed: \n", pin
 		sys.exit()
     	    continue
-        if pin[P_STYLE] != "none":
-            if pin[P_SEQ].isdigit():
-                string.atoi(pin[P_SEQ])
+        if pin.style != "none":
+            if pin.seq.isdigit():
+                string.atoi(pin.seq)
             else:
                 print "pinseq needs to be a number: \n", pin
                 sys.exit()
-        if pin[P_TYPE] not in typelist:
+        if pin.type not in typelist:
             print "Pintype not allowed: \n", pin
             sys.exit()
-        if pin[P_STYLE] not in stylelist:
+        if pin.style not in stylelist:
             print "Style is not allowed: \n", pin
             sys.exit()
-        if pin[P_POS] not in poslist:
+        if pin.pos not in poslist:
             print "Position is not allowed: \n", pin
             sys.exit()
-        if pin[P_POS] == "" and pin[P_NET] == "":
+        if pin.pos == "" and pin.net == "":
             print "There must be either position or a netlabel: \n", pin
             sys.exit()
 
@@ -212,39 +299,8 @@ def splitspecial(str):
                 list.append(letter)
                 isletter=0
     return list
-    
-def pinsort(pin1,pin2):
-    ## rules: nets first, positions second, labels last
-    ## net
-    if pin1[P_NET] != "" and pin2[P_NET] != "":
-        return 0
-    elif pin2[P_NET] != "":
-        return 1
-    elif pin1[P_NET] != "":
-        return -1
-    ## position
-    if pin1[P_POS] > pin2[P_POS]:
-        return -1
-    elif pin1[P_POS] < pin2[P_POS]:
-        return 1
-    ## pinlabel
-    label1 = parselabel(pin1[P_LABEL])
-    label2 = parselabel(pin2[P_LABEL])
-    l1 = splitspecial(label1)
-    l2 = splitspecial(label2)
-    minlen = len(l1)
-    if len(l2) < minlen:
-        minlen = len(l2)
-    for i in xrange(minlen):
-        if i % 2 == 1:
-            ret= sort(string.atoi(l1[i]),string.atoi(l2[i]))
-        else:
-            ret= sort(l1[i],l2[i])
-        if ret != 0:
-            return ret
-    ret=sort(len(l1),len(l2))
-    return ret
 
+    
 def sort(item1,item2):
     if item1 < item2:
         return -1
@@ -277,13 +333,13 @@ def writesym(filename,options,attr,pins):
     numpbottom=0
     numptop = 0
     for pin in pins:
-    	if pin[P_POS] == "l": # left pin
+    	if pin.pos == "l": # left pin
     		numpleft=numpleft+1
-    	elif pin[P_POS] == "r": #right pin
+    	elif pin.pos == "r": #right pin
     		numpright=numpright+1
-    	elif pin[P_POS] == "b": #right pin
+    	elif pin.pos == "b": #right pin
     		numpbottom=numpbottom+1
-    	elif pin[P_POS] == "t": #right pin
+    	elif pin.pos == "t": #right pin
     		numptop=numptop+1
 
     # Calculate the position of the pins in the left and right side.    
@@ -344,27 +400,28 @@ def writesym(filename,options,attr,pins):
         sys.exit()
    
     if o_sort == "yes":
-        pins.sort(pinsort)
+        print "sorting..."
+        pins.sort()
 
     for pin in pins:
-        if pin[P_STYLE] == "none": #
+        if pin.style == "none": #
             continue
-        if pin[P_STYLE]=="spacer":
+        if pin.style=="spacer":
             if o_sort == "yes":
                 print "warning: spacers are not supported when sorting labels"
                 continue
-            elif pin[P_POS] == "l": #left pin
+            elif pin.pos == "l": #left pin
                 plefty=plefty - o_vdist  #where to draw the _next_ pin
-            elif pin[P_POS] == "r": #right pin
+            elif pin.pos == "r": #right pin
                 prighty=prighty - o_vdist
-            elif pin[P_POS] == "b": # bottom pin
+            elif pin.pos == "b": # bottom pin
                 pbottomx=pbottomx + o_hdist
-            elif pin[P_POS] == "t": # top pin
+            elif pin.pos == "t": # top pin
                 ptopx=ptopx + o_hdist
             continue
 ### decide which pindirection to use
         ## TODO: put all constants into a dictionary         
-        if pin[P_POS] == "l": #left pin
+        if pin.pos == "l": #left pin
             basex, basey= pleftx, plefty  #where to draw this pin
             xf, yf= 1, 0  # orientation factors  
             pint=(200,50,6,0) # dx, dy, alignment, angle
@@ -374,7 +431,7 @@ def writesym(filename,options,attr,pins):
             negl=(0, CHARHIGH*4+20,0,0) # dx,dy,vert,rotate (base is label)
             swap=0   # swap words in label ?
             plefty=plefty - o_vdist  #where to draw the _next_ pin
-        elif pin[P_POS] == "r": #right pin
+        elif pin.pos == "r": #right pin
             basex, basey = prightx, prighty 
             xf, yf= -1, 0
             pint=(-200,50,0,0)
@@ -384,7 +441,7 @@ def writesym(filename,options,attr,pins):
             negl=(0, CHARHIGH*4+20,2,0)
             swap=1
             prighty=prighty - o_vdist
-        elif pin[P_POS] == "b": # bottom pin
+        elif pin.pos == "b": # bottom pin
             basex, basey=pbottomx, pbottomy
             xf, yf= 0, 1
             if o_rotate == "yes": # bottom pin with 90° text
@@ -401,7 +458,7 @@ def writesym(filename,options,attr,pins):
                 negl=(0,CHARHIGH*4+20,1,0)
             swap=0
             pbottomx=pbottomx + o_hdist
-        elif pin[P_POS] == "t": # top pin
+        elif pin.pos == "t": # top pin
             basex, basey=ptopx, ptopy
             xf, yf= 0, -1
             if o_rotate == "yes": # with 90° text
@@ -420,8 +477,8 @@ def writesym(filename,options,attr,pins):
                 swap=0
             ptopx=ptopx + o_hdist
 ### draw the pin
-        if (pin[P_STYLE]=="dot" or  #short pin and dot?
-            pin[P_STYLE]=="dotclk"):
+        if (pin.style=="dot" or  #short pin and dot?
+            pin.style=="dotclk"):
             x=basex + xf*200
             y=basey + yf*200
         else:
@@ -433,23 +490,23 @@ def writesym(filename,options,attr,pins):
         pintx, pinty, pinta, pintr=pint
         x=basex+pintx
         y=basey+pinty
-        if pin[P_POS] == "t": # top pin
+        if pin.pos == "t": # top pin
 	    y += 50
         f.write("T %i"%x+" %i"%y+" 5 8 1 1 %i"%pintr+" %i 1\n"%pinta)
-        f.write("pinnumber="+pin[P_NR]+"\n")
+        f.write("pinnumber="+pin.nr+"\n")
 ### draw pinseq
         pintx, pinty, pinta, pintr=pinq
         x=basex+pintx
         y=basey+pinty
-        if pin[P_POS] == "t": # top pin
+        if pin.pos == "t": # top pin
 	    y += 50
         f.write("T %i"%x+" %i"%y+" 5 8 0 1 %i"%pintr+" %i 1\n"%pinta)
-        f.write("pinseq="+pin[P_SEQ]+"\n")
+        f.write("pinseq="+pin.seq+"\n")
 ### draw pinlabel and pintype
         pinlx, pinly, pinla, pinlr=pinl
         pinax, pinay, pinaa, pinar=pina
-        if (pin[P_STYLE]=="clk" or  #move label if clocksign
-            pin[P_STYLE]=="dotclk"):
+        if (pin.style=="clk" or  #move label if clocksign
+            pin.style=="dotclk"):
             pinlx=pinlx + xf*75
             pinly=pinly + yf*75
             pinax=pinax + xf*75
@@ -459,22 +516,22 @@ def writesym(filename,options,attr,pins):
         pinax=pinax + basex
         pinay=pinay + basey
         if o_wordswap=="yes" and swap==1:
-            label=swapwords(pin[P_LABEL])
+            label=swapwords(pin.label)
         else:
-            label=pin[P_LABEL]
+            label=pin.label
         f.write("T %i"%pinlx+" %i"%pinly+" 9 8 1 1 %i"%pinlr+" %i 1\n"%pinla)
         f.write("pinlabel="+label+"\n")
         f.write("T %i"%pinax+" %i"%pinay+" 5 8 0 1 %i"%pinar+" %i 1\n"%pinaa)
-        f.write("pintype="+pin[P_TYPE]+"\n")
+        f.write("pintype="+pin.type+"\n")
         f.write("}\n")
 ### draw the negation bubble
-        if (pin[P_STYLE]=="dot" or pin[P_STYLE]=="dotclk"):
+        if (pin.style=="dot" or pin.style=="dotclk"):
             x=basex + xf*250
             y=basey + yf*250
             f.write("V %i"%x+" %i"%y +" 50 6 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n")
 ### draw the clocksign
-        if (pin[P_STYLE]=="clk" or
-            pin[P_STYLE]=="dotclk"):
+        if (pin.style=="clk" or
+            pin.style=="dotclk"):
             x1=basex+ xf*400
             y1=basey+ yf*400
             x2=x1- xf*100 +yf*75
@@ -541,11 +598,11 @@ def writesym(filename,options,attr,pins):
 
     nets={}
     for pin in pins:
-        if pin[P_STYLE] == "none":
-            if not nets.has_key(pin[P_NET]):
-                nets[pin[P_NET]] = pin[P_NR]
+        if pin.style == "none":
+            if not nets.has_key(pin.net):
+                nets[pin.net] = pin.nr
             else:
-                nets[pin[P_NET]] = nets[pin[P_NET]] + ","+ pin[P_NR]
+                nets[pin.net] = nets[pin.net] + ","+ pin.nr
     for key,value in nets.items():
         f.write("T %i" %textx + " %i"% texty + " 5 10 0 0 0 0 1\n")
         f.write("net=" + key + ":" + value + "\n")
@@ -566,22 +623,37 @@ def mergeoptions(source_opt,pre_opt):
 def generate_pinseq(pins):
     seq=1
     for nr in xrange(len(pins)):
-        if pins[nr][P_STYLE] not in ["none","spacer"]:
-            pins[nr][P_SEQ] = "%i"%seq
+        if pins[nr].style not in ["none","spacer"]:
+            pins[nr].seq = "%i"%seq
             seq = seq + 1
     return pins
 
 ###################### MAIN #################################################
 
-## TODO: use getopt
+## parse command line options
 try:
-    file_in=sys.argv[1]
-    file_out=sys.argv[2]
+    opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
 except:
-    print "tragesym version " + VERSION
-    print "Bad arguments, usage is: ", sys.argv[0] ,"infile outfile"
+    usage()
     sys.exit()
-    
+
+## handle command line options
+for o, a in opts:
+    if o in ("-h", "--help"):
+        usage()
+        sys.exit()
+
+## get files
+if len(args) != 2:
+    usage()
+    sys.exit()
+
+file_in=args[0]
+file_out=args[1]
+if not os.path.exists(file_in):
+    print "Input file " + file_in + " not found."
+    sys.exit()
+
 ## read sourcefile
 opts,attr,pins=readsrc(file_in)
 



_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs