From 6caa00df87da8992df4dc34551665a3f245bb5ad Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Sun, 23 Nov 2003 22:12:12 +0000 Subject: [PATCH] Initial checkin. Main udf image building class. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5461 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/makeudfimage/UdfBuilder.cpp | 114 +++++++++++++++++++++++ src/apps/bin/makeudfimage/UdfBuilder.h | 40 ++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/apps/bin/makeudfimage/UdfBuilder.cpp create mode 100644 src/apps/bin/makeudfimage/UdfBuilder.h diff --git a/src/apps/bin/makeudfimage/UdfBuilder.cpp b/src/apps/bin/makeudfimage/UdfBuilder.cpp new file mode 100644 index 0000000000..64ac20f755 --- /dev/null +++ b/src/apps/bin/makeudfimage/UdfBuilder.cpp @@ -0,0 +1,114 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//---------------------------------------------------------------------- + +/*! \file UdfBuilder.cpp + + Main UDF image building class implementation. +*/ + +#include "UdfBuilder.h" + +#include + +#include "Debug.h" + +UdfBuilder::UdfBuilder(const ProgressListener &listener) + : fListener(listener) +{ +} + +status_t +UdfBuilder::InitCheck() const +{ + return B_OK; +} + +status_t +UdfBuilder::Build() const +{ + DEBUG_INIT("UdfBuilder"); + _PrintError("This is an error."); + _PrintWarning("This is a warning."); + _PrintUpdate(VERBOSITY_LOW, "This is a VERBOSITY_LOW update."); + _PrintUpdate(VERBOSITY_HIGH, "This is a VERBOSITY_HIGH update."); + RETURN(B_ERROR); +} + +/*! \brief Uses vsprintf() to output the given format string and arguments + into the given message string. + + va_start() must be called prior to calling this function to obtain the + \a arguments parameter, but va_end() must *not* be called upon return, + as this function takes the liberty of doing so for you. +*/ +status_t +UdfBuilder::_FormatString(char *message, const char *formatString, va_list arguments) const +{ + status_t error = message && formatString ? B_OK : B_BAD_VALUE; + if (!error) { + vsprintf(message, formatString, arguments); + va_end(arguments); + } + return error; +} + +/*! \brief Outputs a printf()-style error message to the listener. +*/ +void +UdfBuilder::_PrintError(const char *formatString, ...) const +{ + if (!formatString) { + DEBUG_INIT_ETC("UdfBuilder", ("formatString: `%s'", formatString)); + PRINT(("ERROR: _PrintError() called with NULL format string!\n")); + return; + } + char message[kMaxUpdateStringLength]; + va_list arguments; + va_start(arguments, formatString); + status_t error = _FormatString(message, formatString, arguments); + if (!error) + fListener.OnError(message); +} + +/*! \brief Outputs a printf()-style warning message to the listener. +*/ +void +UdfBuilder::_PrintWarning(const char *formatString, ...) const +{ + if (!formatString) { + DEBUG_INIT_ETC("UdfBuilder", ("formatString: `%s'", formatString)); + PRINT(("ERROR: _PrintWarning() called with NULL format string!\n")); + return; + } + char message[kMaxUpdateStringLength]; + va_list arguments; + va_start(arguments, formatString); + status_t error = _FormatString(message, formatString, arguments); + if (!error) + fListener.OnWarning(message); +} + +/*! \brief Outputs a printf()-style update message to the listener + at the given verbosity level. +*/ +void +UdfBuilder::_PrintUpdate(VerbosityLevel level, const char *formatString, ...) const +{ + if (!formatString) { + DEBUG_INIT_ETC("UdfBuilder", ("level: %d, formatString: `%s'", + level, formatString)); + PRINT(("ERROR: _PrintUpdate() called with NULL format string!\n")); + return; + } + char message[kMaxUpdateStringLength]; + va_list arguments; + va_start(arguments, formatString); + status_t error = _FormatString(message, formatString, arguments); + if (!error) + fListener.OnUpdate(level, message); +} + diff --git a/src/apps/bin/makeudfimage/UdfBuilder.h b/src/apps/bin/makeudfimage/UdfBuilder.h new file mode 100644 index 0000000000..5befd6b53b --- /dev/null +++ b/src/apps/bin/makeudfimage/UdfBuilder.h @@ -0,0 +1,40 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//---------------------------------------------------------------------- + +/*! \file UdfBuilder.h + + Main UDF image building class interface declarations. +*/ + +#ifndef _UDF_BUILDER_H +#define _UDF_BUILDER_H + +#include +#include +#include + +#include "ProgressListener.h" + +class UdfBuilder { +public: + UdfBuilder(const ProgressListener &listener); + status_t InitCheck() const; + status_t Build() const; +private: + //! Maximum length of string generated by calls to any _Print*() functions + static const int kMaxUpdateStringLength = 1024; + + status_t _FormatString(char *message, const char *formatString, va_list arguments) const; + void _PrintError(const char *formatString, ...) const; + void _PrintWarning(const char *formatString, ...) const; + void _PrintUpdate(VerbosityLevel level, const char *formatString, ...) const; + + const ProgressListener &fListener; +}; + + +#endif // _UDF_BUILDER_H