enum compile_type type;
};
-static void compiler_name(MemPool p, struct Compiler* c) {
+ANN static void compiler_name(MemPool p, struct Compiler* c) {
m_str d = strdup(c->base);
c->name = strsep(&d, ":");
if(d)
free(d);
}
-static inline void compiler_error(MemPool p, const struct Compiler* c) {
+ANN static inline void compiler_error(MemPool p, const struct Compiler* c) {
if(c->args) {
for(m_uint i = 0; i < vector_size(c->args); ++i) {
const m_str str = (m_str)vector_at(c->args, i);
}
}
-static void compiler_clean(MemPool p, const struct Compiler* c) {
+ANN static void compiler_clean(MemPool p, const struct Compiler* c) {
if(c->name)
xfree(c->name);
/* test c->type because COMPILE_FILE does not own file */
free_ast(p, c->ast);
}
-static m_bool _compiler_open(struct Compiler* c) {
+ANN static m_bool _compiler_open(struct Compiler* c) {
if(c->type == COMPILE_NAME) {
m_str name = c->name;
c->name = realpath(name, NULL);
return GW_OK;
}
-static inline m_bool compiler_open(MemPool p, struct Compiler* c) {
+#ifndef BUILD_ON_WINDOWS
+#include <sys/stat.h>
+ANN static int is_reg(const m_str path) {
+ struct stat s;
+ stat(path, &s);
+ return S_ISREG(s.st_mode);
+}
+#else
+ANN static bool is_reg(const m_str path) {
+ cionst DWORD dw = GetFileAttributes(path);
+ return !(dw == INVALID_FILE_ATTRIBUTES ||
+ dw & FILE_ATTRIBUTE_DIRECTORY);
+}
+#endif
+
+ANN static inline m_bool compiler_open(MemPool p, struct Compiler* c) {
char name[strlen(c->name) + 1];
strcpy(name, c->name);
+ if(!is_reg(name)) {
+ gw_err(_("'%s': is a not a regular file\n"), name);
+ return GW_ERROR;
+ }
if(_compiler_open(c) < 0) {
compiler_error(p, c);
- gw_err(_("'%s': no such file\n"), name);
+ gw_err(_("can't open '%s'\n"), name);
return GW_ERROR;
}
return GW_OK;
}
-static inline m_bool _check(struct Gwion_* gwion, struct Compiler* c) {
+ANN static inline m_bool _check(struct Gwion_* gwion, struct Compiler* c) {
struct AstGetter_ arg = { c->name, c->file, gwion->st, .ppa=gwion->ppa };
CHECK_OB((c->ast = parse(&arg)))
gwion->env->name = c->name;
return GW_OK;
}
-static m_uint _compile(struct Gwion_* gwion, struct Compiler* c) {
+ANN static m_uint _compile(struct Gwion_* gwion, struct Compiler* c) {
CHECK_BB(compiler_open(gwion->mp, c))
if(_check(gwion, c) < 0) {
gw_err(_("while compiling file '%s'\n"), c->base);
return GW_OK;
}
-static m_uint compile(struct Gwion_* gwion, struct Compiler* c) {
+ANN static m_uint compile(struct Gwion_* gwion, struct Compiler* c) {
compiler_name(gwion->mp, c);
MUTEX_LOCK(gwion->data->mutex);
const m_uint ret = _compile(gwion, c);
return ret;
}
-m_uint compile_filename(struct Gwion_* gwion, const m_str filename) {
+ANN m_uint compile_filename(struct Gwion_* gwion, const m_str filename) {
struct Compiler c = { .base=filename, .type=COMPILE_NAME };
return compile(gwion, &c);
}
-m_uint compile_string(struct Gwion_* vm, const m_str filename, const m_str data) {
+ANN m_uint compile_string(struct Gwion_* vm, const m_str filename, const m_str data) {
struct Compiler c = { .base=filename, .type=COMPILE_MSTR, .data=data };
return compile(vm, &c);
}
-m_uint compile_file(struct Gwion_* vm, const m_str filename, FILE* file) {
+ANN m_uint compile_file(struct Gwion_* vm, const m_str filename, FILE* file) {
struct Compiler c = { .base=filename, .type=COMPILE_FILE, .file=file };
return compile(vm, &c);
}