6c01ca045449 — Duncan Ross Palmer 1 year, 2 months ago
main function now triggers options parsing
1 files changed, 64 insertions(+), 67 deletions(-)

M bin/raw2c
M bin/raw2c +64 -67
@@ 31,6 31,24 @@ 
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+package FileOrDir;
+use strict;
+use warnings;
+
+sub new {
+	my ($class) = @_;
+
+	return bless({
+		handle => undef,
+	}, $class);
+}
+
+sub handle {
+	my ($self, @args) = @_;
+	($self->{handle}) = @args if (scalar(@args));
+	return $self->{handle};
+}
+
 package Options;
 use strict;
 use warnings;

          
@@ 39,13 57,13 @@ sub new {
 	my ($class) = @_;
 
 	return bless({
-		quiet => 0,
+		quiet          => 0,
 		nullTerminator => 0,
-		symbol => '',
-		header => '',
-		inputFileName => '',
+		symbol         => '',
+		header         => '',
+		inputFileName  => '',
 		outputFileName => '',
-		recurse => 0,
+		recurse        => 0,
 	}, $class);
 }
 

          
@@ 163,7 181,21 @@ use POSIX qw(EXIT_SUCCESS);
 
 sub new {
 	my ($class) = @_;
-	return bless({}, $class);
+	return bless({
+		optionsParser => OptionsParser->new(),
+		options => undef,
+	}, $class);
+}
+
+sub optionsParser {
+	my ($self) = @_;
+	return $self->{optionsParser};
+}
+
+sub options {
+	my ($self, @args) = @_;
+	($self->{options}) = @args if (scalar(@args));
+	return $self->{options};
 }
 
 sub getHead() {

          
@@ 189,69 221,14 @@ sub title {
 }
 
 sub main {
+	my ($self) = @_;
 	srand($PID + (time() % 100_000));
-	return EXIT_SUCCESS;
-}
-
-package main;
-use strict;
-use warnings;
-
-exit(Main->new->main()) unless (caller());
-
-#### XXX
-
-#static struct {
-#	int quiet;
-#	int recurse;
-#	int null_terminator;
-#	char *inputFileName;
-#	char *outputFileName;
-#	char *symbolName;
-#	char *headerName;
-#} options;
-
-#struct FileOrDir {
-#	union {
-#		FILE *file;
-#		DIR *dir;
-#	} handle;
-#	int isDir;
-#};
 
-#define compare(string1, string2) \
-#          (0 == strcmp((string1), (string2)))
-#define compareN(string1, string2, n) \
-#          (0 == strncmp((string1), (string2), (n)))
+	my ($input, $output, $header) = FileOrDir->new();
 
-#static void initFileOrDir(struct FileOrDir *fileOrDir, const int isDir);
-#static int parse(int argumentCount, char *argumentVector[]);
-#static void syntax(void);
-#static void title(void);
-#static int openFiles(
-#	struct FileOrDir *pInput,
-#	struct FileOrDir *pOutput,
-#	struct FileOrDir *pHeader
-#);
-#static char randChar(void);
-#static void makeSource(struct FileOrDir *pIn, struct FileOrDir *pOut);
-#static void makeHeader(struct FileOrDir *pHeader);
-#static unsigned long int getFileLength(FILE *fileHandle);
-#static void fileSizeWarning(const char *const fileName, const off_t sz);
+	$self->options($self->optionsParser->parse(\@ARGV));
 
-#int main (int argc, char* argv[]) {
-
-#	struct FileOrDir input, output, header;
-
-#	header.handle.file = NULL;
-
-#	if (parse(argc, argv)) {
-#		syntax();
-#		return EXIT_FAILURE;
-#	}
-
-#	if (!options.quiet) /* Are we allowed to talk? */
-#		title();
+	title() unless ($self->options->quiet);
 
 #	if (openFiles(&input, &output, &header))
 #		return EXIT_FAILURE;

          
@@ 264,8 241,28 @@ exit(Main->new->main()) unless (caller()
 #	fclose(output.handle.file);
 #	if (options.headerName) fclose(header.handle.file);
 
-#	return EXIT_SUCCESS;
-#}
+	return EXIT_SUCCESS;
+}
+
+package main;
+use strict;
+use warnings;
+
+exit(Main->new->main()) unless (caller());
+
+#### XXX
+
+#static void initFileOrDir(struct FileOrDir *fileOrDir, const int isDir);
+#static int openFiles(
+#	struct FileOrDir *pInput,
+#	struct FileOrDir *pOutput,
+#	struct FileOrDir *pHeader
+#);
+#static void makeSource(struct FileOrDir *pIn, struct FileOrDir *pOut);
+#static void makeHeader(struct FileOrDir *pHeader);
+#static unsigned long int getFileLength(FILE *fileHandle);
+#static void fileSizeWarning(const char *const fileName, const off_t sz);
+
 #static void initFileOrDir(struct FileOrDir *fileOrDir, const int isDir) {
 
 #	fileOrDir->isDir = isDir;