Browse Source

source file stuff

feature/dependency-graph
Martin Dørum 3 years ago
parent
commit
1a475ba5ce
6 changed files with 109 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 17
    0
      Makefile
  3. 47
    0
      src/SourceFile.cc
  4. 16
    0
      src/SourceFile.h
  5. 25
    0
      src/main.cc
  6. 3
    0
      test.bbb

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
/build

+ 17
- 0
Makefile View File

@@ -0,0 +1,17 @@
SRCS = src/BBBParser.cc src/SourceFile.cc src/main.cc
HDRS = src/BBBParser.h src/SourceFile.h
BUILD = build
OBJS = $(patsubst %,$(BUILD)/%.o,$(SRCS))
CFLAGS = -g

$(BUILD)/%.cc.o: %.cc $(HDRS)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -c $< -o $@

$(BUILD)/bbbuild: $(OBJS)
@mkdir -p $(@D)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

.PHONY: clean
clean:
rm -rf $(BUILD)

+ 47
- 0
src/SourceFile.cc View File

@@ -0,0 +1,47 @@
#include "SourceFile.h"

#include <iostream>
#include <fstream>
#include <sstream>

static bool startsWith(const std::string &a, const std::string &b, std::string &after) {
if (a.size() < b.size())
return false;

for (size_t i = 0; i < b.size(); ++i) {
if (a[i] != b[i])
return false;
}

after = a.substr(b.size());
return true;
}

static void parseParts(std::vector<std::string> &vec, const std::string &str) {
std::istringstream ss(str);
std::string part;
while (ss >> part) {
vec.push_back(part);
}
}

SourceFile::SourceFile(std::string dir, std::string name):
dir_(std::move(dir)), name_(std::move(name)) {

std::ifstream file(dir_ + "/" + name_);

std::string line;
std::string content;
while (std::getline(file, line)) {
if (line.size() < 4) continue;
if (line[0] != '/' || line[1] != '/' || line[2] != '#') continue;

if (startsWith(line, "//# pkgs:", content)) {
parseParts(pkgs_, content);
} else if (startsWith(line, "//# cflags:", content)) {
parseParts(pkgs_, content);
} else if (startsWith(line, "//# ldflags:", content)) {
parseParts(pkgs_, content);
}
}
}

+ 16
- 0
src/SourceFile.h View File

@@ -0,0 +1,16 @@
#pragma once

#include <vector>
#include <string>

class SourceFile {
public:
SourceFile(std::string dir, std::string name);

private:
std::string dir_;
std::string name_;
std::vector<std::string> pkgs_;
std::vector<std::string> cflags_;
std::vector<std::string> ldflags_;
};

+ 25
- 0
src/main.cc View File

@@ -0,0 +1,25 @@
#include <unistd.h>
#include <fstream>

#include "SourceFile.h"
#include "BBBParser.h"

void readDir(std::string dir, std::vector<SourceFile> sources) {
}

int main(int argc, char **argv) {
std::ifstream file("test.bbb");
BBBParser parser(file, BBBParser::FLAG_NONE);

BBBParser::Variables vars;
parser.parse(vars);

std::cout << "\nVariables found:\n";
for (auto &kv: vars) {
std::cout << kv.first << ":\n";
for (auto &val: kv.second) {
std::cout << "\t'" << val << "'\n";
}
}
}

+ 3
- 0
test.bbb View File

@@ -0,0 +1,3 @@
hello = "How are "you" my person" this\ is\ another "and a third"
"this is a fourth" = no
nope = ${hello}

Loading…
Cancel
Save