Skip to content

Commit 5b58481

Browse files
committed
Code cleanup
1 parent 2e1afb5 commit 5b58481

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

src/bin2cpp/bin2cpp.samples.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@
2626
--file=..\..\test\bin2cpp_unittest\generated_files\testText1000\testText1000.bin --output=. --override
2727

2828
--noheader --dir=..\..\test\bin2cpp_unittest\generated_files\testIssue56a\input_files --output=..\..\test\bin2cpp_unittest\generated_files\testIssue56a\compiled_sources --chunksize=200 --managerfile=FileManager56a.h --registerfile --namespace=issue56a --override
29+
30+
31+
--plainoutput --file=..\..\test\bin2cpp_unittest\generated_files\testSequential1000\testSequential1000.bin

src/bin2cpp/main.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ struct ARGUMENTS
134134
};
135135

136136
//pre-declarations
137-
bool generateFile(const ARGUMENTS & args, const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator);
138-
bool generateManagerFile(const ARGUMENTS & args, const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator);
139-
APP_ERROR_CODES processInputFile(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator);
140-
APP_ERROR_CODES processInputDirectory(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator);
141-
APP_ERROR_CODES processManagerFiles(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator);
142-
APP_ERROR_CODES processPlainOutput(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator);
143-
std::string getDefaultFunctionIdentifier(const ARGUMENTS & args, const Context & c, Dictionary & identifiers_dictionary);
144-
std::string getDefaultHeaderFile(const ARGUMENTS & args, const Context & c);
137+
bool generateFile(const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator);
138+
bool generateManagerFile(const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator);
139+
APP_ERROR_CODES processInputFile(const Context & c, bin2cpp::IGenerator * generator);
140+
APP_ERROR_CODES processInputDirectory(const Context & c, bin2cpp::IGenerator * generator);
141+
APP_ERROR_CODES processManagerFiles(const Context & c, bin2cpp::IGenerator * generator);
142+
APP_ERROR_CODES processPlainOutput(const Context & c, bin2cpp::IGenerator * generator);
143+
std::string getDefaultFunctionIdentifier(const Context & c, Dictionary & identifiers_dictionary);
144+
std::string getDefaultHeaderFile(const Context & c);
145145

146146
void printHeader()
147147
{
@@ -320,14 +320,14 @@ int main(int argc, char* argv[])
320320
if (!ra::cli::ParseArgument("identifier", c.functionIdentifier, argc, argv))
321321
{
322322
//identifier is not manually specified.
323-
c.functionIdentifier = getDefaultFunctionIdentifier(args, c, identifiers_dictionary);
323+
c.functionIdentifier = getDefaultFunctionIdentifier(c, identifiers_dictionary);
324324
}
325325

326326
//headerfile
327327
if (!ra::cli::ParseArgument("headerfile", c.headerFilename, argc, argv))
328328
{
329329
//use the file name without extension as 'headerfile'.
330-
c.headerFilename = getDefaultHeaderFile(args, c);
330+
c.headerFilename = getDefaultHeaderFile(c);
331331
}
332332
}
333333

@@ -442,7 +442,7 @@ int main(int argc, char* argv[])
442442
//process file, directory or plain format
443443
if (c.plainOutput)
444444
{
445-
APP_ERROR_CODES error = processPlainOutput(args, c, generator);
445+
APP_ERROR_CODES error = processPlainOutput(c, generator);
446446
if (error != APP_ERROR_SUCCESS)
447447
{
448448
ra::logging::Log(ra::logging::LOG_ERROR, "%s.", getErrorCodeDescription(error));
@@ -451,7 +451,7 @@ int main(int argc, char* argv[])
451451
}
452452
else if (c.hasInputFile)
453453
{
454-
APP_ERROR_CODES error = processInputFile(args, c, generator);
454+
APP_ERROR_CODES error = processInputFile(c, generator);
455455
if (error != APP_ERROR_SUCCESS)
456456
{
457457
ra::logging::Log(ra::logging::LOG_ERROR, "%s.", getErrorCodeDescription(error));
@@ -460,7 +460,7 @@ int main(int argc, char* argv[])
460460
}
461461
else if (c.hasInputDir)
462462
{
463-
APP_ERROR_CODES error = processInputDirectory(args, c, generator);
463+
APP_ERROR_CODES error = processInputDirectory(c, generator);
464464
if (error != APP_ERROR_SUCCESS)
465465
{
466466
ra::logging::Log(ra::logging::LOG_ERROR, "%s.", getErrorCodeDescription(error));
@@ -471,7 +471,7 @@ int main(int argc, char* argv[])
471471
//should we also generate the FileManager class?
472472
if (c.hasManagerFile)
473473
{
474-
APP_ERROR_CODES error = processManagerFiles(args, c, generator);
474+
APP_ERROR_CODES error = processManagerFiles(c, generator);
475475
if (error != APP_ERROR_SUCCESS)
476476
{
477477
ra::logging::Log(ra::logging::LOG_ERROR, "%s.", getErrorCodeDescription(error));
@@ -482,7 +482,7 @@ int main(int argc, char* argv[])
482482
return APP_ERROR_SUCCESS;
483483
}
484484

485-
std::string getDefaultFunctionIdentifier(const ARGUMENTS & args, const Context & c, Dictionary & identifiers_dictionary)
485+
std::string getDefaultFunctionIdentifier(const Context & c, Dictionary & identifiers_dictionary)
486486
{
487487
std::string output;
488488

@@ -493,7 +493,7 @@ std::string getDefaultFunctionIdentifier(const ARGUMENTS & args, const Context &
493493
return output;
494494
}
495495

496-
std::string getDefaultHeaderFile(const ARGUMENTS & args, const Context & c)
496+
std::string getDefaultHeaderFile(const Context & c)
497497
{
498498
std::string output;
499499

@@ -504,7 +504,7 @@ std::string getDefaultHeaderFile(const ARGUMENTS & args, const Context & c)
504504
return output;
505505
}
506506

507-
APP_ERROR_CODES processInputFile(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator)
507+
APP_ERROR_CODES processInputFile(const Context & c, bin2cpp::IGenerator * generator)
508508
{
509509
// printing info
510510
std::string info;
@@ -524,7 +524,6 @@ APP_ERROR_CODES processInputFile(const ARGUMENTS & args, const Context & c, bin2
524524
if (!ra::filesystem::FileExists(c.inputFilePath.c_str()))
525525
return APP_ERROR_INPUTFILENOTFOUND;
526526

527-
ARGUMENTS argsCopy = args;
528527
Context cCopy = c;
529528

530529
//prepare output files path
@@ -560,19 +559,19 @@ APP_ERROR_CODES processInputFile(const ARGUMENTS & args, const Context & c, bin2
560559
}
561560

562561
//process files
563-
bool headerResult = generateFile(args, c, outputHeaderPath, generator);
562+
bool headerResult = generateFile(c, outputHeaderPath, generator);
564563
if (!headerResult)
565564
return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
566565

567-
bool cppResult = generateFile(args, c, outputCppPath, generator);
566+
bool cppResult = generateFile(c, outputCppPath, generator);
568567
if (!cppResult)
569568
return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
570569

571570
//success
572571
return APP_ERROR_SUCCESS;
573572
}
574573

575-
APP_ERROR_CODES processInputDirectory(const ARGUMENTS & args, const Context& c, bin2cpp::IGenerator * generator)
574+
APP_ERROR_CODES processInputDirectory(const Context& c, bin2cpp::IGenerator * generator)
576575
{
577576
//check if input dir exists
578577
if (!ra::filesystem::DirectoryExists(c.inputDirPath.c_str()))
@@ -612,7 +611,6 @@ APP_ERROR_CODES processInputDirectory(const ARGUMENTS & args, const Context& c,
612611
const std::string & file = files[i];
613612

614613
//build a 'headerfile' and 'identifier' argument for this file...
615-
ARGUMENTS argsCopy = args;
616614
Context cCopy = c;
617615

618616
//replace 'dir' input by current file input
@@ -621,10 +619,10 @@ APP_ERROR_CODES processInputDirectory(const ARGUMENTS & args, const Context& c,
621619
cCopy.inputFilePath = file;
622620

623621
//use the file name without extension as 'headerfile'.
624-
cCopy.headerFilename = getDefaultHeaderFile(argsCopy, cCopy);
622+
cCopy.headerFilename = getDefaultHeaderFile(cCopy);
625623

626624
//use the file name without extension as 'identifier'.
627-
cCopy.functionIdentifier = getDefaultFunctionIdentifier(argsCopy, cCopy, identifiers_dictionary);
625+
cCopy.functionIdentifier = getDefaultFunctionIdentifier(cCopy, identifiers_dictionary);
628626

629627
//build a relative file path
630628
std::string relative_file_path = file;
@@ -654,7 +652,7 @@ APP_ERROR_CODES processInputDirectory(const ARGUMENTS & args, const Context& c,
654652
}
655653

656654
//process this file...
657-
APP_ERROR_CODES error = processInputFile(argsCopy, cCopy, generator);
655+
APP_ERROR_CODES error = processInputFile(cCopy, generator);
658656
if (error != APP_ERROR_SUCCESS)
659657
return error;
660658

@@ -686,7 +684,7 @@ FILE_UPDATE_MODE getFileUpdateMode(const std::string & input_file_path, const st
686684
return UPDATING;
687685
}
688686

689-
bool generateFile(const ARGUMENTS & args, const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator)
687+
bool generateFile(const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator)
690688
{
691689
FILE_UPDATE_MODE mode = getFileUpdateMode(c.inputFilePath, output_file_path, c.overrideExistingFiles);
692690

@@ -717,7 +715,7 @@ bool generateFile(const ARGUMENTS & args, const Context & c, const std::string &
717715
return result;
718716
}
719717

720-
bool generateManagerFile(const ARGUMENTS & args, const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator)
718+
bool generateManagerFile(const Context & c, const std::string & output_file_path, bin2cpp::IGenerator * generator)
721719
{
722720
std::string processPath = ra::process::GetCurrentProcessPath();
723721
FILE_UPDATE_MODE mode = getFileUpdateMode(processPath, output_file_path, c.overrideExistingFiles);
@@ -748,7 +746,7 @@ bool generateManagerFile(const ARGUMENTS & args, const Context & c, const std::s
748746
return result;
749747
}
750748

751-
APP_ERROR_CODES processManagerFiles(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator)
749+
APP_ERROR_CODES processManagerFiles(const Context & c, bin2cpp::IGenerator * generator)
752750
{
753751
// printing info
754752
std::string info;
@@ -766,25 +764,24 @@ APP_ERROR_CODES processManagerFiles(const ARGUMENTS & args, const Context & c, b
766764
std::string outputCppPath = c.outputDirPath + ra::filesystem::GetPathSeparatorStr() + cppFilename;
767765

768766
//process files
769-
bool headerResult = generateManagerFile(args, c, outputHeaderPath, generator);
767+
bool headerResult = generateManagerFile(c, outputHeaderPath, generator);
770768
if (!headerResult)
771769
return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
772770

773-
bool cppResult = generateManagerFile(args, c, outputCppPath, generator);
771+
bool cppResult = generateManagerFile(c, outputCppPath, generator);
774772
if (!cppResult)
775773
return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
776774

777775
//success
778776
return APP_ERROR_SUCCESS;
779777
}
780778

781-
APP_ERROR_CODES processPlainOutput(const ARGUMENTS & args, const Context & c, bin2cpp::IGenerator * generator)
779+
APP_ERROR_CODES processPlainOutput(const Context & c, bin2cpp::IGenerator * generator)
782780
{
783781
//check if input file exists
784782
if (!ra::filesystem::FileExists(c.inputFilePath.c_str()))
785783
return APP_ERROR_INPUTFILENOTFOUND;
786784

787-
ARGUMENTS argsCopy = args;
788785
Context cCopy = c;
789786

790787
//configure the generator

0 commit comments

Comments
 (0)