-
Notifications
You must be signed in to change notification settings - Fork 2
Commandline args --help #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2e587b3
87e8ac1
819dbed
dcb9762
1b2841e
d9fb643
ad6b9d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,28 @@ | |
| #include <sys/types.h> | ||
| #include <unistd.h> | ||
| #include <sys/wait.h> | ||
| #include <getopt.h> | ||
| #include <string> | ||
|
|
||
| using namespace std; | ||
| const int MAX_PROCESSES = 4; | ||
| const char* const COMPILER = "g++"; | ||
|
|
||
| const string help_header = "\ | ||
| KTPuild\n\ | ||
| An application that makes the compiling of large projects easier. The\n\ | ||
| intended use for EECS 280 students attending the University of \n\ | ||
| Michigan. Built and maintained by Kappa Theta Pi Alpha Chapter. For reporting\n\ | ||
| bugs or requesting features please visit: https://github.com/ktp-dev/KTPuild\n"; | ||
|
|
||
| const string help_msg = "\n\ | ||
| Usages:\n\ | ||
| KTPuild\n\ | ||
| KTPuild -h | --help\n\ | ||
| \n\ | ||
| Options:\n\ | ||
| -h | --help: display help information\n\n"; | ||
|
|
||
|
|
||
| void run_command(const vector<string>& command) { | ||
| //To run a command, we have to call execvp. execvp expects a char** (C style array) that is null terminated. Thus, convert our nice C++ array of strings to a C array of C strings. Also, print them out so the user knows what we are running. | ||
|
|
@@ -92,29 +109,93 @@ void link_executable(const Buildfile& buildfile, const vector<string>& cpp_files | |
| } | ||
| } | ||
|
|
||
| int main() { | ||
| bool is_created(const string &filename){ | ||
|
|
||
| // tests for the existence of the file with success being a 0 | ||
| if(access(filename.c_str(), F_OK) == 0) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
|
Comment on lines
+112
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this diff will go away once you merge in pull #1 to this branch |
||
| bool parse_commandline_args(int argc, char** &argv) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we take a char** by reference? |
||
| { | ||
| struct option longOpts[] = { | ||
| { "help", no_argument, nullptr, 'h' }, | ||
| { nullptr, 0, nullptr, '\0' } | ||
| }; | ||
|
|
||
| int option; | ||
|
|
||
| while((option = getopt_long(argc, argv, "h", longOpts, nullptr))!= -1) | ||
| { | ||
| switch(option) | ||
| { | ||
| case 'h': | ||
| { | ||
| std::cout<<(help_header + help_msg); | ||
| return false; | ||
| } | ||
| default: | ||
| { | ||
| throw std::runtime_error(help_msg); | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| int main(int argc, char ** argv) { | ||
| /* | ||
| * 1) get the cpp files | ||
| * 2) determine what cpp files to recompile | ||
| * 1) parse for commandline arguments | ||
| * 2) get the cpp files | ||
| * 3) determine what cpp files to recompile | ||
| * - need to recompile if no obj file we have to create it, or if there is an obj file, | ||
| * but the cpp file has been modified more recently than the obj file | ||
| * 3) if none, we are done | ||
| * 4) else, recompile them (done!) | ||
| * 5) relink everything | ||
| * 6) done! | ||
| * - need to check to see if there is an executable created | ||
| * 4) if none, we are done | ||
| * 5) else, recompile them (done!) | ||
| * 6) relink everything | ||
| * 7) done! | ||
| */ | ||
| try { | ||
|
|
||
| /* | ||
| parse command line arguments, if we get false back we encountered either a help or invalid | ||
| option and should exit the program while displaying the help message. | ||
| */ | ||
| if(!parse_commandline_args(argc, argv)) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| Buildfile buildfile; | ||
| vector<string> cpp_filename = buildfile.get_cpp_files(); //1 | ||
| vector<string> changed; | ||
| for (string &file : cpp_filename) { //2 | ||
| if (has_changed(file)) | ||
| changed.push_back(file); | ||
| } | ||
| //now we know what cpp files have changed | ||
| if (changed.empty()) //TODO: also ensure exe exists | ||
| // if there is nothing to recompile and the executable has been created we are done | ||
| if (changed.empty() && is_created(buildfile.get_executable_name())) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto about merging pull #1 |
||
| return 0; //3 | ||
|
|
||
| int main() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| int main() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| int main() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| compile_object_files(buildfile, changed); //4 | ||
| link_executable(buildfile, cpp_filename); //4 | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should include some more information about what the normal usage will do? Or is that better left for man pages in a later commit?