#!/usr/bin/python

formats=dict([x.split(None,1) for x in """L x1 y1 x2 y2 color width capstyle dashstyle dashlength dashspace
G x1 y1 width height angle ratio mirrored embedded
B x y width height color width capstyle dashtype dashlength dashspace filltype fillwidth angle1 pitch1 angle2 pitch2
V x y radius color width capstyle dashtype dashlength dashspace filltype fillwidh angle1 pitch1 angle2 pitch2
A x y radius startangle sweepangle color width capstyle dashtype dashlength dashspace
T x y color size visibility show_name_value angle alignment num_lines
N x1 y1 x2 y2 color
U x1 y1 x2 y2 color ripperdir
P x1 y1 x2 y2 color pintype whichend
C x y selectable angle mirror basename""".split('\n')])

scaleable=['x','y','x1','y1','x2','y2','width','height','radius','size']

import sys

try:
    scale=float(sys.argv[1])
except:
    print >>sys.stderr, "Use like this: \n%s SCALE < infile.sym > outfile.sym"%sys.argv[0]
    print >>sys.stderr, "Where SCALE is the amount to scale from the origin, \ne.g 2.0 for doubling the size"
    sys.exit(1)

def rescale(l):
    bits=l.split()

    try:
        format_type=bits.pop(0)
        my_format=formats[format_type].split()
    except IndexError,KeyError:
        return l

    if not len(bits)==len(my_format):
        return l

    return ' '.join([format_type]+[(m in scaleable and "%d"%(float(b)*scale) or b) for m,b in zip(my_format,bits)])

print '\n'.join([rescale(l.strip()) for l in sys.stdin.readlines()])

