From e8481054f4242ab6725dc2d9d0bf92c0d1927dad Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Sat, 4 Oct 2014 10:07:05 +0400 Subject: [PATCH] ajout des fonction __get{h,i,}() --- lib/ulib/.ulibver | 2 +- lib/ulib/awk | 19 +++++++++++++++++++ lib/ulib/base | 16 +++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/ulib/.ulibver b/lib/ulib/.ulibver index ca81d09..c782d26 100644 --- a/lib/ulib/.ulibver +++ b/lib/ulib/.ulibver @@ -1 +1 @@ -003005000 +003006000 diff --git a/lib/ulib/awk b/lib/ulib/awk index f2ddbda..98c890a 100644 --- a/lib/ulib/awk +++ b/lib/ulib/awk @@ -402,6 +402,25 @@ function do_once(key) { return 1 } +function __geth(field, HEADERS, nbfields, i) { + nbfields = array_len(HEADERS) + if (int(field) == field) { + field = int(field) + if (field >= 1 && field <= nbfields) return field + else return 0 + } + field = tolower(field) + for (i = 1; i <= nbfields; i++) { + if (field == tolower(HEADERS[i])) { + return i + } + } + return 0 +} +function __geti(num, HEADERS) { if (num != 0) return HEADERS[num] } +function __get(field, HEADERS) { return __geti(__geth(field, HEADERS), HEADERS) } + + function ogeth(field, nbfields, i) { nbfields = array_len(ORIGHEADERS) if (int(field) == field) { diff --git a/lib/ulib/base b/lib/ulib/base index 52d7da8..713f349 100644 --- a/lib/ulib/base +++ b/lib/ulib/base @@ -1995,8 +1995,11 @@ function __array_parsecsv(fields, line, nbfields, colsep, qchar, echar, shou i = i + 1 } if (nbfields) { - while (array_len(fields) < nbfields) { - fields[array_len(fields) + 1] = "" + nbfields = int(nbfields) + i = array_len(fields) + while (i < nbfields) { + i++ + fields[i] = "" } } return array_len(fields) @@ -2068,7 +2071,7 @@ function printcsv(output, fields) { array_fill(fields) array_printcsv(fields, output) } -function array_findcsv(fields, input, field, value, nbfields, orig, found) { +function array_findcsv(fields, input, field, value, nbfields, orig, found, i) { array_new(orig) array_fill(orig) array_new(fields) @@ -2085,8 +2088,11 @@ function array_findcsv(fields, input, field, value, nbfields, orig, fou if (!found) { delete fields if (nbfields) { - while (array_len(fields) < nbfields) { - fields[array_len(fields) + 1] = "" + nbfields = int(nbfields) + i = array_len(fields) + while (i < nbfields) { + i++ + fields[i] = "" } } }