first commit

This commit is contained in:
Bob Polis 2019-09-21 14:04:05 +02:00
commit bf9fc8296e
2 changed files with 81 additions and 0 deletions

46
Makefile Normal file
View File

@ -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)

35
main.cpp Normal file
View File

@ -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 <unistd.h>
#include <libgen.h>
// C++
#include <iostream>
using namespace std;
// libcommon
#include <libcommon/libcommon.h>
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<char*>(argv[0])) << ": " << ex.what() << '\n';
result = EXIT_FAILURE;
}
return result;
}