Skip to content
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

Some refactors to main.c #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 27 additions & 20 deletions main.c
Original file line number Diff line number Diff line change
@@ -198,6 +198,24 @@ static void printhelp()
}
}

static void tryfile(const char *name)
{
FILE *fp;
#ifdef _MSC_VER
errno_t err = fopen_s(&fp, name, "rb");
if (err != 0) {
#else
fp = fopen(name, "rb");
if (fp == NULL) {
#endif
haderrors++;
return;
}
dofile(fp, name);
fclose(fp);
didparse = 1;
}

static void doparse(int argc, char **argv)
{
int i;
@@ -220,34 +238,16 @@ static void doparse(int argc, char **argv)
continue;
}

FILE *fp;
#ifdef _MSC_VER
errno_t err = fopen_s(&fp, argv[i], "rb");
if (err != 0) {
#else
fp = fopen(argv[i], "rb");
if (fp == NULL) {
#endif
printf("Error: Cannot open %s\n", argv[i]);
haderrors++;
continue;
}

dofile(fp, argv[i]);
didparse = 1;
fclose(fp);
tryfile(argv[i]);
}
if (argc == 1) {
didparse = 1;
dofile(stdin, "<stdin>");
}
}

int main(int argc, char **argv)
static int ret()
{
init();
doparse(argc, argv);

if (!haderrors && didparse) {
printf("Parse successful: %8d lines: %s\n", totlines, "<total>");
if (ignorederrors) {
@@ -266,3 +266,10 @@ int main(int argc, char **argv)
return 1;
}
}

int main(int argc, char **argv)
{
init();
doparse(argc, argv);
return ret();
}