terminer les lignes de code awk par des point-virgules pour satisfaire le linter
This commit is contained in:
parent
95e5fdcbf3
commit
916d869af8
|
@ -1,157 +1,157 @@
|
||||||
# -*- coding: utf-8 mode: awk -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
# -*- coding: utf-8 mode: awk -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||||
|
|
||||||
function mkindices(values, indices, i, j) {
|
function mkindices(values, indices, i, j) {
|
||||||
array_new(indices)
|
array_new(indices);
|
||||||
j = 1
|
j = 1;
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
indices[j++] = int(i)
|
indices[j++] = int(i);
|
||||||
}
|
}
|
||||||
return asort(indices)
|
return asort(indices);
|
||||||
}
|
}
|
||||||
function array_new(dest) {
|
function array_new(dest) {
|
||||||
dest[0] = 0 # forcer awk à considérer dest comme un tableau
|
dest[0] = 0; # forcer awk à considérer dest comme un tableau
|
||||||
delete dest
|
delete dest;
|
||||||
}
|
}
|
||||||
function array_newsize(dest, size, i) {
|
function array_newsize(dest, size, i) {
|
||||||
dest[0] = 0 # forcer awk à considérer dest comme un tableau
|
dest[0] = 0; # forcer awk à considérer dest comme un tableau
|
||||||
delete dest
|
delete dest;
|
||||||
size = int(size)
|
size = int(size);
|
||||||
for (i = 1; i <= size; i++) {
|
for (i = 1; i <= size; i++) {
|
||||||
dest[i] = ""
|
dest[i] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function array_len(values, count, i) {
|
function array_len(values, count, i) {
|
||||||
# length(array) a un bug sur awk 3.1.5
|
# length(array) a un bug sur awk 3.1.5
|
||||||
# cette version est plus lente mais fonctionne toujours
|
# cette version est plus lente mais fonctionne toujours
|
||||||
count = 0
|
count = 0;
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
count++
|
count++;
|
||||||
}
|
}
|
||||||
return count
|
return count;
|
||||||
}
|
}
|
||||||
function array_copy(dest, src, count, indices, i) {
|
function array_copy(dest, src, count, indices, i) {
|
||||||
array_new(dest)
|
array_new(dest);
|
||||||
count = mkindices(src, indices)
|
count = mkindices(src, indices);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
dest[indices[i]] = src[indices[i]]
|
dest[indices[i]] = src[indices[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function array_getlastindex(src, count, indices) {
|
function array_getlastindex(src, count, indices) {
|
||||||
count = mkindices(src, indices)
|
count = mkindices(src, indices);
|
||||||
if (count == 0) return 0
|
if (count == 0) return 0;
|
||||||
return indices[count]
|
return indices[count];
|
||||||
}
|
}
|
||||||
function array_add(dest, value, lastindex) {
|
function array_add(dest, value, lastindex) {
|
||||||
lastindex = array_getlastindex(dest)
|
lastindex = array_getlastindex(dest);
|
||||||
dest[lastindex + 1] = value
|
dest[lastindex + 1] = value;
|
||||||
}
|
}
|
||||||
function array_deli(dest, i, l) {
|
function array_deli(dest, i, l) {
|
||||||
i = int(i)
|
i = int(i);
|
||||||
if (i == 0) return
|
if (i == 0) return;
|
||||||
l = array_len(dest)
|
l = array_len(dest);
|
||||||
while (i < l) {
|
while (i < l) {
|
||||||
dest[i] = dest[i + 1]
|
dest[i] = dest[i + 1];
|
||||||
i++
|
i++;
|
||||||
}
|
}
|
||||||
delete dest[l]
|
delete dest[l];
|
||||||
}
|
}
|
||||||
function array_del(dest, value, ignoreCase, i) {
|
function array_del(dest, value, ignoreCase, i) {
|
||||||
do {
|
do {
|
||||||
i = key_index(value, dest, ignoreCase)
|
i = key_index(value, dest, ignoreCase);
|
||||||
if (i != 0) array_deli(dest, i)
|
if (i != 0) array_deli(dest, i);
|
||||||
} while (i != 0)
|
} while (i != 0);
|
||||||
}
|
}
|
||||||
function array_extend(dest, src, count, lastindex, indices, i) {
|
function array_extend(dest, src, count, lastindex, indices, i) {
|
||||||
lastindex = array_getlastindex(dest)
|
lastindex = array_getlastindex(dest);
|
||||||
count = mkindices(src, indices)
|
count = mkindices(src, indices);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
dest[lastindex + i] = src[indices[i]]
|
dest[lastindex + i] = src[indices[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function array_fill(dest, i) {
|
function array_fill(dest, i) {
|
||||||
array_new(dest)
|
array_new(dest);
|
||||||
for (i = 1; i <= NF; i++) {
|
for (i = 1; i <= NF; i++) {
|
||||||
dest[i] = $i
|
dest[i] = $i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function array_getline(src, count, indices, i, j) {
|
function array_getline(src, count, indices, i, j) {
|
||||||
$0 = ""
|
$0 = "";
|
||||||
count = mkindices(src, indices)
|
count = mkindices(src, indices);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
j = indices[i]
|
j = indices[i];
|
||||||
$j = src[j]
|
$j = src[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function array_appendline(src, count, indices, i, nf, j) {
|
function array_appendline(src, count, indices, i, nf, j) {
|
||||||
count = mkindices(src, indices)
|
count = mkindices(src, indices);
|
||||||
nf = NF
|
nf = NF;
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
j = nf + indices[i]
|
j = nf + indices[i];
|
||||||
$j = src[indices[i]]
|
$j = src[indices[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function in_array(value, values, ignoreCase, i) {
|
function in_array(value, values, ignoreCase, i) {
|
||||||
if (ignoreCase) {
|
if (ignoreCase) {
|
||||||
value = tolower(value)
|
value = tolower(value);
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
if (tolower(values[i]) == value) return 1
|
if (tolower(values[i]) == value) return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
if (values[i] == value) return 1
|
if (values[i] == value) return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
function key_index(value, values, ignoreCase, i) {
|
function key_index(value, values, ignoreCase, i) {
|
||||||
if (ignoreCase) {
|
if (ignoreCase) {
|
||||||
value = tolower(value)
|
value = tolower(value);
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
if (tolower(values[i]) == value) return int(i)
|
if (tolower(values[i]) == value) return int(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
if (values[i] == value) return int(i)
|
if (values[i] == value) return int(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
function array2s(values, prefix, sep, suffix, noindices, first, i, s) {
|
function array2s(values, prefix, sep, suffix, noindices, first, i, s) {
|
||||||
if (!prefix) prefix = "["
|
if (!prefix) prefix = "[";
|
||||||
if (!sep) sep = ", "
|
if (!sep) sep = ", ";
|
||||||
if (!suffix) suffix = "]"
|
if (!suffix) suffix = "]";
|
||||||
s = prefix
|
s = prefix;
|
||||||
first = 1
|
first = 1;
|
||||||
for (i in values) {
|
for (i in values) {
|
||||||
if (first) first = 0
|
if (first) first = 0;
|
||||||
else s = s sep
|
else s = s sep;
|
||||||
if (!noindices) s = s "[" i "]="
|
if (!noindices) s = s "[" i "]=";
|
||||||
s = s values[i]
|
s = s values[i];
|
||||||
}
|
}
|
||||||
s = s suffix
|
s = s suffix;
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function array2so(values, prefix, sep, suffix, noindices, count, indices, i, s) {
|
function array2so(values, prefix, sep, suffix, noindices, count, indices, i, s) {
|
||||||
if (!prefix) prefix = "["
|
if (!prefix) prefix = "[";
|
||||||
if (!sep) sep = ", "
|
if (!sep) sep = ", ";
|
||||||
if (!suffix) suffix = "]"
|
if (!suffix) suffix = "]";
|
||||||
s = prefix
|
s = prefix;
|
||||||
count = mkindices(values, indices)
|
count = mkindices(values, indices);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
if (i > 1) s = s sep
|
if (i > 1) s = s sep;
|
||||||
if (!noindices) s = s "[" indices[i] "]="
|
if (!noindices) s = s "[" indices[i] "]=";
|
||||||
s = s values[indices[i]]
|
s = s values[indices[i]];
|
||||||
}
|
}
|
||||||
s = s suffix
|
s = s suffix;
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function array_join(values, sep, prefix, suffix, count, indices, i, s) {
|
function array_join(values, sep, prefix, suffix, count, indices, i, s) {
|
||||||
s = prefix
|
s = prefix;
|
||||||
count = mkindices(values, indices)
|
count = mkindices(values, indices);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
if (i > 1) s = s sep
|
if (i > 1) s = s sep;
|
||||||
s = s values[indices[i]]
|
s = s values[indices[i]];
|
||||||
}
|
}
|
||||||
s = s suffix
|
s = s suffix;
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,141 +1,141 @@
|
||||||
# -*- coding: utf-8 mode: awk -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
# -*- coding: utf-8 mode: awk -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||||
|
|
||||||
function num(s) {
|
function num(s) {
|
||||||
if (s ~ /^[0-9]+$/) return int(s)
|
if (s ~ /^[0-9]+$/) return int(s);
|
||||||
else return s
|
else return s;
|
||||||
}
|
}
|
||||||
function ord(s, i) {
|
function ord(s, i) {
|
||||||
s = substr(s, 1, 1)
|
s = substr(s, 1, 1);
|
||||||
i = index(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", s)
|
i = index(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", s);
|
||||||
if (i != 0) i += 32 - 1
|
if (i != 0) i += 32 - 1;
|
||||||
return i
|
return i;
|
||||||
}
|
}
|
||||||
function hex(i, s) {
|
function hex(i, s) {
|
||||||
s = sprintf("%x", i)
|
s = sprintf("%x", i);
|
||||||
if (length(s) < 2) s = "0" s
|
if (length(s) < 2) s = "0" s;
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function qhtml(s) {
|
function qhtml(s) {
|
||||||
gsub(/&/, "\\&", s)
|
gsub(/&/, "\\&", s);
|
||||||
gsub(/"/, "\\"", s)
|
gsub(/"/, "\\"", s);
|
||||||
gsub(/>/, "\\>", s)
|
gsub(/>/, "\\>", s);
|
||||||
gsub(/</, "\\<", s)
|
gsub(/</, "\\<", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function unquote_html(s) {
|
function unquote_html(s) {
|
||||||
gsub(/</, "<", s)
|
gsub(/</, "<", s);
|
||||||
gsub(/>/, ">", s)
|
gsub(/>/, ">", s);
|
||||||
gsub(/"/, "\"", s)
|
gsub(/"/, "\"", s);
|
||||||
gsub(/&/, "\\&", s)
|
gsub(/&/, "\\&", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function qawk(s) {
|
function qawk(s) {
|
||||||
gsub(/\\/, "\\\\", s)
|
gsub(/\\/, "\\\\", s);
|
||||||
gsub(/"/, "\\\"", s)
|
gsub(/"/, "\\\"", s);
|
||||||
gsub(/\n/, "\\n", s)
|
gsub(/\n/, "\\n", s);
|
||||||
return "\"" s "\""
|
return "\"" s "\"";
|
||||||
}
|
}
|
||||||
function qval(s) {
|
function qval(s) {
|
||||||
gsub(/'/, "'\\''", s)
|
gsub(/'/, "'\\''", s);
|
||||||
return "'" s "'"
|
return "'" s "'";
|
||||||
}
|
}
|
||||||
function sqval(s) {
|
function sqval(s) {
|
||||||
return " " qval(s)
|
return " " qval(s);
|
||||||
}
|
}
|
||||||
function qvals( i, line) {
|
function qvals( i, line) {
|
||||||
line = ""
|
line = "";
|
||||||
for (i = 1; i <= NF; i++) {
|
for (i = 1; i <= NF; i++) {
|
||||||
if (i > 1) line = line " "
|
if (i > 1) line = line " ";
|
||||||
line = line qval($i)
|
line = line qval($i);
|
||||||
}
|
}
|
||||||
return line
|
return line;
|
||||||
}
|
}
|
||||||
function sqvals() {
|
function sqvals() {
|
||||||
return " " qvals()
|
return " " qvals();
|
||||||
}
|
}
|
||||||
function qarr(values, prefix, i, count, line) {
|
function qarr(values, prefix, i, count, line) {
|
||||||
line = prefix
|
line = prefix;
|
||||||
count = array_len(values)
|
count = array_len(values);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
if (i > 1 || line != "") line = line " "
|
if (i > 1 || line != "") line = line " ";
|
||||||
line = line qval(values[i])
|
line = line qval(values[i]);
|
||||||
}
|
}
|
||||||
return line
|
return line;
|
||||||
}
|
}
|
||||||
function qregexp(s) {
|
function qregexp(s) {
|
||||||
gsub(/[[\\.^$*+?()|{]/, "\\\\&", s)
|
gsub(/[[\\.^$*+?()|{]/, "\\\\&", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function qsubrepl(s) {
|
function qsubrepl(s) {
|
||||||
gsub(/\\/, "\\\\", s)
|
gsub(/\\/, "\\\\", s);
|
||||||
gsub(/&/, "\\\\&", s)
|
gsub(/&/, "\\\\&", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function qgrep(s) {
|
function qgrep(s) {
|
||||||
gsub(/[[\\.^$*]/, "\\\\&", s)
|
gsub(/[[\\.^$*]/, "\\\\&", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function qegrep(s) {
|
function qegrep(s) {
|
||||||
gsub(/[[\\.^$*+?()|{]/, "\\\\&", s)
|
gsub(/[[\\.^$*+?()|{]/, "\\\\&", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function qsql(s, suffix) {
|
function qsql(s, suffix) {
|
||||||
gsub(/'/, "''", s)
|
gsub(/'/, "''", s);
|
||||||
return "'" s "'" (suffix != ""? " " suffix: "")
|
return "'" s "'" (suffix != ""? " " suffix: "");
|
||||||
}
|
}
|
||||||
function cqsql(s, suffix) {
|
function cqsql(s, suffix) {
|
||||||
return "," qsql(s, suffix)
|
return "," qsql(s, suffix);
|
||||||
}
|
}
|
||||||
function unquote_mysqlcsv(s) {
|
function unquote_mysqlcsv(s) {
|
||||||
gsub(/\\n/, "\n", s)
|
gsub(/\\n/, "\n", s);
|
||||||
gsub(/\\t/, "\t", s)
|
gsub(/\\t/, "\t", s);
|
||||||
gsub(/\\0/, "\0", s)
|
gsub(/\\0/, "\0", s);
|
||||||
gsub(/\\\\/, "\\", s)
|
gsub(/\\\\/, "\\", s);
|
||||||
return s
|
return s;
|
||||||
}
|
}
|
||||||
function sval(s) {
|
function sval(s) {
|
||||||
if (s == "") return s
|
if (s == "") return s;
|
||||||
else return " " s
|
else return " " s;
|
||||||
}
|
}
|
||||||
function cval(s, suffix) {
|
function cval(s, suffix) {
|
||||||
suffix = suffix != ""? " " suffix: ""
|
suffix = suffix != ""? " " suffix: "";
|
||||||
if (s == "") return s
|
if (s == "") return s;
|
||||||
else return "," s suffix
|
else return "," s suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printto(s, output) {
|
function printto(s, output) {
|
||||||
if (output == "") {
|
if (output == "") {
|
||||||
print s
|
print s;
|
||||||
} else if (output ~ /^>>/) {
|
} else if (output ~ /^>>/) {
|
||||||
sub(/^>>/, "", output)
|
sub(/^>>/, "", output);
|
||||||
print s >>output
|
print s >>output;
|
||||||
} else if (output ~ /^>/) {
|
} else if (output ~ /^>/) {
|
||||||
sub(/^>/, "", output)
|
sub(/^>/, "", output);
|
||||||
print s >output
|
print s >output;
|
||||||
} else if (output ~ /^\|&/) {
|
} else if (output ~ /^\|&/) {
|
||||||
sub(/^\|&/, "", output)
|
sub(/^\|&/, "", output);
|
||||||
print s |&output
|
print s |&output;
|
||||||
} else if (output ~ /^\|/) {
|
} else if (output ~ /^\|/) {
|
||||||
sub(/^\|/, "", output)
|
sub(/^\|/, "", output);
|
||||||
print s |output
|
print s |output;
|
||||||
} else {
|
} else {
|
||||||
print s >output
|
print s >output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function find_line(input, field, value, orig, line) {
|
function find_line(input, field, value, orig, line) {
|
||||||
orig = $0
|
orig = $0;
|
||||||
line = ""
|
line = "";
|
||||||
while ((getline <input) > 0) {
|
while ((getline <input) > 0) {
|
||||||
if ($field == value) {
|
if ($field == value) {
|
||||||
line = $0
|
line = $0;
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(input)
|
close(input);
|
||||||
$0 = orig
|
$0 = orig;
|
||||||
return line
|
return line;
|
||||||
}
|
}
|
||||||
function merge_line(input, field, key, line) {
|
function merge_line(input, field, key, line) {
|
||||||
line = find_line(input, field, $key)
|
line = find_line(input, field, $key);
|
||||||
if (line != "") $0 = $0 FS line
|
if (line != "") $0 = $0 FS line;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,51 +2,51 @@
|
||||||
|
|
||||||
function date__parse_fr(date, parts, y, m, d) {
|
function date__parse_fr(date, parts, y, m, d) {
|
||||||
if (match(date, /([0-9][0-9]?)\/([0-9][0-9]?)\/([0-9][0-9][0-9][0-9])/, parts)) {
|
if (match(date, /([0-9][0-9]?)\/([0-9][0-9]?)\/([0-9][0-9][0-9][0-9])/, parts)) {
|
||||||
y = int(parts[3])
|
y = int(parts[3]);
|
||||||
m = int(parts[2])
|
m = int(parts[2]);
|
||||||
d = int(parts[1])
|
d = int(parts[1]);
|
||||||
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d))
|
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d));
|
||||||
} else if (match(date, /([0-9][0-9]?)\/([0-9][0-9]?)\/([0-9][0-9])/, parts)) {
|
} else if (match(date, /([0-9][0-9]?)\/([0-9][0-9]?)\/([0-9][0-9])/, parts)) {
|
||||||
basey = int(strftime("%Y")); basey = basey - basey % 100
|
basey = int(strftime("%Y")); basey = basey - basey % 100;
|
||||||
y = basey + int(parts[3])
|
y = basey + int(parts[3]);
|
||||||
m = int(parts[2])
|
m = int(parts[2]);
|
||||||
d = int(parts[1])
|
d = int(parts[1]);
|
||||||
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d))
|
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d));
|
||||||
}
|
}
|
||||||
return -1
|
return -1;
|
||||||
}
|
}
|
||||||
function date__parse_mysql(date, parts, y, m, d) {
|
function date__parse_mysql(date, parts, y, m, d) {
|
||||||
if (match(date, /([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])/, parts)) {
|
if (match(date, /([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])/, parts)) {
|
||||||
y = int(parts[1])
|
y = int(parts[1]);
|
||||||
m = int(parts[2])
|
m = int(parts[2]);
|
||||||
d = int(parts[3])
|
d = int(parts[3]);
|
||||||
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d))
|
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d));
|
||||||
}
|
}
|
||||||
return -1
|
return -1;
|
||||||
}
|
}
|
||||||
function date__parse_any(date, serial) {
|
function date__parse_any(date, serial) {
|
||||||
serial = date__parse_fr(date)
|
serial = date__parse_fr(date);
|
||||||
if (serial == -1) serial = date__parse_mysql(date)
|
if (serial == -1) serial = date__parse_mysql(date);
|
||||||
return serial
|
return serial;
|
||||||
}
|
}
|
||||||
function date_serial(date) {
|
function date_serial(date) {
|
||||||
return date__parse_any(date)
|
return date__parse_any(date);
|
||||||
}
|
}
|
||||||
function date_parse(date, serial) {
|
function date_parse(date, serial) {
|
||||||
serial = date__parse_any(date)
|
serial = date__parse_any(date);
|
||||||
if (serial == -1) return date
|
if (serial == -1) return date;
|
||||||
return strftime("%d/%m/%Y", serial)
|
return strftime("%d/%m/%Y", serial);
|
||||||
}
|
}
|
||||||
function date_monday(date, serial, dow) {
|
function date_monday(date, serial, dow) {
|
||||||
serial = date__parse_any(date)
|
serial = date__parse_any(date);
|
||||||
if (serial == -1) return date
|
if (serial == -1) return date;
|
||||||
dow = strftime("%u", serial)
|
dow = strftime("%u", serial);
|
||||||
serial -= (dow - 1) * 86400
|
serial -= (dow - 1) * 86400;
|
||||||
return strftime("%d/%m/%Y", serial)
|
return strftime("%d/%m/%Y", serial);
|
||||||
}
|
}
|
||||||
function date_add(date, nbdays, serial) {
|
function date_add(date, nbdays, serial) {
|
||||||
serial = date__parse_any(date)
|
serial = date__parse_any(date);
|
||||||
if (serial == -1) return date
|
if (serial == -1) return date;
|
||||||
serial += nbdays * 86400
|
serial += nbdays * 86400;
|
||||||
return strftime("%d/%m/%Y", serial)
|
return strftime("%d/%m/%Y", serial);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,199 +3,199 @@
|
||||||
@include "base.array.awk"
|
@include "base.array.awk"
|
||||||
|
|
||||||
function csv__parse_quoted(line, destl, colsep, qchar, echar, pos, tmpl, nextc, resl) {
|
function csv__parse_quoted(line, destl, colsep, qchar, echar, pos, tmpl, nextc, resl) {
|
||||||
line = substr(line, 2)
|
line = substr(line, 2);
|
||||||
resl = ""
|
resl = "";
|
||||||
while (1) {
|
while (1) {
|
||||||
pos = index(line, qchar)
|
pos = index(line, qchar);
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
# chaine mal terminee
|
# chaine mal terminee
|
||||||
resl = resl line
|
resl = resl line;
|
||||||
destl[0] = ""
|
destl[0] = "";
|
||||||
destl[1] = 0
|
destl[1] = 0;
|
||||||
return resl
|
return resl;
|
||||||
}
|
}
|
||||||
if (echar != "" && pos > 1) {
|
if (echar != "" && pos > 1) {
|
||||||
# tenir compte du fait qu"un caratère peut être mis en échappement
|
# tenir compte du fait qu"un caratère peut être mis en échappement
|
||||||
prevc = substr(line, pos - 1, 1)
|
prevc = substr(line, pos - 1, 1);
|
||||||
quotec = substr(line, pos, 1)
|
quotec = substr(line, pos, 1);
|
||||||
nextc = substr(line, pos + 1, 1)
|
nextc = substr(line, pos + 1, 1);
|
||||||
if (prevc == echar) {
|
if (prevc == echar) {
|
||||||
# qchar en échappement
|
# qchar en échappement
|
||||||
tmpl = substr(line, 1, pos - 2)
|
tmpl = substr(line, 1, pos - 2);
|
||||||
resl = resl tmpl quotec
|
resl = resl tmpl quotec;
|
||||||
line = substr(line, pos + 1)
|
line = substr(line, pos + 1);
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
tmpl = substr(line, 1, pos - 1)
|
tmpl = substr(line, 1, pos - 1);
|
||||||
if (nextc == colsep || nextc == "") {
|
if (nextc == colsep || nextc == "") {
|
||||||
# fin de champ ou fin de ligne
|
# fin de champ ou fin de ligne
|
||||||
resl = resl tmpl
|
resl = resl tmpl;
|
||||||
destl[0] = substr(line, pos + 2)
|
destl[0] = substr(line, pos + 2);
|
||||||
destl[1] = nextc == colsep
|
destl[1] = nextc == colsep;
|
||||||
return resl
|
return resl;
|
||||||
} else {
|
} else {
|
||||||
# erreur de syntaxe: guillemet non mis en échappement
|
# erreur de syntaxe: guillemet non mis en échappement
|
||||||
# ignorer cette erreur et prendre le guillemet quand meme
|
# ignorer cette erreur et prendre le guillemet quand meme
|
||||||
resl = resl tmpl quotec
|
resl = resl tmpl quotec;
|
||||||
line = substr(line, pos + 1)
|
line = substr(line, pos + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# pas d"échappement pour qchar. il est éventuellement doublé
|
# pas d"échappement pour qchar. il est éventuellement doublé
|
||||||
tmpl = substr(line, 1, pos - 1)
|
tmpl = substr(line, 1, pos - 1);
|
||||||
quotec = substr(line, pos, 1)
|
quotec = substr(line, pos, 1);
|
||||||
nextc = substr(line, pos + 1, 1)
|
nextc = substr(line, pos + 1, 1);
|
||||||
if (nextc == colsep || nextc == "") {
|
if (nextc == colsep || nextc == "") {
|
||||||
# fin de champ ou fin de ligne
|
# fin de champ ou fin de ligne
|
||||||
resl = resl tmpl
|
resl = resl tmpl;
|
||||||
destl[0] = substr(line, pos + 2)
|
destl[0] = substr(line, pos + 2);
|
||||||
destl[1] = nextc == colsep
|
destl[1] = nextc == colsep;
|
||||||
return resl
|
return resl;
|
||||||
} else if (nextc == qchar) {
|
} else if (nextc == qchar) {
|
||||||
# qchar en echappement
|
# qchar en echappement
|
||||||
resl = resl tmpl quotec
|
resl = resl tmpl quotec;
|
||||||
line = substr(line, pos + 2)
|
line = substr(line, pos + 2);
|
||||||
} else {
|
} else {
|
||||||
# erreur de syntaxe: guillemet non mis en échappement
|
# erreur de syntaxe: guillemet non mis en échappement
|
||||||
# ignorer cette erreur et prendre le guillemet quand meme
|
# ignorer cette erreur et prendre le guillemet quand meme
|
||||||
resl = resl tmpl quotec
|
resl = resl tmpl quotec;
|
||||||
line = substr(line, pos + 1)
|
line = substr(line, pos + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function csv__parse_unquoted(line, destl, colsep, qchar, echar, pos) {
|
function csv__parse_unquoted(line, destl, colsep, qchar, echar, pos) {
|
||||||
pos = index(line, colsep)
|
pos = index(line, colsep);
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
destl[0] = ""
|
destl[0] = "";
|
||||||
destl[1] = 0
|
destl[1] = 0;
|
||||||
return line
|
return line;
|
||||||
} else {
|
} else {
|
||||||
destl[0] = substr(line, pos + 1)
|
destl[0] = substr(line, pos + 1);
|
||||||
destl[1] = 1
|
destl[1] = 1;
|
||||||
return substr(line, 1, pos - 1)
|
return substr(line, 1, pos - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function csv__array_parse(fields, line, nbfields, colsep, qchar, echar, shouldparse, destl, i) {
|
function csv__array_parse(fields, line, nbfields, colsep, qchar, echar, shouldparse, destl, i) {
|
||||||
array_new(fields)
|
array_new(fields);
|
||||||
array_new(destl)
|
array_new(destl);
|
||||||
i = 1
|
i = 1;
|
||||||
shouldparse = 0
|
shouldparse = 0;
|
||||||
# shouldparse permet de gérer le cas où un champ vide est en fin de ligne.
|
# shouldparse permet de gérer le cas où un champ vide est en fin de ligne.
|
||||||
# en effet, après "," il faut toujours parser, même si line==""
|
# en effet, après "," il faut toujours parser, même si line==""
|
||||||
while (shouldparse || line != "") {
|
while (shouldparse || line != "") {
|
||||||
if (index(line, qchar) == 1) {
|
if (index(line, qchar) == 1) {
|
||||||
value = csv__parse_quoted(line, destl, colsep, qchar, echar)
|
value = csv__parse_quoted(line, destl, colsep, qchar, echar);
|
||||||
line = destl[0]
|
line = destl[0];
|
||||||
shouldparse = destl[1]
|
shouldparse = destl[1];
|
||||||
} else {
|
} else {
|
||||||
value = csv__parse_unquoted(line, destl, colsep, qchar, echar)
|
value = csv__parse_unquoted(line, destl, colsep, qchar, echar);
|
||||||
line = destl[0]
|
line = destl[0];
|
||||||
shouldparse = destl[1]
|
shouldparse = destl[1];
|
||||||
}
|
}
|
||||||
fields[i] = value
|
fields[i] = value;
|
||||||
i = i + 1
|
i = i + 1;
|
||||||
}
|
}
|
||||||
if (nbfields) {
|
if (nbfields) {
|
||||||
nbfields = int(nbfields)
|
nbfields = int(nbfields);
|
||||||
i = array_len(fields)
|
i = array_len(fields);
|
||||||
while (i < nbfields) {
|
while (i < nbfields) {
|
||||||
i++
|
i++;
|
||||||
fields[i] = ""
|
fields[i] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array_len(fields)
|
return array_len(fields);
|
||||||
}
|
}
|
||||||
BEGIN {
|
BEGIN {
|
||||||
DEFAULT_COLSEP = ","
|
DEFAULT_COLSEP = ",";
|
||||||
DEFAULT_QCHAR = "\""
|
DEFAULT_QCHAR = "\"";
|
||||||
DEFAULT_ECHAR = ""
|
DEFAULT_ECHAR = "";
|
||||||
}
|
}
|
||||||
function array_parsecsv2(fields, line, nbfields, colsep, qchar, echar) {
|
function array_parsecsv2(fields, line, nbfields, colsep, qchar, echar) {
|
||||||
return csv__array_parse(fields, line, nbfields, colsep, qchar, echar)
|
return csv__array_parse(fields, line, nbfields, colsep, qchar, echar);
|
||||||
}
|
}
|
||||||
function array_parsecsv(fields, line, nbfields, colsep, qchar, echar) {
|
function array_parsecsv(fields, line, nbfields, colsep, qchar, echar) {
|
||||||
if (colsep == "") colsep = DEFAULT_COLSEP
|
if (colsep == "") colsep = DEFAULT_COLSEP;
|
||||||
if (qchar == "") qchar = DEFAULT_QCHAR
|
if (qchar == "") qchar = DEFAULT_QCHAR;
|
||||||
if (echar == "") echar = DEFAULT_ECHAR
|
if (echar == "") echar = DEFAULT_ECHAR;
|
||||||
return csv__array_parse(fields, line, nbfields, colsep, qchar, echar)
|
return csv__array_parse(fields, line, nbfields, colsep, qchar, echar);
|
||||||
}
|
}
|
||||||
function parsecsv(line, fields) {
|
function parsecsv(line, fields) {
|
||||||
array_parsecsv(fields, line)
|
array_parsecsv(fields, line);
|
||||||
array_getline(fields)
|
array_getline(fields);
|
||||||
return NF
|
return NF;
|
||||||
}
|
}
|
||||||
function getlinecsv(file, fields) {
|
function getlinecsv(file, fields) {
|
||||||
if (file) {
|
if (file) {
|
||||||
getline <file
|
getline <file;
|
||||||
} else {
|
} else {
|
||||||
getline
|
getline;
|
||||||
}
|
}
|
||||||
return parsecsv($0)
|
return parsecsv($0);
|
||||||
}
|
}
|
||||||
function csv__should_quote(s) {
|
function csv__should_quote(s) {
|
||||||
if (s ~ /^[[:blank:][:cntrl:][:space:]]/) return 1
|
if (s ~ /^[[:blank:][:cntrl:][:space:]]/) return 1;
|
||||||
if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1
|
if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1;
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
function array_formatcsv2(fields, colsep, mvsep, qchar, echar, count, indices, line, i, value) {
|
function array_formatcsv2(fields, colsep, mvsep, qchar, echar, count, indices, line, i, value) {
|
||||||
line = ""
|
line = "";
|
||||||
count = mkindices(fields, indices)
|
count = mkindices(fields, indices);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
value = fields[indices[i]]
|
value = fields[indices[i]];
|
||||||
if (i > 1) line = line colsep
|
if (i > 1) line = line colsep;
|
||||||
if (qchar != "" && index(value, qchar) != 0) {
|
if (qchar != "" && index(value, qchar) != 0) {
|
||||||
if (echar != "") gsub(qchar, quote_subrepl(echar) "&", value);
|
if (echar != "") gsub(qchar, quote_subrepl(echar) "&", value);;
|
||||||
else gsub(qchar, "&&", value);
|
else gsub(qchar, "&&", value);;
|
||||||
}
|
}
|
||||||
if (qchar != "" && (index(value, mvsep) != 0 || index(value, colsep) != 0 || index(value, qchar) != 0 || csv__should_quote(value))) {
|
if (qchar != "" && (index(value, mvsep) != 0 || index(value, colsep) != 0 || index(value, qchar) != 0 || csv__should_quote(value))) {
|
||||||
line = line qchar value qchar
|
line = line qchar value qchar;
|
||||||
} else {
|
} else {
|
||||||
line = line value
|
line = line value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return line
|
return line;
|
||||||
}
|
}
|
||||||
function array_formatcsv(fields) {
|
function array_formatcsv(fields) {
|
||||||
return array_formatcsv2(fields, ",", ";", "\"", "")
|
return array_formatcsv2(fields, ",", ";", "\"", "");
|
||||||
}
|
}
|
||||||
function array_printcsv(fields, output) {
|
function array_printcsv(fields, output) {
|
||||||
printto(array_formatcsv(fields), output)
|
printto(array_formatcsv(fields), output);
|
||||||
}
|
}
|
||||||
function get_formatcsv( fields) {
|
function get_formatcsv( fields) {
|
||||||
array_fill(fields)
|
array_fill(fields);
|
||||||
return array_formatcsv(fields)
|
return array_formatcsv(fields);
|
||||||
}
|
}
|
||||||
function formatcsv() {
|
function formatcsv() {
|
||||||
$0 = get_formatcsv()
|
$0 = get_formatcsv();
|
||||||
}
|
}
|
||||||
function printcsv(output, fields) {
|
function printcsv(output, fields) {
|
||||||
array_fill(fields)
|
array_fill(fields);
|
||||||
array_printcsv(fields, output)
|
array_printcsv(fields, output);
|
||||||
}
|
}
|
||||||
function array_findcsv(fields, input, field, value, nbfields, orig, found, i) {
|
function array_findcsv(fields, input, field, value, nbfields, orig, found, i) {
|
||||||
array_new(orig)
|
array_new(orig);
|
||||||
array_fill(orig)
|
array_fill(orig);
|
||||||
array_new(fields)
|
array_new(fields);
|
||||||
found = 0
|
found = 0;
|
||||||
while ((getline <input) > 0) {
|
while ((getline <input) > 0) {
|
||||||
array_parsecsv(fields, $0, nbfields)
|
array_parsecsv(fields, $0, nbfields);
|
||||||
if (fields[field] == value) {
|
if (fields[field] == value) {
|
||||||
found = 1
|
found = 1;
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(input)
|
close(input);
|
||||||
array_getline(orig)
|
array_getline(orig);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
delete fields
|
delete fields;
|
||||||
if (nbfields) {
|
if (nbfields) {
|
||||||
nbfields = int(nbfields)
|
nbfields = int(nbfields);
|
||||||
i = array_len(fields)
|
i = array_len(fields);
|
||||||
while (i < nbfields) {
|
while (i < nbfields) {
|
||||||
i++
|
i++;
|
||||||
fields[i] = ""
|
fields[i] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found
|
return found;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,31 +27,31 @@ function base64__rshift(var, x) {
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
BEGIN {
|
BEGIN {
|
||||||
BASE64__BYTES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
BASE64__BYTES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
}
|
}
|
||||||
function b64decode(src, result, base1, base2, base3, base4) {
|
function b64decode(src, result, base1, base2, base3, base4) {
|
||||||
result = ""
|
result = "";
|
||||||
while (length(src) > 0) {
|
while (length(src) > 0) {
|
||||||
# Specify byte values
|
# Specify byte values
|
||||||
base1 = substr(src, 1, 1)
|
base1 = substr(src, 1, 1);
|
||||||
base2 = substr(src, 2, 1)
|
base2 = substr(src, 2, 1);
|
||||||
base3 = substr(src, 3, 1); if (base3 == "") base3 = "="
|
base3 = substr(src, 3, 1); if (base3 == "") base3 = "=";
|
||||||
base4 = substr(src, 4, 1); if (base4 == "") base4 = "="
|
base4 = substr(src, 4, 1); if (base4 == "") base4 = "=";
|
||||||
# Now find numerical position in BASE64 string
|
# Now find numerical position in BASE64 string
|
||||||
byte1 = index(BASE64__BYTES, base1) - 1
|
byte1 = index(BASE64__BYTES, base1) - 1;
|
||||||
if (byte1 < 0) byte1 = 0
|
if (byte1 < 0) byte1 = 0;
|
||||||
byte2 = index(BASE64__BYTES, base2) - 1
|
byte2 = index(BASE64__BYTES, base2) - 1;
|
||||||
if (byte2 < 0) byte2 = 0
|
if (byte2 < 0) byte2 = 0;
|
||||||
byte3 = index(BASE64__BYTES, base3) - 1
|
byte3 = index(BASE64__BYTES, base3) - 1;
|
||||||
if (byte3 < 0) byte3 = 0
|
if (byte3 < 0) byte3 = 0;
|
||||||
byte4 = index(BASE64__BYTES, base4) - 1
|
byte4 = index(BASE64__BYTES, base4) - 1;
|
||||||
if (byte4 < 0) byte4 = 0
|
if (byte4 < 0) byte4 = 0;
|
||||||
# Reconstruct ASCII string
|
# Reconstruct ASCII string
|
||||||
result = result sprintf( "%c", base64__lshift(base64__and(byte1, 63), 2) + base64__rshift(base64__and(byte2, 48), 4) )
|
result = result sprintf( "%c", base64__lshift(base64__and(byte1, 63), 2) + base64__rshift(base64__and(byte2, 48), 4) );
|
||||||
if (base3 != "=") result = result sprintf( "%c", base64__lshift(base64__and(byte2, 15), 4) + base64__rshift(base64__and(byte3, 60), 2) )
|
if (base3 != "=") result = result sprintf( "%c", base64__lshift(base64__and(byte2, 15), 4) + base64__rshift(base64__and(byte3, 60), 2) );
|
||||||
if (base4 != "=") result = result sprintf( "%c", base64__lshift(base64__and(byte3, 3), 6) + byte4 )
|
if (base4 != "=") result = result sprintf( "%c", base64__lshift(base64__and(byte3, 3), 6) + byte4 );
|
||||||
# Decrease incoming string with 4
|
# Decrease incoming string with 4
|
||||||
src = substr(src, 5)
|
src = substr(src, 5);
|
||||||
}
|
}
|
||||||
return result
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue