Skip to content

Commit

Permalink
fix(lex): fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Dec 17, 2023
1 parent 9b85dd9 commit ff5294e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/mln_lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,23 +466,30 @@ int mln_lex_push_input_file_stream(mln_lex_t *lex, mln_string_t *path)
mln_string_t tmp;
struct dirent *entry;
DIR *directory;

#if defined(WIN32)
WIN32_FIND_DATA fileData;
#endif
if ((directory = opendir(p)) == NULL) {
mln_lex_error_set(lex, MLN_LEX_EFPATH);
return -1;
}
p[n++] = '/';
while ((entry = readdir(directory)) != NULL) {
if (entry->d_type != DT_REG || entry->d_name[0] == '.') {
continue;
}
m = strlen(entry->d_name);
if (sizeof(p)-1-n < m)
m = sizeof(p) - 1 - n;
memcpy(p + n, entry->d_name, m);
p[n + m] = 0;
mln_string_nset(&tmp, p, n + m);
path = &tmp;
#if defined(WIN32)
FindClose(FindFirstFile(p, &fileData));
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY || entry->d_name[0] == '.') {
#else
if (entry->d_type != DT_REG || entry->d_name[0] == '.') {
#endif
continue;
}

if ((in = mln_lex_input_new(lex, M_INPUT_T_FILE, path, &err, lex->line)) == NULL) {
lex->error = err;
Expand Down Expand Up @@ -598,6 +605,9 @@ int mln_lex_check_file_loop(mln_lex_t *lex, mln_string_t *path)
DIR *directory;
mln_string_t tmp;
struct dirent *entry;
#if defined(WIN32)
WIN32_FIND_DATA fileData;
#endif

if ((directory = opendir(p)) == NULL) {
mln_lex_error_set(lex, MLN_LEX_EFPATH);
Expand All @@ -606,16 +616,21 @@ int mln_lex_check_file_loop(mln_lex_t *lex, mln_string_t *path)

p[n++] = '/';
while ((entry = readdir(directory)) != NULL) {
if (entry->d_type != DT_REG || entry->d_name[0] == '.') {
continue;
}
m = strlen(entry->d_name);
if (sizeof(p)-1-n < m)
m = sizeof(p) - 1 - n;
memcpy(p + n, entry->d_name, m);
p[n + m] = 0;
mln_string_nset(&tmp, p, n + m);
path = &tmp;
#if defined(WIN32)
FindClose(FindFirstFile(p, &fileData));
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY || entry->d_name[0] == '.') {
#else
if (entry->d_type != DT_REG || entry->d_name[0] == '.') {
#endif
continue;
}

if (lex->cur != NULL && !mln_string_strcmp(path, lex->cur->data)) {
mln_lex_error_set(lex, MLN_LEX_EINCLUDELOOP);
Expand Down

0 comments on commit ff5294e

Please sign in to comment.