2013-10-23 10:10:20 +02:00
|
|
|
/*===-- helpers.c - tool for testing libLLVM and llvm-c API ---------------===*\
|
|
|
|
|* *|
|
2019-01-19 09:50:56 +01:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
|
|
|
|* Exceptions. *|
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information. *|
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
2013-10-23 10:10:20 +02:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
|
|
|
|* Helper functions *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define MAX_TOKENS 512
|
|
|
|
#define MAX_LINE_LEN 1024
|
|
|
|
|
2016-02-05 14:31:14 +01:00
|
|
|
void llvm_tokenize_stdin(void (*cb)(char **tokens, int ntokens)) {
|
2013-10-23 10:10:20 +02:00
|
|
|
char line[MAX_LINE_LEN];
|
|
|
|
char *tokbuf[MAX_TOKENS];
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), stdin)) {
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
if (line[0] == ';' || line[0] == '\n')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while (c < MAX_TOKENS) {
|
|
|
|
tokbuf[c] = strtok(c ? NULL : line, " \n");
|
|
|
|
if (!tokbuf[c])
|
|
|
|
break;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
if (c)
|
|
|
|
cb(tokbuf, c);
|
|
|
|
}
|
|
|
|
}
|