~ubuntu-branches/ubuntu/trusty/geda-utils/trusty

« back to all changes in this revision

Viewing changes to scripts/sarlacc_sym

  • Committer: Bazaar Package Importer
  • Author(s): Hamish Moffatt
  • Date: 2005-03-15 23:04:53 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050315230453-x3x6qtw9qv17zbnf
Tags: 20050313-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
##  Library version 0.94
 
4
##  This program is released under the terms of the GNU GPL
 
5
##  See www.fsf.org for a copy of the license
 
6
##
 
7
##  Copyright 1999 Matthew Ettus
 
8
##  For more info, email matt@ettus.com
 
9
##
 
10
##  This program will convert ORCAD text libraries to gEDA components
 
11
##
 
12
##  Changes 0.94 by <egil@kvaleberg.no>, october 5th 2002
 
13
##      Implement CLK modifier
 
14
##      Implement negation for text ('\'-character)
 
15
##      Doubled size to better fit with gEDA symbols
 
16
##      Default to U? refdes, fixed refdes and made visible
 
17
##      Define sarlacc_dim attribute for sarlacc_scheme
 
18
##      Command line options
 
19
##
 
20
##  Changes 0.93 by <egil@kvaleberg.no>, october 4th 2002
 
21
##      Pin attribs modified for 20020825 convention
 
22
##      File format to 20020825 convention
 
23
##      Give duplicate components correct names
 
24
##      Implemented BITMAP
 
25
##      Implemented CONVERT
 
26
##      Implemented multiple slot component
 
27
##      Better syntax check for pin defs
 
28
##      Removed negative coordinates by adding an offset
 
29
##      Got rid of need to calculate text sizes
 
30
##      Got the ARC right
 
31
##      Graphics components has invisible pin labels
 
32
##      Implemented pintype PWR
 
33
##      Implement pintypes (IN, I/O, hiZ, OUT, PAS, OC, OE)
 
34
##
 
35
##  Todo
 
36
##      Implement symbols like THREE_STATE
 
37
##      Implement FILL (?)
 
38
##
 
39
 
 
40
$version = "0.94";
 
41
$gedaversion="20020825";
 
42
 
 
43
#
 
44
# colors
 
45
#
 
46
$pin_color = 1;         # white
 
47
$graphic_color = 3;     # green
 
48
$attribute_color = 5;   # yellow
 
49
$text_color = 9;        # green
 
50
 
 
51
#
 
52
# symbol scaling
 
53
#
 
54
 
 
55
# was 6:
 
56
$pinnumsize = 8;
 
57
$partnamesize = 10;
 
58
# was 100:
 
59
$scale = 200;
 
60
 
 
61
$pinlen = 3;
 
62
$xoffset = $pinlen * $scale;
 
63
$yoffset = $pinlen * $scale;
 
64
 
 
65
#
 
66
# character width table (approximate)
 
67
#
 
68
@char_width=(
 
69
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
70
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
71
     11,14,14,22,28,28,24,10,12,12,16,20,14,20,12,18,
 
72
     26,16,26,20,26,20,24,20,22,26,12,12,20,20,20,20,
 
73
     36,29,29,28,26,29,21,30,29,9,21,27,22,32,28,32,
 
74
     25,32,26,25,23,27,27,37,27,25,27,12,14,12,20,25,
 
75
     10,24,22,22,20,20,12,24,20,8,10,19,9,32,20,20,
 
76
     20,24,14,18,12,19,20,28,19,20,21,12,10,12,22,0,
 
77
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
78
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
79
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
80
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
81
     0,0,0,0,29,29,0,0,0,0,0,0,0,0,0,0,
 
82
     0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,
 
83
     0,0,0,0,24,24,0,0,0,0,0,0,0,0,0,0,
 
84
     0,0,0,0,0,0,20,0,0,0,0,0,0,0,0,0
 
85
);                                           
 
86
 
 
87
sub string_len 
 
88
 
89
    $char_points = 2;
 
90
    $width = 0;
 
91
    @expanded = unpack "C*",$_[0];
 
92
    foreach $char (@expanded)
 
93
    {
 
94
        $width += $char_width[$char];
 
95
    }
 
96
    $width = ($_[1]*$width)/$char_points;
 
97
    return $width;
 
98
}         
 
99
 
 
100
#
 
101
#  draw a pin
 
102
#  $x1
 
103
#  $x2
 
104
#  $dx
 
105
#  $dy
 
106
#
 
107
sub draw_pin
 
108
{
 
109
        local $sx,$sy;
 
110
        local $x2,$y2;
 
111
        $sx = 0;
 
112
        $sx = 1 if ($dx > 0);
 
113
        $sx = -1 if ($dx < 0);
 
114
        $sy = 0;
 
115
        $sy = 1 if ($dy > 0);
 
116
        $sy = -1 if ($dy < 0);
 
117
 
 
118
        $x2 = $x1 + $sx * $len;
 
119
        $y2 = $y1 + $sy * $len;
 
120
 
 
121
        if( $is_clk )
 
122
        {
 
123
                local $xa,$ya,$xb,$xb;
 
124
 
 
125
                $xa = $x1 - $sy * $spacing;
 
126
                $xb = $x1 - $sx * $spacing;
 
127
                $ya = $y1 - $sx * $spacing;
 
128
                $yb = $y1 - $sy * $spacing;
 
129
                print COMPONENT "L $xa $ya $xb $yb $graphic_color".
 
130
                                   " 0 0 0 -1 -1\n";
 
131
                $xa = $x1 + $sy * $spacing;
 
132
                $ya = $y1 + $sx * $spacing;
 
133
                print COMPONENT "L $xa $ya $xb $yb $graphic_color".
 
134
                                   " 0 0 0 -1 -1\n";
 
135
        }
 
136
 
 
137
        if ( not ($pinlabel =~ /\$/) && not $is_graphic)
 
138
        {
 
139
                # negation?
 
140
                if ( $pinlabel =~ /\\/ )
 
141
                {
 
142
                        local $w;
 
143
                        $pinlabel =~ tr/\\//d;
 
144
                        $w = string_len($pinlabel,$pinnumsize);
 
145
 
 
146
                        if ($w > 0) {
 
147
                                local $xa,$ya,$xb,$xb;
 
148
 
 
149
                                $xa = $x1 + abs($sy) * $spacing
 
150
                                          - $sx * $spacing;
 
151
                                $xb = $x1 + abs($sy) * $spacing
 
152
                                          - $sx * ($spacing + $w);
 
153
                                $ya = $y1 + abs($sx) * $spacing
 
154
                                          - $sy * $spacing;
 
155
                                $yb = $y1 + abs($sx) * $spacing
 
156
                                          - $sy * ($spacing + $w);
 
157
                                print COMPONENT "L $xa $ya $xb $yb $text_color".
 
158
                                        " 0 0 0 -1 -1\n";
 
159
                        }
 
160
                }
 
161
        }
 
162
 
 
163
        if( $dotsize )
 
164
        {
 
165
                local $rad;
 
166
 
 
167
                $rad = $dotsize / 2;
 
168
                $x1 += $sx * $rad;
 
169
                $y1 += $sy * $rad;
 
170
                print COMPONENT "V $x1 $y1 $rad $pin_color ",
 
171
                                   " 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n";
 
172
                $x1 += $sx * $rad;
 
173
                $y1 += $sy * $rad;
 
174
        }
 
175
 
 
176
        print COMPONENT "P $x1 $y1 $x2 $y2 $pin_color\n";
 
177
}
 
178
 
 
179
#
 
180
#  define a pin
 
181
#  $pinseq
 
182
#  $place
 
183
#  $pinnumbers
 
184
#  $pintype
 
185
#  $pinlabel
 
186
#  $slots
 
187
#  $is_graphic
 
188
#
 
189
sub def_pin
 
190
{
 
191
        if ($pinnumbers =~ /^(.*)[ \t]+([A-Za-z]+)[ \t]*$/ )
 
192
        {
 
193
                $pinnumbers = $1;
 
194
                $modifier = $2;
 
195
        }
 
196
        else
 
197
        {
 
198
                $modifier = "";
 
199
        }
 
200
        chomp $pinnumbers;
 
201
 
 
202
        $len = $pinlen * $scale;
 
203
        $visibility = 1;
 
204
        $dotsize = 0;
 
205
        $is_clk = 0;
 
206
        if ($modifier eq "DOT")
 
207
        {
 
208
                $dotsize = $scale / 2;
 
209
        }
 
210
        elsif ($modifier eq "SHORT")
 
211
        {
 
212
                $len = $scale;
 
213
        }
 
214
        elsif ($modifier eq "CLK")
 
215
        {
 
216
                $is_clk = 1;
 
217
        }
 
218
        elsif ($modifier ne "")
 
219
        {
 
220
                print "Modifier not supported: $modifier\n";
 
221
        }
 
222
 
 
223
        $is_pwr = 0;
 
224
        if ($pintype eq "PWR")
 
225
        {
 
226
                $is_pwr = 1;
 
227
                $visibility = 0;
 
228
        }
 
229
        elsif (($a = $pintype_assoc{$pintype}) ne "")
 
230
        {
 
231
                $pintype = $a;
 
232
        }
 
233
        elsif ($pintype ne "")
 
234
        {
 
235
                ## BAD others are: tp clk pwr
 
236
                print "Pintype not supported: $pintype\n";
 
237
        }
 
238
 
 
239
        # by gEDA convention
 
240
        $pinlabel = "Vcc" if ($pinlabel eq "VCC");
 
241
 
 
242
        #
 
243
        #  extract the pin numbers
 
244
        #
 
245
        if ($slots > 1)
 
246
        {
 
247
                $length = @array = split(" ",$pinnumbers);
 
248
                if ($length != $slots)
 
249
                {
 
250
                        print "Error: incorrect number of pins $length, should be $slots\n";
 
251
                        exit;
 
252
                }
 
253
                if (not $is_pwr)
 
254
                {
 
255
                        $def_slot[$pinseq] = [ @array ];
 
256
                }
 
257
                $pinnumber = $array[0];
 
258
        }
 
259
        else
 
260
        {
 
261
                $pinnumber = $pinnumbers;
 
262
        }
 
263
        $pinnumber =~ tr/ //d;
 
264
        $pinnumber =~ tr/\'//d;
 
265
        $pinnumalign = 0;
 
266
        $pinnumangle = 0;
 
267
        $pinlabelalign = 0;
 
268
        $pinlabelangle = 0;
 
269
 
 
270
        #
 
271
        #  place the label
 
272
        #
 
273
        $letter = $num = $place;
 
274
        $letter =~ tr/0-9//d;
 
275
        $num =~ tr/LRTB//d;
 
276
        $spacing = $scale / 2;
 
277
 
 
278
        if ($letter eq "L")
 
279
        {
 
280
                $x1 = $xoffset;
 
281
                $y1 = $yoffset + $ysize - $num*$scale;
 
282
                $dx = -$len;
 
283
                $dy = 0;
 
284
                $textx = $xoffset - $spacing;
 
285
                $texty = $y1 + $scale/10;
 
286
                $namex = $xoffset + $spacing;
 
287
                $namey = $y1;
 
288
                $pinlabelalign = 1;
 
289
                $pinnumalign = 6;
 
290
        }
 
291
        elsif ($letter eq "R")
 
292
        {
 
293
                $x1 = $xoffset + $xsize;
 
294
                $y1 = $yoffset + $ysize - $num*$scale;
 
295
                $dx = $len;
 
296
                $dy = 0;
 
297
                $textx = $xoffset + $xsize + $spacing;
 
298
                $texty = $y1 + $scale/10;
 
299
                $namex = $xoffset + $xsize - $spacing;
 
300
                $namey = $y1;
 
301
                $pinlabelalign = 7;
 
302
        }
 
303
        elsif ($letter eq "T")
 
304
        {
 
305
                $x1 = $xoffset + $num*$scale;
 
306
                $y1 = $yoffset + $ysize;
 
307
                $dx = 0;
 
308
                $dy = $len;
 
309
                $textx = $x1 - $scale/10;
 
310
                $texty = $yoffset + $ysize + $spacing;
 
311
                $namex = $x1;
 
312
                $namey = $yoffset + $ysize - $spacing;
 
313
                $pinnumangle = $pinlabelangle = 90;
 
314
                $pinlabelalign = 7;
 
315
        }
 
316
        elsif ($letter eq "B")
 
317
        {
 
318
                $y1 = $yoffset;
 
319
                $x1 = $xoffset + $num*$scale;
 
320
                $dx = 0;
 
321
                $dy = -$len;
 
322
                $textx = $x1 - $scale/10;
 
323
                $texty = $yoffset - $spacing;
 
324
                $namex = $x1;
 
325
                $namey = $yoffset + $spacing;
 
326
                $pinnumangle = $pinlabelangle = 90;
 
327
                $pinlabelalign = 1;
 
328
                $pinnumalign = 6;
 
329
        }
 
330
        else
 
331
        {
 
332
                print "Cannot happen: $letter\n";
 
333
                exit;
 
334
        }
 
335
 
 
336
        if( $is_pwr )
 
337
        {
 
338
                if ($pinnumber ne "")
 
339
                {
 
340
                        print COMPONENT "T $textx $texty $attribute_color $pinnumsize 0 0 0 0\n";
 
341
                        print COMPONENT "net=$pinlabel:$pinnumber\n";
 
342
                }
 
343
        }
 
344
        else
 
345
        {
 
346
                draw_pin();
 
347
 
 
348
                ++$pinseq;
 
349
 
 
350
                print COMPONENT "{\n";
 
351
 
 
352
                # *EK* use pinnumber= and pinseq= for 20020825
 
353
                if ($pinnumber ne "")
 
354
                {
 
355
                        print COMPONENT "T $textx $texty $attribute_color $pinnumsize $visibility 1 $pinnumangle $pinnumalign\n";
 
356
                        print COMPONENT "pinnumber=$pinnumber\n";
 
357
                }
 
358
                print COMPONENT "T $textx $texty $attribute_color $pinnumsize 0 0 0 0\n";
 
359
                print COMPONENT "pinseq=$pinseq\n";
 
360
                print COMPONENT "T $textx $texty $attribute_color $pinnumsize 0 0 0 0\n";
 
361
                print COMPONENT "pintype=$pintype\n";
 
362
 
 
363
                if ( not ($pinlabel =~ /\$/) )
 
364
                {
 
365
                        # do not show label if graphic package
 
366
                        $visibility = 0 if ($is_graphic);
 
367
 
 
368
                        print COMPONENT "T $namex $namey $text_color ",
 
369
                        "$pinnumsize $visibility 1 $pinlabelangle $pinlabelalign\n";
 
370
                        print COMPONENT "pinlabel=$pinlabel\n";
 
371
                }
 
372
                print COMPONENT "}\n";
 
373
        }
 
374
}
 
375
 
 
376
#
 
377
#  define all pins
 
378
#  $is_graphic
 
379
#
 
380
sub def_all_pins
 
381
{
 
382
        $pinseq = 0;
 
383
 
 
384
        #
 
385
        #  define the pins
 
386
        #
 
387
        for ($pin = 0; $pin < $pins; ++$pin)
 
388
        {
 
389
                $place      = $def_place[$pin];
 
390
                $pinnumbers = $def_pinnumbers[$pin];
 
391
                $pintype    = $def_pintype[$pin];
 
392
                $pinlabel   = $def_pinlabel[$pin];
 
393
 
 
394
                def_pin();
 
395
        }
 
396
}
 
397
 
 
398
#
 
399
#  next component
 
400
#  $component
 
401
#  $namelist
 
402
#  $slots
 
403
#
 
404
sub def_component
 
405
{
 
406
        open(COMPONENT,">$component-$convert.sym");
 
407
        print COMPONENT "v $gedaversion\n";
 
408
 
 
409
        print COMPONENT "T $scale 0 $attribute_color $partnamesize 1 1 0 0\n";
 
410
        print COMPONENT "refdes=$refdes?\n";
 
411
 
 
412
        # make displayed name also an attribute
 
413
        print COMPONENT "T $scale $scale $attribute_color $partnamesize 1 1 0 0\n";
 
414
        print COMPONENT "partno=$component\n";
 
415
        print COMPONENT "T $scale $scale $attribute_color $partnamesize 0 1 0 0\n";
 
416
        print COMPONENT "device=$component\n";
 
417
 
 
418
 
 
419
        if ( $slots > 1 )
 
420
        {
 
421
                print COMPONENT "T $scale $scale $attribute_color $partnamesize 0 0 0 0\n";
 
422
                print COMPONENT "slot=1\n";
 
423
                print COMPONENT "T $scale $scale $attribute_color $partnamesize 0 0 0 0\n";
 
424
                print COMPONENT "numslots=$slots\n";
 
425
        }
 
426
        else
 
427
        {
 
428
                print COMPONENT "T $scale $scale $attribute_color $partnamesize 0 0 0 0\n";
 
429
                print COMPONENT "numslots=0\n";
 
430
        }
 
431
 
 
432
        $pins = 0;
 
433
 
 
434
        #
 
435
        #  scan the pins
 
436
        #
 
437
        while (($line = <LIBRARY>) =~
 
438
            /(^[LRTB][0-9]+)(.*)[ \t]+([A-Za-z\/]+)[ \t]+'(.*)'/ )
 
439
        #      L1            3 DOT     I/O               'OUTPUT'
 
440
        {
 
441
                $def_place[$pins]        = $1;
 
442
                $def_pinnumbers[$pins]   = $2;
 
443
                $def_pintype[$pins]      = $3;
 
444
                $def_pinlabel[$pins]     = $4;
 
445
                ++$pins;
 
446
        }
 
447
 
 
448
        #
 
449
        #  define the body
 
450
        #
 
451
 
 
452
        #skip Orcad bitmaps
 
453
        while ($line =~ /\{/)
 
454
        {
 
455
                $line = <LIBRARY>;
 
456
        }
 
457
 
 
458
        if ( $line =~ /BITMAP[ \t]+'(.*)'/ )
 
459
        {
 
460
                $is_graphic = 1;
 
461
                def_all_pins();
 
462
 
 
463
                # re-use previous vector image
 
464
                $def_body = $body{$1};
 
465
 
 
466
                $line = <LIBRARY>;
 
467
        }
 
468
        elsif (( $line = <LIBRARY>) =~ /VECTOR/ )
 
469
        {
 
470
                $is_graphic = 1;
 
471
                def_all_pins();
 
472
 
 
473
                $def_body="";
 
474
                while (not (( $line = <LIBRARY>) =~ /END/))
 
475
                {
 
476
                        if ($line =~ /LINE/)
 
477
                        {
 
478
                                ($dummy,$x1,$y1,$x2,$y2)=
 
479
                                        split(" ",$line);
 
480
                                $x1 = $xoffset + $x1*$scale;
 
481
                                $y1 = $yoffset + $ysize - $y1*$scale;
 
482
                                $x2 = $xoffset + $x2*$scale;
 
483
                                $y2 = $yoffset + $ysize - $y2*$scale;
 
484
                                $def_body .= "L $x1 $y1 $x2 $y2 $graphic_color".
 
485
                                           " 0 0 0 -1 -1\n";
 
486
                        }
 
487
                        elsif($line =~ /TEXT/)
 
488
                        {
 
489
                                # BAD set textsize properly , check multi-line text
 
490
                                ($dummy,$x1,$y1,$textsize,$text)=split(" ",$line);
 
491
                                $x1 = $xoffset + $x1*$scale;
 
492
                                $y1 = $yoffset + $ysize - $y1*$scale;
 
493
 
 
494
                                # print "Text=$text\n";
 
495
                                if ($text eq "OPEN_L")
 
496
                                {
 
497
                                        # BAD ignore
 
498
                                }
 
499
                                elsif ($text eq "OPEN_H")
 
500
                                {
 
501
                                        # BAD ignore
 
502
                                }
 
503
                                elsif ($text eq "THREE_STATE")
 
504
                                {
 
505
                                        # BAD ignore
 
506
                                }
 
507
                                elsif ($text !~ /'/)
 
508
                                {
 
509
                                        print "Symbol not supported: $text\n";
 
510
                                }
 
511
                                else 
 
512
                                {
 
513
                                        $text=~ tr/\'//d;
 
514
                                        $textsize *= $pinnumsize;
 
515
                                        $def_body .= "T $x1 $y1 $graphic_color $textsize 1 0 0 0\n".
 
516
                                                   "$text\n";
 
517
                                }
 
518
                        }
 
519
                        elsif ($line =~ /CIRCLE/)
 
520
                        {
 
521
                                ($dummy,$x1,$y1,$radius) = split(" ",$line);
 
522
                                $x1 = $xoffset + $x1*$scale;
 
523
                                $y1 = $yoffset + $ysize - $y1*$scale;
 
524
                                $radius *= $scale;
 
525
                                $def_body .= "V $x1 $y1 $radius $graphic_color".
 
526
                                           " 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n";
 
527
                        }
 
528
                        elsif ($line =~ /ARC/)
 
529
                        {
 
530
                                ($dummy,$x1,$y1,$dx1,$dy1,$dx2,$dy2,$rad) =
 
531
                                                        split(" ",$line);
 
532
                                $x1 = $xoffset + $x1*$scale;
 
533
                                $y1 = $yoffset + $ysize - $y1*$scale;
 
534
                                $factor = 180 / atan2(1,1) / 4;
 
535
                                $startangle = int ( $factor * atan2 (-$dy1, $dx1));
 
536
                                $endangle = int ( $factor * atan2 (-$dy2, $dx2));
 
537
                                $sweepangle = $endangle - $startangle;
 
538
                                # Orcad brain damage: ARC is always < 180 deg
 
539
                                if ($sweepangle > 180) {
 
540
                                        $sweepangle -= 360;
 
541
                                }
 
542
                                if ($sweepangle < -180) {
 
543
                                        $sweepangle += 360;
 
544
                                }
 
545
                                $rad *= $scale;
 
546
                                $def_body .= "A $x1 $y1 $rad".
 
547
                                        " $startangle $sweepangle $graphic_color".
 
548
                                        " 0 0 0 -1 -1\n";
 
549
                        }
 
550
                        elsif ($line =~ /FILL/)
 
551
                        {
 
552
                                # BAD Ignore FILL
 
553
                        }
 
554
                        else
 
555
                        {
 
556
                                print "Unrecognized tag:\n $line \n";
 
557
                                exit;
 
558
                        }
 
559
                }
 
560
 
 
561
                $line = <LIBRARY>;
 
562
        }
 
563
        else
 
564
        {
 
565
                $is_graphic = 0;
 
566
                def_all_pins();
 
567
 
 
568
                $x1 = $xoffset;
 
569
                $y1 = $yoffset;
 
570
 
 
571
                $def_body = "B $x1 $y1 $xsize $ysize $graphic_color".
 
572
                          " 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n";
 
573
 
 
574
        }
 
575
 
 
576
        #
 
577
        #  define slots, if any
 
578
        #
 
579
        if ($slots > 1)
 
580
        {
 
581
                for ($s = 0; $s < $slots; ++$s)
 
582
                {
 
583
                        print COMPONENT "T $scale $scale $attribute_color $partnamesize 0 0 0 0\n";
 
584
                        print COMPONENT "slotdef=",$s+1;
 
585
                        $c = ":";
 
586
 
 
587
                        for ($n = 0; $n < $pinseq; ++$n)
 
588
                        {
 
589
                                $pin = $def_slot[$n][$s];
 
590
                                print COMPONENT "$c$pin";
 
591
                                $c = ",";
 
592
                        }
 
593
                        print COMPONENT "\n";
 
594
                }
 
595
        }
 
596
 
 
597
        #
 
598
        #  emit text for body
 
599
        #
 
600
        print COMPONENT "$def_body";
 
601
        $body{$component} = "$def_body";
 
602
 
 
603
        #
 
604
        # for sarlacc_schem
 
605
        #
 
606
        print COMPONENT "T $scale $scale $attribute_color $partnamesize 0 0 0 0\n";
 
607
        print COMPONENT "sarlacc_dim=$xoffset,$yoffset,$xsize,$ysize\n";
 
608
 
 
609
        close(COMPONENT);
 
610
 
 
611
        #
 
612
        # make copies for multiple component names.
 
613
        # device= changed to suit
 
614
        #
 
615
        foreach $duplicate (@namelist)
 
616
        {
 
617
                # make duplicate component, remembering to change device name
 
618
                `cat $component-1.sym                   |
 
619
                 sed "s/partno=$component/partno=$duplicate/" |
 
620
                 sed "s/device=$component/device=$duplicate/" |
 
621
                 cat >$duplicate-1.sym`;
 
622
        }
 
623
}
 
624
 
 
625
#
 
626
#  main loop
 
627
#  arg: library name
 
628
#
 
629
sub main_loop
 
630
{
 
631
    local $library = $_[0];
 
632
 
 
633
    open(LIBRARY,$library ) or die "Can't open $library:  $!\n";
 
634
 
 
635
    $line = <LIBRARY>;
 
636
    if ( not ($line =~ /Compiled/ ))
 
637
    {
 
638
            print $line;
 
639
            print "Not a library file: $library\n";
 
640
            die;
 
641
    }
 
642
 
 
643
    while (not (<LIBRARY> =~ /PREFIX/)){};
 
644
    while (not (<LIBRARY> =~ /END/)){};
 
645
 
 
646
    $line = <LIBRARY>;
 
647
 
 
648
    while (not (eof LIBRARY))
 
649
    {
 
650
            if ($line =~ /\'/)
 
651
            {
 
652
                    $component = $line;
 
653
                    $component =~ s/\'//g;
 
654
                    chomp $component;
 
655
                    $component =~ s/\r//g;
 
656
                    $component =~ s/\ /_/g;
 
657
                    $convert = 1;
 
658
                    $refdes="U";
 
659
 
 
660
                    # Handle components with multiple names....
 
661
                    @namelist = ();
 
662
                    while (($line = <LIBRARY>) =~ /^\'/)
 
663
                    {
 
664
                            $line =~ s/\'//g;
 
665
                            chomp $line;
 
666
                            $line =~ s/\r//g;
 
667
                            $line =~ s/\ /_/g;
 
668
                            push @namelist ,( $line);
 
669
                    }
 
670
 
 
671
                    if ($line =~ /REFERENCE/)
 
672
                    {
 
673
                            ($dummy,$refdes) = split("\'",$line);
 
674
                            $line = <LIBRARY>;
 
675
                    }
 
676
 
 
677
                    ($dummy,$x,$y,$slots) = split("=}",$line);
 
678
                    ($xsize) = split(" ",$x);
 
679
                    ($ysize) = split(" ",$y);
 
680
                    $xsize *= $scale;
 
681
                    $ysize *= $scale;
 
682
 
 
683
                    chomp $slots;
 
684
                    $slots =~ tr/ //d;
 
685
 
 
686
                    # print "Define: $component\n";
 
687
 
 
688
                    def_component();
 
689
            }
 
690
            elsif ( $line =~ /CONVERT/ )
 
691
            {
 
692
                   $convert += 1;
 
693
                   def_component();
 
694
            }
 
695
            else
 
696
            {
 
697
                   $line = <LIBRARY>;
 
698
            }
 
699
    }
 
700
    close(LIBRARY);
 
701
}
 
702
 
 
703
#
 
704
#  main
 
705
#
 
706
 
 
707
# pin types for Orcad to gEDA
 
708
$pintype_assoc{'PWR'} = "pwr";
 
709
$pintype_assoc{'IN'}  = "in";
 
710
$pintype_assoc{'I/O'} = "io";
 
711
$pintype_assoc{'OUT'} = "out";
 
712
$pintype_assoc{'hiZ'} = "tri";
 
713
$pintype_assoc{'PAS'} = "pas";
 
714
$pintype_assoc{'OC'}  = "oc";
 
715
$pintype_assoc{'OE'}  = "oe";
 
716
 
 
717
$argc = @ARGV;
 
718
 
 
719
for ($argn = 0; $argn < @ARGV; ++$argn)
 
720
{
 
721
        $arg = $ARGV[$argn];
 
722
        if ($arg =~ /^-([A-Za-z?])(.*)$/ ) {
 
723
                if ($1 eq "s") {
 
724
                        $scale = $2;
 
725
                } elsif ($1 eq "v") {
 
726
                        print "sarlacc_sym ver $version\n";
 
727
                } else {
 
728
                        print "Convert Oracd symbol library (text format) to gEDA\n";
 
729
                        print "\nUsage:   sarlacc_sym [options] library",
 
730
                           "\nOptions:",
 
731
                         # "\n         -d<dir>  directory for symbols",
 
732
                           "\n         -h       help",
 
733
                           "\n         -s<n>    scale <n>%, default is $scale",
 
734
                           "\n         -v       version",
 
735
                           "\n\n";
 
736
                        die;
 
737
                }
 
738
        } else {
 
739
                main_loop($arg);
 
740
        }
 
741
}
 
742
 
 
743
 
 
744
 
 
745
 
 
746
 
 
747
 
 
748
 
 
749