5ea99e7be35b — Duncan Ross Palmer 1 year, 2 months ago
Finish command-line argument processing
2 files changed, 36 insertions(+), 13 deletions(-)

M bin/raw2c
M t/raw2c.pl
M bin/raw2c +12 -12
@@ 103,6 103,12 @@ sub recurse {
 	return $self->{recurse};
 }
 
+sub header {
+	my ($self, @args) = @_;
+	($self->{header}) = @args if (scalar(@args));
+	return $self->{header};
+}
+
 package OptionsParser;
 use strict;
 use warnings;

          
@@ 137,23 143,17 @@ sub parse {
 			$options->nullTerminator(1);
 		} elsif ($arg eq '-r') {
 			$options->recurse(1);
-#		} else if (compareN(argumentVector[i], "--symbol", 8)) {
-#			char *pointer = argumentVector[i];
-#			pointer += 8; /* Move along to symbol name */
-#			if ('\0' != pointer[0]) pointer++;
-#			options.symbolName = pointer;
-#		} else if (compareN(argumentVector[i], "--header", 8)) {
-#			char *pointer = argumentVector[i];
-#			pointer += 8; /* Move along to symbol name */
-#			if ('\0' != pointer[0]) pointer++;
-#			options.headerName = pointer;
+		} elsif ($arg =~ m/^--symbol=(\w+)$/o) {
+			$options->symbolName($1);
+		} elsif ($arg =~ m/^--header=(.*)$/o) {
+			$options->header($1);
 		} else { # Must be a filename
 			if (!$options->inputFileName) {
 				$options->inputFileName($arg);
 			} elsif (!$options->outputFileName) {
 				$options->outputFileName($arg);
 			} else {
-				die('Too many filenames specified');
+				die("Too many filenames specified: $arg");
 			}
 		}
 	}

          
@@ 164,7 164,7 @@ sub parse {
 
 	if (!$options->symbolName) {
 		if (!$options->quiet) {
-			printf("No symbol name was specified, a random symbol will be generated.\n");
+			print("No symbol name was specified, a random symbol will be generated.\n");
 		}
 
 		$options->symbolName($self->randomSymbol());

          
M t/raw2c.pl +24 -1
@@ 70,7 70,7 @@ sub testParse {
 	my ($self) = @_;
 	my $options;
 
-	plan tests => 3;
+	plan tests => 6;
 
 	$self->sut(OptionsParser->new());
 

          
@@ 104,6 104,29 @@ sub testParse {
 		ok(!$options->recurse, 'recurse flag is *NOT* set without -r');
 	};
 
+	subtest symbol => sub {
+		plan tests => 1;
+
+		my $symbol = '_u1thKamsstRod4kuG0';
+		$options = $self->sut->parse(["--symbol=$symbol", 'input.bin', 'output.c']);
+		is($options->symbolName, $symbol, 'symbol overridden with --symbol');
+	};
+
+	subtest header => sub {
+		plan tests => 1;
+
+		my $header = 'a/b/1a87fa14-c82d-11e9-889c-f23c9173fe51.h';
+		$options = $self->sut->parse(["--header=$header", 'input.bin', 'output.c']);
+		is($options->header, $header, 'symbol overridden with --header');
+	};
+
+	subtest filenames => sub {
+		plan tests => 2;
+
+		is($options->inputFileName, 'input.bin', 'inputFileName set');
+		is($options->outputFileName, 'output.c', 'outputFileName set');
+	};
+
 	return EXIT_SUCCESS;
 }