Skip to content

main.cpp: error out when file/path provided by -I or -include= does not exist #435

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,47 @@ int main(int argc, char **argv)
}
} else if (filename) {
std::cout << "error: multiple filenames specified" << std::endl;
std::exit(1);
return 1;
} else {
filename = arg;
}
}

if (error)
std::exit(1);
return 1;

if (quiet && error_only) {
std::cout << "error: -e cannot be used in conjunction with -q" << std::endl;
std::exit(1);
return 1;
}

// TODO: move this logic into simplecpp?
{
bool inc_missing = false;
for (const std::string& inc : dui.includes) {
std::ifstream f(inc);
if (!f.is_open()) {
inc_missing = true;
std::cout << "error: could not open include '" << inc << "'" << std::endl;
}
}
if (inc_missing)
return 1;
}
{
bool inc_missing = false;
for (const std::string& inc : dui.includePaths) {
// TODO: check if this is a directory
std::ifstream f(inc);
if (!f.is_open()) {
inc_missing = true;
std::cout << "error: could not find include path '" << inc << "'" << std::endl;
}
}
if (inc_missing)
return 1;
}

if (!filename) {
std::cout << "Syntax:" << std::endl;
std::cout << "simplecpp [options] filename" << std::endl;
Expand All @@ -102,7 +129,7 @@ int main(int argc, char **argv)
std::cout << " -q Quiet mode (no output)." << std::endl;
std::cout << " -is Use std::istream interface." << std::endl;
std::cout << " -e Output errors only." << std::endl;
std::exit(0);
return 0;
}

dui.removeComments = true;
Expand All @@ -115,7 +142,7 @@ int main(int argc, char **argv)
std::ifstream f(filename);
if (!f.is_open()) {
std::cout << "error: could not open file '" << filename << "'" << std::endl;
std::exit(1);
return 1;
}
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
} else {
Expand Down
Loading