ecpg_keywords.c
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:2k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. /*-------------------------------------------------------------------------
  2.  *
  3.  * keywords.c
  4.  *   lexical token lookup for reserved words in postgres embedded SQL
  5.  *
  6.  *-------------------------------------------------------------------------
  7.  */
  8. #include <ctype.h>
  9. #include <string.h>
  10. #include "postgres.h"
  11. #include "extern.h"
  12. #include "preproc.h"
  13. /*
  14.  * List of (keyword-name, keyword-token-value) pairs.
  15.  *
  16.  * !!WARNING!!: This list must be sorted, because binary
  17.  *  search is used to locate entries.
  18.  */
  19. static ScanKeyword ScanKeywords[] = {
  20. /* name value */
  21. {"at", SQL_AT},
  22. {"autocommit", SQL_AUTOCOMMIT},
  23. {"bool", SQL_BOOL},
  24. {"break", SQL_BREAK},
  25. {"call", SQL_CALL},
  26. {"connect", SQL_CONNECT},
  27. {"connection", SQL_CONNECTION},
  28. {"continue", SQL_CONTINUE},
  29. {"deallocate", SQL_DEALLOCATE},
  30. {"disconnect", SQL_DISCONNECT},
  31. {"enum", SQL_ENUM},
  32. {"found", SQL_FOUND},
  33. {"free", SQL_FREE},
  34. {"go", SQL_GO},
  35. {"goto", SQL_GOTO},
  36. {"identified", SQL_IDENTIFIED},
  37. {"immediate", SQL_IMMEDIATE},
  38. {"indicator", SQL_INDICATOR},
  39. {"int", SQL_INT},
  40. {"long", SQL_LONG},
  41. {"off", SQL_OFF},
  42. {"open", SQL_OPEN},
  43. {"prepare", SQL_PREPARE},
  44. {"reference", SQL_REFERENCE},
  45. {"release", SQL_RELEASE},
  46. {"section", SQL_SECTION},
  47. {"short", SQL_SHORT},
  48. {"signed", SQL_SIGNED},
  49. {"sqlerror", SQL_SQLERROR},
  50. {"sqlprint", SQL_SQLPRINT},
  51. {"sqlwarning", SQL_SQLWARNING},
  52. {"stop", SQL_STOP},
  53. {"struct", SQL_STRUCT},
  54. {"unsigned", SQL_UNSIGNED},
  55. {"var", SQL_VAR},
  56. {"whenever", SQL_WHENEVER},
  57. };
  58. ScanKeyword *
  59. ScanECPGKeywordLookup(char *text)
  60. {
  61. ScanKeyword *low = &ScanKeywords[0];
  62. ScanKeyword *high = endof(ScanKeywords) - 1;
  63. ScanKeyword *middle;
  64. int difference;
  65. while (low <= high)
  66. {
  67. middle = low + (high - low) / 2;
  68. difference = strcmp(middle->name, text);
  69. if (difference == 0)
  70. return middle;
  71. else if (difference < 0)
  72. low = middle + 1;
  73. else
  74. high = middle - 1;
  75. }
  76. return NULL;
  77. }