mirror of
https://github.com/kevinnlsamuel/stdouterr.git
synced 2025-12-06 09:55:58 +05:30
cleanup
This commit is contained in:
16
src/main.c
16
src/main.c
@@ -10,7 +10,7 @@ unsigned long int hash(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// define hashes of legal cli flags
|
// define hashes of legal cli flags
|
||||||
/*
|
/*TODO:
|
||||||
#define OUTPUT hash("-o");
|
#define OUTPUT hash("-o");
|
||||||
#define ERROR hash("-e");
|
#define ERROR hash("-e");
|
||||||
#define NOOUT hash("-t");
|
#define NOOUT hash("-t");
|
||||||
@@ -19,6 +19,7 @@ unsigned long int hash(){
|
|||||||
|
|
||||||
// default values
|
// default values
|
||||||
char *output = "This is output", *error = "This is an error message";
|
char *output = "This is output", *error = "This is an error message";
|
||||||
|
// "boolean" true values
|
||||||
int printOut = 1, printErr = 1;
|
int printOut = 1, printErr = 1;
|
||||||
|
|
||||||
// to make the cli args globally available
|
// to make the cli args globally available
|
||||||
@@ -41,10 +42,7 @@ int parse(const int index){
|
|||||||
int _return_value = 1;
|
int _return_value = 1;
|
||||||
char* param = argv[index];
|
char* param = argv[index];
|
||||||
|
|
||||||
//printf("currently parsing index %d of argv: %s\n", index, param);
|
|
||||||
|
|
||||||
if(param[0] == '-') {
|
if(param[0] == '-') {
|
||||||
//printf("it's an option\n");
|
|
||||||
switch(param [1]){
|
switch(param [1]){
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage();
|
print_usage();
|
||||||
@@ -68,6 +66,10 @@ int parse(const int index){
|
|||||||
print_usage();
|
print_usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "ERROR: unrecognised flags\n");
|
||||||
|
print_usage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash `param`
|
// hash `param`
|
||||||
@@ -99,16 +101,14 @@ int parse(const int index){
|
|||||||
|
|
||||||
int main(const int argc, char **_argv){
|
int main(const int argc, char **_argv){
|
||||||
|
|
||||||
//look for alt method to make _argv globally accessible
|
//TODO: alt method to make _argv globally accessible
|
||||||
argv = malloc( sizeof *argv * argc);
|
argv = malloc( sizeof *argv * argc);
|
||||||
for(int i=0; i<argc; i++){
|
for(int i=0; i<argc; i++){
|
||||||
argv[i] = _argv[i];
|
argv[i] = _argv[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc > 1){
|
if(argc > 1){
|
||||||
//parse the arguments
|
for(int counter = 1; counter < argc;){
|
||||||
int counter = 1;
|
|
||||||
while ( counter < argc ){
|
|
||||||
counter += parse(counter);
|
counter += parse(counter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user