Skip to content

Commit

Permalink
Remove unused TCL_ARRAY code.
Browse files Browse the repository at this point in the history
  • Loading branch information
resuna committed May 6, 2022
1 parent 132ddc5 commit ae42d50
Showing 1 changed file with 1 addition and 205 deletions.
206 changes: 1 addition & 205 deletions generic/pgtclCmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,207 +41,6 @@ static int build_param_array(Tcl_Interp *interp, int nParams, Tcl_Obj *CONST obj

static void report_connection_error(Tcl_Interp *interp, PGconn *conn);

#ifdef TCL_ARRAYS

#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#define DIGIT(c) ((c) - '0')


/*
* translate_escape()
*
* This function performs in-place translation of a single C-style
* escape sequence pointed by p. Curly braces { } and double-quote
* are left escaped if they appear inside an array.
* The value returned is the pointer to the last character (the one
* just before the rest of the buffer).
*/

static inline char *
translate_escape(char *p, int isArray)
{
char c,
*q,
*s;

#ifdef TCL_ARRAYS_DEBUG_ESCAPE
printf(" escape = '%s'\n", p);
#endif
/* Address of the first character after the escape sequence */
s = p + 2;
switch (c = *(p + 1))
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
c = DIGIT(c);
if (ISOCTAL(*s))
c = (c << 3) + DIGIT(*s++);
if (ISOCTAL(*s))
c = (c << 3) + DIGIT(*s++);
*p = c;
break;
case 'b':
*p = '\b';
break;
case 'f':
*p = '\f';
break;
case 'n':
*p = '\n';
break;
case 'r':
*p = '\r';
break;
case 't':
*p = '\t';
break;
case 'v':
*p = '\v';
break;
case '\\':
case '{':
case '}':
case '"':

/*
* Backslahes, curly braces and double-quotes are left escaped
* if they appear inside an array. They will be unescaped by
* Tcl in Tcl_AppendElement. The buffer position is advanced
* by 1 so that the this character is not processed again by
* the caller.
*/
if (isArray)
return p + 1;
else
*p = c;
break;
case '\0':

/*
* This means a backslash at the end of the string. It should
* never happen but in that case replace the \ with a \0 but
* don't shift the rest of the buffer so that the caller can
* see the end of the string and terminate.
*/
*p = c;
return p;
break;
default:

/*
* Default case, store the escaped character over the
* backslash and shift the buffer over itself.
*/
*p = c;
}
/* Shift the rest of the buffer over itself after the current char */
q = p + 1;
for (; *s;)
*q++ = *s++;
*q = '\0';
#ifdef TCL_ARRAYS_DEBUG_ESCAPE
printf(" after = '%s'\n", p);
#endif
return p;
}

/*
* tcl_value()
*
* This function does in-line conversion of a value returned by libpq
* into a tcl string or into a tcl list if the value looks like the
* representation of a postgres array.
*/

static char *
tcl_value(char *value)
{
int literal,
last;
char *p;

if (!value)
return NULL;


#ifdef TCL_ARRAYS_DEBUG
printf("pq_value = '%s'\n", value);
#endif
last = strlen(value) - 1;
if ((last >= 1) && (value[0] == '{') && (value[last] == '}'))
{
/* Looks like an array, replace ',' with spaces */
/* Remove the outer pair of { }, the last first! */
value[last] = '\0';
value++;
literal = 0;
for (p = value; *p; p++)
{
if (!literal)
{
/* We are at the list level, look for ',' and '"' */
switch (*p)
{
case '"': /* beginning of literal */
literal = 1;
break;
case ',': /* replace the ',' with space */
*p = ' ';
break;
}
}
else
{
/* We are inside a C string */
switch (*p)
{
case '"': /* end of literal */
literal = 0;
break;
case '\\':

/*
* escape sequence, translate it
*/
p = translate_escape(p, 1);
break;
}
}
if (!*p)
break;
}
}
else
{
/* Looks like a normal scalar value */
for (p = value; *p; p++)
{
if (*p == '\\')
{
/*
* escape sequence, translate it
*/
p = translate_escape(p, 0);
}
if (!*p)
break;
}
}
#ifdef TCL_ARRAYS_DEBUG
printf("tcl_value = '%s'\n\n", value);
#endif
return value;
}
#else /* TCL_ARRAYS */
#define tcl_value(x) x
#endif /* TCL_ARRAYS */

static Tcl_Encoding utf8encoding = NULL;

/*
Expand Down Expand Up @@ -294,9 +93,6 @@ char *utfString(const char *externalString)
* the returned field is actually null and, if so, the null string value
* associated with the connection is returned.
*
* If array-into-list processing has been defined, it is also performed,
* which is probably a bad idea, since it can be tricked by legitimate
* data, but that's tcl_value's fault, if TCL_ARRAYS is defined.
*/

static char *
Expand All @@ -323,7 +119,7 @@ PGgetvalue ( PGresult *result, char *nullString, int tupno, int fieldNumber )
}

/* string is not empty */
return tcl_value (string);
return string;
}

/**********************************
Expand Down

0 comments on commit ae42d50

Please sign in to comment.