PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
keywords.c File Reference
#include "postgres.h"
#include "parser/gramparse.h"
#include "parser/kwlist.h"
Include dependency graph for keywords.c:

Go to the source code of this file.

Macros

#define PG_KEYWORD(a, b, c)   {a,b,c},
 

Functions

const ScanKeywordScanKeywordLookup (const char *text, const ScanKeyword *keywords, int num_keywords)
 

Variables

const ScanKeyword ScanKeywords []
 
const int NumScanKeywords = lengthof(ScanKeywords)
 

Macro Definition Documentation

#define PG_KEYWORD (   a,
  b,
  c 
)    {a,b,c},

Definition at line 26 of file keywords.c.

Function Documentation

const ScanKeyword* ScanKeywordLookup ( const char *  text,
const ScanKeyword keywords,
int  num_keywords 
)

Definition at line 64 of file keywords.c.

References difference(), i, ScanKeyword::name, NAMEDATALEN, NULL, and word().

Referenced by fmtId(), plpgsql_yylex(), quote_identifier(), and ScanECPGKeywordLookup().

67 {
68  int len,
69  i;
70  char word[NAMEDATALEN];
71  const ScanKeyword *low;
72  const ScanKeyword *high;
73 
74  len = strlen(text);
75  /* We assume all keywords are shorter than NAMEDATALEN. */
76  if (len >= NAMEDATALEN)
77  return NULL;
78 
79  /*
80  * Apply an ASCII-only downcasing. We must not use tolower() since it may
81  * produce the wrong translation in some locales (eg, Turkish).
82  */
83  for (i = 0; i < len; i++)
84  {
85  char ch = text[i];
86 
87  if (ch >= 'A' && ch <= 'Z')
88  ch += 'a' - 'A';
89  word[i] = ch;
90  }
91  word[len] = '\0';
92 
93  /*
94  * Now do a binary search using plain strcmp() comparison.
95  */
96  low = keywords;
97  high = keywords + (num_keywords - 1);
98  while (low <= high)
99  {
100  const ScanKeyword *middle;
101  int difference;
102 
103  middle = low + (high - low) / 2;
104  difference = strcmp(middle->name, word);
105  if (difference == 0)
106  return middle;
107  else if (difference < 0)
108  low = middle + 1;
109  else
110  high = middle - 1;
111  }
112 
113  return NULL;
114 }
#define NAMEDATALEN
const char * name
Definition: keywords.h:26
Datum difference(PG_FUNCTION_ARGS)
#define NULL
Definition: c.h:226
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1245
int i
Definition: c.h:435

Variable Documentation

const int NumScanKeywords = lengthof(ScanKeywords)
const ScanKeyword ScanKeywords[]