Imported Upstream version 0.14.2+dfsg1
This commit is contained in:
parent
fb3990e9e5
commit
41a01dbf05
529 changed files with 25112 additions and 2336 deletions
|
|
@ -602,6 +602,24 @@ static inline void cf_adderror_unexpected_eof(struct cf_preprocessor *pp,
|
|||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static inline void insert_path(struct cf_preprocessor *pp,
|
||||
struct dstr *str_file)
|
||||
{
|
||||
const char *file;
|
||||
const char *slash;
|
||||
|
||||
if (pp && pp->lex && pp->lex->file) {
|
||||
file = pp->lex->file;
|
||||
slash = strrchr(file, '/');
|
||||
if (slash) {
|
||||
struct dstr path = {0};
|
||||
dstr_ncopy(&path, file, slash - file + 1);
|
||||
dstr_insert_dstr(str_file, 0, &path);
|
||||
dstr_free(&path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cf_include_file(struct cf_preprocessor *pp,
|
||||
const struct cf_token *file_token)
|
||||
{
|
||||
|
|
@ -615,6 +633,7 @@ static void cf_include_file(struct cf_preprocessor *pp,
|
|||
dstr_init(&str_file);
|
||||
dstr_copy_strref(&str_file, &file_token->str);
|
||||
dstr_mid(&str_file, &str_file, 1, str_file.len-2);
|
||||
insert_path(pp, &str_file);
|
||||
|
||||
/* if dependency already exists, run preprocessor on it */
|
||||
for (i = 0; i < pp->dependencies.num; i++) {
|
||||
|
|
|
|||
|
|
@ -346,6 +346,7 @@ void dstr_ncopy(struct dstr *dst, const char *array, const size_t len)
|
|||
|
||||
dst->array = bmemdup(array, len + 1);
|
||||
dst->len = len;
|
||||
dst->capacity = len + 1;
|
||||
|
||||
dst->array[len] = 0;
|
||||
}
|
||||
|
|
@ -363,6 +364,7 @@ void dstr_ncopy_dstr(struct dstr *dst, const struct dstr *str, const size_t len)
|
|||
newlen = size_min(len, str->len);
|
||||
dst->array = bmemdup(str->array, newlen + 1);
|
||||
dst->len = newlen;
|
||||
dst->capacity = newlen + 1;
|
||||
|
||||
dst->array[newlen] = 0;
|
||||
}
|
||||
|
|
@ -430,10 +432,11 @@ void dstr_insert(struct dstr *dst, const size_t idx, const char *array)
|
|||
new_len = dst->len + len;
|
||||
|
||||
dstr_ensure_capacity(dst, new_len + 1);
|
||||
dst->len = new_len;
|
||||
|
||||
memmove(dst->array+idx+len, dst->array+idx, dst->len - idx + 1);
|
||||
memcpy(dst->array+idx, array, len);
|
||||
|
||||
dst->len = new_len;
|
||||
}
|
||||
|
||||
void dstr_insert_dstr(struct dstr *dst, const size_t idx,
|
||||
|
|
@ -450,10 +453,11 @@ void dstr_insert_dstr(struct dstr *dst, const size_t idx,
|
|||
new_len = dst->len + str->len;
|
||||
|
||||
dstr_ensure_capacity(dst, (new_len+1));
|
||||
dst->len = new_len;
|
||||
|
||||
memmove(dst->array+idx+str->len, dst->array+idx, dst->len - idx + 1);
|
||||
memcpy(dst->array+idx, str->array, str->len);
|
||||
|
||||
dst->len = new_len;
|
||||
}
|
||||
|
||||
void dstr_insert_ch(struct dstr *dst, const size_t idx, const char ch)
|
||||
|
|
|
|||
|
|
@ -85,6 +85,37 @@ int64_t os_fgetsize(FILE *file)
|
|||
return size;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int os_stat(const char *file, struct stat *st)
|
||||
{
|
||||
if (file) {
|
||||
wchar_t w_file[512];
|
||||
size_t size = os_utf8_to_wcs(file, 0, w_file, sizeof(w_file));
|
||||
if (size > 0) {
|
||||
struct _stat st_w32;
|
||||
int ret = _wstat(w_file, &st_w32);
|
||||
if (ret == 0) {
|
||||
st->st_dev = st_w32.st_dev;
|
||||
st->st_ino = st_w32.st_ino;
|
||||
st->st_mode = st_w32.st_mode;
|
||||
st->st_nlink = st_w32.st_nlink;
|
||||
st->st_uid = st_w32.st_uid;
|
||||
st->st_gid = st_w32.st_gid;
|
||||
st->st_rdev = st_w32.st_rdev;
|
||||
st->st_size = st_w32.st_size;
|
||||
st->st_atime = st_w32.st_atime;
|
||||
st->st_mtime = st_w32.st_mtime;
|
||||
st->st_ctime = st_w32.st_ctime;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int os_fseeki64(FILE *file, int64_t offset, int origin)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ EXPORT FILE *os_wfopen(const wchar_t *path, const char *mode);
|
|||
EXPORT FILE *os_fopen(const char *path, const char *mode);
|
||||
EXPORT int64_t os_fgetsize(FILE *file);
|
||||
|
||||
#ifdef _WIN32
|
||||
EXPORT int os_stat(const char *file, struct stat *st);
|
||||
#else
|
||||
#define os_stat stat
|
||||
#endif
|
||||
|
||||
EXPORT int os_fseeki64(FILE *file, int64_t offset, int origin);
|
||||
EXPORT int64_t os_ftelli64(FILE *file);
|
||||
|
||||
|
|
|
|||
|
|
@ -287,6 +287,7 @@ static char *convert_string(const char *str, size_t len)
|
|||
dstr_replace(&out, "\\n", "\n");
|
||||
dstr_replace(&out, "\\t", "\t");
|
||||
dstr_replace(&out, "\\r", "\r");
|
||||
dstr_replace(&out, "\\\"", "\"");
|
||||
|
||||
return out.array;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue