Text processing/2: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Re-ran program following recovery and mirroring of full data file.)
Line 107: Line 107:
text s;
text s;


if (l_length(l) != 49) {
if (~l != 49) {
error("wrong number of fields");
error("wrong number of fields");
}
}


s = lf_q_text(l);
s = l[0];
if (length(s) != 10 || s[4] != '-' || s[7] != '-') {
if (~s != 10 || s[4] != '-' || s[7] != '-') {
error("bad date format");
error("bad date format");
}
}
atoi(delete(delete(s, 7), 4));
l[0] = atoi(delete(delete(s, 7), 4));


i = 1;
i = 1;
while (i < 49) {
while (i < 49) {
l_r_real(l, i, atof(l_q_text(l, i)));
l[i] = atof(l[i]);
i += 1;
i += 1;
l_r_integer(l, i, atoi(l_q_text(l, i)));
l[i] = atoi(l[i]);
i += 1;
i += 1;
}
}
Line 129: Line 129:
main(void)
main(void)
{
{
integer goods;
integer goods, i, v;
file f;
file f;
list l;
list l;
record r;
index x;


goods = 0;
goods = 0;


f_affix(f, "readings.txt");
f.affix("readings.txt");


while (f_list(f, l, 0) != -1) {
while (f.list(l, 0) != -1) {
if (!trap(check_format, l)) {
if (!trap(check_format, l)) {
if (r_key(r, l_head(l))) {
if (x.key(v = lf_pick(l))) {
v_form("duplicate ~ line\n", l_head(l));
v_form("duplicate ~ line\n", v);
} else {
}
integer i;


r_put(r, l_head(l), 0);
x[v] = 0;
i = 2;
i = 1;
while (i < 49) {
while (i < 48) {
if (l_q_integer(l, i) != 1) {
if (l[i] < 1) {
break;
break;
}
i += 2;
}
if (49 < i) {
goods += 1;
}
}
i += 2;
}
if (48 < i) {
goods += 1;
}
}
}
}
}
}


o_integer(goods);
o_(goods, " good lines\n");
o_text(" good unique lines\n");


return 0;
return 0;
}</lang>
}</lang>
{{out}} (the "reading.txt" needs to be converted to UNIX end-of-line)
{{out}} (the "reading.txt" needs to be converted to UNIX end-of-line)
<pre>duplicate 1990-03-25 line
<pre>duplicate 19900325 line
duplicate 1991-03-31 line
duplicate 19910331 line
duplicate 1992-03-29 line
duplicate 19920329 line
duplicate 1993-03-28 line
duplicate 19930328 line
duplicate 1995-03-26 line
duplicate 19950326 line
5013 good unique lines</pre>
5017 good lines</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==