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
14#include "llvm-c-test.h"
15#include <stdio.h>
16#include <string.h>
17
18#define MAX_TOKENS 512
19#define MAX_LINE_LEN 1024
20
21void tokenize_stdin(void (*cb)(char **tokens, int ntokens)) {
22  char line[MAX_LINE_LEN];
23  char *tokbuf[MAX_TOKENS];
24
25  while (fgets(line, sizeof(line), stdin)) {
26    int c = 0;
27
28    if (line[0] == ';' || line[0] == '\n')
29      continue;
30
31    while (c < MAX_TOKENS) {
32      tokbuf[c] = strtok(c ? NULL : line, " \n");
33      if (!tokbuf[c])
34        break;
35      c++;
36    }
37    if (c)
38      cb(tokbuf, c);
39  }
40}
41