Index: ossp-pkg/var/TODO RCS File: /v/ossp/cvs/ossp-pkg/var/Attic/TODO,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/var/Attic/TODO,v' 2>/dev/null --- TODO 2001/11/14 12:59:24 1.5 +++ TODO 2001/11/20 15:33:07 1.6 @@ -1,104 +1,64 @@ OSSP var - - Doku sollte ein Beispiel für Quoting von Shell- und - Regexp-Ausdrücken enthalten. + - Man braucht ein Schleifenkonstrukt, das über Arrays iteriert: - - Unterstützung von PCRE. + [${foo}${bar}] + Dies wird so interpretiert, daß der Parser an den Variablennamen + den jeweiligen Index anhängt, und die ganze Zeile expandiert, + solange, bis _alle_ in dem Konstrukt verwandten Variablen für den + derzeitigen Index undefiniert sind -- sind nur einzelne Variablen + undefiniert, werden sie durch den Leerstring "" ersetzt. Text + innerhalb des Konstrukten wird "verbatim" in jeder Zeile erhalten, + beispielsweise: ----- RSE: -------------------------------------------------------------------- + [${foo}: ${bar}\n] -- HAS TO BE: adding a var_error() function which translates var_rc_t - into a text version ala strerror(3). - -- HAS TO BE: still missing PCRE support plus corresponding Autoconf stuff - -- CAN BE: as in L2, reduce the large 1024 auto-variable with a a lot - smaller (on 32-bit boxes just 21 bytes) but still fully - sufficiently-sized variable: - -Index: var.c -=================================================================== -RCS file: /u/rse/arc/cvs/ossp/ossp-pkg/var/var.c,v -retrieving revision 1.14 -diff -u -d -u -d -r1.14 var.c ---- var.c 2001/11/14 11:11:01 1.14 -+++ var.c 2001/11/14 11:37:54 -@@ -1261,8 +1261,8 @@ - - case '#': /* Substitute length of the string. */ - if (data->begin) { -- char buf[1024]; -- sprintf(buf, "%d", data->end - data->begin); -+ char buf[((sizeof(int)*8)/3)+10]; /* sufficient size: <#bits> x log_10(2) + safety */ -+ sprintf(buf, "%d", (int)(data->end - data->begin)); - tokenbuf_free(data); - if (!tokenbuf_assign(data, buf, strlen(buf))) { - rc = VAR_ERR_OUT_OF_MEMORY; - -- SHOULD BE: the "magic" number 256 in name class definitions would be - nice if replaced by a symbolic name - -- SHOULD BE: the expand_octal() function checks that in the octal number - NNN (representing a character) the first number is not larger than - 3 because the 0xff is (octal) 377. Unfortunately this still allows - things like 399 which is illegal because larger than 0xff (the maximum - fitting into an 8-bit character). My suggestions: - -Index: var.c -=================================================================== -RCS file: /u/rse/arc/cvs/ossp/ossp-pkg/var/var.c,v -retrieving revision 1.15 -diff -u -d -u -d -r1.15 var.c ---- var.c 2001/11/14 12:02:40 1.15 -+++ var.c 2001/11/14 12:14:49 -@@ -209,7 +209,7 @@ - - static var_rc_t expand_octal(const char **src, char **dst, const char *end) - { -- unsigned char c; -+ unsigned int c; - - if (end - *src < 3) - return VAR_ERR_INCOMPLETE_OCTAL; -@@ -217,8 +217,6 @@ - return VAR_ERR_INVALID_OCTAL; - - c = **src - '0'; -- if (c > 3) -- return VAR_ERR_OCTAL_TOO_LARGE; - c *= 8; - ++(*src); - -@@ -227,6 +225,9 @@ - ++(*src); - - c += **src - '0'; -+ -+ if (c > 0xff) -+ return VAR_ERR_OCTAL_TOO_LARGE; - - **dst = (char) c; - ++(*dst); - -- SHOULD BE: the tokenbuf functions like tokenbuf_append() return - 1 or 0 and the other routines convert this into var_rc_t values. I - recommend to change the tokenbuf functions to already return var_rc_t - values and pass this value through in other functions. This way the - different errors in tokenbuf_append() are visible, too. - -- CAN BE: I IMHO would reduce the code size of the recursive descent parser - by 1. making the prototype and corresponding parameter names of all - functions identical (see for example text() for a current exclusion) - and then use a macro to replace the long prototype description on - every function. - -- SHOULD BE: the return code semantics are still not clear to me - (perhaps it is solved by documentation). Especially it confuses me a lot - that internally it uses "int" instead of "var_rc_t" and does arithmetics - like "1 + rc" before finanlly it is casted to an var_rc_t. So how should - anyone can do anything reasonable with return codes > 0. He does not - know what they mean, doesn't he? + Hierzu muß var_expand() wissen, wie sie einen indizierten + Variablenzugriff erzeugen kann. Hierzu wird var_config_t um + "char startindex" und "char endindex" erweitert. Weiterhin wird in + var_config_t "char current_index" ein Zeichen konfiguriert, unter + dem der aktuelle Index der Schleife zu bekommen ist. Defaults + werden sein: "[", "]" und "#" respektive. ------------------------------------------------------------------------- + Wenn Variablen innerhalb des Konstruktes bereits einen Index haben, + wird dieser (unter Beachtung eventuell notwendiger Arithmetik) + berechnet und "fest" verwendet, zum Beispiel: + [${foo[1]}] + + oder + + [${foo[(#+1)/2]}] + + Dementsprechend sind die folgenden Ausdrück equivalent: + + [${foo[#]}] == [${foo}] + + Wir unterstützen die vier Grundrechenarten, Modulo und Klammerung + für arithmetische Operationen. + + Weiterhin wird der Callback um einen Parameter "int index" + erweitert, welchen im Falle eines "normalen Variablenzugriffs" auf + Null gesetzt wird. Zugriffe auf Indices, die nicht existieren, + müssen vom Callback mit "UNDEFINED" quittiert werden. Ein Zugriff + auf einen negativen Index liefert die Anzahl der Elemente in dem + Array als String zurück. Ebenso liefert das Konstrukt ${foo:#} die + Anzahl der Elemente zurück, wenn $foo ein Array ist. + + [...]-Konstrukte können beliebig tief geschachtelt werden. + + Innerhalb von Indixangaben dürfen erneut Variablen verwendet + werden. + + Arrays werden nur in "expressions" erkannt, und im Konstrukt werden + auch nur "expressions" gesondert behandelt; normale Variablen + werden in jedem Pass normal expandiert. + + Sind "stardindex", "endindex" oder "current_index" leer (gleich + '\0'), wird dieses Konstrukt vom Parser nicht erkannt und als Text + interpretiert -- abgesehen von den Variablen, natürlich, welche + aber nicht in einer Schleife expandiert werden, noch werden beim + Callback Array-Elemente abgefragt. + + - Abgabe: 6.12.2001 zum Nikolaustag im CVS.