1996-07-09 06:22:35 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-13 23:22:53 +00:00
|
|
|
* scansup.c
|
1997-09-07 05:04:48 +00:00
|
|
|
* support routines for the lex/flex scanner, used by both the normal
|
1996-07-09 06:22:35 +00:00
|
|
|
* backend as well as the bootstrap backend
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1999-09-11 22:26:47 +00:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/parser/scansup.c,v 1.17 1999/09/11 22:26:35 tgl Exp $
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-08-27 07:42:29 +00:00
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
#include <ctype.h>
|
1997-11-26 01:14:33 +00:00
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
#include "postgres.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "parser/scansup.h"
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 05:04:48 +00:00
|
|
|
* scanstr
|
|
|
|
*
|
1996-07-09 06:22:35 +00:00
|
|
|
* if the string passed in has escaped codes, map the escape codes to actual
|
|
|
|
* chars
|
|
|
|
*
|
1999-09-11 22:26:47 +00:00
|
|
|
* the string returned is palloc'd and should eventually be pfree'd by the
|
|
|
|
* caller!
|
1996-07-09 06:22:35 +00:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
1998-02-26 04:46:47 +00:00
|
|
|
char *
|
1996-07-09 06:22:35 +00:00
|
|
|
scanstr(char *s)
|
|
|
|
{
|
1999-09-11 22:26:47 +00:00
|
|
|
char *newStr;
|
1997-09-08 02:41:22 +00:00
|
|
|
int len,
|
|
|
|
i,
|
|
|
|
j;
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
if (s == NULL || s[0] == '\0')
|
1999-09-11 22:26:47 +00:00
|
|
|
return pstrdup("");
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
len = strlen(s);
|
|
|
|
|
1999-09-11 22:26:47 +00:00
|
|
|
newStr = palloc(len+1); /* string cannot get longer */
|
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
for (i = 0, j = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (s[i] == '\'')
|
|
|
|
{
|
1999-05-25 16:15:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: if scanner is working right, unescaped quotes can
|
|
|
|
* only appear in pairs, so there should be another character.
|
1999-02-07 23:59:59 +00:00
|
|
|
*/
|
|
|
|
i++;
|
|
|
|
newStr[j] = s[i];
|
1997-09-07 05:04:48 +00:00
|
|
|
}
|
1999-02-07 23:59:59 +00:00
|
|
|
else if (s[i] == '\\')
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
1999-02-07 23:59:59 +00:00
|
|
|
i++;
|
|
|
|
switch (s[i])
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
1999-02-07 23:59:59 +00:00
|
|
|
case 'b':
|
|
|
|
newStr[j] = '\b';
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
newStr[j] = '\f';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
newStr[j] = '\n';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
newStr[j] = '\r';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
newStr[j] = '\t';
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
long octVal = 0;
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1999-02-07 23:59:59 +00:00
|
|
|
for (k = 0;
|
1997-09-07 05:04:48 +00:00
|
|
|
s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
|
1999-02-07 23:59:59 +00:00
|
|
|
k++)
|
|
|
|
octVal = (octVal << 3) + (s[i + k] - '0');
|
|
|
|
i += k - 1;
|
|
|
|
newStr[j] = ((char) octVal);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newStr[j] = s[i];
|
|
|
|
break;
|
|
|
|
} /* switch */
|
|
|
|
} /* s[i] == '\\' */
|
|
|
|
else
|
|
|
|
newStr[j] = s[i];
|
1997-09-07 05:04:48 +00:00
|
|
|
j++;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
1997-09-07 05:04:48 +00:00
|
|
|
newStr[j] = '\0';
|
|
|
|
return newStr;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|