aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp84
1 files changed, 77 insertions, 7 deletions
diff --git a/src/main.cpp b/src/main.cpp
index d49ae1f..ce914b7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -18,7 +18,7 @@ void usage()
exit(1);
}
-void validateProjectPath(const char *projectPath)
+void validateDirectoryPath(const char *projectPath)
{
FileType projectPathFileType = getFileType(projectPath);
if(projectPathFileType == FileType::FILE_NOT_FOUND)
@@ -33,7 +33,7 @@ void validateProjectPath(const char *projectPath)
}
}
-void validateProjectConfPath(const char *projectConfPath)
+void validateFilePath(const char *projectConfPath)
{
FileType projectConfFileType = getFileType(projectConfPath);
if(projectConfFileType == FileType::FILE_NOT_FOUND)
@@ -43,11 +43,66 @@ void validateProjectConfPath(const char *projectConfPath)
}
else if(projectConfFileType == FileType::DIRECTORY)
{
- printf("Expected project conf (%s) to be a directory, was a file", projectConfPath);
+ printf("Expected project path (%s) to be a file, was a directory", projectConfPath);
exit(5);
}
}
+class SibsConfig : public ConfigCallback
+{
+protected:
+ void processObject(StringView name) override
+ {
+ currentObject = name;
+ printf("Process object: %.*s\n", name.size, name.data);
+ }
+
+ void processField(StringView name, const ConfigValue &value) override
+ {
+ printf("Process field: %.*s, value: ", name.size, name.data);
+ if(value.isSingle())
+ {
+ printf("\"%.*s\"", value.asSingle().size, value.asSingle().data);
+ }
+ else
+ {
+ printf("[");
+ int i = 0;
+ for(auto listElement : value.asList())
+ {
+ if(i > 0)
+ printf(", ");
+ printf("\"%.*s\"", listElement.size, listElement.data);
+ ++i;
+ }
+ printf("]");
+ }
+ printf("\n");
+ }
+
+ void finished() override
+ {
+
+ }
+
+private:
+ StringView currentObject;
+};
+
+const char *sourceFileExtensions[] = { "cc", "cpp", "cxx" };
+bool isSourceFile(tinydir_file *file)
+{
+ if(!file->is_reg)
+ return false;
+
+ for(const char *sourceFileExtension : sourceFileExtensions)
+ {
+ if(_tinydir_strcmp(sourceFileExtension, file->extension) == 0)
+ return true;
+ }
+
+ return false;
+}
int main(int argc, const char **argv)
{
@@ -55,22 +110,37 @@ int main(int argc, const char **argv)
usage();
const char *projectPath = argv[1];
- validateProjectPath(projectPath);
+ validateDirectoryPath(projectPath);
string projectConfFilePath = projectPath;
projectConfFilePath += "/project.conf";
- validateProjectConfPath(projectConfFilePath.c_str());
+ validateFilePath(projectConfFilePath.c_str());
- auto result = readConf(projectConfFilePath.c_str());
+ SibsConfig sibsConfig;
+ Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig);
if(result.isOk())
{
}
else
{
- printf("Failed to read config: %s\n", result.getErrMsg());
+ printf("Failed to read config: %s\n", result.getErrMsg().c_str());
exit(6);
}
+ string projectSrcPath = string(projectPath) + "/src";
+ validateDirectoryPath(projectSrcPath.c_str());
+ walkDirFiles(projectSrcPath.c_str(), [](tinydir_file *file)
+ {
+ if (isSourceFile(file))
+ {
+ printf("source file: %s\n", file->path);
+ }
+ else
+ {
+ printf("non source file: %s\n", file->path);
+ }
+ });
+
return 0;
} \ No newline at end of file