diff --git a/tester/Makefile b/tester/Makefile new file mode 100644 index 0000000..ba6cdc8 --- /dev/null +++ b/tester/Makefile @@ -0,0 +1,45 @@ +BIN := $(shell basename $$(pwd)) + +SRCS := $(wildcard *.cpp) +OBJS := $(subst .cpp,.o,$(SRCS)) +DEPS := $(subst .cpp,.d,$(SRCS)) + +CXX ?= g++ +PKG_CONFIG ?= pkg-config + +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin +DATADIR ?= $(PREFIX)/share +MANDIR ?= $(DATADIR)/man + +RM := /bin/rm -f +INSTALL := /usr/bin/install -c + +CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -pthread +ifeq ($(DEBUG),1) + CXXFLAGS += -D DEBUG -O0 +else + CXXFLAGS += -D NDEBUG -O3 +endif + +LDLIBS := -lm -lpthread -lsclogging + +all: $(BIN) + +$(BIN): $(OBJS) $(DEPS) + $(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(BIN) + +%.o: %.cpp %.d Makefile + $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< + +-include *.d + +%.d: ; + +.PHONY: clean install + +clean: + $(RM) $(OBJS) $(DEPS) $(BIN) + +install: $(BIN) + $(INSTALL) $(BIN) $(DESTDIR)$(BINDIR) diff --git a/tester/main.cpp b/tester/main.cpp new file mode 100644 index 0000000..42a20f1 --- /dev/null +++ b/tester/main.cpp @@ -0,0 +1,69 @@ +// +// main.cpp +// tester +// +// Created by Bob Polis at 2020-04-29 +// Copyright (c) 2020 SwiftCoder. All rights reserved. +// + +#include +#include +#include +#include +#include + +void print_help() { + std::cout << "usage: tester [-h][-v]\n"; + std::cout << " -h, --help show this help text and exit\n"; + std::cout << " -v, --version show version number and exit\n"; +} + +void print_version() { + std::cout << "tester version 1.0\n"; +} + +int main(int argc, const char * argv[]) { + try { + struct option long_options[] = { + {"help", no_argument, nullptr, 'h'}, + {"test", required_argument, nullptr, 't'}, + {"version", no_argument, nullptr, 'v'}, + {nullptr, 0, nullptr, 0} + }; + int opt_char, option_index; + while ((opt_char = getopt_long(argc, const_cast(argv), "ht:v", long_options, &option_index)) != -1) { + switch (opt_char) { + case 0: { + // handle long-only options here + std::string optname {long_options[option_index].name}; + break; + } + case 'h': + print_help(); + return EXIT_SUCCESS; + case 'v': + print_version(); + return EXIT_SUCCESS; + case '?': + throw std::runtime_error("unrecognized option"); + } + } + if (optind == argc) { + // here when no file args + } + for (int i = optind; i < argc; ++i) { + try { + // process file argv[i] + } catch (const std::runtime_error& ex) { + std::cerr << "tester: " << ex.what() << '\n'; + } + } + std::cout << "hello, tester\n"; + sc::logger logger(sc::loglevel::debug); + logger.msg(sc::loglevel::info, 42, " = ", 6, " x ", 7); + } catch (const std::exception& ex) { + std::cerr << "tester: " << ex.what() << '\n'; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/tester/tester b/tester/tester new file mode 100755 index 0000000..1be82c3 Binary files /dev/null and b/tester/tester differ