diff options
author | yusukes@chromium.org <yusukes@chromium.org@a4e77c2c-9104-11de-800e-5b313e0d2bf3> | 2009-11-04 04:56:32 +0000 |
---|---|---|
committer | yusukes@chromium.org <yusukes@chromium.org@a4e77c2c-9104-11de-800e-5b313e0d2bf3> | 2009-11-04 04:56:32 +0000 |
commit | d257d186ae2a08042a412824678f98241a1a4f3c (patch) | |
tree | 54b0cf89c22d1a1de3d7866f01d8a98dcbe8565f /test/ot-sanitise.cc | |
parent | 11e88a133d0bc47723c2e9e06df471e2f60bb350 (diff) | |
download | ots-d257d186ae2a08042a412824678f98241a1a4f3c.tar.gz |
initial commit.
git-svn-id: http://ots.googlecode.com/svn/trunk@2 a4e77c2c-9104-11de-800e-5b313e0d2bf3
Diffstat (limited to 'test/ot-sanitise.cc')
-rw-r--r-- | test/ot-sanitise.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/ot-sanitise.cc b/test/ot-sanitise.cc new file mode 100644 index 0000000..313a6bc --- /dev/null +++ b/test/ot-sanitise.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// A very simple driver program while sanitises the file given as argv[1] and +// writes the sanitised version to stdout. + +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <cstdio> +#include <cstdlib> + +#include "file-stream.h" +#include "opentype-sanitiser.h" + +namespace { + +int Usage(const char *argv0) { + std::fprintf(stderr, "Usage: %s ttf_file > dest_ttf_file\n", argv0); + return 1; +} + +} // namespace + +int main(int argc, char **argv) { + if (argc != 2) return Usage(argv[0]); + if (::isatty(1)) return Usage(argv[0]); + + const int fd = ::open(argv[1], O_RDONLY); + if (fd < 0) { + ::perror("open"); + return 1; + } + + struct stat st; + ::fstat(fd, &st); + + uint8_t *data = new uint8_t[st.st_size]; + if (::read(fd, data, st.st_size) != st.st_size) { + ::perror("read"); + return 1; + } + ::close(fd); + + ots::FILEStream output(stdout); + const bool result = ots::Process(&output, data, st.st_size); + + if (!result) { + std::fprintf(stderr, "Failed to sanitise file!\n"); + } + return !result; +} |