Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / bin / makeudfimage / ConsoleListener.cpp
blobe949193685a54bb9df46e18e4c2dbcce8df5e845
1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
4 //
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //----------------------------------------------------------------------
8 /*! \file ConsoleListener.cpp
10 Console-based implementation of ProgressListener interface.
13 #include "ConsoleListener.h"
15 #include <stdio.h>
16 #include <string.h>
18 static const char * const kDivider =
19 "----------------------------------------------------------------------";
21 /*! \brief Creates a new ConsoleListener object with the given verbosity level.
23 All output from said listener is sent to standard output via printf().
25 \param level All update messages with verbosity levels below this value
26 will be ignored. If level is \c VERBOSITY_NONE, no output
27 whatsoever (including errors and warnings) will be
28 generated.
29 */
30 ConsoleListener::ConsoleListener(VerbosityLevel level)
31 : fLevel(level)
35 void
36 ConsoleListener::OnStart(const char *sourceDirectory, const char *outputFile,
37 const char *udfVolumeName, uint16 udfRevision) const
39 if (Level() > VERBOSITY_NONE) {
40 printf("%s\n", kDivider);
41 printf("Source directory: `%s'\n", sourceDirectory);
42 printf("Output file: `%s'\n", outputFile);
43 printf("UDF Volume Name: `%s'\n", udfVolumeName);
44 printf("UDF Revision: %01x.%01x%01x\n",
45 (udfRevision & 0x0f00) >> 8,
46 (udfRevision & 0x00f0) >> 4,
47 (udfRevision & 0x000f));
48 printf("%s\n", kDivider);
52 void
53 ConsoleListener::OnError(const char *message) const
55 if (Level() > VERBOSITY_NONE)
56 printf("ERROR: %s\n", message);
59 void
60 ConsoleListener::OnWarning(const char *message) const
62 if (Level() > VERBOSITY_NONE)
63 printf("WARNING: %s\n", message);
66 void
67 ConsoleListener::OnUpdate(VerbosityLevel level, const char *message) const
69 if (Level() > VERBOSITY_NONE && level <= Level()) {
70 switch (level) {
71 case VERBOSITY_MEDIUM:
72 printf(" ");
73 break;
74 case VERBOSITY_HIGH:
75 printf(" ");
76 break;
77 default:
78 break;
80 printf("%s\n", message);
84 void
85 ConsoleListener::OnCompletion(status_t result, const Statistics &statistics) const
87 if (Level() > VERBOSITY_NONE) {
88 if (result == B_OK) {
89 uint64 directories = statistics.Directories();
90 uint64 files = statistics.Files();
91 uint64 symlinks = statistics.Symlinks();
92 printf("Finished\n");
93 printf("- Build time: %s\n", statistics.ElapsedTimeString().c_str());
94 printf("- Directories: %Ld director%s in %s\n",
95 directories, directories == 1 ? "y" : "ies",
96 statistics.DirectoryBytesString().c_str());
97 printf("- Files: %Ld file%s in %s\n",
98 files, files == 1 ? "" : "s",
99 statistics.FileBytesString().c_str());
100 if (symlinks > 0)
101 printf("- Symlinks: No symlink support yet; %Ld symlink%s ommitted\n", symlinks,
102 symlinks == 1 ? "" : "s");
103 printf("- Image size: %s\n", statistics.ImageSizeString().c_str());
104 } else {
105 printf("----------------------------------------------------------------------\n");
106 printf("Build failed with error: 0x%lx, `%s'\n", result,
107 strerror(result));
108 printf("----------------------------------------------------------------------\n");