LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Scripting magic badly needed (https://www.linuxquestions.org/questions/linux-software-2/scripting-magic-badly-needed-4175457693/)

business_kid 04-10-2013 01:19 PM

Scripting magic badly needed
 
I am trying to modify a file 85,000 lines long, so you'll understand why I don't want to do it manually. Kicad complains about the line numbers in bold because it can't draw them. Apologies for the length of this, but it's one component after the other, each with the same mistake.
Code:

#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I
X I1 3 -300 -100 200 R 40 40 1 1 I
X O 4 300 0 200 L 40 40 1 1 O I
# Gate Name: B
# Symbol Name: 7400

P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 6 -300 100 200 R 40 40 2 1 I
X I1 8 -300 -100 200 R 40 40 2 1 I
X O 9 300 0 200 L 40 40 2 1 O I
# Gate Name: C
# Symbol Name: 7400

P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 13 -300 100 200 R 40 40 3 1 I
X I1 14 -300 -100 200 R 40 40 3 1 I
X O 12 300 0 200 L 40 40 3 1 O I
# Gate Name: D
# Symbol Name: 7400

P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 18 -300 100 200 R 40 40 4 1 I
X I1 19 -300 -100 200 R 40 40 4 1 I
# Gate Name: P
# Symbol Name: PWRN

T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 10 0 -300 200 U 40 40 5 1 W
X VCC 20 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF

What is below works - I've tested it. How the heck do I get it inserted automagically?

Code:

DEF 7400D IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I
X I1 2 -300 -100 200 R 40 40 1 1 I
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW

P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I
X I1 5 -300 -100 200 R 40 40 2 1 I
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW

P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I
X I1 10 -300 -100 200 R 40 40 3 1 I
X O 8 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW

P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I
X I1 13 -300 -100 200 R 40 40 4 1 I
X O 11 300 0 200 L 40 40 4 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW

T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF

Any ideas welcome. Changing back versions is not really an option. There are 2 very troublesome dependencies to compile for this, and the required options on the first are a mystery. So I end up compiling dependency 1, dependency 2 (which uses 1) and then kicad which barfs with an error related to dependency 1. It's an endless loop.

unSpawn 04-10-2013 01:49 PM

sed -i "s|^.*Symbol.Name.*|\0\n# DRAW|g" -e "s|^.*Gate.*|# ENDDRAW\n\0|g" /path/to/file?

druuna 04-10-2013 01:49 PM

Have a look at this:
Code:

sed -re 's/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e 's/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/' infile

business_kid 04-11-2013 04:36 AM

Gentlemen, I am highly impressed! Thank you both for your attempts, which show more than a little intelligence and savvy. I couldn't follow either of them. I copied the file twice, and renamed them unspawn.lib and druuna.lib. UnSpawn's command returned
Quote:

bash-4.2$ sed -i "s|^.*Symbol.Name.*|\0\n# DRAW|g" -e "s|^.*Gate.*|# ENDDRAW\n\0|g" unspawn.lib
sed: can't read s|^.*Symbol.Name.*|\0\n# DRAW|g: No such file or directory
As I took it there was a typo, I left it there.

Druuna's command clogged stdout. So I reran as
Quote:

sed -re 's/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e 's/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/' -i druuna.lib
And it was nearly perfect. Again, the Bold is undesired and should cause errors. Two draw commands without an 'enddraw' breaches syntax. If we got rid of the first one, that would be perfect. I would point out that there are sometimes more or no lines between the line beginning F1 and the first draw - user definition space. There's a web interface for creating devices, and it produces a different format to the supplied libs. Those F0 - F2 lines should not be drawn.

I hung the file (74xx-eu.lib) up here. It's 2.2mb and it allows a test of this.

Code:

# Dev Name: 7400D
# Package Name: SO14
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400D IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
DRAW
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I
X I1 2 -300 -100 200 R 40 40 1 1 I
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I
X I1 5 -300 -100 200 R 40 40 2 1 I
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I
X I1 10 -300 -100 200 R 40 40 3 1 I
X O 8 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I
X I1 13 -300 -100 200 R 40 40 4 1 I
X O 11 300 0 200 L 40 40 4 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF

FWIW, I have Slackware-14.0. bash-4.2$ sed --version returns "GNU sed version 4.2.1".

pan64 04-11-2013 05:13 AM

probably this:
awk ' /# Gate Name:/ { print "ENDDRAW" } { print $0 } /# Symbol Name/ { print "DRAW" } ' test.txt

druuna 04-11-2013 05:23 AM

A little tinkering with my original solution:
Code:

sed -re 's/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e '20,$s/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/' infile > outfile
Results in (using your original example in post #1):
Code:

#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400      This time not followed by DRAW
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I
X I1 3 -300 -100 200 R 40 40 1 1 I
X O 4 300 0 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 6 -300 100 200 R 40 40 2 1 I
X I1 8 -300 -100 200 R 40 40 2 1 I
X O 9 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 13 -300 100 200 R 40 40 3 1 I
X I1 14 -300 -100 200 R 40 40 3 1 I
X O 12 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 18 -300 100 200 R 40 40 4 1 I
X I1 19 -300 -100 200 R 40 40 4 1 I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 10 0 -300 200 U 40 40 5 1 W
X VCC 20 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF


business_kid 04-11-2013 06:52 AM

I'll try today's work in a second, and post again.

@UnSpawn: Your command did process the file, and inserted the ENDDRAW commands in the right place AFAICT. No Draw commands. Only pedantic interpreters would puke on a second ENDDRAW. There are extra ones, but that's because I ran the command more than once.

Code:

# Dev Name: 7400D
# Package Name: SO14
# Dev Tech: ''
# Dev Prefix: IC
# ENDDRAW
# ENDDRAW
# Gate count = 5
#
DEF 7400D IC 0 40 Y Y 5 L N
# ENDDRAW
# ENDDRAW
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I
X I1 2 -300 -100 200 R 40 40 1 1 I
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
# ENDDRAW
# ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I
X I1 5 -300 -100 200 R 40 40 2 1 I
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# ENDDRAW
# ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I
X I1 10 -300 -100 200 R 40 40 3 1 I
X O 8 300 0 200 L 40 40 3 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: D
# Symbol Name: 7400
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I
X I1 13 -300 -100 200 R 40 40 4 1 I
X O 11 300 0 200 L 40 40 4 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF

#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# ENDDRAW
# ENDDRAW
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
# ENDDRAW
# ENDDRAW
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I
X I1 3 -300 -100 200 R 40 40 1 1 I
X O 4 300 0 200 L 40 40 1 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: B
# Symbol Name: 7400
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 6 -300 100 200 R 40 40 2 1 I
X I1 8 -300 -100 200 R 40 40 2 1 I
X O 9 300 0 200 L 40 40 2 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: C
# Symbol Name: 7400
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 13 -300 100 200 R 40 40 3 1 I
X I1 14 -300 -100 200 R 40 40 3 1 I
X O 12 300 0 200 L 40 40 3 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: D
# Symbol Name: 7400
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 18 -300 100 200 R 40 40 4 1 I
X I1 19 -300 -100 200 R 40 40 4 1 I
X O 16 300 0 200 L 40 40 4 1 O I
# ENDDRAW
# ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 10 0 -300 200 U 40 40 5 1 W
X VCC 20 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF


business_kid 04-11-2013 08:00 AM

@pan64: Thank you I had thought of awk, but I have suffering enough with this. Your command inserted too many DRAW & ENDDRAW commands, as you see, the bold entries will cause it to puke. The file is 85000 lines long, one definition after another. I marked a split below.

Code:

DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF
***Comment: end of last device***

#
# Dev Name: 7400FK
# Package Name: LCC20
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400FK IC 0 40 Y Y 5 L N
ENDDRAW
# Gate Name: A
# Symbol Name: 7400
DRAW
F0 "IC" 100 125 50 H V L B
F1 "7400FK" 100 -200 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 2 -300 100 200 R 40 40 1 1 I
X I1 3 -300 -100 200 R 40 40 1 1 I

The rest of the entry is alters flawlessly :-).

@Druuna: PERFECT File is converted. Thank you kindly.
EDIT: Actually, not perfect, just nearly perfect. I got errors every 50 lines or so of this nature
Code:

#
DEF 74148FK IC 0 40 Y Y 2 L N
# Gate Name: A
# Symbol Name: 74148
DRAW
F0 "IC" -300 525 50 H V L B
F1 "74148FK" -300 -700 50 H V L B
F2 "74xx-eu-LCC20" 0 150 50 H I C C
DRAW
P 2 1 0 0 -300 -600 300 -600
P 2 1 0 0 300 -600 300 500
P 2 1 0 0 300 500 -300 500
P 2 1 0 0 -300 500 -300 -600
X 0 13 -500 400 200 R 40 40 1 1 I I
X 1 14 -500 300 200 R 40 40 1 1 I I

With component definitions of 15-25 lines generally, That's every second or third component, and about 1500 errors - a lot to correct by hand. Sod's Law definitely applies! I checked the original file, (which is eagle's components converted) and the original is good.

druuna 04-11-2013 09:21 AM

I've had a better look at the example you posted and you do need some additional tweaks to get it working (100%??)

This is getting ugly, but it seems to do the trick for as far as I can tell:
Code:

# split for better readability
sed -re '35,$s/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' \
    -e '35,${/DEF /,/F0 /!s/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/}' infile > outfile

# as a one-liner
sed -re '35,$s/# Gate Name: ([B-Z])/ENDDRAW\n# Gate Name: \1/' -e '35,${/DEF /,/F0 /!s/# Symbol Name: (.*)/# Symbol Name: \1\nDRAW/}' infile > outfile

Output example of the first block:
Code:

EESchema-LIBRARY Version 2.3  29/04/2008-12:21:03
# Converted with eagle2kicad.ulp Version 0.9
# Device count = 1807
#
# Dev Name: 7400D
# Package Name: SO14
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 5
#
DEF 7400D IC 0 40 Y Y 5 L N
# Gate Name: A
# Symbol Name: 7400
F0 "IC" 100 125 50 H V L B
F1 "7400D" 100 -200 50 H V L B
F2 "74xx-eu-SO14" 0 150 50 H I C C
DRAW
P 2 1 0 0 -100 200 -100 -200
A -100 0 200 -899 899 1 1 0 N -100 -200 -100 200
X I0 1 -300 100 200 R 40 40 1 1 I
X I1 2 -300 -100 200 R 40 40 1 1 I
X O 3 300 0 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: B
# Symbol Name: 7400
DRAW
P 2 2 0 0 -100 200 -100 -200
A -100 0 200 -899 899 2 1 0 N -100 -200 -100 200
X I0 4 -300 100 200 R 40 40 2 1 I
X I1 5 -300 -100 200 R 40 40 2 1 I
X O 6 300 0 200 L 40 40 2 1 O I
ENDDRAW
# Gate Name: C
# Symbol Name: 7400
DRAW
P 2 3 0 0 -100 200 -100 -200
A -100 0 200 -899 899 3 1 0 N -100 -200 -100 200
X I0 9 -300 100 200 R 40 40 3 1 I
X I1 10 -300 -100 200 R 40 40 3 1 I
X O 8 300 0 200 L 40 40 3 1 O I
ENDDRAW
# Gate Name: D
# Symbol Name: 7400
DRAW
P 2 4 0 0 -100 200 -100 -200
A -100 0 200 -899 899 4 1 0 N -100 -200 -100 200
X I0 12 -300 100 200 R 40 40 4 1 I
X I1 13 -300 -100 200 R 40 40 4 1 I
X O 11 300 0 200 L 40 40 4 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 5 0 GND
T 1 50 175 50 0 5 0 VCC
X GND 7 0 -300 200 U 40 40 5 1 W
X VCC 14 0 300 200 D 40 40 5 1 W
ENDDRAW
ENDDEF

Output example of the last issue you posted:
Code:

#
# Dev Name: 74148D
# Package Name: SO16
# Dev Tech: ''
# Dev Prefix: IC
# Gate count = 2
#
DEF 74148D IC 0 40 Y Y 2 L N
# Gate Name: A
# Symbol Name: 74148
F0 "IC" -300 525 50 H V L B
F1 "74148D" -300 -700 50 H V L B
F2 "74xx-eu-SO16" 0 150 50 H I C C
DRAW
P 2 1 0 0 -300 -600 300 -600
P 2 1 0 0 300 -600 300 500
P 2 1 0 0 300 500 -300 500
P 2 1 0 0 -300 500 -300 -600
X 0 10 -500 400 200 R 40 40 1 1 I I
X 1 11 -500 300 200 R 40 40 1 1 I I
X 2 12 -500 200 200 R 40 40 1 1 I I
X 3 13 -500 100 200 R 40 40 1 1 I I
X 4 1 -500 0 200 R 40 40 1 1 I I
X 5 2 -500 -100 200 R 40 40 1 1 I I
X 6 3 -500 -200 200 R 40 40 1 1 I I
X 7 4 -500 -300 200 R 40 40 1 1 I I
X A0 9 500 400 200 L 40 40 1 1 O I
X A1 7 500 300 200 L 40 40 1 1 O I
X A2 6 500 200 200 L 40 40 1 1 O I
X EI 5 -500 -500 200 R 40 40 1 1 I I
X EO 15 500 -500 200 L 40 40 1 1 O
X GS 14 500 -400 200 L 40 40 1 1 O I
ENDDRAW
# Gate Name: P
# Symbol Name: PWRN
DRAW
T 1 50 -155 50 0 2 0 GND
T 1 50 175 50 0 2 0 VCC
X GND 8 0 -300 200 U 40 40 2 1 W
X VCC 16 0 300 200 D 40 40 2 1 W
ENDDRAW
ENDDEF


business_kid 04-11-2013 02:26 PM

@Druuna:

You're on the ball this time. Perfect. Thank you for the effort and willingness to help on this.

I can't test it definitively, because I made the mistake of letting F-18 update, and it's all over the place again.(watch for flame throwers :-). That's my universal experience with F-18. It was nagging me about important updates but I'm unable to boot it atm. That's important all right :-P. It looks like an error in an update to me,
http://www.linuxquestions.org/questi...te-4175457817/

but it just could be a kernel command line.

I spent 2 days doctoring and debugging an extra library of the parts in my design, and a 48pin chip I have to add to them, and I found someone had done some of it already :-/.

David the H. 04-11-2013 05:51 PM

Just to be clear, you need to bracket all instances of "Gate Name" and "Symbol Name" except for the first one? And the lines are always paired?

How about this?
Code:

sed -e '1,/^# Symbol Name/b; -e '/^# Gate Name/i ENDDRAW' -e '/^# Symbol Name/a DRAW' infile
It ignores (branches to the end) every line up to and including the first 'Symbol Name', then simply inserts/appends on every matching pattern after that.

A similar modification could probably be done with pan64's awk command.


Another, probably easier, option would be to simply bracket all lines, then go back and re-edit the file again to remove them from entry A.

allend 04-11-2013 07:47 PM

Quote:

Just to be clear, you need to bracket all instances of "Gate Name" and "Symbol Name" except for the first one? And the lines are always paired?
I do not read the problem that way.
What is required is:
1. a DRAW command is inserted either after a line starting "# Symbol Name" if the next line does not start with F
or
after the last line starting with F following a line starting "# Symbol Name".
2. an ENDDRAW command is inserted after the last line starting with X in a block starting with a line "# Symbol Name".

I think a scripting solution is required.

chrism01 04-11-2013 09:04 PM

Agreed. I am impressed by the sed skills, but given the warning about differing formats in post #4, I think a programming soln would be more flexible.

allend 04-11-2013 11:12 PM

My attempt at a bash solution.
Code:

#!/bin/bash

file=$1
need_draw=false
need_enddraw=false

while read line ;  do
  if [[ ${line:0:13} == "# Symbol Name" ]]; then
    need_draw=true;
    need_enddraw=true;
  elif [[ ${line:0:11} == "# Gate Name" ]] && $need_enddraw; then
    echo "ENDDRAW";
    need_enddraw=false;
  elif [[ ${line:0:4} == "DRAW" ]] && $need_draw; then
    need_draw=false;
  elif [[ ${line:0:1} != "F" ]] && $need_draw; then
    echo "DRAW";
    need_draw=false;
  fi
  echo "$line";
done < $file


business_kid 04-12-2013 09:20 AM

In answer to the queries: I read the problem as (a) adding an ENDDRAW before a gate name _while_inside_ a draw instruction, and then (b) adding a DRAW after the Symbol name provided (a) has happened. Gate A should never be altered.

The background is that there is about 1000 basic 74xx parts, but these are continually remarketed in new technologies and different packages. A 7400, for instance, can be 7400, or [W]74X[Y]00[Z], where
W = a manufacturer prefix - each manufacturer chooses his own unique one, but also borrows others
X = technology. LS, HC, S, F, AC, HV, LV, AUC, etc. At least a dozen technology permutations exist, and more are continually developed
Y = A refinement, flavour, or spin of the technology. (e.g hc, hct)
Z = A package suffix. The 74AUC uses tiny packaging unique to it atm, AFAICT.

The package bit is hugely important as schematics transfer to PCB layout where the package size is critical. In the old days weeks used to be lost doing this manually. Now weeks are lost setting up cad programs to do it automatically :-/.

The 85000 line file is Here On My Skydrive. It's 2.2Mb

@Allend: I copied that file to allend.lib and ran it as you see. Hope that was right.
Code:

bash-4.2$ ./allend.sh allend.lib
./allend.sh: line 8: conditional binary operator expected
./allend.sh: line 8: syntax error near `Name"'
./allend.sh: line 8: `  if [[  == "# Symbol Name" ]]; then'
bash-4.2$ cat allend.lib | ./allend.sh -
./allend.sh: line 8: conditional binary operator expected
./allend.sh: line 8: syntax error near `Name"'
./allend.sh: line 8: `  if [[  == "# Symbol Name" ]]; then'

I repeat, this is 85,000 lines long - one definition after the other. Your script seems to think of one definition per file, to the extent that I grasp it.

@David_The_H:
Just to be clear, you need to bracket all instances of "Gate Name" and "Symbol Name" except for the first one? And the lines are always paired?

Yes. They don't always exist, but in a device with many gates the eagle --> kicad converter left them there.There is always a power gate at the end. No good news, I'm afraid. When i tried your sed (copy 'n' paste) I got
Code:

sed -e '1,/^# Symbol Name/b; -e '/^# Gate Name/i ENDDRAW' -e '/^# Symbol Name/a DRAW' 74xx-eu.lib > DavidTheH.lib
>

I did try to fix the commas, but I didn't hit on it, and felt a bit like the sorcerer's apprentice, so I quit before I did damage.


All times are GMT -5. The time now is 11:59 PM.