forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
par2rtf_so.ulp
213 lines (191 loc) · 6.64 KB
/
par2rtf_so.ulp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* This EAGLE User Language Program prints a board's
* Partlist and its "Bill Of Material" in RTF.
* Tested and works under Star Office 6.0
* Published under GNU-Public-License
* Ing.-Büro Völpel GmbH
* Author: Thomas Bronner
* Email: [email protected]
*/
string hexb(char c)
{
string buf = "";
sprintf(buf, "%X", c);
buf = "\\\'" + buf;
return (buf);
}
string convert(string str)
{
string buf ="";
int i, len;
len = strlen(str);
for (i=0;i<len;i++)
{
if (str[i] == '\\')
{
buf = buf + '/';
}
else if (str[i] > 127)
{
buf = buf + hexb(str[i]);
}
else
{
buf = buf + str[i];
}
}
return buf;
}
void PartLine(string Name, string Value, string Package)
{
Name = convert(Name);
Value = convert(Value);
Package = convert(Package);
printf("\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx1118"
"\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx3121"
"\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx4712"
"\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx9922"
"\\pard\\widctlpar\\intbl\\plain"
"\\ql{\\f1 %-s}"
"\\cell"
"{\\f1 %-s}"
"\\cell"
"{\\f1 %-s}"
"\\cell"
"\\cell\\row\\pard\\plain\n", Name, Value, Package);
}
int ValueLine(string Quantity, string Value, string Package, string Parts)
{
Quantity = convert(Quantity);
Value = convert(Value);
Package = convert(Package);
Parts = convert(Parts);
printf("\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx1118"
"\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx3121"
"\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx4712"
"\\trowd\\trql\\trrh360\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrw1"
"\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0"
"\\cellx9922"
"\\pard\\intbl\\plain"
"\\ql{\\f1 %-s}"
"\\cell"
"{\\f1 %-s}"
"\\cell"
"{\\f1 %-s}"
"\\cell"
"{\\f1 %-s}"
, Quantity, Value, Package, Parts);
return 50;
}
if (board) board(B)
{
output(filesetext(B.name, ".RTF"),"wt")
{
printf("\{\\rtf1\\ansi\\deff8\\deflang1033\\sectd\\pard\n");
printf("{\\fonttbl{\\f1\\fnil\\fprq0\\fcharset0 Times New Roman;}}");
printf("\{\\colortbl;\\red0\\green0\\blue0;\\red204\\green204\\blue204;\\red128\\green128\\blue128;}\n");
printf("\\footery0 {\\footer \\pard\\plain {\\ltrch\\loch\\f1 Seite {\\field{\\*\\fldinst \\\\page}{\\fldrslt 2}}}\\par}");
printf("\\headery0 {\\header \\pard\\plain {"
"\\f1 Partlist exported from %s at %s}}",
convert(B.name), t2string(time()));
printf("\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clcbpat2\\clvertal"
"\\cellx1118"
"\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\clbrdrr\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clcbpat2\\clvertal"
"\\cellx3121"
"\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\clbrdrr\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clcbpat2\\clvertal"
"\\cellx4712"
"\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\clbrdrr\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\clcbpat2\\clvertal"
"\\cellx9922"
"\\pard\\intbl\\plain "
"\\b\\qc{\\ltrch\\loch\\f1 Part}"
"\\cell "
"{\\ltrch\\loch\\f1 Value}"
"\\cell "
"{\\ltrch\\loch\\f1 Package}"
"\\cell"
"{\\ltrch\\loch\\f1 Comments}"
"\\cell\\row\\pard \\plain \n");
numeric string ename[], evalue[], pname[];
int cnt = 0, index[];
B.elements(E)
{
ename[cnt] = E.name;
evalue[cnt] = E.value;
pname[cnt] = E.package.name;
cnt++;
}
sort(cnt, index, ename);
for (int i = 0; i < cnt; i++)
PartLine(ename[index[i]], evalue[index[i]], pname[index[i]]);
string lastvalue = "? ? ?", lastpack = "? ? ?", parts = "";
printf("\\line \n");
printf("\\sect \\headery0 {\\header \\pard\\plain {"
"\\f1 Bill of materials exported from %s at %s }}\n", convert(B.name), t2string(time()));
printf("\\footery0 {\\footer \\pard\\plain {\\ltrch\\loch\\f1 Seite {\\field{\\*\\fldinst \\\\page}{\\fldrslt 2}}}\\par}");
printf("\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clcbpat2\\clvertal"
"\\cellx1118"
"\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\clbrdrr\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clcbpat2\\clvertal"
"\\cellx3121"
"\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\clbrdrr\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clcbpat2\\clvertal"
"\\cellx4712"
"\\trowd\\trql\\trhdr\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrl\\clbrdrr\\brdrs"
"\\brdrw1\\brdrcf1\\brsp0\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\brsp0\\clbrdrr\\clcbpat2\\clvertal"
"\\cellx9922"
"\\pard\\intbl\\plain "
"\\b\\qc{\\ltrch\\loch\\f1 Qty}"
"\\cell "
"{\\ltrch\\loch\\f1 Value}"
"\\cell "
"{\\ltrch\\loch\\f1 Package}"
"\\cell"
"{\\ltrch\\loch\\f1 Parts}"
"\\cell\\pard \\plain \n");
sort(cnt, index, evalue, pname, ename);
for (int n = 0; n < cnt; n++)
{
int i = index[n];
if ((lastvalue != evalue[i]) || (lastpack != pname[i]))
{
lastvalue = evalue[i];
lastpack = pname[i];
int quantity = 1;
for (int j = n + 1; j < cnt && (lastvalue == evalue[index[j]]) &&
(lastpack == pname[index[j]]); ++j)
++quantity;
printf("\\cell\\row");
string buf;
sprintf(buf, "%d", quantity);
ValueLine(buf, evalue[i], pname[i], "");
}
else
{
printf(", ");
}
printf("\\f1");
printf(ename[i]);
}
printf("\\cell\\row}");
}
}