utiliser array_len() au lieu de length() pour compatibilité avec une vieille version de gawk
This commit is contained in:
parent
305f9e821a
commit
82f47e0c2a
58
lib/ulib/awk
58
lib/ulib/awk
|
@ -403,7 +403,7 @@ function do_once(key) {
|
|||
}
|
||||
|
||||
function ogeth(field, nbfields, i) {
|
||||
nbfields = length(ORIGHEADERS)
|
||||
nbfields = array_len(ORIGHEADERS)
|
||||
if (int(field) == field) {
|
||||
field = int(field)
|
||||
if (field >= 1 && field <= nbfields) return field
|
||||
|
@ -421,7 +421,7 @@ function ogeti(num) { if (num != 0) return ORIGFIELDS[num] }
|
|||
function oget(field) { return ogeti(ogeth(field)) }
|
||||
|
||||
function geth(field, nbfields, i) {
|
||||
nbfields = length(HEADERS)
|
||||
nbfields = array_len(HEADERS)
|
||||
if (int(field) == field) {
|
||||
field = int(field)
|
||||
if (field >= 1 && field <= nbfields) return field
|
||||
|
@ -440,7 +440,7 @@ function seth(field, value) { sethi(geth(field), value) }
|
|||
function addh(field, num) {
|
||||
num = geth(field)
|
||||
if (num == 0) {
|
||||
num = length(HEADERS) + 1
|
||||
num = array_len(HEADERS) + 1
|
||||
HEADERS[num] = field
|
||||
}
|
||||
return num
|
||||
|
@ -457,7 +457,7 @@ function set(field, value) { seti(geth(field), value) }
|
|||
function add(field, value, num, i, max) {
|
||||
num = addh(field)
|
||||
i = NF
|
||||
max = length(HEADERS)
|
||||
max = array_len(HEADERS)
|
||||
if (i < max) {
|
||||
i = i + 1
|
||||
while(i <= max) {
|
||||
|
@ -518,7 +518,7 @@ function resetheaders() {
|
|||
}
|
||||
function resetfields( nf) {
|
||||
$0 = ""
|
||||
nf = length(HEADERS)
|
||||
nf = array_len(HEADERS)
|
||||
$nf = ""
|
||||
}
|
||||
function copyfield(field) {
|
||||
|
@ -526,7 +526,7 @@ function copyfield(field) {
|
|||
}
|
||||
function copyfields(fields, array) {
|
||||
split(fields, array, /,/)
|
||||
for (i = 1; i <= length(array); i++) {
|
||||
for (i = 1; i <= array_len(array); i++) {
|
||||
copyfield(array[i])
|
||||
}
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ function checkfields(fields, missings, array, r, field) {
|
|||
array_new(missings)
|
||||
split(fields, array, /,/)
|
||||
r = 1
|
||||
for (i = 1; i <= length(array); i++) {
|
||||
for (i = 1; i <= array_len(array); i++) {
|
||||
field = array[i]
|
||||
if (geth(field) == 0) {
|
||||
array_add(missings, field)
|
||||
|
@ -550,7 +550,7 @@ function checkvalues(fields, missings, array, r, field) {
|
|||
array_new(missings)
|
||||
split(fields, array, /,/)
|
||||
r = 1
|
||||
for (i = 1; i <= length(array); i++) {
|
||||
for (i = 1; i <= array_len(array); i++) {
|
||||
field = array[i]
|
||||
if (geth(field) == 0 || !get(field)) {
|
||||
array_add(missings, field)
|
||||
|
@ -561,9 +561,9 @@ function checkvalues(fields, missings, array, r, field) {
|
|||
}
|
||||
function mapfields(fieldmap, mapitems, parts) {
|
||||
split(fieldmap, mapitems, /,/)
|
||||
for (i = 1; i <= length(mapitems); i++) {
|
||||
for (i = 1; i <= array_len(mapitems); i++) {
|
||||
split(mapitems[i], parts, /:/)
|
||||
if (length(parts) != 2) continue
|
||||
if (array_len(parts) != 2) continue
|
||||
desti = geth(parts[1])
|
||||
srci = geth(parts[2])
|
||||
if (desti == 0 && srci != 0) {
|
||||
|
@ -586,9 +586,9 @@ function build_skipfs(keepfields, skipfields, skipfs, addfs, keepfs, kee
|
|||
for (i in tmpfields) {
|
||||
array_del(keepfs, tmpfields[i], 1)
|
||||
}
|
||||
keepfs_count = length(keepfs)
|
||||
keepfs_count = array_len(keepfs)
|
||||
# puis construire la liste des champs à supprimer dans skipfs
|
||||
headers_count = length(HEADERS)
|
||||
headers_count = array_len(HEADERS)
|
||||
for (i = 1; i <= headers_count; i++) {
|
||||
field = HEADERS[i]
|
||||
if (!in_array(field, keepfs, 1)) {
|
||||
|
@ -604,24 +604,24 @@ function build_skipfs(keepfields, skipfields, skipfs, addfs, keepfs, kee
|
|||
array_add(addfs, field)
|
||||
}
|
||||
}
|
||||
return length(skipfs)
|
||||
return array_len(skipfs)
|
||||
}
|
||||
function filterheaders(skipfs, addfs, skipfs_count, addfs_count) {
|
||||
skipfs_count = length(skipfs)
|
||||
skipfs_count = array_len(skipfs)
|
||||
for (i = skipfs_count; i >= 1; i--) {
|
||||
array_deli(HEADERS, skipfs[i])
|
||||
}
|
||||
addfs_count = length(addfs)
|
||||
addfs_count = array_len(addfs)
|
||||
for (i = 1; i <= addfs_count; i++) {
|
||||
addh(addfs[i])
|
||||
}
|
||||
}
|
||||
function filterfields(skipfs, addfs, skipfs_count) {
|
||||
skipfs_count = length(skipfs)
|
||||
skipfs_count = array_len(skipfs)
|
||||
for (i = skipfs_count; i >= 1; i--) {
|
||||
deli(skipfs[i])
|
||||
}
|
||||
addfs_count = length(addfs)
|
||||
addfs_count = array_len(addfs)
|
||||
for (i = 1; i <= addfs_count; i++) {
|
||||
add(addfs[i], "")
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ function lawkcsv() {
|
|||
}'
|
||||
local append_beforescript=
|
||||
local awkscript='{
|
||||
array_parsecsv(ORIGFIELDS, $0, length(ORIGHEADERS))
|
||||
array_parsecsv(ORIGFIELDS, $0, array_len(ORIGHEADERS))
|
||||
if (reset_fields) { resetfields() } else { copyall() }
|
||||
}'
|
||||
local append_awkscript=
|
||||
|
@ -912,7 +912,7 @@ END { exit ec }"
|
|||
lawkcsv ${skip_lines:+-s "$skip_lines"} ${parse_headers:+-h} \
|
||||
${sepconf:+--sepconf "$sepconf"} ${colsep:+--colsep "$colsep"} ${qchar:+--qchar "$qchar"} ${echar:+--echar "$echar"} \
|
||||
${no_headers:+--no-headers} -v quiet:int=$quiet \
|
||||
--re '{array_parsecsv(ORIGFIELDS, $0, length(ORIGHEADERS))}' -a "$grepscript" \
|
||||
--re '{array_parsecsv(ORIGFIELDS, $0, array_len(ORIGHEADERS))}' -a "$grepscript" \
|
||||
-- "${headers[@]}" -- "${inputfiles[@]}"
|
||||
local r=$?
|
||||
|
||||
|
@ -1320,7 +1320,7 @@ parse_headers && do_once("parse-headers") {
|
|||
lkeepfs[@] rkeepfs[@] \
|
||||
"$__AWKCSV_FUNCTIONS"'
|
||||
function lgeth(field, nbfields, i) {
|
||||
nbfields = length(lheaders)
|
||||
nbfields = array_len(lheaders)
|
||||
if (int(field) == field) {
|
||||
field = int(field)
|
||||
if (field >= 1 && field <= nbfields) return field
|
||||
|
@ -1335,7 +1335,7 @@ function lgeth(field, nbfields, i) {
|
|||
return 0
|
||||
}
|
||||
function rgeth(field, nbfields, i) {
|
||||
nbfields = length(rheaders)
|
||||
nbfields = array_len(rheaders)
|
||||
if (int(field) == field) {
|
||||
field = int(field)
|
||||
if (field >= 1 && field <= nbfields) return field
|
||||
|
@ -1378,10 +1378,10 @@ function keepf(lfields, rfields, i) {
|
|||
}
|
||||
}
|
||||
function printmerged(lline, rline, nocopy, linecsv, tmplinecsv) {
|
||||
if (lline != "") array_parsecsv(lfields, lline, length(lheaders))
|
||||
else array_newsize(lfields, length(lheaders))
|
||||
if (rline != "") array_parsecsv(rfields, rline, length(rheaders))
|
||||
else array_newsize(rfields, length(rheaders))
|
||||
if (lline != "") array_parsecsv(lfields, lline, array_len(lheaders))
|
||||
else array_newsize(lfields, array_len(lheaders))
|
||||
if (rline != "") array_parsecsv(rfields, rline, array_len(rheaders))
|
||||
else array_newsize(rfields, array_len(rheaders))
|
||||
if (postproc) {
|
||||
if (!nocopy) copyf(lfields, rfields)
|
||||
keepf(lfields, rfields)
|
||||
|
@ -1397,7 +1397,7 @@ function printmerged(lline, rline, nocopy, linecsv, tmplinecsv) {
|
|||
BEGIN {
|
||||
if (parse_headers) {
|
||||
array_parsecsv(lheaders, lheaderscsv)
|
||||
lheaders_count = length(lheaders)
|
||||
lheaders_count = array_len(lheaders)
|
||||
if (lprefix != "") {
|
||||
for (i = 1; i <= lheaders_count; i++) {
|
||||
lheaders[i] = lprefix lheaders[i]
|
||||
|
@ -1408,7 +1408,7 @@ BEGIN {
|
|||
if (!lkey) lkey = 1
|
||||
|
||||
array_parsecsv(rheaders, rheaderscsv)
|
||||
rheaders_count = length(rheaders)
|
||||
rheaders_count = array_len(rheaders)
|
||||
if (rprefix != "") {
|
||||
for (i = 1; i <= rheaders_count; i++) {
|
||||
rheaders[i] = rprefix rheaders[i]
|
||||
|
@ -1439,7 +1439,7 @@ BEGIN {
|
|||
}
|
||||
asort(lskipfs)
|
||||
}
|
||||
lskipfs_count = length(lskipfs)
|
||||
lskipfs_count = array_len(lskipfs)
|
||||
|
||||
array_new(rskipfs)
|
||||
if (!in_array("*", rkeepfs)) {
|
||||
|
@ -1452,7 +1452,7 @@ BEGIN {
|
|||
}
|
||||
asort(rskipfs)
|
||||
}
|
||||
rskipfs_count = length(rskipfs)
|
||||
rskipfs_count = array_len(rskipfs)
|
||||
|
||||
if (parse_headers) {
|
||||
# afficher les en-têtes après traitement de lkeepfs et rkeepfs, parce que
|
||||
|
|
Loading…
Reference in New Issue