Skip to content

Commit 419f1cf

Browse files
Merge pull request #35 from clarityflowers/master
Handle modules with no dirname
2 parents 34f7853 + bc2a748 commit 419f1cf

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/cognac.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,12 @@ module_t* create_module(char* path)
435435
char* path3 = path2;
436436
for (char* s = path2 ; *s ; ++s) if (*s == '/') path2 = s+1;
437437
for (char* s = path2 ; *s ; ++s) if (*s == '.') { *s = '\0'; break; }
438-
path2[-1] = '\0';
438+
if (path2 != path3) {
439+
path2[-1] = '\0';
440+
path3 = lowercase(path3);
441+
} else {
442+
path3 = NULL;
443+
}
439444
mod->prefix = lowercase(path2);
440445
mod->dir = path3;
441446
mod->tree = NULL;
@@ -3289,10 +3294,12 @@ void _compute_modules(ast_list_t* A, module_t* m)
32893294
*i = '\0';
32903295
for (module_list_t* mm = m->uses ; mm ; mm = mm->next)
32913296
if (!strcmp(mm->mod->prefix, mod_name)) goto end;
3292-
char* filename = alloc(strlen(m->dir) + strlen(mod_name) + 6);
3297+
char* filename = alloc((m->dir ? strlen(m->dir) : 0) + strlen(mod_name) + 6);
32933298
*filename = '\0';
3294-
strcpy(filename, m->dir);
3295-
strcat(filename, "/");
3299+
if (m->dir) {
3300+
strcpy(filename, m->dir);
3301+
strcat(filename, "/");
3302+
}
32963303
strcat(filename, mod_name);
32973304
strcat(filename, ".cog");
32983305
module_t* M = create_module(filename);

0 commit comments

Comments
 (0)