Anders Waldenborg | 2bef1a6 | 2013-10-23 08:10:20 +0000 | [diff] [blame] | 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 | |
Anders Waldenborg | 2bef1a6 | 2013-10-23 08:10:20 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | #define MAX_TOKENS 512 |
| 18 | #define MAX_LINE_LEN 1024 |
| 19 | |
Benjamin Kramer | 2e13053 | 2016-02-05 13:31:14 +0000 | [diff] [blame] | 20 | void llvm_tokenize_stdin(void (*cb)(char **tokens, int ntokens)) { |
Anders Waldenborg | 2bef1a6 | 2013-10-23 08:10:20 +0000 | [diff] [blame] | 21 | char line[MAX_LINE_LEN]; |
| 22 | char *tokbuf[MAX_TOKENS]; |
| 23 | |
| 24 | while (fgets(line, sizeof(line), stdin)) { |
| 25 | int c = 0; |
| 26 | |
| 27 | if (line[0] == ';' || line[0] == '\n') |
| 28 | continue; |
| 29 | |
| 30 | while (c < MAX_TOKENS) { |
| 31 | tokbuf[c] = strtok(c ? NULL : line, " \n"); |
| 32 | if (!tokbuf[c]) |
| 33 | break; |
| 34 | c++; |
| 35 | } |
| 36 | if (c) |
| 37 | cb(tokbuf, c); |
| 38 | } |
| 39 | } |