1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //----------------------------------------------------------------------
10 Command-line shell for makeudfimage
17 #include "ConsoleListener.h"
19 #include "UdfBuilder.h"
22 // The following settings are essentially default values
23 // for all the command-line options (except for the last
25 : fVerbosityLevel(VERBOSITY_LOW
)
29 , fSourceDirectory("")
32 , fUdfRevision(0x0201)
38 Shell::Run(int argc
, char *argv
[])
41 status_t error
= _ProcessArguments(argc
, argv
);
43 if (fUdfVolumeName
== "")
44 fUdfVolumeName
= "(Unnamed UDF Volume)";
45 ConsoleListener
listener(fVerbosityLevel
);
46 UdfBuilder
builder(fOutputFile
.c_str(), fBlockSize
, fDoUdf
,
47 fUdfVolumeName
.c_str(), fUdfRevision
, fDoIso
, "ISO_VOLUME",
48 fSourceDirectory
.c_str(), listener
, fTruncate
);
49 error
= builder
.InitCheck();
51 error
= builder
.Build();
61 Shell::_ProcessArguments(int argc
, char *argv
[]) {
62 DEBUG_INIT_ETC("Shell", ("argc: %d", argc
));
64 // Throw all the arguments into a handy list
65 std::list
<std::string
> argumentList
;
66 for (int i
= 1; i
< argc
; i
++)
67 argumentList
.push_back(std::string(argv
[i
]));
69 bool foundSourceDirectory
= false;
70 bool foundOutputFile
= false;
71 bool foundUdfVolumeName
= false;
73 // Now bust out some processing
74 int argumentCount
= argumentList
.size();
76 for(std::list
<std::string
>::iterator i
= argumentList
.begin();
77 i
!= argumentList
.end();
80 std::string
&arg
= *i
;
81 if (arg
== "-h" || arg
== "--help") {
84 } else if (arg
== "-v0" || arg
== "--quiet") {
85 fVerbosityLevel
= VERBOSITY_NONE
;
86 } else if (arg
== "-v1") {
87 fVerbosityLevel
= VERBOSITY_LOW
;
88 } else if (arg
== "-v2") {
89 fVerbosityLevel
= VERBOSITY_MEDIUM
;
90 } else if (arg
== "-v3") {
91 fVerbosityLevel
= VERBOSITY_HIGH
;
92 } else if (arg
== "-r" || arg
== "--revision") {
96 fUdfRevision
= 0x0150;
97 else if (*i
== "2.01")
98 fUdfRevision
= 0x0201;
100 printf("ERROR: invalid UDF revision `%s'; please specify `1.50' "
101 "or `2.01'\n", i
->c_str());
104 } else if (arg
== "-t" || arg
== "--no-truncate") {
107 if (index
== argumentCount
-3) {
108 // Take this argument as the source dir
109 fSourceDirectory
= arg
;
110 foundSourceDirectory
= true;
111 } else if (index
== argumentCount
-2) {
112 // Take this argument as the output filename
114 foundOutputFile
= true;
115 } else if (index
== argumentCount
-1) {
116 // Take this argument as the udf volume name
117 fUdfVolumeName
= arg
;
118 foundUdfVolumeName
= true;
120 printf("ERROR: invalid argument `%s'\n", arg
.c_str());
129 status_t error
= B_OK
;
130 if (!foundSourceDirectory
) {
131 printf("ERROR: no source directory specified\n");
134 if (!foundOutputFile
) {
135 printf("ERROR: no output file specified\n");
138 if (!foundUdfVolumeName
) {
139 printf("ERROR: no volume name specified\n");
149 Shell::_PrintHelp() {
150 printf("usage: makeudfimage [options] <source-directory> <output-file> <udf-volume-name>\n");
151 printf("example: makeudfimage /boot/home/mail mail.udf \"Mail Backup\"\n");
153 printf("VALID OPTIONS:\n");
154 printf(" -h, --help Displays this help text.\n");
155 printf(" --quiet Turns off console output.\n");
156 printf(" -r, --revision <udf-revision> Selects the UDF revision to use. Supported\n");
157 printf(" revisions are 1.50 and 2.01. Defaults to 2.01.\n");
158 printf(" -t, --no-trunc Don't truncate output file if it already\n");
159 printf(" exists.\n");
163 #define MAKEUDFIMAGE_VERSION "1.0.0"
164 #ifndef MAKEUDFIMAGE_VERSION
165 # define MAKEUDFIMAGE_VERSION ("development version " __DATE__ ", " __TIME__)
169 Shell::_PrintTitle() {
170 printf("makeudfimage %s\n", MAKEUDFIMAGE_VERSION
);
171 printf("Copyright © 2004 Tyler Dauwalder\n");