Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Remove dependency on gflags library.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Jul 29, 2015
1 parent 69cb6a3 commit 2d0b10e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Expand Up @@ -8,6 +8,7 @@ find_package(Boost COMPONENTS system filesystem REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Ogg REQUIRED ogg)
pkg_check_modules(Vorbis REQUIRED vorbis vorbisenc)
pkg_check_modules(GLog REQUIRED libglog)

set (GTEST_ROOT "/usr/src/gtest/")
if(EXISTS ${GTEST_ROOT})
Expand All @@ -21,8 +22,8 @@ if (FVE_BUILD_TESTS)
add_subdirectory(${GTEST_ROOT} gtest)
endif ()

include_directories(./ ${Ogg_INCLUDE_DIRS} ${Vorbis_INCLUDE_DIRS})
link_directories(./ ${Ogg_LIBRARY_DIRS} ${Vorbis_LIBRARY_DIRS})
include_directories(./ ${Ogg_INCLUDE_DIRS} ${Vorbis_INCLUDE_DIRS} ${GLog_INCLUDE_DIRS})
link_directories(./ ${Ogg_LIBRARY_DIRS} ${Vorbis_LIBRARY_DIRS} ${GLog_LIBRARY_DIRS})

add_subdirectory(src)

1 change: 0 additions & 1 deletion README.md
Expand Up @@ -27,7 +27,6 @@ sudo aptitude install \
libboost-filesystem-dev \
libboost-iostreams-dev \
libboost-system-dev \
libgflags-dev \
libgoogle-glog-dev \
libgtest-dev \
libogg-dev \
Expand Down
9 changes: 4 additions & 5 deletions src/CMakeLists.txt
Expand Up @@ -17,24 +17,23 @@ add_library(fsb STATIC
fsb/container.hpp
fsb/fsb.hpp)
target_link_libraries(fsb
glog
${GLog_LIBRARIES}
${Ogg_LIBRARIES}
${Vorbis_LIBRARIES})

add_executable(extractor
fsb/extractor.cpp)
target_link_libraries(extractor
fsb
glog
gflags
${GLog_LIBRARIES}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY})

add_executable(headers_generator_tool
fsb/vorbis/headers_generator_tool.cpp)
target_link_libraries(headers_generator_tool
fsb
glog
${GLog_LIBRARIES}
${Vorbis_LIBRARIES})

if(FVE_BUILD_TESTS)
Expand All @@ -47,6 +46,6 @@ if(FVE_BUILD_TESTS)
add_test(fsb_test fsb_test)
target_link_libraries(fsb_test
fsb
glog
${GLog_LIBRARIES}
gtest gtest_main)
endif()
68 changes: 47 additions & 21 deletions src/fsb/extractor.cpp
Expand Up @@ -13,20 +13,13 @@
#include "fsb/container.hpp"

#include <boost/filesystem.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>

#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>

DEFINE_string(password, "",
"password used to encode file");
DEFINE_string(destination, "",
"directory where extracted files will be placed, "
"current working directory is used by default");
DEFINE_bool(list, false,
"only list content of container without extracting content");

namespace {

struct extractor_options {
Expand All @@ -36,17 +29,50 @@ struct extractor_options {
std::vector<boost::filesystem::path> paths;
};

void usage(const char *name) {
std::cout <<
"Usage: " << name << " [OPTION]... [FSB_FILE]...\n"
"Extracts or lists content of Vorbis files from FSB5 container.\n"
"\n"
"Options:\n"
" -h --help display this help and exit\n"
" -p --password password used to encode FSB files\n"
" -d --destination directory where extracted files will be placed,\n"
" current working directory is used by default\n"
" -l --list only list content of container without extracting\n";
}

extractor_options parse_options(int argc, char **argv) {
extractor_options options;
options.password = FLAGS_password;
options.destination = FLAGS_destination.empty() ?
boost::filesystem::current_path() : FLAGS_destination;
options.extract = !FLAGS_list;

for (int i=1; i < argc; ++i) {
options.paths.push_back(argv[i]);
options.destination = boost::filesystem::current_path();
options.extract = true;

for (int argi=1; argi < argc; ++argi) {
const char *arg = argv[argi];
if (std::strcmp("--help", arg) == 0 || std::strcmp("-h", arg) == 0) {
usage(argv[0]);
exit(EXIT_SUCCESS);
} else if (std::strcmp("--password", arg) == 0 || std::strcmp("-p", arg) == 0) {
CHECK(argi + 1 < argc) << "An argument is required for " << arg << '.';
options.password = argv[++argi];
} else if (std::strcmp("--destination", arg) == 0 || std::strcmp("-d", arg) == 0) {
CHECK(argi + 1 < argc) << "An argument is required for " << arg << '.';
options.destination = argv[++argi];
} else if (std::strcmp("--list", arg) == 0 || std::strcmp("-l", arg) == 0) {
options.extract = false;
} else if (std::strcmp("--", arg) == 0) {
while (++argi < argc)
options.paths.push_back(arg);
break;
} else if (arg[0] == '-') {
std::cerr << "Unrecognized flag: " << arg << std::endl;
usage(argv[0]);
exit(EXIT_FAILURE);
} else {
options.paths.push_back(arg);
}
}

return options;
}

Expand Down Expand Up @@ -78,12 +104,10 @@ void print_sample(std::ostream & os, const fsb::sample & sample) {

int main(int argc, char **argv) {
google::InitGoogleLogging(argv[0]);
google::SetUsageMessage(std::string(argv[0]) + " file.fsb");
google::ParseCommandLineFlags(&argc, &argv, true);

std::size_t sample_number = 0;
const extractor_options options = parse_options(argc, argv);

std::size_t sample_number = 0;
for (const auto & path : options.paths) {
std::ifstream stream(path.native(),
std::ios_base::in | std::ios_base::binary);
Expand All @@ -110,11 +134,13 @@ int main(int argc, char **argv) {
<< sample.name << std::endl;
continue;
}

std::ofstream output(path.native());
CHECK(output) << "Failed to open output file: " << path;
container.extract_sample(sample, output);
}
}
}

return 0;
}
}

0 comments on commit 2d0b10e

Please sign in to comment.