Add slackware package database parser
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -2,3 +2,6 @@ | |||||||
| /config/tea-cleaner.toml | /config/tea-cleaner.toml | ||||||
| /log/ | /log/ | ||||||
| /tmp/ | /tmp/ | ||||||
|  | CMakeLists.txt | ||||||
|  | /.cache/ | ||||||
|  | /build/ | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								cli/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								cli/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | #include <filesystem> | ||||||
|  | #include <iostream> | ||||||
|  | #include "katja/database.hpp" | ||||||
|  |  | ||||||
|  | int main() | ||||||
|  | { | ||||||
|  |     for (const auto& entry : std::filesystem::directory_iterator(katja::database)) | ||||||
|  |     { | ||||||
|  |         katja::database_package database_entry{ entry.path().filename() }; | ||||||
|  |  | ||||||
|  |         std::cout << database_entry.to_string() << std::endl; | ||||||
|  |     } | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
							
								
								
									
										28
									
								
								include/katja/database.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								include/katja/database.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | #include <string> | ||||||
|  |  | ||||||
|  | namespace katja | ||||||
|  | { | ||||||
|  |     constexpr const char *database = "/var/lib/pkgtools/packages"; | ||||||
|  |  | ||||||
|  |     class database_package | ||||||
|  |     { | ||||||
|  |         database_package(std::string&& name, std::string&& version, | ||||||
|  |                 std::string&& architecture, std::string&& build_tag); | ||||||
|  |  | ||||||
|  |         static database_package create_database_package(const std::string& fullname); | ||||||
|  |  | ||||||
|  |     public: | ||||||
|  |         const std::string build_tag; | ||||||
|  |         const std::string architecture; | ||||||
|  |         const std::string version; | ||||||
|  |         const std::string name; | ||||||
|  |  | ||||||
|  |         database_package(const std::string& fullname); | ||||||
|  |  | ||||||
|  |         std::string to_string() const; | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										67
									
								
								katja/database.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								katja/database.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,67 @@ | |||||||
|  | #include "katja/database.hpp" | ||||||
|  |  | ||||||
|  | namespace katja | ||||||
|  | { | ||||||
|  |     database_package database_package::create_database_package(const std::string& fullname) | ||||||
|  |     { | ||||||
|  |         std::string::const_reverse_iterator begin_iterator = std::crbegin(fullname); | ||||||
|  |         std::string::const_reverse_iterator end_iterator = begin_iterator; | ||||||
|  |         int minus_counter = 0; | ||||||
|  |  | ||||||
|  |         std::string build_tag; | ||||||
|  |         std::string architecture; | ||||||
|  |         std::string version; | ||||||
|  |  | ||||||
|  |         for (; begin_iterator != std::crend(fullname) && minus_counter < 3; ++begin_iterator) | ||||||
|  |         { | ||||||
|  |             if (*begin_iterator == '-') | ||||||
|  |             { | ||||||
|  |                 if (minus_counter == 0) | ||||||
|  |                 { | ||||||
|  |                     build_tag = std::string(begin_iterator.base(), end_iterator.base()); | ||||||
|  |                 } | ||||||
|  |                 else if (minus_counter == 1) | ||||||
|  |                 { | ||||||
|  |                     architecture = std::string(begin_iterator.base(), end_iterator.base()); | ||||||
|  |                 } | ||||||
|  |                 else if (minus_counter == 2) | ||||||
|  |                 { | ||||||
|  |                     version = std::string(begin_iterator.base(), end_iterator.base()); | ||||||
|  |                 } | ||||||
|  |                 end_iterator = begin_iterator + 1; | ||||||
|  |                 ++minus_counter; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return database_package(std::string(fullname.cbegin(), end_iterator.base()), | ||||||
|  |                 std::move(version), std::move(architecture), std::move(build_tag)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     database_package::database_package(std::string&& name, std::string&& version, | ||||||
|  |                 std::string&& architecture, std::string&& build_tag) | ||||||
|  |         : name(name), version(version), architecture(version), build_tag(build_tag) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     database_package::database_package(const std::string& fullname) | ||||||
|  |         : database_package(create_database_package(fullname)) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     std::string database_package::to_string() const | ||||||
|  |     { | ||||||
|  |         std::string package_string; | ||||||
|  |         const std::size_t total_size = this->name.size() + this->version.size() | ||||||
|  |             + this->architecture.size() + this->build_tag.size() + 3; | ||||||
|  |  | ||||||
|  |         package_string.reserve(total_size); | ||||||
|  |         package_string.append(this->name); | ||||||
|  |         package_string.push_back('-'); | ||||||
|  |         package_string.append(this->version); | ||||||
|  |         package_string.push_back('-'); | ||||||
|  |         package_string.append(this->architecture); | ||||||
|  |         package_string.push_back('-'); | ||||||
|  |         package_string.append(this->build_tag); | ||||||
|  |  | ||||||
|  |         return package_string; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user