Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial version. Opens and closes PST files.

  • Loading branch information...
commit 105bb804e9cff1345664d64de729e6e7f8f679d8 0 parents
@uckelman authored
Showing with 118 additions and 0 deletions.
  1. +41 −0 Makefile
  2. +77 −0 src/main.cpp
41 Makefile
@@ -0,0 +1,41 @@
+
+INCDIR := include
+SRCDIR := src
+OBJDIR := bin
+DEPDIR := bin
+BINDIR := bin
+
+CXX := g++
+CPPFLAGS := -c -O -g -pg -W -Wall -Wextra -pedantic -pipe -MMD -MP
+#CPPFLAGS := -c -O3 -W -Wall -Wextra -pedantic -pipe -MMD -MP
+INCLUDES := -I$(INCDIR)
+LDLIBS := -lstdc++ -lpff
+
+SOURCES := main.cpp
+OBJECTS := $(SOURCES:.cpp=.o)
+DEPS := $(OBJECTS:.o=.d)
+
+SOURCES := $(SOURCES:%=$(SRCDIR)/%)
+OBJECTS := $(OBJECTS:%=$(OBJDIR)/%)
+DEPS := $(DEPS:%=$(DEPDIR)/%)
+BINARY := $(BINDIR)/pstrip
+
+all: $(BINARY)
+
+debug: CPPFLAGS += -g -pg -fprofile-arcs -ftest-coverage
+debug: CPPFLAGS := $(filter-out -O3,$(CPPFLAGS))
+debug: LDFLAGS += -pg -fprofile-arcs
+debug: all
+
+-include $(DEPS)
+
+$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
+ $(CXX) $(CPPFLAGS) $(INCLUDES) -c -o $@ $<
+
+$(BINARY): $(OBJECTS)
+ $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
+
+clean:
+ $(RM) $(BINARY) $(OBJECTS) $(DEPS)
+
+.PHONY: all clean debug
77 src/main.cpp
@@ -0,0 +1,77 @@
+
+#include <cstdio>
+#include <cstdlib>
+#include <exception>
+#include <stdexcept>
+#include <string>
+
+#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include <libpff.h>
+
+
+class libpff_error: public std::exception {
+public:
+ libpff_error(libpff_error_t* error) {
+ char buf[MAXLEN];
+ libpff_error_sprint(error, buf, MAXLEN);
+ libpff_error_free(&error);
+ Msg = buf;
+ }
+
+ virtual ~libpff_error() throw() {}
+
+ virtual const char* what() const throw() { return Msg.c_str(); }
+
+private:
+ static const size_t MAXLEN = 1024;
+
+ std::string Msg;
+};
+
+libpff_file_t* create_file() {
+ libpff_file_t* file = 0;
+ libpff_error_t* error = 0;
+
+ if (libpff_file_initialize(&file, &error) != 1) {
+ throw libpff_error(error);
+ }
+
+ return file;
+}
+
+void destroy_file(libpff_file_t* file) {
+ libpff_error_t* error = 0;
+ if (libpff_file_free(&file, &error) != 1) {
+ throw libpff_error(error);
+ }
+}
+
+int main(int argc, char** argv) {
+ if (argc != 2) {
+ throw std::runtime_error("Wrong number arguments");
+ }
+
+ libpff_error_t* error = 0;
+
+ boost::shared_ptr<libpff_file_t> file(create_file(), &destroy_file);
+
+ try {
+ if (libpff_file_open(file.get(), argv[1], LIBPFF_OPEN_READ, &error) != 1) {
+ throw libpff_error(error);
+ }
+
+// do something here
+
+ if (libpff_file_close(file.get(), &error) != 1) {
+ throw libpff_error(error);
+ }
+ }
+ catch (const std::exception& e) {
+ std::cerr << e.what() << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.