ncd_tokenizer_test.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file ncd_tokenizer_test.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <stddef.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <misc/debug.h>
  26. #include <base/BLog.h>
  27. #include <ncd/NCDConfigTokenizer.h>
  28. int error;
  29. static int tokenizer_output (void *user, int token, char *value, size_t pos)
  30. {
  31. if (token == NCD_ERROR) {
  32. printf("error at %zd\n", pos);
  33. error = 1;
  34. return 0;
  35. }
  36. switch (token) {
  37. case NCD_EOF:
  38. printf("eof\n");
  39. break;
  40. case NCD_TOKEN_CURLY_OPEN:
  41. printf("curly_open\n");
  42. break;
  43. case NCD_TOKEN_CURLY_CLOSE:
  44. printf("curly_close\n");
  45. break;
  46. case NCD_TOKEN_ROUND_OPEN:
  47. printf("round_open\n");
  48. break;
  49. case NCD_TOKEN_ROUND_CLOSE:
  50. printf("round_close\n");
  51. break;
  52. case NCD_TOKEN_SEMICOLON:
  53. printf("semicolon\n");
  54. break;
  55. case NCD_TOKEN_DOT:
  56. printf("dot\n");
  57. break;
  58. case NCD_TOKEN_COMMA:
  59. printf("comma\n");
  60. break;
  61. case NCD_TOKEN_PROCESS:
  62. printf("process\n");
  63. break;
  64. case NCD_TOKEN_NAME:
  65. printf("name %s\n", value);
  66. break;
  67. case NCD_TOKEN_STRING:
  68. printf("string %s\n", value);
  69. break;
  70. default:
  71. ASSERT(0);
  72. }
  73. return 1;
  74. }
  75. int main (int argc, char **argv)
  76. {
  77. if (argc < 1) {
  78. return 1;
  79. }
  80. if (argc != 2) {
  81. printf("Usage: %s <string>\n", argv[0]);
  82. return 1;
  83. }
  84. BLog_InitStdout();
  85. error = 0;
  86. NCDConfigTokenizer_Tokenize(argv[1], strlen(argv[1]), tokenizer_output, NULL);
  87. if (error) {
  88. return 1;
  89. }
  90. return 0;
  91. }