summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile30
-rw-r--r--main.cpp27
3 files changed, 59 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..38a0404
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/obj
+datetags
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..834f021
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,30 @@
+CXX = g++
+CXXFLAGS = -Wall -Wextra -std=c++17 -O2 -g -flto
+LDFLAGS = $(CXXFLAGS)
+TARGET = datetags
+
+SOURCES = $(wildcard *.cpp)
+
+OBJDIR = obj
+
+.PHONY: all clean
+
+all: $(TARGET)
+
+clean:
+ @echo "Cleaning"
+ @rm -f $(TARGET)
+ @rm -rf $(OBJDIR)
+
+
+$(OBJDIR)/%.o: %.cpp $(wildcard *.h) | $(OBJDIR)
+ @mkdir -p $(dir $@)
+ @echo "CXX $<"
+ @$(CXX) $(CXXFLAGS) -c -o $@ $<
+
+$(TARGET): $(patsubst %.cpp,$(OBJDIR)/%.o,$(SOURCES)) | $(OBJDIR)
+ @echo "LD -o $@"
+ @$(CXX) -o $@ $^ $(LDFLAGS)
+
+$(OBJDIR):
+ @mkdir -p $(OBJDIR)
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..51262e9
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+#include <ctime>
+#include <sys/time.h>
+
+
+int main() {
+ std::string line;
+ while (std::getline(std::cin, line)) {
+ struct timeval tv;
+ gettimeofday(&tv, nullptr);
+
+ const struct tm *tm = localtime(&tv.tv_sec);
+
+ char buffer[128];
+ const ssize_t nw =
+ strftime(buffer, sizeof buffer - 7, "%Y-%m-%d %H:%M:%S.", tm);
+
+ int multiplier = 100000;
+ for (int i = 0; i < 6; i++) {
+ buffer[nw + i] = '0' + tv.tv_usec / multiplier % 10;
+ multiplier /= 10;
+ }
+ buffer[nw + 6] = '\0';
+
+ std::cout << buffer << ' ' << line << std::endl;
+ }
+}