From bf9fc8296ef153abe6ccbd0fe0586b7551b47563 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sat, 21 Sep 2019 14:04:05 +0200 Subject: [PATCH] first commit --- Makefile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 Makefile create mode 100644 main.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1b208ad --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +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 += -O3 +endif + +LDLIBS := -lm -lpthread -lcommon +LDFLAGS := + +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/main.cpp b/main.cpp new file mode 100644 index 0000000..e5b34f7 --- /dev/null +++ b/main.cpp @@ -0,0 +1,35 @@ +// +// main.cpp +// valid-utf8 +// +// Created by Bob Polis at 2019-09-21 +// Copyright (c) 2019 SwiftCoder. All rights reserved. +// + +// UNIX +#include +#include + +// C++ +#include +using namespace std; + +// libcommon +#include + +int main(int argc, const char * argv[]) { + int result = EXIT_SUCCESS; + try { + string text; + if (argc == 1) { + cin >> text; + } else { + text = su::file_get_contents(argv[1]); + } + result = su::is_valid_utf8(text) ? EXIT_SUCCESS : EXIT_FAILURE; + } catch (const exception& ex) { + cerr << basename(const_cast(argv[0])) << ": " << ex.what() << '\n'; + result = EXIT_FAILURE; + } + return result; +}