helpers.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*===-- helpers.c - tool for testing libLLVM and llvm-c API ---------------===*\
  2. |* *|
  3. |* The LLVM Compiler Infrastructure *|
  4. |* *|
  5. |* This file is distributed under the University of Illinois Open Source *|
  6. |* License. See LICENSE.TXT for details. *|
  7. |* *|
  8. |*===----------------------------------------------------------------------===*|
  9. |* *|
  10. |* Helper functions *|
  11. |* *|
  12. \*===----------------------------------------------------------------------===*/
  13. #include "llvm-c-test.h"
  14. #include <stdio.h>
  15. #include <string.h>
  16. #define MAX_TOKENS 512
  17. #define MAX_LINE_LEN 1024
  18. void tokenize_stdin(void (*cb)(char **tokens, int ntokens)) {
  19. char line[MAX_LINE_LEN];
  20. char *tokbuf[MAX_TOKENS];
  21. while (fgets(line, sizeof(line), stdin)) {
  22. int c = 0;
  23. if (line[0] == ';' || line[0] == '\n')
  24. continue;
  25. while (c < MAX_TOKENS) {
  26. tokbuf[c] = strtok(c ? NULL : line, " \n");
  27. if (!tokbuf[c])
  28. break;
  29. c++;
  30. }
  31. if (c)
  32. cb(tokbuf, c);
  33. }
  34. }