Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PopulateFlagsAndValues(int cmdLineArgCount, char **cmdLineArguments)
- {
- //https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html#Using-Getopt See for docs on getopt use. (Its the GNU docs)
- extern int optind;
- extern char *optarg;
- int option;
- #define OperativeOptions (option = getopt(cmdLineArgCount, cmdLineArguments, "a:m:x"))
- #define AddError "Add number desired is not in supported range. Please use a number between 1-500 (Inclusive)."
- #define MultiplyError "Multipicative factor desired is not in supported range. Please choose a number between 1-10 (Inclusive)."
- while (OperativeOptions != -1)
- {
- switch (option)
- {
- case 'a':
- {
- a_flag = true ;
- a_number = atoi(optarg);
- break;
- }
- case 'm':
- {
- m_flag = true ;
- m_number = atoi(optarg);
- break;
- }
- case 'x':
- {
- x_flag = true;
- break;
- }
- default:
- printf("\n%s\n", "Options switch did not find a defined case.");
- }
- }
- #define ValueMissingError "Could not find value in arguments to use operation on. Please enter a value."
- #define ValueError "Value number desired is not in supported range. Please use a number between 1-50 (Inclusive)."
- if (optind < cmdLineArgCount)
- {
- v_flag = true;
- value = atoi(cmdLineArguments[optind]);
- }
- else
- {
- printf("\n%s\n", ValueMissingError);
- }
- if (!IsValueLegal(value))
- {
- printf("\n%s\n", ValueError);
- InvalidateFlags();
- }
- else if (!IsAddLegal(a_number))
- {
- printf("\n%s\n", AddError);
- InvalidateFlags();
- }
- else if (!IsMultiplyLegal(m_number))
- {
- printf("\n%s\n", MultiplyError);
- InvalidateFlags();
- }
- }
Add Comment
Please, Sign In to add comment