ncd_tokenizer_test.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <ncdconfig/NCDConfigTokenizer.h>
  27. int error;
  28. static int tokenizer_output (void *user, int token, char *value, size_t pos)
  29. {
  30. if (token == NCD_ERROR) {
  31. printf("error at %zd\n", pos);
  32. error = 1;
  33. return 0;
  34. }
  35. switch (token) {
  36. case NCD_EOF:
  37. printf("eof\n");
  38. break;
  39. case NCD_TOKEN_CURLY_OPEN:
  40. printf("curly_open\n");
  41. break;
  42. case NCD_TOKEN_CURLY_CLOSE:
  43. printf("curly_close\n");
  44. break;
  45. case NCD_TOKEN_SEMICOLON:
  46. printf("semicolon\n");
  47. break;
  48. case NCD_TOKEN_DOT:
  49. printf("dot\n");
  50. break;
  51. case NCD_TOKEN_INTERFACE:
  52. printf("interface\n");
  53. break;
  54. case NCD_TOKEN_NAME:
  55. printf("name %s\n", value);
  56. break;
  57. case NCD_TOKEN_STRING:
  58. printf("string %s\n", value);
  59. break;
  60. default:
  61. ASSERT(0);
  62. }
  63. return 1;
  64. }
  65. int main (int argc, char **argv)
  66. {
  67. if (argc < 1) {
  68. return 1;
  69. }
  70. if (argc != 2) {
  71. printf("Usage: %s <string>\n", argv[0]);
  72. return 1;
  73. }
  74. error = 0;
  75. NCDConfigTokenizer_Tokenize(argv[1], strlen(argv[1]), tokenizer_output, NULL);
  76. if (error) {
  77. return 1;
  78. }
  79. return 0;
  80. }