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