brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 5653765 Raw
40 lines · c
1/*===-- helpers.c - tool for testing libLLVM and llvm-c API ---------------===*\2|*                                                                            *|3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|4|* Exceptions.                                                                *|5|* See https://llvm.org/LICENSE.txt for license information.                  *|6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|7|*                                                                            *|8|*===----------------------------------------------------------------------===*|9|*                                                                            *|10|* Helper functions                                                           *|11|*                                                                            *|12\*===----------------------------------------------------------------------===*/13 14#include <stdio.h>15#include <string.h>16 17#define MAX_TOKENS 51218#define MAX_LINE_LEN 102419 20void llvm_tokenize_stdin(void (*cb)(char **tokens, int ntokens)) {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}40