mirror of
https://github.com/NotAShelf/Hyprdoctor.git
synced 2024-11-26 15:16:49 +00:00
initial commit
This commit is contained in:
parent
9254ee4032
commit
18b5585f0d
2 changed files with 85 additions and 0 deletions
21
Makefile
Normal file
21
Makefile
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# compiler settings
|
||||||
|
CXX = g++
|
||||||
|
CXXFLAGS = -Wall -std=c++11
|
||||||
|
|
||||||
|
# general variables
|
||||||
|
TARGET = main
|
||||||
|
SRC = main.cpp
|
||||||
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
# compile
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c $<
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ) $(TARGET)
|
||||||
|
|
64
main.cpp
Normal file
64
main.cpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// value of an environment variable
|
||||||
|
const char *getEnvVar(const char *name) {
|
||||||
|
const char *value = std::getenv(name);
|
||||||
|
if (value == nullptr) {
|
||||||
|
throw std::runtime_error(std::string("Environment variable ") + name +
|
||||||
|
" is not set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// print the value of an environment variable
|
||||||
|
void printEnvVar(const char *name) {
|
||||||
|
const char *value = getEnvVar(name);
|
||||||
|
std::cout << name << "=" << value << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read the logs and return the lines that start with [ERR]
|
||||||
|
// which are standard errors
|
||||||
|
std::vector<std::string> readErrLines(const std::string &filePath) {
|
||||||
|
std::ifstream file(filePath);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
throw std::runtime_error("Unable to open file at " + filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
std::vector<std::string> errLines;
|
||||||
|
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
if (line.substr(0, 5) == "[ERR]") {
|
||||||
|
errLines.push_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
return errLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const char *envVar = getEnvVar("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
|
std::cout << "Variable HYPRLAND_INSTANCE_SIGNATURE is set to " << envVar
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::string filePath = "/tmp/hypr/" + std::string(envVar);
|
||||||
|
std::vector<std::string> errLines = readErrLines(filePath);
|
||||||
|
|
||||||
|
// print error lines
|
||||||
|
for (const auto &line : errLines) {
|
||||||
|
std::cout << line << std::endl;
|
||||||
|
}
|
||||||
|
} catch (const std::runtime_error &e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue