File: 249.htm

package info (click to toggle)
eagle 4.16-5
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 36,508 kB
  • sloc: sh: 82; makefile: 32
file content (100 lines) | stat: -rw-r--r-- 3,542 bytes parent folder | download | duplicates (2)
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
<html>
<head>
<title>EAGLE Help: lookup()</title>
</head>
<body bgcolor=white>
<font face=Helvetica,Arial>
<hr>
<i>EAGLE Help</i>
<h1><center>lookup()</center></h1>
<hr>
<dl>
<dt>
<b>Function</b>
<dd>
Looks up data in a string array.
<p>
<dt>
<b>Syntax</b>
<dd>
<tt>string lookup(string array[], string key, int field_index[, char separator]);</tt><br>
<tt>string lookup(string array[], string key, string field_name[, char separator]);</tt>
<p>
<dt>
<b>Returns</b>
<dd>
<tt>lookup</tt> returns the value of the field identified by <tt>field_index</tt>
or <tt>field_name</tt>.<br>
If the field doesn't exist, or no string matching <tt>key</tt> is found,
an empty string is returned.
<p>
</dl>
<b>See also</b> <a href=240.htm>fileread</a>,
<a href=264.htm>strsplit</a>
<p>
An <tt>array</tt> that can be used with <tt>lookup()</tt> consists of strings of text,
each string representing one data record.
<p>
Each data record contains an arbitrary number of fields, which are separated by
the character <tt>separator</tt> (default is <tt>'\t'</tt>, the tabulator).
The first field in a record is used as the <tt>key</tt> and is numbered <tt>0</tt>.
<p>
All records must have unique <tt>key</tt> fields and none of the <tt>key</tt> fields
may be empty - otherwise it is undefined which record will be found.
<p>
If the first string in the <tt>array</tt> contains a "Header" record (i.e. a record where
each field describes its contents), using <tt>lookup</tt> with a <tt>field_name</tt>
string automatically determines the index of that field. This allows using the
<tt>lookup</tt> function without exactly knowing which field index contains
the desired data.<br>
It is up to the user to make sure that the first record actually
contains header information.
<p>
If the <tt>key</tt> parameter in the call to <tt>lookup()</tt> is an empty
string, the first string of the <tt>array</tt> will be used. This allows a program to
determine whether there is a header record with the required field names.
<p>
If a field contains the <tt>separator</tt> character, that field must be enclosed
in double quotes (as in <tt>"abc;def"</tt>, assuming the semicolon (<tt>';'</tt>)
is used as separator). The same applies if the field contains double quotes
(<tt>"</tt>), in which case the double quotes inside the field have to be doubled
(as in <tt>"abc;""def"";ghi"</tt>, which would be <tt>abc;"def";ghi</tt>).<br>
<b>It is best to use the default "tab" separator, which doesn't have these problems
(no field can contain a tabulator).</b>
<p>
Here's an example data file (<tt>';'</tt> has been used as separator for better readability):
<pre>
Name;Manufacturer;Code;Price
7400;Intel;I-01-234-97;$0.10
68HC12;Motorola;M68HC1201234;$3.50
</pre>
<p>
<b>Example</b>
<pre>
string OrderCodes[];
if (fileread(OrderCodes, "ordercodes") &gt; 0) {
   if (lookup(OrderCodes, "", "Code", ';')) {
      schematic(SCH) {
        SCH.parts(P) {
          string OrderCode;
          // both following statements do exactly the same:
          OrderCode = lookup(OrderCodes, P.device.name, "Code", ';');
          OrderCode = lookup(OrderCodes, P.device.name, 2, ';');
          }
        }
      }
   else
      dlgMessageBox("Missing 'Code' field in file 'ordercodes');
   }
</pre>

<hr>
<table width=100% cellspacing=0 border=0><tr><td align=left><font face=Helvetica,Arial>
<a href=index.htm>Index</a>
</font></td><td align=right><font face=Helvetica,Arial size=-1>
<i>Copyright &copy; 2005 CadSoft Computer GmbH</i>
</font></td></tr></table>
<hr>
</font>
</body>
</html>