]> granicus.if.org Git - postgresql/blob - src/interfaces/ecpg/preproc/c_keywords.c
Fixed some bugs.
[postgresql] / src / interfaces / ecpg / preproc / c_keywords.c
1 /*-------------------------------------------------------------------------
2  *
3  * keywords.c
4  *        lexical token lookup for reserved words in postgres embedded SQL
5  *
6  *-------------------------------------------------------------------------
7  */
8 #include "postgres_fe.h"
9
10 #include <ctype.h>
11
12 #include "extern.h"
13 #include "preproc.h"
14
15 /*
16  * List of (keyword-name, keyword-token-value) pairs.
17  *
18  * !!WARNING!!: This list must be sorted, because binary
19  *               search is used to locate entries.
20  */
21 static ScanKeyword ScanKeywords[] = {
22         /* name                                 value                   */
23         {"VARCHAR", VARCHAR},
24         {"auto", S_AUTO},
25         {"bool", SQL_BOOL},
26         {"char", CHAR_P},
27         {"const", S_CONST},
28         {"enum", SQL_ENUM},
29         {"extern", S_EXTERN},
30         {"float", FLOAT_P},
31         {"hour", HOUR_P},
32         {"int", INT_P},
33         {"long", SQL_LONG},
34         {"minute", MINUTE_P},
35         {"month", MONTH_P},
36         {"register", S_REGISTER},
37         {"second", SECOND_P},
38         {"short", SQL_SHORT},
39         {"signed", SQL_SIGNED},
40         {"static", S_STATIC},
41         {"struct", SQL_STRUCT},
42         {"to", TO},
43         {"typedef", S_TYPEDEF},
44         {"union", UNION},
45         {"unsigned", SQL_UNSIGNED},
46         {"varchar", VARCHAR},
47         {"volatile", S_VOLATILE},
48         {"year", YEAR_P},       
49 };
50
51 ScanKeyword *
52 ScanCKeywordLookup(char *text)
53 {
54         ScanKeyword *low = &ScanKeywords[0];
55         ScanKeyword *high = endof(ScanKeywords) - 1;
56         ScanKeyword *middle;
57         int                     difference;
58
59         while (low <= high)
60         {
61                 middle = low + (high - low) / 2;
62                 difference = strcmp(middle->name, text);
63                 if (difference == 0)
64                         return middle;
65                 else if (difference < 0)
66                         low = middle + 1;
67                 else
68                         high = middle - 1;
69         }
70
71         return NULL;
72 }