This commit is contained in:
ryanfleury
2021-01-21 23:47:23 -07:00
5 changed files with 168 additions and 11 deletions
+15 -8
View File
@@ -991,7 +991,8 @@ MD_NodeTable_Insert(MD_NodeTable *table, MD_NodeTableCollisionRule collision_rul
MD_FUNCTION_IMPL MD_Token
MD_ZeroToken(void)
{
MD_Token token = {0};
MD_Token token;
_MD_MemoryZero(&token, sizeof(token));
return token;
}
@@ -1064,7 +1065,8 @@ MD_Parse_BumpNext(MD_ParseCtx *ctx)
MD_FUNCTION_IMPL MD_Token
MD_Parse_LexNext(MD_ParseCtx *ctx)
{
MD_Token token = {0};
MD_Token token;
_MD_MemoryZero(&token, sizeof(token));
MD_u8 *one_past_last = ctx->file_contents.str + ctx->file_contents.size;
MD_u8 *first = ctx->at;
@@ -1239,7 +1241,8 @@ MD_Parse_PeekSkipSome(MD_ParseCtx *ctx, MD_TokenGroups skip_groups)
MD_b32 skip_whitespace = (skip_groups & MD_TokenGroup_Whitespace);
MD_b32 skip_regular = (skip_groups & MD_TokenGroup_Regular);
MD_Token result = {0};
MD_Token result;
_MD_MemoryZero(&result, sizeof(result));
loop:
{
@@ -1272,6 +1275,7 @@ MD_Parse_Require(MD_ParseCtx *ctx, MD_String8 string)
int result = 0;
MD_Token token_any = MD_Parse_PeekSkipSome(ctx, 0);
MD_Token token_regular;
if(MD_StringMatch(token_any.string, string, 0))
{
result = 1;
@@ -1279,7 +1283,7 @@ MD_Parse_Require(MD_ParseCtx *ctx, MD_String8 string)
goto end;
}
MD_Token token_regular = MD_Parse_PeekSkipSome(ctx, MD_TokenGroup_Comment|MD_TokenGroup_Whitespace);
token_regular = MD_Parse_PeekSkipSome(ctx, MD_TokenGroup_Comment|MD_TokenGroup_Whitespace);
if(MD_StringMatch(token_regular.string, string, 0))
{
result = 1;
@@ -1396,7 +1400,8 @@ _MD_ParseOneNode(MD_ParseCtx *ctx)
MD_ParseResult result = {0};
result.node = MD_NilNode();
MD_Token token = {0};
MD_Token token;
_MD_MemoryZero(&token, sizeof(token));
MD_Node *first_tag = 0;
MD_Node *last_tag = 0;
@@ -1574,7 +1579,8 @@ _MD_ParseTagList(MD_ParseCtx *ctx, MD_Node **first_out, MD_Node **last_out)
for(;MD_Parse_Require(ctx, MD_S8Lit("@"));)
{
MD_Token name = {0};
MD_Token name;
_MD_MemoryZero(&name, sizeof(name));
if(MD_Parse_RequireKind(ctx, MD_TokenKind_Identifier, &name))
{
MD_Node *tag = _MD_MakeNodeFromToken_Ctx(ctx, MD_NodeKind_Tag, name);
@@ -1905,7 +1911,7 @@ MD_TagCountFromNodeAndString(MD_Node *node, MD_String8 string, MD_StringMatchFla
MD_FUNCTION_IMPL void
MD_NodeMessage(MD_Node *node, MD_MessageKind kind, MD_String8 str)
{
char *kind_name = kind == MD_MessageKind_Error ? "error" : "warning";
const char *kind_name = kind == MD_MessageKind_Error ? "error" : "warning";
MD_CodeLoc loc = MD_CodeLocFromNode(node);
fprintf(stderr, "%.*s(%i:%i): %s: %.*s\n",
MD_StringExpand(loc.filename),
@@ -2267,12 +2273,13 @@ MD_PRIVATE_FUNCTION_IMPL MD_Expr *
_MD_ParseExpr_(_MD_NodeParseCtx *ctx, int precedence_in)
{
MD_Expr *expr = _MD_ParseUnaryExpr(ctx);
MD_ExprKind expr_kind;
if(MD_ExprIsNil(expr))
{
goto end_parse;
}
MD_ExprKind expr_kind = MD_BinaryExprKindFromNode(ctx->at);
expr_kind = MD_BinaryExprKindFromNode(ctx->at);
if(expr_kind != MD_ExprKind_Nil)
{
for(int precedence = MD_ExprPrecFromExprKind(expr_kind);
+1 -1
View File
@@ -17,7 +17,7 @@ MD_MALLOC_Alloc(void *ctx, MD_u64 size)
static void*
MD_MALLOC_GetCtx(void)
{
return(MD_MALLOC_Alloc);
return((void *)MD_MALLOC_Alloc);
}
/*
+50 -2
View File
@@ -1,9 +1,57 @@
// LICENSE AT END OF FILE (MIT).
#include <dirent.h>
#include <sys/stat.h>
#define MD_IMPL_FileIterIncrement MD_POSIX_FileIterIncrement
static MD_b32
_MD_OS_IMPL_FileIter_Increment(MD_FileIter *it, MD_String8 path, MD_FileInfo *out_info)
MD_POSIX_FileIterIncrement(MD_FileIter *it, MD_String8 path, MD_FileInfo *out_info)
{
MD_b32 result = 0;
DIR *dir = (DIR *)(it->state);
if(dir == 0)
{
dir = opendir((char*)path.str);
}
struct dirent *dir_entry = 0;
if(dir && (dir_entry = readdir(dir)))
{
out_info->filename = MD_PushStringF("%s", dir_entry->d_name);
out_info->flags = 0;
if(path.size > 1 && path.str[path.size-1] == '/')
{
path.size -= 1;
}
MD_String8 cfile_path = MD_PushStringF("%.*s/%s", MD_StringExpand(path), dir_entry->d_name);
// NOTE(mal): On Linux, fstatat(2) would save us from doing path manipulation and avoid some race
// conditions but we would need to make space for an extra directory file descriptor
// inside MD_FileIter struct. We would also stop being POSIX-compliant.
struct stat st;
if(stat((char *)cfile_path.str, &st) == 0)
{
if((st.st_mode & S_IFMT) == S_IFDIR)
{
out_info->flags |= MD_FileFlag_Directory;
}
out_info->file_size = st.st_size;
}
result = 1;
}
else
{
closedir(dir);
dir = 0;
result = 0;
}
it->state = *(MD_u64 *)(&dir);
return result;
}
/*
@@ -14,4 +62,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/