/* MAIN */ int main(void) { /* Call the functions */ float milesPerGallon, lowPerGallon, highPerGallon, milesTraveled, gallonsPurchased, lowCost, highCost; WelcomeMessage(); AskUserForInput(milesPerGallon, lowPerGallon, highPerGallon, milesTraveled, gallonsPurchased, lowCost, highCost); return(0); }
OutFiles::OutFiles() { char buffer[PATH]; #ifdef _WIN64 GetModuleFileName(NULL, buffer, sizeof(buffer)-1); #elif __linux__ readlink("/proc/self/exe", buffer, sizeof(buffer)-1); #endif std::string::size_type pos = std::string(buffer).find_last_of(SEP); path = std::string(buffer).substr(0, pos); outName = path + SEP + "OUTPUT.txt"; errName = path + SEP + "ERROR.txt"; dataPath = path + SEP + "DATA" + SEP + "data.h5"; remove(&outName[0]); //Converts std::string to char array output.open(&outName[0], std::ofstream::out | std::ofstream::app); if (!output.is_open()) { std::cerr << "Couldn't open '" << outName << "'." << std::endl; TerminateODIS(); } output.close(); WelcomeMessage(); remove(&errName[0]); //Converts std::string to char array error.open(&errName[0], std::ofstream::out | std::ofstream::app); if (!error.is_open()) { std::cerr << "Couldn't open '" << outName << "'." << std::endl; TerminateODIS(); } error << "ODIS error file. Warnings and model termination errors will be written here." << std::endl << std::endl; error.close(); };
int main(int argc, char** argv) { bool32 FlagActivated = 0; for(int i=0; i < argc; i++) { char Flag[MAX_FLAG_CHAR]; // NOTE: '-' Indicate that a flag name is what comes next if(argv[i][0] == '-') { int IndexArray = 0; for(argv[i][1]; *argv[i]; argv[i]++) { if (IndexArray < (MAX_FLAG_CHAR - 1)) { Flag[IndexArray] = *argv[i]; IndexArray++; } } if (CompareStrings(Flag, "-h", 2) == 0) { FlagActivated = FlagActivated|HELP_FLAG; //0x00 ShowHelpPage(); } else if (CompareStrings(Flag, "-cc", 3) == 0) { FlagActivated = FlagActivated|CHANGE_TARGET_DIRECTORY_FLAG; // 0x01 } else if (CompareStrings(Flag, "-s", 2) == 0) { FlagActivated = FlagActivated|SOURCE_FILE_FLAG; // 0x02 } else { // logging } } // NOTE: '@' represents char that indicates that what comes next is an diretory else if(argv[i][0] == '@') { } else { // logging } } bool Running = true; bool ProjectAssigned = false; tree_directory *TreeRootDirectory; tree_directory *TreeActualDirectory; char PathToPrepend[MAX_PATH_SIZE]; WelcomeMessage(); while(Running) { char CommandLine[MAX_LINE_SIZE]; char CLineLowerCase[MAX_LINE_SIZE]; char CommandName[MAX_LINE_SIZE]; char CommandAction[MAX_LINE_SIZE]; printf("\nC-environment Shell> "); // TODO: Make space before first world do not count for the string comparisons gets_s(CommandLine, MAX_LINE_SIZE); IgnoreSpaces(CommandLine, CharArrayCount(CommandLine)); printf("CommandLine without spaces before: '%s'", CommandLine); BreakString(CommandLine, CharArrayCount(CLineLowerCase), CommandName, CommandAction, SPACE_CHAR); ToLowerCase(CommandName, CLineLowerCase, MAX_LINE_SIZE); #if 0 // NOTE: Debug Lines printf("CommandLine: %s\tCLineLowerCase: %s\nCommandAction: %s",CommandLine, CLineLowerCase, CommandAction); #endif // TODO: Program still have some problems with parsing the input with spaces before command if(CompareStrings(CLineLowerCase, "setprojectname", sizeof("setprojectname")) == 0) { if (IS_EMPTY_STRING(CommandAction)) { printf("\nAction for command '%s' not found\n Usage:\t'%s [Project Name]'\n", CLineLowerCase, CLineLowerCase); } TreeRootDirectory = TreeDirectoryCreate(CommandAction); TreeActualDirectory = TreeRootDirectory; StringCopy(PathToPrepend, CommandAction, CharArrayCount(CommandAction)); AppendString(PathToPrepend, "/"); ProjectAssigned = true; } else if(CompareStrings(CLineLowerCase, "createdir", sizeof("createdir")) == 0) { char ActualPath[MAX_PATH_SIZE]; StringCopy(ActualPath, PathToPrepend, CharArrayCount(PathToPrepend)); if (ProjectAssigned && !IS_EMPTY_STRING(CommandAction)) { // TODO: Parse if the directory name is valid // TODO: Prevent PathToPrepend to grow AppendString(PathToPrepend, CommandAction); AppendString(PathToPrepend, "/"); // TODO: Virtual file system structured in a tree tree_directory *TreeDirectory = TreeDirectoryCreate(ActualPath); // NOTE: More debug lines printf("Path: %s", ActualPath); printf("Path2: %s", TreeDirectory->PathName); TreeDirectoryAddNode(TreeActualDirectory, TreeDirectory); } else if (!ProjectAssigned) { // TODO: logging system } else if (IS_EMPTY_STRING(CommandAction)) { // TODO: Logging system } StringCopy(PathToPrepend, ActualPath, CharArrayCount(ActualPath)); } // TODO: Not sure how to do pathfinder right now! else if(CompareStrings(CLineLowerCase, "setdir", sizeof("setdir")) == 0) { char *DirName = CommandAction; if (!IS_EMPTY_STRING(CommandAction)) { if (TreeDirSearchBrother(TreeActualDirectory, DirName)) { AppendString(PathToPrepend, CommandAction); AppendString(PathToPrepend, "/"); TreeDirGoToDirectory(TreeActualDirectory, DirName); } } } else if(CompareStrings(CLineLowerCase, "saveconfig", sizeof("saveconfig")) == 0) { // TODO: Save settings to a file, that can be evoked lately, or in any other // instance of the program } else if(CompareStrings(CLineLowerCase, "exit", sizeof("exit")) == 0) { Running = false; } else { printf("\nCommand not found. Type '-h' for help. Command 'exit' is self explanatory.\n"); } } return 0; }