Skip to content
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
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -266,3 +266,10 @@ int main(int argc, char **argv)
return 1;
}
}

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