#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "parse.h"
#include "smatch.h"
int open_data_file(const char *filename)
{
char buf[256];
int fd;
fd = open(filename, O_RDONLY);
if (fd >= 0)
return fd;
if (!data_dir)
return -1;
snprintf(buf, 256, "%s/%s", data_dir, filename);
return open(buf, O_RDONLY);
}
int open_schema_file(const char *schema)
{
char buf[256];
int fd;
fd = open_data_file(schema);
if (fd >= 0)
return fd;
snprintf(buf, 256, "%s/smatch_data/%s", bin_dir, schema);
return open(buf, O_RDONLY);
}
struct token *get_tokens_file(const char *filename)
{
int fd;
struct token *token;
if (option_no_data)
return NULL;
fd = open_data_file(filename);
if (fd < 0)
return NULL;
token = tokenize(filename, fd, NULL, NULL);
close(fd);
return token;
}