2020-05-09 17:33:25 +00:00
|
|
|
#if 0
|
|
|
|
ctime -begin ${0%.*}.ctm
|
|
|
|
gcc -g -Wall -fsanitize=address -std=c99 $0 -o ${0%.*}
|
|
|
|
#clang -g -fsanitize=address -std=c99 $0 -o ${0%.*}
|
|
|
|
ctime -end ${0%.*}.ctm
|
|
|
|
exit
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// config
|
|
|
|
//
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define ArgCountPointer(...) (sizeof((void *[]){__VA_ARGS__})/sizeof(void *))
|
|
|
|
|
|
|
|
#define DigitsInInt(I) DigitsInInt_(I, sizeof(*I))
|
|
|
|
uint8_t
|
|
|
|
DigitsInInt_(void *Int, uint8_t WidthInBytes)
|
|
|
|
{
|
|
|
|
uint8_t Result = 0;
|
|
|
|
switch(WidthInBytes)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
int8_t This = *(int8_t *)Int;
|
|
|
|
if(This <= 0) { This = ~This; ++Result; if(This == 0) { ++Result; return Result; } }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
int16_t This = *(int16_t *)Int;
|
|
|
|
if(This <= 0) { This = ~This; ++Result; if(This == 0) { ++Result; return Result; } }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
int32_t This = *(int32_t *)Int;
|
|
|
|
if(This <= 0) { This = ~This; ++Result; if(This == 0) { ++Result; return Result; } }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
int64_t This = *(int64_t *)Int;
|
|
|
|
if(This <= 0) { This = ~This; ++Result; if(This == 0) { ++Result; return Result; } }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DigitsInUint(I) DigitsInUint_(I, sizeof(*I))
|
|
|
|
uint8_t
|
|
|
|
DigitsInUint_(void *Uint, uint8_t WidthInBytes)
|
|
|
|
{
|
|
|
|
uint32_t Result = 0;
|
|
|
|
switch(WidthInBytes)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
uint8_t This = *(uint8_t *)Uint;
|
|
|
|
if(This == 0) { ++Result; return Result; }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
uint16_t This = *(uint16_t *)Uint;
|
|
|
|
if(This == 0) { ++Result; return Result; }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
uint32_t This = *(uint32_t *)Uint;
|
|
|
|
if(This == 0) { ++Result; return Result; }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
uint64_t This = *(uint64_t *)Uint;
|
|
|
|
if(This == 0) { ++Result; return Result; }
|
|
|
|
for(; This > 0; This /= 10) { ++Result; }
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define MakeString(Format, ...) MakeString_(__FILE__, __LINE__, Format, ArgCountPointer(__VA_ARGS__), __VA_ARGS__)
|
|
|
|
string
|
|
|
|
MakeString_(char *Filename, int LineNumber, char *Format, int ArgCount, ...)
|
|
|
|
{
|
|
|
|
// NOTE(matt): Be sure to free built strings when you're finished with them
|
|
|
|
//
|
|
|
|
// Usage:
|
|
|
|
//
|
|
|
|
// Similar to printf and friends, MakeString() takes a format string as its first argument.
|
|
|
|
// While printf has many format specifiers - e.g. %s, %d, %c - MakeString() has two: s, l
|
|
|
|
// s: Null-terminated string, i.e. char *
|
|
|
|
// l: Length-string, i.e. string *
|
|
|
|
// We allocate memory, null-terminate and return the char *
|
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
// 1. char *BuiltString = MakeString("ss", "First", "Second");
|
|
|
|
// 2. char *Input = "First";
|
|
|
|
// char *BuiltString = MakeString("ss", Input, "Second");
|
|
|
|
// 3. string Input = { .Base = "Second", .Length = StringLength("Second") };
|
|
|
|
// char *BuiltString = MakeString("sl", "First", &Input);
|
|
|
|
|
|
|
|
int FormatLength = StringLength(Format);
|
|
|
|
if(FormatLength != ArgCount)
|
|
|
|
{
|
|
|
|
Colourise(CS_FAILURE); fprintf(stderr, "%s:%d MakeString()", Filename, LineNumber); Colourise(CS_END);
|
|
|
|
fprintf(stderr,
|
|
|
|
"\n"
|
|
|
|
" MakeString() has been passed a format string containing ");
|
|
|
|
|
|
|
|
Colourise(CS_BLUE_BOLD); fprintf(stderr, "%d specifier%s", FormatLength, FormatLength == 1 ? "" : "s"); Colourise(CS_END);
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
",\n"
|
|
|
|
" and ");
|
|
|
|
|
|
|
|
Colourise(CS_BLUE_BOLD); fprintf(stderr, "%d argument%s", ArgCount, ArgCount == 1 ? "" : "s"); Colourise(CS_END);
|
|
|
|
|
|
|
|
fprintf(stderr, ", but these numbers should be equal.\n");
|
|
|
|
__asm__("int3");
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(matt): Type-checking, if possible?
|
|
|
|
va_list Args;
|
|
|
|
va_start(Args, ArgCount);
|
|
|
|
string Result = {};
|
|
|
|
for(int i = 0; i < FormatLength; ++i)
|
|
|
|
{
|
|
|
|
switch(Format[i])
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
char *Next = va_arg(Args, char *);
|
|
|
|
int NextLength = StringLength(Next);
|
|
|
|
Result.Base = realloc(Result.Base, Result.Length + NextLength);
|
|
|
|
char *Ptr = Result.Base + Result.Length;
|
|
|
|
while(*Next) { *Ptr++ = *Next++; }
|
|
|
|
Result.Length += NextLength;
|
|
|
|
} break;
|
|
|
|
case 'l':
|
|
|
|
{
|
|
|
|
string *Next = va_arg(Args, string *);
|
|
|
|
Result.Base = realloc(Result.Base, Result.Length + Next->Length);
|
|
|
|
char *Ptr = Result.Base + Result.Length;
|
|
|
|
int j;
|
|
|
|
for(j = 0; j < Next->Length && Next->Base[j]; ++j)
|
|
|
|
{
|
|
|
|
*Ptr++ = Next->Base[j];
|
|
|
|
}
|
|
|
|
Result.Length += j;
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Colourise(CS_FAILURE); fprintf(stderr, "%s:%d", Filename, LineNumber); Colourise(CS_END);
|
|
|
|
fprintf(stderr, "\n"
|
|
|
|
" MakeString() has been passed an unsupported format specifier: %c\n", Format[i]);
|
|
|
|
__asm__("int3");
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(Args);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MakeString0(Format, ...) MakeString0_(__FILE__, __LINE__, Format, ArgCountPointer(__VA_ARGS__), __VA_ARGS__)
|
|
|
|
char *
|
|
|
|
MakeString0_(char *Filename, int LineNumber, char *Format, int ArgCount, ...)
|
|
|
|
{
|
|
|
|
// NOTE(matt): Be sure to free built strings when you're finished with them
|
|
|
|
//
|
|
|
|
// Usage:
|
|
|
|
//
|
|
|
|
// Similar to printf and friends, MakeString() takes a format string as its first argument.
|
|
|
|
// While printf has many format specifiers - e.g. %s, %d, %c - MakeString() has two: s, l
|
|
|
|
// s: Null-terminated string, i.e. char *
|
|
|
|
// l: Length-string, i.e. string *
|
|
|
|
// We allocate memory, null-terminate and return the char *
|
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
// 1. char *BuiltString = MakeString("ss", "First", "Second");
|
|
|
|
// 2. char *Input = "First";
|
|
|
|
// char *BuiltString = MakeString("ss", Input, "Second");
|
|
|
|
// 3. string Input = { .Base = "Second", .Length = StringLength("Second") };
|
|
|
|
// char *BuiltString = MakeString("sl", "First", &Input);
|
|
|
|
|
|
|
|
int FormatLength = StringLength(Format);
|
|
|
|
if(FormatLength != ArgCount)
|
|
|
|
{
|
|
|
|
Colourise(CS_FAILURE); fprintf(stderr, "%s:%d MakeString0()", Filename, LineNumber); Colourise(CS_END);
|
|
|
|
fprintf(stderr,
|
|
|
|
"\n"
|
|
|
|
" MakeString0() has been passed a format string containing ");
|
|
|
|
|
|
|
|
Colourise(CS_BLUE_BOLD); fprintf(stderr, "%d specifier%s", FormatLength, FormatLength == 1 ? "" : "s"); Colourise(CS_END);
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
",\n"
|
|
|
|
" and ");
|
|
|
|
|
|
|
|
Colourise(CS_BLUE_BOLD); fprintf(stderr, "%d argument%s", ArgCount, ArgCount == 1 ? "" : "s"); Colourise(CS_END);
|
|
|
|
|
|
|
|
fprintf(stderr, ", but these numbers should be equal.\n");
|
|
|
|
__asm__("int3");
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(matt): Type-checking, if possible?
|
|
|
|
va_list Args;
|
|
|
|
va_start(Args, ArgCount);
|
|
|
|
char *Result = 0;
|
|
|
|
int RequiredSpace = 0;
|
|
|
|
for(int i = 0; i < FormatLength; ++i)
|
|
|
|
{
|
|
|
|
switch(Format[i])
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
char *Next = va_arg(Args, char *);
|
|
|
|
int NextLength = StringLength(Next);
|
|
|
|
Result = realloc(Result, RequiredSpace + NextLength);
|
|
|
|
char *Ptr = Result + RequiredSpace;
|
|
|
|
while(*Next) { *Ptr++ = *Next++; }
|
|
|
|
RequiredSpace += NextLength;
|
|
|
|
} break;
|
|
|
|
case 'l':
|
|
|
|
{
|
|
|
|
string *Next = va_arg(Args, string *);
|
|
|
|
Result = realloc(Result, RequiredSpace + Next->Length);
|
|
|
|
char *Ptr = Result + RequiredSpace;
|
|
|
|
int j;
|
|
|
|
for(j = 0; j < Next->Length && Next->Base[j]; ++j)
|
|
|
|
{
|
|
|
|
*Ptr++ = Next->Base[j];
|
|
|
|
}
|
|
|
|
RequiredSpace += j;
|
|
|
|
} break;
|
|
|
|
case 'd':
|
|
|
|
{
|
|
|
|
int32_t Next = *va_arg(Args, int32_t *);
|
|
|
|
int NextLength = DigitsInInt(&Next);
|
|
|
|
Result = realloc(Result, RequiredSpace + NextLength);
|
|
|
|
char *Ptr = Result + RequiredSpace;
|
|
|
|
sprintf(Ptr, "%d", Next);
|
|
|
|
RequiredSpace += NextLength;
|
|
|
|
} break;
|
|
|
|
case 'u':
|
|
|
|
{
|
|
|
|
uint32_t Next = *va_arg(Args, uint32_t *);
|
|
|
|
int NextLength = DigitsInUint(&Next);
|
|
|
|
Result = realloc(Result, RequiredSpace + NextLength);
|
|
|
|
char *Ptr = Result + RequiredSpace;
|
|
|
|
sprintf(Ptr, "%u", Next);
|
|
|
|
RequiredSpace += NextLength;
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Colourise(CS_FAILURE); fprintf(stderr, "%s:%d", Filename, LineNumber); Colourise(CS_END);
|
|
|
|
fprintf(stderr, "\n"
|
|
|
|
" MakeString0() has been passed an unsupported format specifier: %c\n", Format[i]);
|
|
|
|
__asm__("int3");
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(Args);
|
|
|
|
++RequiredSpace;
|
|
|
|
Result = realloc(Result, RequiredSpace);
|
|
|
|
Result[RequiredSpace - 1] = '\0';
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushToken(tokens *Set, token *Token)
|
|
|
|
{
|
|
|
|
// NOTE(matt): We don't bother to push comments or newlines on to the token list
|
|
|
|
//PrintFunctionName("PushToken()");
|
|
|
|
if(!(Token->Type == TOKEN_NULL || Token->Type == TOKEN_COMMENT || Token->Type == TOKEN_NEWLINE))
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
token *This = MakeSpaceInBook(&Set->Token);
|
2020-05-15 01:35:55 +00:00
|
|
|
This->Type = Token->Type;
|
|
|
|
This->LineNumber = Set->CurrentLine;
|
2020-05-09 17:33:25 +00:00
|
|
|
|
|
|
|
if(Token->Type == TOKEN_NUMBER)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
This->int64_t = StringToInt(Token->Content);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
This->Content = Token->Content;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintToken(token *T, uint64_t Index)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "[%lu, %s] ", Index, TokenTypeStrings[T->Type]);
|
|
|
|
if(T->Type == TOKEN_NUMBER)
|
|
|
|
{
|
|
|
|
Colourise(CS_BLUE_BOLD);
|
|
|
|
fprintf(stderr, "%li", T->int64_t);
|
|
|
|
Colourise(CS_END);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(T->Type == TOKEN_COMMENT)
|
|
|
|
{
|
|
|
|
PrintStringC(CS_BLACK_BOLD, T->Content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintString(T->Content);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintTokens(tokens *T)
|
|
|
|
{
|
|
|
|
//PrintFunctionName("PrintTokens()");
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < T->Token.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintToken(GetPlaceInBook(&T->Token, i), i);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens *
|
2020-05-15 01:35:55 +00:00
|
|
|
PushTokens(memory_book *TokensList)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
tokens *This = MakeSpaceInBook(TokensList);
|
2020-06-24 12:29:18 +00:00
|
|
|
This->Token = InitBook(MBT_TOKEN, 16);
|
2020-05-15 01:35:55 +00:00
|
|
|
This->CurrentLine = 1;
|
|
|
|
return This;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeTokensList(memory_book *TokensList)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < TokensList->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
tokens *This = GetPlaceInBook(TokensList, i);
|
|
|
|
This->CurrentIndex = 0;
|
|
|
|
This->CurrentLine = 0;
|
|
|
|
FreeBook(&This->Token);
|
|
|
|
FreeFile(&This->File);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
TokensList->ItemCount = 0;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SkipWhitespace(tokens *T, buffer *B)
|
|
|
|
{
|
|
|
|
while(B->Ptr - B->Location < B->Size &&
|
|
|
|
(*B->Ptr == ' ' ||
|
|
|
|
//*B->Ptr == '\n' ||
|
|
|
|
*B->Ptr == '\t'))
|
|
|
|
{
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Advance(buffer *B, uint64_t Distance)
|
|
|
|
{
|
|
|
|
if(B->Ptr + Distance - B->Location <= B->Size)
|
|
|
|
{
|
|
|
|
B->Ptr += Distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
GetUTF8Character(char *Ptr, uint64_t BytesRemaining)
|
|
|
|
{
|
|
|
|
string Result = {};
|
|
|
|
if((uint8_t)(Ptr[0] & 0b11111000) == 0b11110000)
|
|
|
|
{
|
|
|
|
++Result.Length;
|
|
|
|
if(BytesRemaining >= 3)
|
|
|
|
{
|
|
|
|
if((uint8_t)(Ptr[1] & 0b11000000) == 0b10000000 &&
|
|
|
|
(uint8_t)(Ptr[2] & 0b11000000) == 0b10000000 &&
|
|
|
|
(uint8_t)(Ptr[3] & 0b11000000) == 0b10000000)
|
|
|
|
{
|
|
|
|
Result.Length = 4;
|
|
|
|
Result.Base = Ptr;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((uint8_t)(Ptr[0] & 0b11110000) == 0b11100000)
|
|
|
|
{
|
|
|
|
++Result.Length;
|
|
|
|
if(BytesRemaining >= 2)
|
|
|
|
{
|
|
|
|
if((uint8_t)(Ptr[1] & 0b11000000) == 0b10000000 &&
|
|
|
|
(uint8_t)(Ptr[2] & 0b11000000) == 0b10000000)
|
|
|
|
{
|
|
|
|
Result.Length = 3;
|
|
|
|
Result.Base = Ptr;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((uint8_t)(Ptr[0] & 0b11100000) == 0b11000000)
|
|
|
|
{
|
|
|
|
++Result.Length;
|
|
|
|
if(BytesRemaining >= 1)
|
|
|
|
{
|
|
|
|
if((uint8_t)(Ptr[1] & 0b11000000) == 0b10000000)
|
|
|
|
{
|
|
|
|
Result.Length = 2;
|
|
|
|
Result.Base = Ptr;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((uint8_t)(Ptr[0] & 0b10000000) == 0b00000000)
|
|
|
|
{
|
|
|
|
++Result.Length;
|
|
|
|
Result.Base = Ptr;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(; BytesRemaining >= Result.Length; ++Result.Length)
|
|
|
|
{
|
|
|
|
if(((uint8_t)(Ptr[Result.Length] & 0b11111000) == 0b11110000) ||
|
|
|
|
((uint8_t)(Ptr[Result.Length] & 0b11110000) == 0b11100000) ||
|
|
|
|
((uint8_t)(Ptr[Result.Length] & 0b11100000) == 0b11000000) ||
|
|
|
|
((uint8_t)(Ptr[Result.Length] & 0b10000000) == 0b00000000))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string ID;
|
|
|
|
string Icon;
|
|
|
|
string IconNormal;
|
|
|
|
string IconFocused;
|
|
|
|
icon_type IconType;
|
|
|
|
uint64_t IconVariants;
|
|
|
|
asset *IconAsset;
|
|
|
|
string URL;
|
|
|
|
} support;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string ID;
|
|
|
|
string Icon;
|
|
|
|
string IconNormal;
|
|
|
|
string IconDisabled;
|
|
|
|
string IconFocused;
|
|
|
|
icon_type IconType;
|
|
|
|
uint64_t IconVariants;
|
|
|
|
asset *IconAsset;
|
|
|
|
|
|
|
|
string Name;
|
|
|
|
bool Hidden;
|
|
|
|
} medium;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string ID;
|
|
|
|
string Name;
|
2021-05-30 18:39:47 +00:00
|
|
|
// TODO(matt): string SortName;
|
|
|
|
string QuoteUsername;
|
2020-05-09 17:33:25 +00:00
|
|
|
string Homepage;
|
2020-05-15 01:35:55 +00:00
|
|
|
_memory_book(support) Support;
|
2020-05-09 17:33:25 +00:00
|
|
|
} person;
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string ID;
|
|
|
|
string Name;
|
|
|
|
string Plural;
|
|
|
|
bool NonSpeaking;
|
|
|
|
} role;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
person *Person;
|
|
|
|
role *Role;
|
|
|
|
} credit;
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
typedef struct project
|
|
|
|
{
|
|
|
|
string ID;
|
|
|
|
string Lineage;
|
|
|
|
|
|
|
|
string Title;
|
|
|
|
string HTMLTitle;
|
|
|
|
string Unit;
|
|
|
|
string HMMLDir;
|
|
|
|
string TemplatesDir;
|
|
|
|
string SearchTemplatePath;
|
|
|
|
string PlayerTemplatePath;
|
|
|
|
|
|
|
|
string BaseDir;
|
|
|
|
string BaseURL;
|
|
|
|
string SearchLocation;
|
|
|
|
string PlayerLocation;
|
|
|
|
string Theme;
|
|
|
|
|
|
|
|
string Art;
|
|
|
|
uint64_t ArtVariants;
|
|
|
|
asset *ArtAsset;
|
|
|
|
|
|
|
|
string Icon;
|
|
|
|
string IconNormal;
|
|
|
|
string IconDisabled;
|
|
|
|
string IconFocused;
|
|
|
|
icon_type IconType;
|
|
|
|
uint64_t IconVariants;
|
|
|
|
asset *IconAsset;
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
string StreamUsername;
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2021-01-25 18:09:30 +00:00
|
|
|
string VODPlatform; // TODO(matt): Make this an enum
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-17 01:04:26 +00:00
|
|
|
bool DenyBespokeTemplates;
|
2020-05-09 17:33:25 +00:00
|
|
|
bool SingleBrowserTab;
|
|
|
|
bool IgnorePrivacy;
|
|
|
|
|
|
|
|
person *Owner;
|
2021-05-30 18:39:47 +00:00
|
|
|
_memory_book(credit *) Credit;
|
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(person *) Indexer;
|
|
|
|
_memory_book(person *) Guest;
|
|
|
|
_memory_book(person *) CoHost;
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
_memory_book(medium) Medium;
|
|
|
|
medium *DefaultMedium;
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
_memory_book(project) Child;
|
|
|
|
|
|
|
|
struct project *Parent;
|
2020-05-09 17:33:25 +00:00
|
|
|
|
|
|
|
genre Genre;
|
|
|
|
numbering_scheme NumberingScheme;
|
|
|
|
|
|
|
|
db_project_index Index;
|
|
|
|
template PlayerTemplate;
|
|
|
|
template SearchTemplate;
|
|
|
|
} project;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string DatabaseLocation;
|
|
|
|
string CacheDir;
|
|
|
|
|
|
|
|
string GlobalTemplatesDir;
|
|
|
|
string GlobalSearchTemplatePath;
|
|
|
|
string GlobalSearchDir;
|
|
|
|
string GlobalSearchURL;
|
|
|
|
string GlobalTheme;
|
|
|
|
template SearchTemplate;
|
|
|
|
|
|
|
|
string AssetsRootDir;
|
|
|
|
string AssetsRootURL;
|
|
|
|
string CSSDir;
|
|
|
|
string ImagesDir;
|
|
|
|
string JSDir;
|
|
|
|
string QueryString;
|
|
|
|
|
|
|
|
bool RespectingPrivacy;
|
2020-06-24 12:29:18 +00:00
|
|
|
bool SuppressingPrompts;
|
2020-05-09 17:33:25 +00:00
|
|
|
time_t PrivacyCheckInterval;
|
|
|
|
uint8_t LogLevel;
|
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
_memory_book(person) Person;
|
2021-05-30 18:39:47 +00:00
|
|
|
_memory_book(role) Role;
|
2020-05-15 01:35:55 +00:00
|
|
|
_memory_book(project) Project;
|
2020-05-09 17:33:25 +00:00
|
|
|
memory_book ResolvedVariables;
|
|
|
|
} config;
|
|
|
|
|
|
|
|
char *ExpandPath(string Path, string *RelativeToFile); // NOTE(matt): Forward declared. Consider reorganising the code?
|
|
|
|
void PushWatchHandle(string Path, extension_id Extension, watch_type Type, project *Project, asset *Asset); // NOTE(matt): Forward declared. Consider reorganising the code?
|
|
|
|
|
|
|
|
tokens *
|
2020-05-15 01:35:55 +00:00
|
|
|
Tokenise(memory_book *TokensList, string Path)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
tokens *Result = 0;
|
|
|
|
char *Path0 = MakeString0("l", &Path);
|
|
|
|
FILE *Handle = 0;
|
|
|
|
PushWatchHandle(Path, EXT_NULL, WT_CONFIG, 0, 0);
|
|
|
|
if((Handle = fopen(Path0, "r")))
|
|
|
|
{
|
|
|
|
fclose(Handle);
|
2020-05-15 01:35:55 +00:00
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
Result = PushTokens(TokensList);
|
|
|
|
Result->File = InitFile(0, &Path, EXT_NULL);
|
|
|
|
ReadFileIntoBuffer(&Result->File);
|
|
|
|
buffer *B = &Result->File.Buffer;
|
|
|
|
SkipWhitespace(Result, B);
|
|
|
|
while(B->Ptr - B->Location < B->Size)
|
|
|
|
{
|
|
|
|
token T = {};
|
|
|
|
uint64_t Advancement = 0;
|
|
|
|
|
|
|
|
if(!StringsDifferS(TokenStrings[TOKEN_COMMENT_SINGLE], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_COMMENT;
|
|
|
|
B->Ptr += StringLength(TokenStrings[TOKEN_COMMENT_SINGLE]);
|
|
|
|
SkipWhitespace(Result, B);
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
while(B->Ptr && *B->Ptr != '\n')
|
|
|
|
{
|
|
|
|
++T.Content.Length;
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
if(*B->Ptr == '\n')
|
|
|
|
{
|
|
|
|
++Result->CurrentLine;
|
|
|
|
}
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_COMMENT_MULTI_OPEN], B))
|
|
|
|
{
|
|
|
|
uint64_t CommentDepth = 1;
|
|
|
|
T.Type = TOKEN_COMMENT;
|
|
|
|
B->Ptr += StringLength(TokenStrings[TOKEN_COMMENT_MULTI_OPEN]);
|
|
|
|
SkipWhitespace(Result, B);
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
while(B->Ptr - B->Location < B->Size && CommentDepth)
|
|
|
|
{
|
|
|
|
if(!StringsDifferS(TokenStrings[TOKEN_COMMENT_MULTI_CLOSE], B))
|
|
|
|
{
|
|
|
|
--CommentDepth;
|
|
|
|
B->Ptr += StringLength(TokenStrings[TOKEN_COMMENT_MULTI_CLOSE]);
|
|
|
|
}
|
|
|
|
else if(B->Ptr - B->Location < B->Size && *B->Ptr == '\n')
|
|
|
|
{
|
|
|
|
++Result->CurrentLine;
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_COMMENT_MULTI_OPEN], B))
|
|
|
|
{
|
|
|
|
++CommentDepth;
|
|
|
|
B->Ptr += StringLength(TokenStrings[TOKEN_COMMENT_MULTI_OPEN]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T.Content.Length = B->Ptr - T.Content.Base;
|
|
|
|
Advancement = 0;//StringLength(TokenStrings[TOKEN_COMMENT_MULTI_CLOSE]);
|
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_COMMENT_MULTI_CLOSE], B))
|
|
|
|
{
|
|
|
|
Advancement = 2;
|
|
|
|
T.Type = TOKEN_NULL;
|
|
|
|
string Char = { .Base = B->Ptr, .Length = 2 };
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(Result->File.Path);
|
|
|
|
ConfigError(&Filepath, Result->CurrentLine, S_WARNING, "Mismatched closing multiline comment marker: ", &Char);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_DOUBLEQUOTE], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_STRING;
|
|
|
|
++B->Ptr;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
while(B->Ptr - B->Location < B->Size && *B->Ptr != '"')
|
|
|
|
{
|
|
|
|
if(*B->Ptr == '\\')
|
|
|
|
{
|
|
|
|
++T.Content.Length;
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
++T.Content.Length;
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_MINUS], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_MINUS;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
++T.Content.Length;
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_ASSIGN], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_ASSIGN;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
++T.Content.Length;
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_OPEN_BRACE], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_OPEN_BRACE;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
++T.Content.Length;
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_CLOSE_BRACE], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_CLOSE_BRACE;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
++T.Content.Length;
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
|
|
|
else if(!StringsDifferS(TokenStrings[TOKEN_SEMICOLON], B))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_SEMICOLON;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
++T.Content.Length;
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
|
|
|
else if(IsValidIdentifierCharacter(*B->Ptr))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_IDENTIFIER;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
while(IsValidIdentifierCharacter(*B->Ptr))
|
|
|
|
{
|
|
|
|
++T.Content.Length;
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
Advancement = 0;
|
|
|
|
}
|
|
|
|
else if(IsNumber(*B->Ptr))
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_NUMBER;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
while(IsNumber(*B->Ptr))
|
|
|
|
{
|
|
|
|
++T.Content.Length;
|
|
|
|
++B->Ptr;
|
|
|
|
}
|
|
|
|
Advancement = 0;
|
|
|
|
}
|
|
|
|
else if(*B->Ptr == '\n')
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_NEWLINE;
|
|
|
|
T.Content.Base = B->Ptr;
|
|
|
|
T.Content.Length = 1;
|
|
|
|
++Result->CurrentLine;
|
|
|
|
Advancement = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
T.Type = TOKEN_NULL;
|
|
|
|
string Char = GetUTF8Character(B->Ptr, B->Size - (B->Ptr - B->Location));
|
|
|
|
Advancement = Char.Length;
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(Result->File.Path);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Char.Base)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Result->CurrentLine, S_WARNING, "Unhandled character (ignored): ", &Char);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorInt(&Filepath, Result->CurrentLine, S_WARNING, "Malformed UTF-8 bytes encountered (skipped): ", Char.Length);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PushToken(Result, &T);
|
|
|
|
Advance(B, Advancement);
|
|
|
|
SkipWhitespace(Result, B);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigError(0, 0, S_WARNING, "Unable to open config file: ", &Path);
|
|
|
|
}
|
|
|
|
Free(Path0);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TokenEquals(tokens *T, char *String)
|
|
|
|
{
|
|
|
|
int i = 0;
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
|
|
|
for(; i < This->Content.Length && *String && This->Content.Base[i] == String[i]; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
if(i == This->Content.Length && !String[i])
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TokenIs(tokens *T, token_type Type)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-05-24 23:26:13 +00:00
|
|
|
return(Type == This->Type);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ExpectToken(tokens *T, token_type Type, token *Dest)
|
|
|
|
{
|
|
|
|
bool Result = FALSE;
|
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-05-24 23:26:13 +00:00
|
|
|
if(Type == This->Type)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
Result = TRUE;
|
|
|
|
if(Dest)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
*Dest = *This;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Dest = 0;
|
|
|
|
ConfigErrorExpectation(T, Type, 0);
|
|
|
|
}
|
|
|
|
++T->CurrentIndex;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *FieldTypeNames[] =
|
|
|
|
{
|
|
|
|
"bare",
|
|
|
|
"boolean",
|
|
|
|
"number",
|
|
|
|
"scope",
|
|
|
|
"string",
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
FT_BARE,
|
|
|
|
FT_BOOLEAN,
|
|
|
|
FT_NUMBER,
|
|
|
|
FT_SCOPE,
|
|
|
|
FT_STRING,
|
|
|
|
} config_field_type;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
config_identifier_id ID;
|
|
|
|
config_field_type Type;
|
|
|
|
bool Singleton;
|
|
|
|
bool IsSetLocally;
|
|
|
|
} config_type_field;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
config_identifier_id ID;
|
|
|
|
bool Permeable;
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(config_type_field) Field;
|
2020-05-09 17:33:25 +00:00
|
|
|
} config_type_spec;
|
|
|
|
|
|
|
|
config_type_spec *
|
2020-05-24 23:26:13 +00:00
|
|
|
PushTypeSpec(memory_book *TypeSpecs, config_identifier_id ID, bool IsPermeable)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
//PrintFunctionName("PushTypeSpec()");
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_spec *Result = MakeSpaceInBook(TypeSpecs);
|
|
|
|
Result->ID = ID;
|
2020-06-24 12:29:18 +00:00
|
|
|
Result->Field = InitBook(MBT_CONFIG_TYPE_FIELD, 4);
|
2020-05-24 23:26:13 +00:00
|
|
|
Result->Permeable = IsPermeable;
|
2020-05-09 17:33:25 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushTypeSpecField(config_type_spec *Spec, config_field_type Type, config_identifier_id ID, bool Singleton)
|
|
|
|
{
|
|
|
|
//PrintFunctionName("PushTypeSpecField()");
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *This = MakeSpaceInBook(&Spec->Field);
|
|
|
|
This->Type = Type;
|
|
|
|
This->ID = ID;
|
|
|
|
This->Singleton = Singleton;
|
|
|
|
This->IsSetLocally = FALSE;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(config_type_specs)
|
2020-05-09 17:33:25 +00:00
|
|
|
InitTypeSpecs(void)
|
|
|
|
{
|
|
|
|
//PrintFunctionName("InitTypeSpecs()");
|
2020-06-24 12:29:18 +00:00
|
|
|
memory_book Result = InitBook(MBT_CONFIG_TYPE_SPEC, 16);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
config_type_spec *Root = PushTypeSpec(&Result, IDENT_NULL, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_ASSETS_ROOT_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_ASSETS_ROOT_URL, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_BASE_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_BASE_URL, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_CACHE_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_COHOST, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_CSS_PATH, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_DB_LOCATION, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_DEFAULT_MEDIUM, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GENRE, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GLOBAL_SEARCH_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GLOBAL_SEARCH_TEMPLATE, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GLOBAL_SEARCH_URL, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GLOBAL_TEMPLATES_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GLOBAL_THEME, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_GUEST, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_HMML_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_IMAGES_PATH, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_INDEXER, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_JS_PATH, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_LOG_LEVEL, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_NUMBERING_SCHEME, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_OWNER, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_PLAYER_LOCATION, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_PLAYER_TEMPLATE, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_QUERY_STRING, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_SEARCH_LOCATION, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_SEARCH_TEMPLATE, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_TEMPLATES_DIR, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_STREAM_USERNAME, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_VOD_PLATFORM, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_THEME, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_TITLE, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_HTML_TITLE, TRUE);
|
|
|
|
// TODO(matt): Sort out this title list stuff
|
|
|
|
//
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_TITLE_LIST_DELIMITER, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_TITLE_LIST_PREFIX, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_TITLE_LIST_SUFFIX, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_TITLE_SUFFIX, TRUE);
|
|
|
|
//
|
|
|
|
////
|
|
|
|
PushTypeSpecField(Root, FT_STRING, IDENT_UNIT, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_BARE, IDENT_TITLE_LIST_END, TRUE);
|
2020-05-17 01:04:26 +00:00
|
|
|
PushTypeSpecField(Root, FT_BOOLEAN, IDENT_DENY_BESPOKE_TEMPLATES, TRUE);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Root, FT_BOOLEAN, IDENT_IGNORE_PRIVACY, TRUE);
|
|
|
|
PushTypeSpecField(Root, FT_BOOLEAN, IDENT_SINGLE_BROWSER_TAB, TRUE);
|
2020-06-24 12:29:18 +00:00
|
|
|
PushTypeSpecField(Root, FT_BOOLEAN, IDENT_SUPPRESS_PROMPTS, TRUE);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Root, FT_NUMBER, IDENT_PRIVACY_CHECK_INTERVAL, TRUE);
|
2021-05-31 18:20:52 +00:00
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_CREDIT, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_INCLUDE, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_MEDIUM, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_PERSON, FALSE);
|
2021-05-30 18:39:47 +00:00
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_ROLE, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_PROJECT, FALSE);
|
|
|
|
PushTypeSpecField(Root, FT_SCOPE, IDENT_SUPPORT, FALSE);
|
|
|
|
|
|
|
|
config_type_spec *Support = PushTypeSpec(&Result, IDENT_SUPPORT, FALSE);
|
|
|
|
PushTypeSpecField(Support, FT_STRING, IDENT_ICON, TRUE);
|
|
|
|
PushTypeSpecField(Support, FT_STRING, IDENT_ICON_NORMAL, TRUE);
|
|
|
|
PushTypeSpecField(Support, FT_STRING, IDENT_ICON_FOCUSED, TRUE);
|
|
|
|
PushTypeSpecField(Support, FT_STRING, IDENT_ICON_TYPE, TRUE);
|
|
|
|
PushTypeSpecField(Support, FT_STRING, IDENT_ICON_VARIANTS, TRUE);
|
|
|
|
PushTypeSpecField(Support, FT_STRING, IDENT_URL, TRUE);
|
|
|
|
|
|
|
|
config_type_spec *Include = PushTypeSpec(&Result, IDENT_INCLUDE, FALSE);
|
|
|
|
PushTypeSpecField(Include, FT_STRING, IDENT_ALLOW, FALSE);
|
|
|
|
PushTypeSpecField(Include, FT_STRING, IDENT_DENY, FALSE);
|
|
|
|
|
|
|
|
config_type_spec *Person = PushTypeSpec(&Result, IDENT_PERSON, FALSE);
|
|
|
|
PushTypeSpecField(Person, FT_STRING, IDENT_NAME, TRUE);
|
|
|
|
PushTypeSpecField(Person, FT_STRING, IDENT_HOMEPAGE, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
PushTypeSpecField(Person, FT_STRING, IDENT_QUOTE_USERNAME, TRUE);
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Person, FT_SCOPE, IDENT_SUPPORT, FALSE);
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
config_type_spec *Role = PushTypeSpec(&Result, IDENT_ROLE, FALSE);
|
|
|
|
PushTypeSpecField(Role, FT_STRING, IDENT_NAME, TRUE);
|
|
|
|
PushTypeSpecField(Role, FT_STRING, IDENT_PLURAL, TRUE);
|
|
|
|
PushTypeSpecField(Role, FT_NUMBER, IDENT_POSITION, TRUE);
|
|
|
|
PushTypeSpecField(Role, FT_BOOLEAN, IDENT_NON_SPEAKING, TRUE);
|
|
|
|
|
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
config_type_spec *Credit = PushTypeSpec(&Result, IDENT_CREDIT, FALSE);
|
|
|
|
PushTypeSpecField(Credit, FT_STRING, IDENT_ROLE, FALSE);
|
|
|
|
#endif
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
config_type_spec *Medium = PushTypeSpec(&Result, IDENT_MEDIUM, FALSE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_ICON, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_ICON_NORMAL, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_ICON_FOCUSED, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_ICON_DISABLED, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_ICON_TYPE, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_ICON_VARIANTS, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_STRING, IDENT_NAME, TRUE);
|
|
|
|
PushTypeSpecField(Medium, FT_BOOLEAN, IDENT_HIDDEN, TRUE);
|
|
|
|
|
|
|
|
config_type_spec *Project = PushTypeSpec(&Result, IDENT_PROJECT, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_BASE_DIR, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_BASE_URL, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_COHOST, FALSE); // TODO(matt): Remove
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_DEFAULT_MEDIUM, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_GENRE, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_GUEST, FALSE); // TODO(matt): Remove
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_HMML_DIR, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_INDEXER, FALSE); // TODO(matt): Remove
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_NUMBERING_SCHEME, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_OWNER, TRUE); // NOTE(matt): Do not remove, because ResolveLocalVariable() recognises it
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_PLAYER_LOCATION, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_PLAYER_TEMPLATE, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_QUERY_STRING, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_SEARCH_LOCATION, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_SEARCH_TEMPLATE, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_TEMPLATES_DIR, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_STREAM_USERNAME, TRUE);
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_VOD_PLATFORM, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_THEME, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_TITLE, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_HTML_TITLE, TRUE);
|
|
|
|
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ART, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ART_VARIANTS, TRUE);
|
|
|
|
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ICON, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ICON_NORMAL, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ICON_FOCUSED, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ICON_DISABLED, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ICON_TYPE, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_ICON_VARIANTS, TRUE);
|
|
|
|
// TODO(matt): Sort out this title list stuff
|
|
|
|
//
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_TITLE_LIST_DELIMITER, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_TITLE_LIST_PREFIX, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_TITLE_LIST_SUFFIX, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_TITLE_SUFFIX, TRUE);
|
|
|
|
//
|
|
|
|
////
|
|
|
|
PushTypeSpecField(Project, FT_STRING, IDENT_UNIT, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_BARE, IDENT_TITLE_LIST_END, TRUE);
|
|
|
|
|
|
|
|
// NOTE(matt): Modes
|
2020-05-17 01:04:26 +00:00
|
|
|
PushTypeSpecField(Project, FT_BOOLEAN, IDENT_DENY_BESPOKE_TEMPLATES, TRUE);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_BOOLEAN, IDENT_IGNORE_PRIVACY, TRUE);
|
|
|
|
PushTypeSpecField(Project, FT_BOOLEAN, IDENT_SINGLE_BROWSER_TAB, TRUE);
|
|
|
|
//
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
PushTypeSpecField(Project, FT_SCOPE, IDENT_CREDIT, FALSE);
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
PushTypeSpecField(Project, FT_SCOPE, IDENT_INCLUDE, FALSE);
|
|
|
|
PushTypeSpecField(Project, FT_SCOPE, IDENT_MEDIUM, FALSE);
|
|
|
|
PushTypeSpecField(Project, FT_SCOPE, IDENT_PROJECT, FALSE);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintTypeField(config_type_field *F, config_identifier_id ParentScopeID, int IndentationLevel)
|
|
|
|
{
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[F->ID].String);
|
|
|
|
PrintC(CS_BLACK_BOLD, " [");
|
|
|
|
if(F->Type == FT_NUMBER)
|
|
|
|
{
|
|
|
|
PrintC(CS_BLUE_BOLD, FieldTypeNames[F->Type]);
|
|
|
|
}
|
|
|
|
else if(F->Type == FT_BARE)
|
|
|
|
{
|
|
|
|
PrintC(CS_BLUE, FieldTypeNames[F->Type]);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
Colourise(CS_GREEN_BOLD);
|
|
|
|
fprintf(stderr, "\"%s\"", FieldTypeNames[F->Type]);
|
|
|
|
Colourise(CS_END);
|
|
|
|
}
|
|
|
|
PrintC(CS_BLACK_BOLD, " • ");
|
|
|
|
if(F->Singleton)
|
|
|
|
{
|
|
|
|
PrintC(CS_CYAN, "single");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintC(CS_MAGENTA, "multi");
|
|
|
|
}
|
|
|
|
PrintC(CS_BLACK_BOLD, "]");
|
|
|
|
// TODO(matt): Consider preventing the description from being written if it had already been
|
|
|
|
// written for a higher-level scope
|
|
|
|
if(ConfigIdentifiers[F->ID].IdentifierDescription)
|
|
|
|
{
|
|
|
|
if((F->ID == IDENT_ICON || F->ID == IDENT_NAME) && ParentScopeID == IDENT_MEDIUM)
|
|
|
|
{
|
|
|
|
if(!ConfigIdentifiers[F->ID].IdentifierDescription_MediumDisplayed)
|
|
|
|
{
|
|
|
|
++IndentationLevel;
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
TypesetString(INDENT_WIDTH * IndentationLevel, Wrap0(ConfigIdentifiers[F->ID].IdentifierDescription_Medium));
|
|
|
|
ConfigIdentifiers[F->ID].IdentifierDescription_MediumDisplayed = TRUE;
|
|
|
|
--IndentationLevel;
|
|
|
|
}
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
else if((F->ID == IDENT_NAME) && ParentScopeID == IDENT_ROLE)
|
|
|
|
{
|
|
|
|
if(!ConfigIdentifiers[F->ID].IdentifierDescription_RoleDisplayed)
|
|
|
|
{
|
|
|
|
++IndentationLevel;
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
TypesetString(INDENT_WIDTH * IndentationLevel, Wrap0(ConfigIdentifiers[F->ID].IdentifierDescription_Role));
|
|
|
|
ConfigIdentifiers[F->ID].IdentifierDescription_RoleDisplayed = TRUE;
|
|
|
|
--IndentationLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
else if((F->ID == IDENT_ROLE) && ParentScopeID == IDENT_CREDIT)
|
|
|
|
{
|
|
|
|
if(!ConfigIdentifiers[F->ID].IdentifierDescription_CreditDisplayed)
|
|
|
|
{
|
|
|
|
++IndentationLevel;
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
TypesetString(INDENT_WIDTH * IndentationLevel, Wrap0(ConfigIdentifiers[F->ID].IdentifierDescription_Credit));
|
|
|
|
ConfigIdentifiers[F->ID].IdentifierDescription_CreditDisplayed = TRUE;
|
|
|
|
--IndentationLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!ConfigIdentifiers[F->ID].IdentifierDescriptionDisplayed)
|
|
|
|
{
|
|
|
|
++IndentationLevel;
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
TypesetString(INDENT_WIDTH * IndentationLevel, Wrap0(ConfigIdentifiers[F->ID].IdentifierDescription));
|
|
|
|
ConfigIdentifiers[F->ID].IdentifierDescriptionDisplayed = TRUE;
|
|
|
|
--IndentationLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintTypeSpec(config_type_spec *S, int IndentationLevel)
|
|
|
|
{
|
|
|
|
if(S->ID != IDENT_NULL)
|
|
|
|
{
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
++IndentationLevel;
|
|
|
|
PrintStringC(CS_CYAN, Wrap0(ConfigIdentifiers[S->ID].String));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ConfigIdentifiers[S->ID].IdentifierDescription && !ConfigIdentifiers[S->ID].IdentifierDescriptionDisplayed)
|
|
|
|
{
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
TypesetString(INDENT_WIDTH * IndentationLevel, Wrap0(ConfigIdentifiers[S->ID].IdentifierDescription));
|
|
|
|
ConfigIdentifiers[S->ID].IdentifierDescriptionDisplayed = TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < S->Field.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *This = GetPlaceInBook(&S->Field, i);
|
|
|
|
if(!(S->ID == IDENT_NULL && This->Type == FT_SCOPE))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintTypeField(This, S->ID, IndentationLevel);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(S->ID != IDENT_NULL) { --IndentationLevel; }
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintTypeSpecs(memory_book *TypeSpecs, int IndentationLevel)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
// TODO(matt): Document the fact that scopes within scopes are fully configurable, even though
|
|
|
|
// we only print out the "id" of scopes, omitting their containing fields
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < TypeSpecs->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintTypeSpec(GetPlaceInBook(TypeSpecs, i), IndentationLevel);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeTypeSpecs(memory_book *TypeSpecs)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < TypeSpecs->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_spec *This = GetPlaceInBook(TypeSpecs, i);
|
|
|
|
FreeBook(&This->Field);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(TypeSpecs);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *Filename;
|
|
|
|
uint64_t LineNumber;
|
|
|
|
} token_position;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
config_identifier_id Key;
|
|
|
|
string Value;
|
|
|
|
token_position Position;
|
|
|
|
} config_pair;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
config_identifier_id Key;
|
2021-05-30 18:39:47 +00:00
|
|
|
int64_t Value;
|
2020-05-09 17:33:25 +00:00
|
|
|
token_position Position;
|
|
|
|
} config_int_pair;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
config_identifier_id Key;
|
|
|
|
bool Value;
|
|
|
|
token_position Position;
|
|
|
|
} config_bool_pair;
|
|
|
|
|
|
|
|
typedef struct scope_tree
|
|
|
|
{
|
|
|
|
config_pair ID;
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(scope_tree) Trees;
|
|
|
|
_memory_book(config_pair) Pairs;
|
|
|
|
_memory_book(config_int_pair) IntPairs;
|
|
|
|
_memory_book(config_bool_pair) BoolPairs;
|
2020-05-09 17:33:25 +00:00
|
|
|
struct scope_tree *Parent;
|
|
|
|
config_type_spec TypeSpec;
|
|
|
|
//token_position Position; // NOTE(matt): We chose not to make ScopeTokens() set this value
|
|
|
|
} scope_tree;
|
|
|
|
|
|
|
|
config_type_spec *
|
2020-05-24 23:26:13 +00:00
|
|
|
GetTypeSpec(memory_book *TypeSpecs, config_identifier_id ID)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_spec *Result = 0;
|
|
|
|
for(int i = 0; i < TypeSpecs->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_spec *This = GetPlaceInBook(TypeSpecs, i);
|
|
|
|
if(This->ID == ID)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
SetTypeSpec(scope_tree *Type, memory_book *TypeSpecs)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
config_type_spec *Spec = GetTypeSpec(TypeSpecs, Type->ID.Key);
|
|
|
|
//PrintTypeSpec(Spec);
|
|
|
|
Type->TypeSpec.ID = Spec->ID;
|
|
|
|
Type->TypeSpec.Permeable = Spec->Permeable;
|
2020-06-24 12:29:18 +00:00
|
|
|
Type->TypeSpec.Field = InitBook(MBT_CONFIG_TYPE_FIELD, 4);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Spec->Field.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *Src = GetPlaceInBook(&Spec->Field, i);
|
|
|
|
config_type_field *Dest = MakeSpaceInBook(&Type->TypeSpec.Field);
|
|
|
|
|
|
|
|
Dest->Type = Src->Type;
|
|
|
|
Dest->ID = Src->ID;
|
|
|
|
Dest->Singleton = Src->Singleton;
|
|
|
|
Dest->IsSetLocally = Src->IsSetLocally;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config_type_field *
|
|
|
|
CurrentFieldIsInSpec(config_type_spec *Spec, tokens *T)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
config_type_field *Result = 0;
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Spec)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
token *Token = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
|
|
|
for(int i = 0; i < Spec->Field.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *Field = GetPlaceInBook(&Spec->Field, i);
|
|
|
|
if(!StringsDifferLv0(Token->Content, ConfigIdentifiers[Field->ID].String))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = Field;
|
2020-05-15 01:35:55 +00:00
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string Filename;
|
2020-05-24 23:26:13 +00:00
|
|
|
memory_book Allow;
|
|
|
|
memory_book Deny;
|
2020-05-09 17:33:25 +00:00
|
|
|
} config_include;
|
|
|
|
|
|
|
|
bool
|
2020-05-24 23:26:13 +00:00
|
|
|
ParseMultiStringAssignment(tokens *T, memory_book *Dest, config_type_field *Field)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
token Token = {};
|
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, &Token))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(!ExpectToken(T, TOKEN_STRING, &Token))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
string *This = MakeSpaceInBook(Dest);
|
|
|
|
*This = Token.Content;
|
2020-05-09 17:33:25 +00:00
|
|
|
|
|
|
|
Field->IsSetLocally = TRUE;
|
|
|
|
|
|
|
|
if(!ExpectToken(T, TOKEN_SEMICOLON, &Token))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintCurrentToken(colour_code C, tokens *T)
|
|
|
|
{
|
|
|
|
Colourise(C);
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintToken(GetPlaceInBook(&T->Token, T->CurrentIndex), T->CurrentIndex);
|
2020-05-09 17:33:25 +00:00
|
|
|
Colourise(CS_END);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DepartAssignment(tokens *T)
|
|
|
|
{
|
|
|
|
uint64_t ScopeLevel = 0;
|
|
|
|
do {
|
|
|
|
if(TokenIs(T, TOKEN_IDENTIFIER))
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, 0))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(TokenIs(T, TOKEN_STRING) || TokenIs(T, TOKEN_NUMBER))
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigErrorExpectation(T, TOKEN_STRING, TOKEN_NUMBER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(TokenIs(T, TOKEN_SEMICOLON))
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
|
|
|
else if(TokenIs(T, TOKEN_OPEN_BRACE))
|
|
|
|
{
|
|
|
|
++ScopeLevel;
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigErrorExpectation(T, TOKEN_SEMICOLON, TOKEN_OPEN_BRACE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(TokenIs(T, TOKEN_CLOSE_BRACE))
|
|
|
|
{
|
|
|
|
--ScopeLevel;
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigErrorExpectation(T, TOKEN_IDENTIFIER, TOKEN_CLOSE_BRACE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} while(ScopeLevel > 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DepartIncludeAssignment(tokens *T, uint64_t IncludeIdentifierTokenIndex)
|
|
|
|
{
|
|
|
|
T->CurrentIndex = IncludeIdentifierTokenIndex;
|
|
|
|
return(DepartAssignment(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeString(string *S)
|
|
|
|
{
|
|
|
|
Free(S->Base);
|
|
|
|
S->Length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeInclude(config_include *I)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&I->Allow);
|
|
|
|
FreeBook(&I->Deny);
|
2020-05-09 17:33:25 +00:00
|
|
|
free(I);
|
|
|
|
I = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsStringEmpty(string *S)
|
|
|
|
{
|
|
|
|
return S ? S->Length == 0 : TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeScopeTreeRecursively(scope_tree *T)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&T->Pairs);
|
|
|
|
FreeBook(&T->IntPairs);
|
|
|
|
FreeBook(&T->BoolPairs);
|
|
|
|
FreeBook(&T->TypeSpec.Field);
|
2020-05-09 17:33:25 +00:00
|
|
|
//Free(T->Position.Filename);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < T->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeScopeTreeRecursively(GetPlaceInBook(&T->Trees, i));
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&T->Trees);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeScopeTree(scope_tree *T)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&T->Pairs);
|
|
|
|
FreeBook(&T->IntPairs);
|
|
|
|
FreeBook(&T->BoolPairs);
|
|
|
|
FreeBook(&T->TypeSpec.Field);
|
2020-05-09 17:33:25 +00:00
|
|
|
//Free(T->Position.Filename);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < T->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeScopeTreeRecursively(GetPlaceInBook(&T->Trees, i));
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&T->Trees);
|
2020-05-09 17:33:25 +00:00
|
|
|
Free(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintPair(config_pair *P, char *Delimiter, bool FillSyntax, uint64_t Indentation, bool PrependNewline, bool AppendNewline)
|
|
|
|
{
|
|
|
|
if(PrependNewline) { fprintf(stderr, "\n"); }
|
|
|
|
Indent(Indentation);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[P->Key].String);
|
|
|
|
fprintf(stderr, "%s", Delimiter);
|
|
|
|
if(P->Value.Length)
|
|
|
|
{
|
|
|
|
Colourise(CS_GREEN_BOLD);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
PrintString(P->Value);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
Colourise(CS_END);
|
|
|
|
if(FillSyntax) { fprintf(stderr, ";"); }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW, "[unset]");
|
|
|
|
}
|
|
|
|
if(AppendNewline) { fprintf(stderr, "\n"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintScopeID(config_pair *P, char *Delimiter, uint64_t Indentation)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
Indent(Indentation);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[P->Key].String);
|
|
|
|
fprintf(stderr, "%s", Delimiter);
|
|
|
|
if(P->Value.Length)
|
|
|
|
{
|
|
|
|
Colourise(CS_GREEN_BOLD);
|
|
|
|
fprintf(stderr, "\"");
|
|
|
|
PrintString(P->Value);
|
|
|
|
fprintf(stderr, "\"");
|
|
|
|
Colourise(CS_END);
|
|
|
|
IndentedCarriageReturn(Indentation);
|
|
|
|
fprintf(stderr, "{");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW, "[unset]");
|
|
|
|
}
|
|
|
|
//fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintIntPair(config_int_pair *P, char *Delimiter, bool FillSyntax, uint64_t Indentation, bool PrependNewline, bool AppendNewline)
|
|
|
|
{
|
|
|
|
if(PrependNewline) { fprintf(stderr, "\n"); }
|
|
|
|
Indent(Indentation);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[P->Key].String);
|
|
|
|
fprintf(stderr, "%s", Delimiter);
|
|
|
|
switch(P->Key)
|
|
|
|
{
|
|
|
|
case IDENT_GENRE:
|
|
|
|
{
|
|
|
|
Colourise(CS_GREEN_BOLD);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
fprintf(stderr, "%s", GenreStrings[P->Value]);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
} break;
|
|
|
|
case IDENT_LOG_LEVEL:
|
|
|
|
{
|
|
|
|
Colourise(CS_GREEN_BOLD);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
fprintf(stderr, "%s", LogLevelStrings[P->Value]);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
} break;
|
|
|
|
case IDENT_NUMBERING_SCHEME:
|
|
|
|
{
|
|
|
|
Colourise(CS_GREEN_BOLD);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
fprintf(stderr, "%s", NumberingSchemeStrings[P->Value]);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Colourise(CS_BLUE_BOLD);
|
2021-05-30 18:39:47 +00:00
|
|
|
fprintf(stderr, "%li", P->Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
Colourise(CS_END);
|
|
|
|
if(FillSyntax) { fprintf(stderr, ";"); }
|
|
|
|
if(AppendNewline) { fprintf(stderr, "\n"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintBool(char *Title, bool Bool, char *Delimiter, bool FillSyntax, uint64_t Indentation, bool PrependNewline, bool AppendNewline)
|
|
|
|
{
|
|
|
|
if(PrependNewline) { fprintf(stderr, "\n"); }
|
|
|
|
Indent(Indentation);
|
|
|
|
PrintC(CS_YELLOW_BOLD, Title);
|
|
|
|
fprintf(stderr, "%s", Delimiter);
|
|
|
|
if(Bool == TRUE)
|
|
|
|
{
|
|
|
|
Colourise(CS_GREEN);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
fprintf(stderr, "true");
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Colourise(CS_RED);
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
fprintf(stderr, "false");
|
|
|
|
if(FillSyntax) { fprintf(stderr, "\""); }
|
|
|
|
}
|
|
|
|
Colourise(CS_END);
|
|
|
|
if(FillSyntax) { fprintf(stderr, ";"); }
|
|
|
|
if(AppendNewline) { fprintf(stderr, "\n"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintBoolPair(config_bool_pair *P, char *Delimiter, bool FillSyntax, uint64_t Indentation, bool PrependNewline, bool AppendNewline)
|
|
|
|
{
|
|
|
|
PrintBool(ConfigIdentifiers[P->Key].String, P->Value, Delimiter, FillSyntax, Indentation, PrependNewline, AppendNewline);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintScopeTree(scope_tree *T, int IndentationLevel);
|
|
|
|
void
|
|
|
|
PrintScopeTree(scope_tree *T, int IndentationLevel)
|
|
|
|
{
|
|
|
|
if(T)
|
|
|
|
{
|
|
|
|
if(T->ID.Key != IDENT_NULL)
|
|
|
|
{
|
|
|
|
PrintScopeID(&T->ID, " = ", IndentationLevel);
|
|
|
|
++IndentationLevel;
|
|
|
|
}
|
|
|
|
bool ShouldPrependNewline = TRUE;
|
|
|
|
bool ShouldFillSyntax = TRUE;
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < T->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintPair(GetPlaceInBook(&T->Pairs, i), " = ", ShouldFillSyntax, IndentationLevel, ShouldPrependNewline, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < T->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintIntPair(GetPlaceInBook(&T->IntPairs, i), " = ", ShouldFillSyntax, IndentationLevel, ShouldPrependNewline, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < T->BoolPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintBoolPair(GetPlaceInBook(&T->BoolPairs, i), " = ", ShouldFillSyntax, IndentationLevel, ShouldPrependNewline, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < T->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintScopeTree(GetPlaceInBook(&T->Trees, i), IndentationLevel);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
if(T->ID.Key != IDENT_NULL)
|
|
|
|
{
|
|
|
|
--IndentationLevel;
|
|
|
|
IndentedCarriageReturn(IndentationLevel);
|
|
|
|
fprintf(stderr, "}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushPair(scope_tree *Parent, config_pair *P)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *New = MakeSpaceInBook(&Parent->Pairs);
|
|
|
|
*New = *P;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
config_pair *
|
|
|
|
GetPair(scope_tree *Parent, config_identifier_id FieldID)
|
|
|
|
{
|
|
|
|
config_pair *Result = 0;
|
|
|
|
for(int i = 0; i < Parent->Pairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_pair *This = GetPlaceInBook(&Parent->Pairs, i);
|
|
|
|
if(This->Key == FieldID)
|
|
|
|
{
|
|
|
|
Result = This;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
|
|
|
PushIntPair(scope_tree *Parent, config_int_pair *I)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *New = MakeSpaceInBook(&Parent->IntPairs);
|
|
|
|
*New = *I;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
config_int_pair *
|
|
|
|
GetIntPair(scope_tree *Parent, config_identifier_id FieldID)
|
|
|
|
{
|
|
|
|
config_int_pair *Result = 0;
|
|
|
|
for(int i = 0; i < Parent->IntPairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_int_pair *This = GetPlaceInBook(&Parent->IntPairs, i);
|
|
|
|
if(This->Key == FieldID)
|
|
|
|
{
|
|
|
|
Result = This;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
|
|
|
PushBoolPair(scope_tree *Parent, config_bool_pair *B)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *New = MakeSpaceInBook(&Parent->BoolPairs);
|
|
|
|
*New = *B;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InitScopeBooks(scope_tree *Scope)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
Scope->Trees = InitBook(MBT_SCOPE_TREE, 4);
|
|
|
|
Scope->Pairs = InitBook(MBT_CONFIG_PAIR, 4);
|
|
|
|
Scope->IntPairs = InitBook(MBT_CONFIG_INT_PAIR, 4);
|
|
|
|
Scope->BoolPairs = InitBook(MBT_CONFIG_BOOL_PAIR, 4);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 17:12:54 +00:00
|
|
|
scope_tree *
|
|
|
|
InitRootScopeTree(void)
|
|
|
|
{
|
|
|
|
scope_tree *Result = calloc(1, sizeof(scope_tree));
|
|
|
|
InitScopeBooks(Result);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
scope_tree *
|
2020-05-24 23:26:13 +00:00
|
|
|
PushScope(memory_book *TypeSpecs, scope_tree *Parent, config_pair *ID)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *This = MakeSpaceInBook(&Parent->Trees);
|
|
|
|
InitScopeBooks(This);
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
This->ID = *ID;
|
|
|
|
SetTypeSpec(This, TypeSpecs);
|
|
|
|
This->Parent = Parent;
|
|
|
|
|
|
|
|
return(This);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_identifier_id
|
|
|
|
GetConfigIdentifierFromToken(token *T)
|
|
|
|
{
|
|
|
|
for(config_identifier_id i = 0; i < IDENT_COUNT; ++i)
|
|
|
|
{
|
|
|
|
if(!StringsDifferLv0(T->Content, ConfigIdentifiers[i].String))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IDENT_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_identifier_id
|
|
|
|
GetConfigIdentifierFromString(string S)
|
|
|
|
{
|
|
|
|
for(config_identifier_id i = 0; i < IDENT_COUNT; ++i)
|
|
|
|
{
|
|
|
|
if(!StringsDifferLv0(S, ConfigIdentifiers[i].String))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IDENT_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_type_field *
|
|
|
|
FieldIsInSpec(config_type_spec *Spec, config_identifier_id ID)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *Result = 0;
|
|
|
|
for(int i = 0; i < Spec->Field.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *This = GetPlaceInBook(&Spec->Field, i);
|
|
|
|
if(ID == This->ID)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PairsMatch(config_pair *A, config_pair *B)
|
|
|
|
{
|
|
|
|
return A->Key == B->Key && StringsMatch(A->Value, B->Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
scope_tree *
|
|
|
|
GetScope(scope_tree *T, config_pair *ID, bool Singleton)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *Result = 0;
|
|
|
|
for(int i = 0; i < T->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *This = GetPlaceInBook(&T->Trees, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Singleton)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
if(ID->Key == This->ID.Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
if(PairsMatch(ID, &This->ID))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_pair *
|
|
|
|
GetAssignment(scope_tree *T, config_pair *Assignment, bool Singleton)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *Result = 0;
|
|
|
|
for(int i = 0; i < T->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *This = GetPlaceInBook(&T->Pairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Singleton)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
if(Assignment->Key == This->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
if(PairsMatch(Assignment, This))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_int_pair *
|
|
|
|
GetIntAssignment(scope_tree *T, config_int_pair *Assignment, bool Singleton)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *Result = 0;
|
|
|
|
for(int i = 0; i < T->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *This = GetPlaceInBook(&T->IntPairs, i);
|
|
|
|
if(Assignment->Key == This->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
if(Singleton || Assignment->Value == This->Value)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_bool_pair *
|
|
|
|
GetBoolAssignment(scope_tree *T, config_bool_pair *Assignment, bool Singleton)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *Result = 0;
|
|
|
|
for(int i = 0; i < T->BoolPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *This = GetPlaceInBook(&T->BoolPairs, i);
|
|
|
|
if(Assignment->Key == This->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
if(Singleton || Assignment->Value == This->Value)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *CopyScope(memory_book *TypeSpecs, scope_tree *Dest, scope_tree *Src);
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
CopyScopeContents(memory_book *TypeSpecs, scope_tree *Dest, scope_tree *Src)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *Pair = GetPlaceInBook(&Src->Pairs, i);
|
|
|
|
PushPair(Dest, Pair);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *IntPair = GetPlaceInBook(&Src->IntPairs, i);
|
|
|
|
PushIntPair(Dest, IntPair);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->BoolPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *BoolPair = GetPlaceInBook(&Src->BoolPairs, i);
|
|
|
|
PushBoolPair(Dest, BoolPair);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *Tree = GetPlaceInBook(&Src->Trees, i);
|
|
|
|
CopyScope(TypeSpecs, Dest, Tree);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scope_tree *
|
2020-05-24 23:26:13 +00:00
|
|
|
CopyScope(memory_book *TypeSpecs, scope_tree *Dest, scope_tree *Src)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
Dest = PushScope(TypeSpecs, Dest, &Src->ID);
|
|
|
|
CopyScopeContents(TypeSpecs, Dest, Src);
|
|
|
|
return Dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
MergeScopes(memory_book *TypeSpecs, scope_tree *Dest, scope_tree *Src, bool Intergenerational)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
if(!Intergenerational || Dest->TypeSpec.Permeable)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *Pair = GetPlaceInBook(&Src->Pairs, i);
|
|
|
|
config_type_field *Field = FieldIsInSpec(&Dest->TypeSpec, Pair->Key);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Field)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *ThisAssignment = GetAssignment(Dest, Pair, Field->Singleton);
|
|
|
|
if(!ThisAssignment) { PushPair(Dest, Pair); }
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *IntPair = GetPlaceInBook(&Src->IntPairs, i);
|
|
|
|
config_type_field *Field = FieldIsInSpec(&Dest->TypeSpec, IntPair->Key);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Field)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *ThisAssignment = GetIntAssignment(Dest, IntPair, Field->Singleton);
|
|
|
|
if(!ThisAssignment) { PushIntPair(Dest, IntPair); }
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->BoolPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *BoolPair = GetPlaceInBook(&Src->BoolPairs, i);
|
|
|
|
config_type_field *Field = FieldIsInSpec(&Dest->TypeSpec, BoolPair->Key);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Field)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *ThisAssignment = GetBoolAssignment(Dest, BoolPair, Field->Singleton);
|
|
|
|
if(!ThisAssignment) { PushBoolPair(Dest, BoolPair); }
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Src->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *Tree = GetPlaceInBook(&Src->Trees, i);
|
|
|
|
config_type_field *Field = FieldIsInSpec(&Dest->TypeSpec, Tree->ID.Key);
|
|
|
|
if(Field && !(Intergenerational && Tree->ID.Key == Dest->ID.Key))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *ThisAssignment = GetScope(Dest, &Tree->ID, Field->Singleton);
|
|
|
|
if(!ThisAssignment) { CopyScope(TypeSpecs, Dest, Tree); }
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CRT_NULL,
|
|
|
|
CRT_ALLOW,
|
|
|
|
CRT_DENY,
|
|
|
|
} config_rule_type;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
config_rule_type Scheme;
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(config_identifier_id) ID;
|
2020-05-09 17:33:25 +00:00
|
|
|
} config_include_rules;
|
|
|
|
|
|
|
|
void
|
|
|
|
PushRule(config_include_rules *R, config_identifier_id ID)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < R->ID.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_identifier_id *This = GetPlaceInBook(&R->ID, i);
|
|
|
|
if(ID == *This)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
config_identifier_id *This = MakeSpaceInBook(&R->ID);
|
|
|
|
*This = ID;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-06-24 12:29:18 +00:00
|
|
|
ParseRuleString(string *Filename, memory_book *TypeSpecs, config_type_spec *ParentTypeSpec, config_include_rules *Rules, token *RuleString)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
int i = SkipWhitespaceS(&RuleString->Content, 0);
|
|
|
|
config_type_field *Field = 0;
|
|
|
|
for(; i < RuleString->Content.Length; i = SkipWhitespaceS(&RuleString->Content, i))
|
|
|
|
{
|
|
|
|
if(IsValidIdentifierCharacter(RuleString->Content.Base[i]))
|
|
|
|
{
|
|
|
|
string S = {};
|
|
|
|
S.Base = RuleString->Content.Base + i;
|
|
|
|
for(; i < RuleString->Content.Length && IsValidIdentifierCharacter(RuleString->Content.Base[i]); ++i)
|
|
|
|
{
|
|
|
|
++S.Length;
|
|
|
|
}
|
|
|
|
config_identifier_id ID;
|
|
|
|
if((ID = GetConfigIdentifierFromString(S)) != IDENT_NULL)
|
|
|
|
{
|
|
|
|
if((Field = FieldIsInSpec(ParentTypeSpec, ID)))
|
|
|
|
{
|
|
|
|
PushRule(Rules, ID);
|
|
|
|
if(i == RuleString->Content.Length && (ParentTypeSpec = GetTypeSpec(TypeSpecs, Field->ID)))
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int j = 0; j < ParentTypeSpec->Field.ItemCount; ++j)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *ParentField = GetPlaceInBook(&ParentTypeSpec->Field, j);
|
|
|
|
PushRule(Rules, ParentField->ID);
|
|
|
|
config_type_spec *ThisTypeSpec = GetTypeSpec(TypeSpecs, ParentField->ID);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(ThisTypeSpec)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int k = 0; k < ThisTypeSpec->Field.ItemCount; ++k)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *ThisField = GetPlaceInBook(&ThisTypeSpec->Field, k);
|
|
|
|
PushRule(Rules, ThisField->ID);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigError(Filename, RuleString->LineNumber, S_WARNING, "Field not in spec: ", &S);
|
|
|
|
PrintTypeSpec(ParentTypeSpec, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigError(Filename, RuleString->LineNumber, S_WARNING, "Unknown identifier: ", &S);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(RuleString->Content.Base[i] == '.')
|
|
|
|
{
|
|
|
|
if(Field)
|
|
|
|
{
|
|
|
|
ParentTypeSpec = GetTypeSpec(TypeSpecs, Field->ID);
|
|
|
|
++i;
|
|
|
|
if(!ParentTypeSpec)
|
|
|
|
{
|
|
|
|
string This = Wrap0(ConfigIdentifiers[Field->ID].String);
|
|
|
|
ConfigError(Filename, RuleString->LineNumber, S_WARNING, "Invalid permission, type has no members: ", &This);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigError(Filename, RuleString->LineNumber, S_WARNING, "Malformed rule string. \".\" must be preceded by a valid type", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string Char = GetUTF8Character(RuleString->Content.Base + i, RuleString->Content.Length - i);
|
|
|
|
ConfigError(Filename, RuleString->LineNumber, S_WARNING, "Invalid character in include rule: ", &Char);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc
|
2020-05-24 23:26:13 +00:00
|
|
|
ParseIncludeRules(memory_book *TypeSpecs, config_type_spec *ParentTypeSpec, tokens *T, config_include_rules *Rules)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
uint64_t IncludeIdentifierTokenIndex = T->CurrentIndex - 3;
|
|
|
|
if(TokenIs(T, TOKEN_SEMICOLON))
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
return RC_SUCCESS;
|
|
|
|
}
|
|
|
|
else if(TokenIs(T, TOKEN_OPEN_BRACE))
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
2020-05-15 01:35:55 +00:00
|
|
|
for(; T->CurrentIndex < T->Token.ItemCount;)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(T->File.Path);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(TokenIs(T, TOKEN_IDENTIFIER))
|
|
|
|
{
|
|
|
|
if(TokenEquals(T, "allow"))
|
|
|
|
{
|
|
|
|
if(Rules->Scheme == CRT_DENY)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&Rules->ID);
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_WARNING, "Mixture of allow and deny identifiers in \"include\" scope", 0);
|
2020-05-09 17:33:25 +00:00
|
|
|
return DepartIncludeAssignment(T, IncludeIdentifierTokenIndex) ? RC_SCHEME_MIXTURE : RC_SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
Rules->Scheme = CRT_ALLOW;
|
|
|
|
}
|
|
|
|
else if(TokenEquals(T, "deny"))
|
|
|
|
{
|
|
|
|
if(Rules->Scheme == CRT_ALLOW)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&Rules->ID);
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_WARNING, "Mixture of allow and deny identifiers in \"include\" scope", 0);
|
2020-05-09 17:33:25 +00:00
|
|
|
return DepartIncludeAssignment(T, IncludeIdentifierTokenIndex) ? RC_SCHEME_MIXTURE : RC_SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
Rules->Scheme = CRT_DENY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_WARNING, "Invalid identifier in \"include\" scope: ", &This->Content);
|
2020-05-09 17:33:25 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
" Valid identifiers:\n"
|
|
|
|
" allow\n"
|
|
|
|
" deny\n");
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&Rules->ID);
|
2020-05-09 17:33:25 +00:00
|
|
|
return DepartIncludeAssignment(T, IncludeIdentifierTokenIndex) ? RC_INVALID_IDENTIFIER : RC_SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
++T->CurrentIndex;
|
2020-05-24 23:26:13 +00:00
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, 0)) { FreeBook(&Rules->ID); return RC_SYNTAX_ERROR; }
|
2020-05-09 17:33:25 +00:00
|
|
|
token RuleString = {};
|
2020-05-24 23:26:13 +00:00
|
|
|
if(!ExpectToken(T, TOKEN_STRING, &RuleString)) { FreeBook(&Rules->ID); return RC_SYNTAX_ERROR; }
|
2020-06-24 12:29:18 +00:00
|
|
|
ParseRuleString(&Filepath, TypeSpecs, ParentTypeSpec, Rules, &RuleString);
|
2020-05-24 23:26:13 +00:00
|
|
|
if(!ExpectToken(T, TOKEN_SEMICOLON, 0)) { FreeBook(&Rules->ID); return RC_SYNTAX_ERROR; }
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else if(TokenIs(T, TOKEN_CLOSE_BRACE))
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
return RC_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&Rules->ID);
|
2020-05-09 17:33:25 +00:00
|
|
|
return RC_SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&Rules->ID);
|
2020-05-09 17:33:25 +00:00
|
|
|
ConfigErrorExpectation(T, TOKEN_SEMICOLON, TOKEN_OPEN_BRACE);
|
|
|
|
return RC_SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
return RC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FieldIsPermitted(config_include_rules *Rules, config_type_field *Field)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Rules->ID.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_identifier_id *This = GetPlaceInBook(&Rules->ID, i);
|
|
|
|
if(Field->ID == *This)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
return Rules->Scheme == CRT_ALLOW ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Rules->Scheme == CRT_ALLOW ? FALSE : TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResetFields(config_type_spec *S)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < S->Field.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_type_field *This = GetPlaceInBook(&S->Field, i);
|
|
|
|
This->IsSetLocally = FALSE;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scope_tree *
|
2020-05-24 23:26:13 +00:00
|
|
|
PushDefaultScope(memory_book *TypeSpecs, scope_tree *Parent, config_identifier_id Key, string Value)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
config_pair ID = { .Key = Key, .Value = Value };
|
|
|
|
return PushScope(TypeSpecs, Parent, &ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushDefaultPair(scope_tree *Parent, config_identifier_id Key, string Value)
|
|
|
|
{
|
|
|
|
config_pair Pair = { .Key = Key, .Value = Value };
|
|
|
|
return PushPair(Parent, &Pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushDefaultIntPair(scope_tree *Parent, config_identifier_id Key, uint64_t Value)
|
|
|
|
{
|
|
|
|
config_int_pair IntPair = { .Key = Key, .Value = Value };
|
|
|
|
return PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
void
|
|
|
|
PushDefaultBoolPair(scope_tree *Parent, config_identifier_id Key, bool Value)
|
|
|
|
{
|
|
|
|
config_bool_pair BoolPair = { .Key = Key, .Value = Value };
|
|
|
|
return PushBoolPair(Parent, &BoolPair);
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
#define DEFAULT_PRIVACY_CHECK_INTERVAL 60 * 4
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
SetDefaults(scope_tree *Root, memory_book *TypeSpecs)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
scope_tree *SupportPatreon = PushDefaultScope(TypeSpecs, Root, IDENT_SUPPORT, Wrap0("patreon"));
|
|
|
|
PushDefaultPair(SupportPatreon, IDENT_ICON, Wrap0("cinera_sprite_patreon.png"));
|
|
|
|
PushDefaultIntPair(SupportPatreon, IDENT_ICON_TYPE, IT_GRAPHICAL);
|
|
|
|
PushDefaultIntPair(SupportPatreon, IDENT_ICON_VARIANTS, GetArtVariantFromString(Wrap0("normal")));
|
|
|
|
PushDefaultPair(SupportPatreon, IDENT_URL, Wrap0("https://patreon.com/$person"));
|
|
|
|
|
|
|
|
scope_tree *SupportSendOwl = PushDefaultScope(TypeSpecs, Root, IDENT_SUPPORT, Wrap0("sendowl"));
|
|
|
|
PushDefaultPair(SupportSendOwl, IDENT_ICON, Wrap0("cinera_sprite_sendowl.png"));
|
|
|
|
|
|
|
|
scope_tree *MediumAuthored = PushDefaultScope(TypeSpecs, Root, IDENT_MEDIUM, Wrap0("authored"));
|
|
|
|
PushDefaultPair(MediumAuthored, IDENT_ICON, Wrap0("🗪"));
|
|
|
|
PushDefaultPair(MediumAuthored, IDENT_NAME, Wrap0("Chat Comment"));
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
scope_tree *RoleIndexer = PushDefaultScope(TypeSpecs, Root, IDENT_ROLE, Wrap0("indexer"));
|
|
|
|
PushDefaultPair(RoleIndexer, IDENT_NAME, Wrap0("Indexer"));
|
|
|
|
PushDefaultBoolPair(RoleIndexer, IDENT_NON_SPEAKING, TRUE);
|
|
|
|
PushDefaultIntPair(RoleIndexer, IDENT_POSITION, -1);
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
PushDefaultPair(Root, IDENT_QUERY_STRING, Wrap0("r"));
|
|
|
|
PushDefaultPair(Root, IDENT_THEME, Wrap0("$origin"));
|
|
|
|
PushDefaultPair(Root, IDENT_CACHE_DIR, Wrap0("$XDG_CACHE_HOME/cinera"));
|
|
|
|
PushDefaultPair(Root, IDENT_DB_LOCATION, Wrap0("$XDG_CONFIG_HOME/cinera/cinera.db"));
|
|
|
|
|
|
|
|
// TODO(matt): Consider where the genre setting should apply, project vs entry level
|
|
|
|
PushDefaultIntPair(Root, IDENT_GENRE, GENRE_VIDEO);
|
|
|
|
PushDefaultIntPair(Root, IDENT_NUMBERING_SCHEME, NS_LINEAR);
|
|
|
|
PushDefaultIntPair(Root, IDENT_PRIVACY_CHECK_INTERVAL, DEFAULT_PRIVACY_CHECK_INTERVAL);
|
|
|
|
PushDefaultIntPair(Root, IDENT_LOG_LEVEL, LOG_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
scope_tree *
|
2020-05-24 23:26:13 +00:00
|
|
|
ScopeTokens(scope_tree *Tree, memory_book *TokensList, tokens *T, memory_book *TypeSpecs, config_include_rules *Rules)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
scope_tree *Parent = Tree;
|
2020-05-15 01:35:55 +00:00
|
|
|
for(T->CurrentIndex = 0; T->CurrentIndex < T->Token.ItemCount;)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(T->File.Path);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(TokenIs(T, TOKEN_IDENTIFIER))
|
|
|
|
{
|
|
|
|
config_type_field *Field = CurrentFieldIsInSpec(&Parent->TypeSpec, T);
|
|
|
|
if(Field)
|
|
|
|
{
|
|
|
|
if(!Rules || FieldIsPermitted(Rules, Field))
|
|
|
|
{
|
|
|
|
if(Field->IsSetLocally && Field->Singleton)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_WARNING, "Field already set: ", &This->Content);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
// NOTE(matt): If we get rid of FT_BARE, then the ++T->CurrentIndex that all cases perform could happen
|
|
|
|
// right here
|
|
|
|
config_pair Pair = {};
|
|
|
|
config_int_pair IntPair = {};
|
|
|
|
config_bool_pair BoolPair = {};
|
|
|
|
|
|
|
|
Pair.Key = IntPair.Key = BoolPair.Key = Field->ID;
|
|
|
|
Pair.Position.Filename = IntPair.Position.Filename = BoolPair.Position.Filename = T->File.Path;
|
|
|
|
|
|
|
|
switch(Field->Type)
|
|
|
|
{
|
|
|
|
case FT_BARE:
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
|
|
|
token Value = *This;
|
2020-05-09 17:33:25 +00:00
|
|
|
Pair.Position.LineNumber = Value.LineNumber;
|
|
|
|
|
|
|
|
++T->CurrentIndex;
|
|
|
|
if(!ExpectToken(T, TOKEN_SEMICOLON, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
config_pair *Assignment = 0;
|
|
|
|
if(!(Assignment = GetAssignment(Parent, &Pair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
PushPair(Parent, &Pair);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case FT_BOOLEAN:
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
|
|
|
|
token Value = {};
|
|
|
|
if(!ExpectToken(T, TOKEN_STRING, &Value)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
BoolPair.Position.LineNumber = Value.LineNumber;
|
|
|
|
|
|
|
|
if(!ExpectToken(T, TOKEN_SEMICOLON, 0)) { FreeScopeTree(Tree); return 0; }
|
2020-06-24 12:29:18 +00:00
|
|
|
bool Bool = GetBoolFromString(&Filepath, &Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Bool != -1)
|
|
|
|
{
|
|
|
|
BoolPair.Value = Bool;
|
|
|
|
config_bool_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetBoolAssignment(Parent, &BoolPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = BoolPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushBoolPair(Parent, &BoolPair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { FreeScopeTree(Tree); return 0; }
|
|
|
|
} break;
|
|
|
|
case FT_STRING:
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
|
|
|
|
token Value = {};
|
|
|
|
if(!ExpectToken(T, TOKEN_STRING, &Value)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
Pair.Position.LineNumber = Value.LineNumber;
|
|
|
|
IntPair.Position.LineNumber = Value.LineNumber;
|
|
|
|
|
|
|
|
if(!ExpectToken(T, TOKEN_SEMICOLON, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
|
|
|
|
if(Field->ID == IDENT_NUMBERING_SCHEME)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
numbering_scheme NumberingScheme = GetNumberingSchemeFromString(&Filepath, &Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(NumberingScheme != NS_COUNT)
|
|
|
|
{
|
|
|
|
IntPair.Value = NumberingScheme;
|
|
|
|
config_int_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetIntAssignment(Parent, &IntPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = IntPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { FreeScopeTree(Tree); return 0; }
|
|
|
|
}
|
|
|
|
else if(Field->ID == IDENT_LOG_LEVEL)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
log_level LogLevel = GetLogLevelFromString(&Filepath, &Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(LogLevel != LOG_COUNT)
|
|
|
|
{
|
|
|
|
IntPair.Value = LogLevel;
|
|
|
|
config_int_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetIntAssignment(Parent, &IntPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = IntPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { FreeScopeTree(Tree); return 0; }
|
|
|
|
}
|
|
|
|
else if(Field->ID == IDENT_GENRE)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
genre Genre = GetGenreFromString(&Filepath, &Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Genre != GENRE_COUNT)
|
|
|
|
{
|
|
|
|
IntPair.Value = Genre;
|
|
|
|
config_int_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetIntAssignment(Parent, &IntPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = IntPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { FreeScopeTree(Tree); return 0; }
|
|
|
|
}
|
|
|
|
else if(Field->ID == IDENT_ICON_TYPE)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
icon_type IconType = GetIconTypeFromString(&Filepath, &Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(IconType != IT_COUNT)
|
|
|
|
{
|
|
|
|
IntPair.Value = IconType;
|
|
|
|
config_int_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetIntAssignment(Parent, &IntPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = IntPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { FreeScopeTree(Tree); return 0; }
|
|
|
|
}
|
|
|
|
else if(Field->ID == IDENT_ART_VARIANTS || Field->ID == IDENT_ICON_VARIANTS)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
int64_t ArtVariants = ParseArtVariantsString(&Filepath, &Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(ArtVariants != -1)
|
|
|
|
{
|
|
|
|
IntPair.Value = ArtVariants;
|
|
|
|
config_int_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetIntAssignment(Parent, &IntPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = IntPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { FreeScopeTree(Tree); return 0; }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pair.Value = Value.Content;
|
|
|
|
config_pair *Assignment = 0;
|
|
|
|
|
|
|
|
if((Assignment = GetAssignment(Parent, &Pair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = Pair.Value;
|
|
|
|
Assignment->Position.LineNumber = Pair.Position.LineNumber;
|
|
|
|
Assignment->Position.Filename = Pair.Position.Filename;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushPair(Parent, &Pair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case FT_NUMBER:
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
|
|
|
|
token Value = {};
|
2021-05-30 18:39:47 +00:00
|
|
|
bool IsNegative = FALSE;
|
|
|
|
if(TokenIs(T, TOKEN_MINUS))
|
|
|
|
{
|
|
|
|
IsNegative = TRUE;
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
if(!ExpectToken(T, TOKEN_NUMBER, &Value)) { FreeScopeTree(Tree); return 0; }
|
2021-05-30 18:39:47 +00:00
|
|
|
IntPair.Value = IsNegative ? 0 - Value.int64_t : Value.int64_t;
|
2020-05-09 17:33:25 +00:00
|
|
|
|
|
|
|
if(!ExpectToken(T, TOKEN_SEMICOLON, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
|
|
|
|
config_int_pair *Assignment = 0;
|
|
|
|
if((Assignment = GetIntAssignment(Parent, &IntPair, Field->Singleton)))
|
|
|
|
{
|
|
|
|
Assignment->Value = IntPair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushIntPair(Parent, &IntPair);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case FT_SCOPE:
|
|
|
|
{
|
|
|
|
++T->CurrentIndex;
|
|
|
|
if(!ExpectToken(T, TOKEN_ASSIGN, 0)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
|
|
|
|
token Value = {};
|
|
|
|
if(!ExpectToken(T, TOKEN_STRING, &Value)) { FreeScopeTree(Tree); return 0; }
|
|
|
|
Pair.Value = Value.Content;
|
|
|
|
Pair.Position.LineNumber = Value.LineNumber;
|
|
|
|
|
|
|
|
if(Field->ID == IDENT_INCLUDE)
|
|
|
|
{
|
|
|
|
int IncludePathTokenIndex = T->CurrentIndex - 1;
|
|
|
|
config_include_rules Rules = {};
|
2020-06-24 12:29:18 +00:00
|
|
|
Rules.ID = InitBook(MBT_CONFIG_IDENTIFIER_ID, 4);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(ParseIncludeRules(TypeSpecs, &Parent->TypeSpec, T, &Rules))
|
|
|
|
{
|
|
|
|
case RC_SUCCESS:
|
|
|
|
{
|
|
|
|
string IncluderFilePath = Wrap0(T->File.Path);
|
|
|
|
char *IncludePath = ExpandPath(Pair.Value, &IncluderFilePath);
|
2020-06-24 15:22:50 +00:00
|
|
|
if(IncludePath)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 15:22:50 +00:00
|
|
|
string IncludePathL = Wrap0(IncludePath);
|
|
|
|
|
|
|
|
tokens *I = 0;
|
|
|
|
for(int i = 0; i < TokensList->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 15:22:50 +00:00
|
|
|
tokens *This = GetPlaceInBook(TokensList, i);
|
|
|
|
if(!StringsDifferLv0(Value.Content, This->File.Path))
|
|
|
|
{
|
|
|
|
I = This;
|
|
|
|
I->CurrentIndex = 0;
|
|
|
|
I->CurrentLine = 0;
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-06-24 15:22:50 +00:00
|
|
|
if(!I)
|
|
|
|
{
|
|
|
|
I = Tokenise(TokensList, IncludePathL);
|
|
|
|
}
|
|
|
|
if(I)
|
|
|
|
{
|
|
|
|
Parent = ScopeTokens(Parent, TokensList, I, TypeSpecs, &Rules);
|
|
|
|
FreeBook(&Rules.ID);
|
|
|
|
if(!Parent)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 15:22:50 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, IncludePathTokenIndex);
|
|
|
|
ConfigFileIncludeError(&Filepath, This->LineNumber, Wrap0(IncludePath));
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-06-24 15:22:50 +00:00
|
|
|
Free(IncludePath);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-24 15:22:50 +00:00
|
|
|
ConfigError(&IncluderFilePath, Pair.Position.LineNumber, S_WARNING, "Unable to include file: ", &Pair.Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case RC_SYNTAX_ERROR:
|
|
|
|
{
|
|
|
|
FreeScopeTree(Tree); return 0;
|
|
|
|
} break;
|
2021-05-30 18:39:47 +00:00
|
|
|
case RC_SCHEME_MIXTURE:
|
2020-05-09 17:33:25 +00:00
|
|
|
case RC_INVALID_IDENTIFIER:
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
// TODO(matt): Here is probably where we must fix deduplication of support scopes
|
2020-05-09 17:33:25 +00:00
|
|
|
scope_tree *Search = 0;
|
2020-05-15 01:35:55 +00:00
|
|
|
bool SelfContained = FALSE;
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Field->ID == IDENT_SUPPORT)
|
|
|
|
{
|
|
|
|
scope_tree *ParentP = Parent;
|
|
|
|
Search = GetScope(ParentP, &Pair, Field->Singleton);
|
2020-05-15 01:35:55 +00:00
|
|
|
if(Search) { SelfContained = TRUE; }
|
2020-05-09 17:33:25 +00:00
|
|
|
while(!Search && ParentP->Parent)
|
|
|
|
{
|
|
|
|
ParentP = ParentP->Parent;
|
|
|
|
Search = GetScope(ParentP, &Pair, Field->Singleton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Search = GetScope(Parent, &Pair, Field->Singleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(Search)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
if(Field->ID == IDENT_SUPPORT && !SelfContained)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
Parent = CopyScope(TypeSpecs, Parent, Search);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Parent = Search;
|
|
|
|
MergeScopes(TypeSpecs, Parent, Parent->Parent, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Parent = PushScope(TypeSpecs, Parent, &Pair);
|
|
|
|
if(Parent->ID.Key == IDENT_MEDIUM)
|
|
|
|
{
|
|
|
|
config_bool_pair Hidden = {};
|
|
|
|
Hidden.Key = IDENT_HIDDEN;
|
|
|
|
Hidden.Value = FALSE;
|
|
|
|
PushBoolPair(Parent, &Hidden);
|
|
|
|
}
|
|
|
|
MergeScopes(TypeSpecs, Parent, Parent->Parent, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResetFields(&Parent->TypeSpec);
|
|
|
|
|
|
|
|
if(TokenIs(T, TOKEN_SEMICOLON))
|
|
|
|
{
|
|
|
|
Parent = Parent->Parent;
|
|
|
|
}
|
|
|
|
else if(TokenIs(T, TOKEN_OPEN_BRACE))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigErrorExpectation(T, TOKEN_SEMICOLON, TOKEN_OPEN_BRACE);
|
|
|
|
FreeScopeTree(Tree); return 0;
|
|
|
|
}
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
// NOTE(matt): This may not be appropriate for the IDENT_INCLUDE...
|
|
|
|
Field->IsSetLocally = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_WARNING, "Field not allowed: ", &This->Content);
|
2020-05-09 17:33:25 +00:00
|
|
|
DepartAssignment(T);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_WARNING, "Invalid field: ", &This->Content);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(!DepartAssignment(T))
|
|
|
|
{
|
|
|
|
FreeScopeTree(Tree);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(TokenIs(T, TOKEN_CLOSE_BRACE))
|
|
|
|
{
|
|
|
|
if(!Parent->Parent)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
token *This = GetPlaceInBook(&T->Token, T->CurrentIndex);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, This->LineNumber, S_ERROR, "Syntax error: Unpaired closing brace", 0);
|
2020-05-09 17:33:25 +00:00
|
|
|
FreeScopeTree(Tree);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Parent = Parent->Parent;
|
|
|
|
++T->CurrentIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigErrorExpectation(T, TOKEN_IDENTIFIER, TOKEN_CLOSE_BRACE);
|
|
|
|
FreeScopeTree(Tree);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(matt): Fully nail down the title list stuff. Perhaps, make the title_list_end; identifier somehow indicate to child
|
|
|
|
// scopes that they should not absorb any title_list stuff...
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
token_position Position;
|
|
|
|
config_identifier_id Variable;
|
|
|
|
} resolution_error;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(resolution_error) Errors;
|
|
|
|
_memory_book(resolution_error) Warnings;
|
2020-05-09 17:33:25 +00:00
|
|
|
} resolution_errors;
|
|
|
|
|
|
|
|
void
|
|
|
|
PushError(resolution_errors *E, severity Severity, token_position *Position, config_identifier_id Variable)
|
|
|
|
{
|
|
|
|
if(Severity == S_WARNING)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
resolution_error *This = MakeSpaceInBook(&E->Warnings);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Position)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
This->Position = *Position;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
This->Variable = Variable;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
resolution_error *This = MakeSpaceInBook(&E->Errors);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Position)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
This->Position = *Position;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
This->Variable = Variable;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resolution_error *
|
|
|
|
GetError(resolution_errors *E, severity Severity, token_position *Position, config_identifier_id Variable)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
resolution_error *Result = 0;
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Severity == S_WARNING)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < E->Warnings.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
resolution_error *This = GetPlaceInBook(&E->Warnings, i);
|
|
|
|
if(Position->Filename == This->Position.Filename &&
|
|
|
|
Position->LineNumber == This->Position.LineNumber &&
|
|
|
|
Variable == This->Variable)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < E->Errors.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
resolution_error *This = GetPlaceInBook(&E->Errors, i);
|
|
|
|
if(Position->Filename == This->Position.Filename &&
|
|
|
|
Position->LineNumber == This->Position.LineNumber &&
|
|
|
|
Variable == This->Variable)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeErrors(resolution_errors *E)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeAndReinitialiseBook(&E->Errors);
|
|
|
|
FreeAndReinitialiseBook(&E->Warnings);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
ResolveEnvironmentVariable(memory_book *M, string Variable)
|
|
|
|
{
|
|
|
|
string Result = {};
|
|
|
|
int DollarCharacterBytes = 1;
|
|
|
|
int NullTerminationBytes = 1;
|
|
|
|
// NOTE(matt): Stack-string
|
|
|
|
char Variable0[DollarCharacterBytes + Variable.Length + NullTerminationBytes];
|
|
|
|
char *Ptr = Variable0;
|
|
|
|
if(!StringsMatch(Variable, Wrap0("~")))
|
|
|
|
{
|
|
|
|
*Ptr++ = '$';
|
|
|
|
}
|
|
|
|
for(int i = 0; i < Variable.Length; ++i)
|
|
|
|
{
|
|
|
|
*Ptr++ = Variable.Base[i];
|
|
|
|
}
|
|
|
|
*Ptr = '\0';
|
|
|
|
int Flags = WRDE_NOCMD | WRDE_UNDEF | WRDE_APPEND;
|
|
|
|
wordexp_t Expansions = {};
|
|
|
|
wordexp(Variable0, &Expansions, Flags);
|
|
|
|
if(Expansions.we_wordc > 0)
|
|
|
|
{
|
|
|
|
Result = ExtendStringInBook(M, Wrap0(Expansions.we_wordv[0]));
|
|
|
|
}
|
|
|
|
wordfree(&Expansions);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
role *
|
|
|
|
GetRole(config *C, resolution_errors *E, config_pair *RoleID)
|
|
|
|
{
|
|
|
|
role *Result = 0;
|
|
|
|
for(int i = 0; i < C->Role.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
role *Role = GetPlaceInBook(&C->Role, i);
|
|
|
|
if(!StringsDifferCaseInsensitive(Role->ID, RoleID->Value))
|
|
|
|
{
|
|
|
|
Result = Role;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!Result && !GetError(E, S_WARNING, &RoleID->Position, IDENT_ROLE))
|
|
|
|
{
|
|
|
|
string Filepath = Wrap0(RoleID->Position.Filename);
|
|
|
|
ConfigError(&Filepath, RoleID->Position.LineNumber, S_WARNING, "Could not find role: ", &RoleID->Value);
|
|
|
|
PushError(E, S_WARNING, &RoleID->Position, IDENT_ROLE);
|
2021-05-31 18:20:52 +00:00
|
|
|
WaitForInput();
|
2021-05-30 18:39:47 +00:00
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
role *
|
|
|
|
GetRoleByID(config *C, string ID)
|
|
|
|
{
|
|
|
|
role *Result = 0;
|
|
|
|
for(int i = 0; i < C->Role.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
role *Role = GetPlaceInBook(&C->Role, i);
|
|
|
|
if(!StringsDifferCaseInsensitive(Role->ID, ID))
|
|
|
|
{
|
|
|
|
Result = Role;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-05-31 18:20:52 +00:00
|
|
|
|
|
|
|
if(!Result)
|
|
|
|
{
|
|
|
|
ConfigError(0, 0, S_WARNING, "Could not find role: ", &ID);
|
|
|
|
WaitForInput();
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
person *
|
|
|
|
GetPerson(config *C, resolution_errors *E, config_pair *PersonID)
|
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
person *Result = 0;
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < C->Person.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
person *Person = GetPlaceInBook(&C->Person, i);
|
|
|
|
if(!StringsDifferCaseInsensitive(Person->ID, PersonID->Value))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
Result = Person;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
if(!Result && !GetError(E, S_WARNING, &PersonID->Position, IDENT_PERSON))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(PersonID->Position.Filename);
|
|
|
|
ConfigError(&Filepath, PersonID->Position.LineNumber, S_WARNING, "Could not find person: ", &PersonID->Value);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, &PersonID->Position, IDENT_PERSON);
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
DeriveLineageOfProject(config *C, scope_tree *Project)
|
|
|
|
{
|
|
|
|
string Result = {};
|
2020-06-24 12:29:18 +00:00
|
|
|
memory_book StringList = InitBookOfPointers(MBT_STRING_PTR, 4);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Project)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
string **Writer = MakeSpaceInBook(&StringList);
|
|
|
|
*Writer = &Project->ID.Value;
|
2020-05-09 17:33:25 +00:00
|
|
|
Project = Project->Parent;
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
string Slash = Wrap0("/");
|
2020-05-09 17:33:25 +00:00
|
|
|
while(Project && Project->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
string **Writer = MakeSpaceInBook(&StringList);
|
|
|
|
*Writer = &Slash;
|
|
|
|
|
|
|
|
Writer = MakeSpaceInBook(&StringList);
|
|
|
|
*Writer = &Project->ID.Value;
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
Project = Project->Parent;
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = StringList.ItemCount - 1; i >= 0; --i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
string **Reader = GetPlaceInBook(&StringList, i);
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, **Reader);;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&StringList);
|
2020-05-09 17:33:25 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
EmptyString(void)
|
|
|
|
{
|
|
|
|
string Result = {};
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
DeriveLineageWithoutOriginOfProject(config *C, scope_tree *Project)
|
|
|
|
{
|
|
|
|
string Result = {};
|
2021-01-25 18:09:30 +00:00
|
|
|
memory_book StringList = InitBookOfPointers(MBT_STRING_PTR, 4);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Project->Parent && Project->Parent->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
string **Writer = MakeSpaceInBook(&StringList);
|
|
|
|
*Writer = &Project->ID.Value;
|
2020-05-09 17:33:25 +00:00
|
|
|
Project = Project->Parent;
|
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
string Slash = Wrap0("/");
|
2020-05-09 17:33:25 +00:00
|
|
|
while(Project->Parent && Project->Parent->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
string **Writer = MakeSpaceInBook(&StringList);
|
|
|
|
*Writer = &Slash;
|
|
|
|
|
|
|
|
Writer = MakeSpaceInBook(&StringList);
|
|
|
|
*Writer = &Project->ID.Value;
|
2020-05-09 17:33:25 +00:00
|
|
|
Project = Project->Parent;
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
if(StringList.ItemCount > 0)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = StringList.ItemCount - 1; i >= 0; --i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
string **Reader = GetPlaceInBook(&StringList, i);
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, **Reader);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&StringList);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, EmptyString());
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
ResolveLocalVariable(config *C, resolution_errors *E, scope_tree *Scope, config_identifier_id Variable, token_position *Position)
|
|
|
|
{
|
|
|
|
string Result = {};
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(Position->Filename);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(Variable)
|
|
|
|
{
|
|
|
|
case IDENT_LINEAGE:
|
|
|
|
{
|
|
|
|
if(Scope->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
|
|
|
Result = DeriveLineageOfProject(C, Scope);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string This = Wrap0(ConfigIdentifiers[Variable].String);
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "Variable could not be resolved: ", &This);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_LINEAGE_WITHOUT_ORIGIN:
|
|
|
|
{
|
|
|
|
if(Scope->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
|
|
|
Result = DeriveLineageWithoutOriginOfProject(C, Scope);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string This = Wrap0(ConfigIdentifiers[Variable].String);
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "Variable could not be resolved: ", &This);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_ORIGIN:
|
|
|
|
{
|
|
|
|
if(Scope->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
|
|
|
while(Scope->Parent && Scope->Parent->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
|
|
|
Scope = Scope->Parent;
|
|
|
|
}
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, Scope->ID.Value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string This = Wrap0(ConfigIdentifiers[Variable].String);
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "Variable could not be resolved: ", &This);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_OWNER:
|
|
|
|
{
|
|
|
|
bool Processed = FALSE;
|
2021-05-30 18:39:47 +00:00
|
|
|
while(!Processed && Scope)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
for(int i = 0; i < Scope->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
config_pair *Pair = GetPlaceInBook(&Scope->Pairs, i);
|
|
|
|
if(Variable == Pair->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
if(GetPerson(C, E, Pair))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, Pair->Value);
|
|
|
|
Processed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "Owner set, but the person does not exist: ", &Pair->Value);
|
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
Processed = TRUE;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
Scope = Scope->Parent;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
if(!Processed)
|
|
|
|
{
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "No owner set", 0);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_PERSON:
|
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
// NOTE(matt): Allow scopes within a person scope, e.g. support, to resolve $person
|
|
|
|
while(Scope && Scope->ID.Key != Variable)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
Scope = Scope->Parent;
|
|
|
|
}
|
|
|
|
} // NOTE(matt): Intentional fall-through
|
|
|
|
case IDENT_PROJECT:
|
|
|
|
case IDENT_SUPPORT:
|
|
|
|
{
|
|
|
|
if(Scope && Scope->ID.Key == Variable)
|
|
|
|
{
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, Scope->ID.Value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string This = Wrap0(ConfigIdentifiers[Variable].String);
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "Variable could not be resolved: ", &This);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if(!GetError(E, S_WARNING, Position, Variable))
|
|
|
|
{
|
|
|
|
string This = Wrap0(ConfigIdentifiers[Variable].String);
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigError(&Filepath, Position->LineNumber, S_WARNING, "Unhandled local variable: ", &This);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_WARNING, Position, Variable);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
ResolveString(config *C, resolution_errors *E, scope_tree *Parent, config_pair *S, bool AbsoluteFilePath)
|
|
|
|
{
|
|
|
|
//PrintFunctionName("ResolveString()");
|
|
|
|
string Result = {};
|
|
|
|
ResetPen(&C->ResolvedVariables);
|
|
|
|
for(int i = 0; i < S->Value.Length;)
|
|
|
|
{
|
|
|
|
switch(S->Value.Base[i])
|
|
|
|
{
|
|
|
|
case '$':
|
|
|
|
{
|
|
|
|
string Test = {};
|
|
|
|
++i;
|
|
|
|
if(i < S->Value.Length && S->Value.Base[i] == '{')
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
Test.Base = S->Value.Base + i;
|
|
|
|
while(i < S->Value.Length && S->Value.Base[i] != '}')
|
|
|
|
{
|
|
|
|
++Test.Length;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Test.Base = S->Value.Base + i;
|
|
|
|
while(i < S->Value.Length && IsValidIdentifierCharacter(S->Value.Base[i]))
|
|
|
|
{
|
|
|
|
++Test.Length;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if(i > 0) { --i; }
|
|
|
|
}
|
|
|
|
|
|
|
|
config_identifier_id ID = GetConfigIdentifierFromString(Test);
|
|
|
|
if(ID != IDENT_NULL)
|
|
|
|
{
|
|
|
|
Result = ResolveLocalVariable(C, E, Parent, ID, &S->Position);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Result = ResolveEnvironmentVariable(&C->ResolvedVariables, Test);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case '~':
|
|
|
|
{
|
|
|
|
string Char = { .Base = S->Value.Base + i, .Length = 1 };
|
|
|
|
if(AbsoluteFilePath && i == 0)
|
|
|
|
{
|
|
|
|
Result = ResolveEnvironmentVariable(&C->ResolvedVariables, Char);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, Char);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case '\\': { ++i; }; // NOTE(matt): Intentional fall-through
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
string Char = { .Base = S->Value.Base + i, .Length = 1 };
|
|
|
|
Result = ExtendStringInBook(&C->ResolvedVariables, Char);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
P_ABS,
|
|
|
|
P_REL,
|
|
|
|
} path_relativity;
|
|
|
|
|
|
|
|
string
|
|
|
|
StripSlashes(string Path, path_relativity Relativity)
|
|
|
|
{
|
|
|
|
string Result = Path;
|
2020-05-15 01:35:55 +00:00
|
|
|
if(Relativity == P_REL)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
while(Result.Length > 0 && *Result.Base == '/')
|
2020-05-10 20:25:05 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
++Result.Base;
|
2020-05-10 20:25:05 +00:00
|
|
|
--Result.Length;
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
|
|
|
|
while(Result.Length > 0 && Result.Base[Result.Length - 1] == '/')
|
|
|
|
{
|
|
|
|
--Result.Length;
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HasImageFileExtension(string Path)
|
|
|
|
{
|
|
|
|
return ExtensionMatches(Path, EXT_GIF) ||
|
|
|
|
ExtensionMatches(Path, EXT_JPEG) ||
|
|
|
|
ExtensionMatches(Path, EXT_JPG) ||
|
|
|
|
ExtensionMatches(Path, EXT_PNG);
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
typedef uint64_t variant;
|
2020-05-09 17:33:25 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
string Path;
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(variant) Variants;
|
2020-05-09 17:33:25 +00:00
|
|
|
} variant_string;
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
PushVariantUniquely(resolution_errors *E, memory_book *VariantStrings, string Path, variant Variants, config_identifier_id Identifier)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
if(Path.Length > 0)
|
|
|
|
{
|
|
|
|
bool FoundPath = FALSE;
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < VariantStrings->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
variant_string *ThisVariantString = GetPlaceInBook(VariantStrings, i);
|
|
|
|
if(StringsMatch(ThisVariantString->Path, Path))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
FoundPath = TRUE;
|
|
|
|
bool FoundVariantsMatch = FALSE;
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int VariantsIndex = 0; VariantsIndex < ThisVariantString->Variants.ItemCount; ++VariantsIndex)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
variant Test = *(variant *)GetPlaceInBook(&ThisVariantString->Variants, VariantsIndex);
|
|
|
|
if(Test == Variants)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
FoundVariantsMatch = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!FoundVariantsMatch)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
variant *ThisVariant = MakeSpaceInBook(&ThisVariantString->Variants);
|
|
|
|
*ThisVariant = Variants;
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_ERROR, 0, Identifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!FoundPath)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
variant_string *NewVariantString = MakeSpaceInBook(VariantStrings);
|
|
|
|
NewVariantString->Path = Path;
|
|
|
|
|
2020-06-24 12:29:18 +00:00
|
|
|
NewVariantString->Variants = InitBook(MBT_VARIANT, 4);
|
2020-05-24 23:26:13 +00:00
|
|
|
variant *NewVariants = MakeSpaceInBook(&NewVariantString->Variants);
|
|
|
|
*NewVariants = Variants;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-05-17 21:50:28 +00:00
|
|
|
string String0;
|
|
|
|
string String1;
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(project *) Projects;
|
2020-05-09 17:33:25 +00:00
|
|
|
} config_string_association;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-05-17 21:50:28 +00:00
|
|
|
config_identifier_id ID0;
|
|
|
|
config_identifier_id ID1;
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(config_string_association) Associations;
|
2020-05-09 17:33:25 +00:00
|
|
|
} config_string_associations;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(variant_string) VariantStrings;
|
2020-05-09 17:33:25 +00:00
|
|
|
config_string_associations HMMLDirs;
|
2020-05-17 21:50:28 +00:00
|
|
|
config_string_associations BaseDirAndSearchLocation;
|
|
|
|
config_string_associations BaseDirAndPlayerLocation;
|
2020-05-09 17:33:25 +00:00
|
|
|
} config_verifiers;
|
|
|
|
|
|
|
|
void
|
|
|
|
PushMedium(config *C, resolution_errors *E, config_verifiers *V, project *P, scope_tree *MediumTree)
|
|
|
|
{
|
|
|
|
// TODO(matt): Do we need to warn about incomplete medium information?
|
2020-05-24 23:26:13 +00:00
|
|
|
medium *Medium = MakeSpaceInBook(&P->Medium);
|
2020-05-09 17:33:25 +00:00
|
|
|
Medium->ID = ResolveString(C, E, MediumTree, &MediumTree->ID, FALSE);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < MediumTree->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *This = GetPlaceInBook(&MediumTree->Pairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_ICON: { Medium->Icon = ResolveString(C, E, MediumTree, This, FALSE); } break;
|
|
|
|
case IDENT_ICON_NORMAL: { Medium->IconNormal = ResolveString(C, E, MediumTree, This, FALSE); } break;
|
|
|
|
case IDENT_ICON_FOCUSED: { Medium->IconFocused = ResolveString(C, E, MediumTree, This, FALSE); } break;
|
|
|
|
case IDENT_ICON_DISABLED: { Medium->IconDisabled = ResolveString(C, E, MediumTree, This, FALSE); } break;
|
|
|
|
case IDENT_NAME: { Medium->Name = ResolveString(C, E, MediumTree, This, FALSE); } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < MediumTree->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *This = GetPlaceInBook(&MediumTree->IntPairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_ICON_TYPE: { Medium->IconType = This->Value; } break;
|
|
|
|
case IDENT_ICON_VARIANTS: { Medium->IconVariants = This->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < MediumTree->BoolPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *This = GetPlaceInBook(&MediumTree->BoolPairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_HIDDEN: { Medium->Hidden = This->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Medium->Icon.Length > 0)
|
|
|
|
{
|
|
|
|
if(Medium->IconType == IT_DEFAULT_UNSET)
|
|
|
|
{
|
|
|
|
if(HasImageFileExtension(Medium->Icon))
|
|
|
|
{
|
|
|
|
Medium->IconType = IT_GRAPHICAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Medium->IconType = IT_TEXTUAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(Medium->IconType)
|
|
|
|
{
|
|
|
|
case IT_GRAPHICAL:
|
|
|
|
{
|
|
|
|
PushVariantUniquely(E, &V->VariantStrings, Medium->Icon, Medium->IconVariants, IDENT_ICON);
|
|
|
|
} break;
|
|
|
|
case IT_TEXTUAL:
|
|
|
|
{
|
|
|
|
if(Medium->IconNormal.Length == 0) { Medium->IconNormal = Medium->Icon; }
|
|
|
|
if(Medium->IconFocused.Length == 0) { Medium->IconFocused = Medium->Icon; }
|
|
|
|
if(Medium->IconDisabled.Length == 0) { Medium->IconDisabled = Medium->Icon; }
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
medium *
|
|
|
|
GetMediumFromProject(project *P, string ID)
|
|
|
|
{
|
|
|
|
medium *Result = 0;
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < P->Medium.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
medium *This = GetPlaceInBook(&P->Medium, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(StringsMatch(ID, This->ID))
|
|
|
|
{
|
|
|
|
Result = This;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushSupport(config *C, resolution_errors *E, config_verifiers *V, person *P, scope_tree *SupportTree)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
support *Support = MakeSpaceInBook(&P->Support);
|
2020-05-09 17:33:25 +00:00
|
|
|
Support->ID = ResolveString(C, E, SupportTree, &SupportTree->ID, FALSE);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < SupportTree->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *This = GetPlaceInBook(&SupportTree->Pairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_ICON: { Support->Icon = StripSlashes(ResolveString(C, E, SupportTree, This, FALSE), P_REL); } break;
|
|
|
|
case IDENT_ICON_NORMAL: { Support->IconNormal = ResolveString(C, E, SupportTree, This, FALSE); } break;
|
|
|
|
case IDENT_ICON_FOCUSED: { Support->IconFocused = ResolveString(C, E, SupportTree, This, FALSE); } break;
|
|
|
|
case IDENT_URL: { Support->URL = ResolveString(C, E, SupportTree, This, FALSE); } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < SupportTree->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *This = GetPlaceInBook(&SupportTree->IntPairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_ICON_TYPE: { Support->IconType = This->Value; } break;
|
|
|
|
case IDENT_ICON_VARIANTS: { Support->IconVariants = This->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Support->Icon.Length > 0)
|
|
|
|
{
|
|
|
|
if(Support->IconType == IT_DEFAULT_UNSET)
|
|
|
|
{
|
|
|
|
if(HasImageFileExtension(Support->Icon))
|
|
|
|
{
|
|
|
|
Support->IconType = IT_GRAPHICAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Support->IconType = IT_TEXTUAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(Support->IconType)
|
|
|
|
{
|
|
|
|
case IT_GRAPHICAL:
|
|
|
|
{
|
|
|
|
PushVariantUniquely(E, &V->VariantStrings, Support->Icon, Support->IconVariants, IDENT_ICON);
|
|
|
|
} break;
|
|
|
|
case IT_TEXTUAL:
|
|
|
|
{
|
|
|
|
if(Support->IconNormal.Length == 0) { Support->IconNormal = Support->Icon; }
|
|
|
|
if(Support->IconFocused.Length == 0) { Support->IconFocused = Support->Icon; }
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushPersonOntoConfig(config *C, resolution_errors *E, config_verifiers *V, scope_tree *PersonTree)
|
|
|
|
{
|
|
|
|
//PrintFunctionName("PushPersonOntoConfig()");
|
|
|
|
//PrintScopeTree(PersonTree);
|
2020-05-24 23:26:13 +00:00
|
|
|
person *This = MakeSpaceInBook(&C->Person);
|
2020-05-15 01:35:55 +00:00
|
|
|
This->ID = ResolveString(C, E, PersonTree, &PersonTree->ID, FALSE);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < PersonTree->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *Pair = GetPlaceInBook(&PersonTree->Pairs, i);
|
|
|
|
if(IDENT_NAME == Pair->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
This->Name = ResolveString(C, E, PersonTree, Pair, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
else if(IDENT_HOMEPAGE == Pair->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
This->Homepage = ResolveString(C, E, PersonTree, Pair, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
else if(IDENT_QUOTE_USERNAME == Pair->Key)
|
|
|
|
{
|
|
|
|
This->QuoteUsername = ResolveString(C, E, PersonTree, Pair, FALSE);
|
|
|
|
}
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
if(This->QuoteUsername.Length == 0)
|
|
|
|
{
|
|
|
|
This->QuoteUsername = This->ID;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-24 12:29:18 +00:00
|
|
|
This->Support = InitBook(MBT_SUPPORT, 2);
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < PersonTree->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *ThisSupport = GetPlaceInBook(&PersonTree->Trees, i);
|
|
|
|
PushSupport(C, E, V, This, ThisSupport);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
void
|
|
|
|
PushRoleOntoConfig(config *C, resolution_errors *E, config_verifiers *V, scope_tree *RoleTree)
|
|
|
|
{
|
|
|
|
role *This = MakeSpaceInBook(&C->Role);
|
|
|
|
This->ID = ResolveString(C, E, RoleTree, &RoleTree->ID, FALSE);
|
|
|
|
for(int i = 0; i < RoleTree->Pairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_pair *Pair = GetPlaceInBook(&RoleTree->Pairs, i);
|
|
|
|
if(IDENT_NAME == Pair->Key)
|
|
|
|
{
|
|
|
|
This->Name = ResolveString(C, E, RoleTree, Pair, FALSE);
|
|
|
|
}
|
|
|
|
else if(IDENT_PLURAL == Pair->Key)
|
|
|
|
{
|
|
|
|
This->Plural = ResolveString(C, E, RoleTree, Pair, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i = 0; i < RoleTree->BoolPairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_bool_pair *BoolPair = GetPlaceInBook(&RoleTree->BoolPairs, i);
|
|
|
|
if(IDENT_NON_SPEAKING == BoolPair->Key)
|
|
|
|
{
|
|
|
|
This->NonSpeaking = BoolPair->Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
|
|
|
PushPersonOntoProject(config *C, resolution_errors *E, project *P, config_pair *Actor)
|
|
|
|
{
|
|
|
|
person *Person = GetPerson(C, E, Actor);
|
|
|
|
if(Person)
|
|
|
|
{
|
|
|
|
switch(Actor->Key)
|
|
|
|
{
|
|
|
|
case IDENT_INDEXER:
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
person **Indexer = MakeSpaceInBook(&P->Indexer);
|
2020-05-15 01:35:55 +00:00
|
|
|
*Indexer = Person;
|
2020-05-09 17:33:25 +00:00
|
|
|
} break;
|
|
|
|
case IDENT_COHOST:
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
person **CoHost = MakeSpaceInBook(&P->CoHost);
|
2020-05-15 01:35:55 +00:00
|
|
|
*CoHost = Person;
|
2020-05-09 17:33:25 +00:00
|
|
|
} break;
|
|
|
|
case IDENT_GUEST:
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
person **Guest = MakeSpaceInBook(&P->Guest);
|
2020-05-15 01:35:55 +00:00
|
|
|
*Guest = Person;
|
2020-05-09 17:33:25 +00:00
|
|
|
} break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
PushCredit(config *C, resolution_errors *E, project *P, scope_tree *CreditTree)
|
|
|
|
{
|
|
|
|
CreditTree->ID.Value = ResolveString(C, E, CreditTree, &CreditTree->ID, FALSE);
|
|
|
|
if(CreditTree->ID.Value.Base)
|
|
|
|
{
|
|
|
|
person *Person = GetPerson(C, E, &CreditTree->ID);
|
|
|
|
if(Person)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < CreditTree->Pairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_pair *This = GetPlaceInBook(&CreditTree->Pairs, i);
|
|
|
|
role *Role = GetRole(C, E, This);
|
|
|
|
if(Role)
|
|
|
|
{
|
|
|
|
credit *Credit = MakeSpaceInBook(&P->Credit);
|
|
|
|
// TODO(matt): Sort the P->Credit book by Person->SortName
|
|
|
|
Credit->Role = Role;
|
|
|
|
Credit->Person = Person;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
|
|
|
|
void PushProjectOntoProject(config *C, resolution_errors *E, config_verifiers *Verifiers, project *Parent, scope_tree *ProjectTree);
|
|
|
|
|
|
|
|
void
|
2020-05-15 01:35:55 +00:00
|
|
|
AddProjectToAssociation(config_string_association *A, project *P)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
project **This = MakeSpaceInBook(&A->Projects);
|
|
|
|
*This = P;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-17 21:50:28 +00:00
|
|
|
PushAssociation(config_string_associations *HMMLDirs, string *S0, string *S1, project *P)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *This = MakeSpaceInBook(&HMMLDirs->Associations);
|
2020-06-24 12:29:18 +00:00
|
|
|
This->Projects = InitBookOfPointers(MBT_PROJECT_PTR, 4);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
if(S0) { This->String0 = *S0; }
|
|
|
|
if(S1) { This->String1 = *S1; }
|
|
|
|
AddProjectToAssociation(This, P);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 21:50:28 +00:00
|
|
|
config_string_association *
|
|
|
|
GetAssociation(config_string_associations *Set, string String0, string String1)
|
|
|
|
{
|
|
|
|
config_string_association *Result = 0;
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Set->Associations.ItemCount; ++i)
|
2020-05-17 21:50:28 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *This = GetPlaceInBook(&Set->Associations, i);
|
2020-05-17 21:50:28 +00:00
|
|
|
if(StringsMatch(String0, This->String0) && StringsMatch(String1, This->String1))
|
|
|
|
{
|
|
|
|
Result = This;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_string_association *
|
|
|
|
GetGlobalPathAssociation(config_string_associations *Set, string Path)
|
|
|
|
{
|
|
|
|
config_string_association *Result = 0;
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < Set->Associations.ItemCount; ++i)
|
2020-05-17 21:50:28 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *This = GetPlaceInBook(&Set->Associations, i);
|
2020-05-17 21:50:28 +00:00
|
|
|
if(StringsMatchSized(Path, This->String0.Length, This->String0))
|
|
|
|
{
|
|
|
|
Path = TrimString(Path, This->String0.Length, 0);
|
|
|
|
if(Path.Length == 0 && This->String1.Length == 0)
|
|
|
|
{
|
|
|
|
Result = This;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(StringsMatchSized(Path, 1, Wrap0("/")))
|
|
|
|
{
|
|
|
|
Path = TrimString(Path, 1, 0);
|
|
|
|
if(Path.Length > 0 && StringsMatchSized(Path, This->String1.Length, This->String1))
|
|
|
|
{
|
|
|
|
Result = This;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
2020-05-15 01:35:55 +00:00
|
|
|
SetUniqueHMMLDir(config *C, resolution_errors *E, config_string_associations *HMMLDirs, project *P, scope_tree *ProjectTree, config_pair *HMMLDir)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
string Result = StripSlashes(ResolveString(C, E, ProjectTree, HMMLDir, TRUE), P_ABS);
|
|
|
|
bool Clashed = FALSE;
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < HMMLDirs->Associations.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *This = GetPlaceInBook(&HMMLDirs->Associations, i);
|
|
|
|
if(StringsMatch(Result, This->String0))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
AddProjectToAssociation(This, P);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_ERROR, &HMMLDir->Position, IDENT_HMML_DIR);
|
|
|
|
Clashed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!Clashed)
|
|
|
|
{
|
2020-05-17 21:50:28 +00:00
|
|
|
PushAssociation(HMMLDirs, &Result, 0, P);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
P->HMMLDir = Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-15 01:35:55 +00:00
|
|
|
PushProject(config *C, resolution_errors *E, config_verifiers *V, project *P, scope_tree *ProjectTree)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
P->Medium = InitBook(MBT_MEDIUM, 8);
|
|
|
|
P->Child = InitBook(MBT_PROJECT, 8);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
P->Credit = InitBook(MBT_CREDIT, 4);
|
|
|
|
#else
|
2020-06-24 12:29:18 +00:00
|
|
|
P->Indexer = InitBookOfPointers(MBT_PERSON_PTR, 4);
|
|
|
|
P->CoHost = InitBookOfPointers(MBT_PERSON_PTR, 4);
|
|
|
|
P->Guest = InitBookOfPointers(MBT_PERSON_PTR, 4);
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-15 01:35:55 +00:00
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
config_string_associations *HMMLDirs = &V->HMMLDirs;
|
|
|
|
P->ID = ResolveString(C, E, ProjectTree, &ProjectTree->ID, FALSE);
|
|
|
|
if(P->ID.Length > MAX_PROJECT_ID_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(ProjectTree->ID.Position.Filename);
|
|
|
|
ConfigErrorSizing(&Filepath, ProjectTree->ID.Position.LineNumber, IDENT_PROJECT, &P->ID, MAX_PROJECT_ID_LENGTH);
|
2020-05-09 17:33:25 +00:00
|
|
|
PushError(E, S_ERROR, 0, IDENT_PROJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResetPen(&C->ResolvedVariables);
|
|
|
|
P->Lineage = DeriveLineageOfProject(C, ProjectTree);
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
// NOTE(matt): Initial pass over as-yet unresolvable local variable(s)
|
|
|
|
//
|
|
|
|
for(int i = 0; i < ProjectTree->Pairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_pair *This = GetPlaceInBook(&ProjectTree->Pairs, i);
|
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_OWNER:
|
|
|
|
{
|
|
|
|
// TODO(matt): Do we need to fail completely if owner cannot be found?
|
|
|
|
P->Owner = GetPerson(C, E, This);
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
////
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < ProjectTree->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *This = GetPlaceInBook(&ProjectTree->Trees, i);
|
2021-05-30 18:39:47 +00:00
|
|
|
switch(This->ID.Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
case IDENT_MEDIUM:
|
|
|
|
{
|
|
|
|
PushMedium(C, E, V, P, This);
|
|
|
|
} break;
|
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
case IDENT_CREDIT:
|
|
|
|
{
|
|
|
|
PushCredit(C, E, P, This);
|
|
|
|
} break;
|
|
|
|
#endif
|
|
|
|
default: break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < ProjectTree->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *This = GetPlaceInBook(&ProjectTree->Pairs, i);
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(This->Position.Filename);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_DEFAULT_MEDIUM:
|
|
|
|
{ P->DefaultMedium = GetMediumFromProject(P, This->Value); } break;
|
|
|
|
case IDENT_HMML_DIR:
|
2020-05-15 01:35:55 +00:00
|
|
|
{ SetUniqueHMMLDir(C, E, HMMLDirs, P, ProjectTree, This); } break;
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
case IDENT_INDEXER:
|
|
|
|
case IDENT_COHOST:
|
|
|
|
case IDENT_GUEST:
|
|
|
|
{ PushPersonOntoProject(C, E, P, This); } break;
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
case IDENT_PLAYER_TEMPLATE:
|
|
|
|
{ P->PlayerTemplatePath = StripSlashes(ResolveString(C, E, ProjectTree, This, FALSE), P_REL); } break;
|
|
|
|
case IDENT_THEME:
|
|
|
|
{ P->Theme = ResolveString(C, E, ProjectTree, This, FALSE);
|
|
|
|
if(P->Theme.Length > MAX_THEME_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, This->Position.LineNumber, This->Key,
|
2020-05-09 17:33:25 +00:00
|
|
|
&P->Theme, MAX_THEME_LENGTH);
|
|
|
|
PushError(E, S_ERROR, 0, This->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_TITLE:
|
|
|
|
{
|
|
|
|
P->Title = ResolveString(C, E, ProjectTree, This, FALSE);
|
|
|
|
if(P->Title.Length > MAX_PROJECT_NAME_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, This->Position.LineNumber, This->Key,
|
2020-05-09 17:33:25 +00:00
|
|
|
&P->Title, MAX_PROJECT_NAME_LENGTH);
|
|
|
|
PushError(E, S_ERROR, 0, This->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_HTML_TITLE: { P->HTMLTitle = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
|
|
|
// TODO(matt): Sort out this title list stuff
|
|
|
|
//case IDENT_TITLE_LIST_DELIMITER: { C->Project[C->ProjectCount].HMMLDir = ResolveString(This); } break;
|
|
|
|
//case IDENT_TITLE_LIST_PREFIX: { C->Project[C->ProjectCount].HMMLDir = ResolveString(This); } break;
|
|
|
|
//case IDENT_TITLE_LIST_SUFFIX: { C->Project[C->ProjectCount].HMMLDir = ResolveString(This); } break;
|
|
|
|
//case IDENT_TITLE_SUFFIX: { C->Project[C->ProjectCount].HMMLDir = ResolveString(This); } break;
|
|
|
|
case IDENT_UNIT: { P->Unit = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
|
|
|
case IDENT_BASE_DIR:
|
|
|
|
{
|
|
|
|
P->BaseDir = StripSlashes(ResolveString(C, E, ProjectTree, This, TRUE), P_ABS);
|
|
|
|
if(P->BaseDir.Length > MAX_BASE_DIR_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, This->Position.LineNumber, This->Key,
|
2020-05-09 17:33:25 +00:00
|
|
|
&P->BaseDir, MAX_BASE_DIR_LENGTH);
|
|
|
|
PushError(E, S_ERROR, 0, This->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_BASE_URL:
|
|
|
|
{
|
|
|
|
P->BaseURL = ResolveString(C, E, ProjectTree, This, FALSE);
|
|
|
|
if(P->BaseURL.Length > MAX_BASE_URL_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, This->Position.LineNumber, This->Key,
|
2020-05-09 17:33:25 +00:00
|
|
|
&P->BaseURL, MAX_BASE_URL_LENGTH);
|
|
|
|
PushError(E, S_ERROR, 0, This->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_PLAYER_LOCATION:
|
|
|
|
{
|
|
|
|
P->PlayerLocation = StripSlashes(ResolveString(C, E, ProjectTree, This, FALSE), P_REL);
|
|
|
|
if(P->PlayerLocation.Length > MAX_RELATIVE_PAGE_LOCATION_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, This->Position.LineNumber, This->Key,
|
2020-05-09 17:33:25 +00:00
|
|
|
&P->PlayerLocation, MAX_RELATIVE_PAGE_LOCATION_LENGTH);
|
|
|
|
PushError(E, S_ERROR, 0, This->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_SEARCH_LOCATION:
|
|
|
|
{
|
|
|
|
P->SearchLocation = StripSlashes(ResolveString(C, E, ProjectTree, This, FALSE), P_REL);
|
|
|
|
if(P->SearchLocation.Length > MAX_RELATIVE_PAGE_LOCATION_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, This->Position.LineNumber, This->Key,
|
2020-05-09 17:33:25 +00:00
|
|
|
&P->SearchLocation, MAX_RELATIVE_PAGE_LOCATION_LENGTH);
|
|
|
|
PushError(E, S_ERROR, 0, This->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_SEARCH_TEMPLATE:
|
|
|
|
{ P->SearchTemplatePath = StripSlashes(ResolveString(C, E, ProjectTree, This, FALSE), P_REL); } break;
|
|
|
|
case IDENT_TEMPLATES_DIR:
|
|
|
|
{ P->TemplatesDir = StripSlashes(ResolveString(C, E, ProjectTree, This, TRUE), P_ABS); } break;
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
case IDENT_STREAM_USERNAME:
|
|
|
|
{ P->StreamUsername = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
case IDENT_VOD_PLATFORM:
|
|
|
|
{ P->VODPlatform = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
|
|
|
|
|
|
|
case IDENT_ART: { P->Art = StripSlashes(ResolveString(C, E, ProjectTree, This, FALSE), P_REL); } break;
|
|
|
|
case IDENT_ICON: { P->Icon = StripSlashes(ResolveString(C, E, ProjectTree, This, FALSE), P_REL); } break;
|
|
|
|
case IDENT_ICON_NORMAL: { P->IconNormal = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
|
|
|
case IDENT_ICON_FOCUSED: { P->IconFocused = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
|
|
|
case IDENT_ICON_DISABLED: { P->IconDisabled = ResolveString(C, E, ProjectTree, This, FALSE); } break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < ProjectTree->IntPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_int_pair *This = GetPlaceInBook(&ProjectTree->IntPairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
|
|
|
case IDENT_GENRE: { P->Genre = This->Value; } break;
|
|
|
|
case IDENT_ART_VARIANTS: { P->ArtVariants = This->Value; } break;
|
|
|
|
case IDENT_ICON_TYPE: { P->IconType = This->Value; } break;
|
|
|
|
case IDENT_ICON_VARIANTS: { P->IconVariants = This->Value; } break;
|
|
|
|
case IDENT_NUMBERING_SCHEME: { P->NumberingScheme = This->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < ProjectTree->BoolPairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_bool_pair *This = GetPlaceInBook(&ProjectTree->BoolPairs, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
switch(This->Key)
|
|
|
|
{
|
2020-05-17 01:04:26 +00:00
|
|
|
case IDENT_DENY_BESPOKE_TEMPLATES:
|
|
|
|
{ P->DenyBespokeTemplates = This->Value; } break;
|
2020-05-09 17:33:25 +00:00
|
|
|
case IDENT_IGNORE_PRIVACY:
|
|
|
|
{ P->IgnorePrivacy = This->Value; } break;
|
|
|
|
case IDENT_SINGLE_BROWSER_TAB:
|
|
|
|
{ P->SingleBrowserTab = This->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < ProjectTree->Trees.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
scope_tree *This = GetPlaceInBook(&ProjectTree->Trees, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(This->ID.Key == IDENT_PROJECT)
|
|
|
|
{
|
|
|
|
PushProjectOntoProject(C, E, V, P, This);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 21:50:28 +00:00
|
|
|
config_string_association *BaseDirAndSearchLocation = GetAssociation(&V->BaseDirAndSearchLocation, P->BaseDir, P->SearchLocation);
|
|
|
|
if(BaseDirAndSearchLocation)
|
|
|
|
{
|
|
|
|
PushError(E, S_ERROR, 0, IDENT_SEARCH_LOCATION);
|
|
|
|
AddProjectToAssociation(BaseDirAndSearchLocation, P);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushAssociation(&V->BaseDirAndSearchLocation, &P->BaseDir, &P->SearchLocation, P);
|
|
|
|
}
|
|
|
|
|
|
|
|
config_string_association *BaseDirAndPlayerLocation = GetAssociation(&V->BaseDirAndPlayerLocation, P->BaseDir, P->PlayerLocation);
|
|
|
|
if(BaseDirAndPlayerLocation)
|
|
|
|
{
|
|
|
|
PushError(E, S_ERROR, 0, IDENT_PLAYER_LOCATION);
|
|
|
|
AddProjectToAssociation(BaseDirAndPlayerLocation, P);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PushAssociation(&V->BaseDirAndPlayerLocation, &P->BaseDir, &P->PlayerLocation, P);
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
if(!P->DefaultMedium)
|
|
|
|
{
|
|
|
|
ResetPen(&C->ResolvedVariables);
|
|
|
|
ConfigError(0, 0, S_WARNING, "Unset default_medium for project: ", &P->Lineage);
|
|
|
|
PushError(E, S_WARNING, 0, IDENT_DEFAULT_MEDIUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(P->Art.Length > 0)
|
|
|
|
{
|
|
|
|
PushVariantUniquely(E, &V->VariantStrings, P->Art, P->ArtVariants, IDENT_ART);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(P->Icon.Length > 0)
|
|
|
|
{
|
|
|
|
if(P->IconType == IT_DEFAULT_UNSET)
|
|
|
|
{
|
|
|
|
if(HasImageFileExtension(P->Icon))
|
|
|
|
{
|
|
|
|
P->IconType = IT_GRAPHICAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
P->IconType = IT_TEXTUAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(P->IconType)
|
|
|
|
{
|
|
|
|
case IT_GRAPHICAL:
|
|
|
|
{
|
|
|
|
PushVariantUniquely(E, &V->VariantStrings, P->Icon, P->IconVariants, IDENT_ICON);
|
|
|
|
} break;
|
|
|
|
case IT_TEXTUAL:
|
|
|
|
{
|
|
|
|
if(P->IconNormal.Length == 0) { P->IconNormal = P->Icon; }
|
|
|
|
if(P->IconFocused.Length == 0) { P->IconFocused = P->Icon; }
|
|
|
|
if(P->IconDisabled.Length == 0) { P->IconDisabled = P->Icon; }
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
C->RespectingPrivacy |= !P->IgnorePrivacy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushProjectOntoProject(config *C, resolution_errors *E, config_verifiers *Verifiers, project *Parent, scope_tree *ProjectTree)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
project *P = MakeSpaceInBook(&Parent->Child);
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
PushProject(C, E, Verifiers, P, ProjectTree);
|
2020-05-09 17:33:25 +00:00
|
|
|
P->Parent = Parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
project *
|
|
|
|
GetProjectFromProject(project *Parent, string ID)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
project *Result = 0;
|
2020-05-09 17:33:25 +00:00
|
|
|
if(Parent)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < Parent->Child.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
project *This = GetPlaceInBook(&Parent->Child, i);
|
2020-05-24 23:26:13 +00:00
|
|
|
if(StringsMatch(ID, This->ID))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PushProjectOntoConfig(config *C, resolution_errors *E, config_verifiers *Verifiers, scope_tree *ProjectTree)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
project *P = MakeSpaceInBook(&C->Project);
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
PushProject(C, E, Verifiers, P, ProjectTree);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
project *
|
|
|
|
GetProjectFromConfig(config *C, string ID)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
project *Result = 0;
|
2020-05-09 17:33:25 +00:00
|
|
|
if(C)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < C->Project.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
project *This = GetPlaceInBook(&C->Project, i);
|
2020-05-24 23:26:13 +00:00
|
|
|
if(StringsMatch(ID, This->ID))
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
Result = This;
|
|
|
|
break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintAssociationClashes(config_string_associations *A)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < A->Associations.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *Association = GetPlaceInBook(&A->Associations, i);
|
|
|
|
if(Association->Projects.ItemCount > 1)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-17 21:50:28 +00:00
|
|
|
ConfigError(0, 0, S_ERROR, "Multiple projects share the same:", 0);
|
|
|
|
|
|
|
|
config_pair Assoc0 = { .Key = A->ID0, .Value = Association->String0 };
|
|
|
|
int IndentLevel = 2;
|
|
|
|
PrintPair(&Assoc0, ": ", FALSE, IndentLevel, FALSE, FALSE);
|
|
|
|
if(A->ID1 != IDENT_NULL)
|
|
|
|
{
|
|
|
|
config_pair Assoc1 = { .Key = A->ID1, .Value = Association->String1 };
|
|
|
|
PrintPair(&Assoc1, ": ", FALSE, IndentLevel, TRUE, FALSE);
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
fprintf(stderr, "\n");
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int j = 0; j < Association->Projects.ItemCount; ++j)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
project **P = GetPlaceInBook(&Association->Projects, j);
|
2020-05-17 21:50:28 +00:00
|
|
|
fprintf(stderr, " ");
|
2020-05-24 23:26:13 +00:00
|
|
|
if(*P)
|
2020-05-17 21:50:28 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintStringC(CS_CYAN, (*P)->Lineage);
|
2020-05-17 21:50:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintStringC(CS_RED, Wrap0("[global scope: "));
|
|
|
|
// TODO(matt): Maybe generalise this, next time we're in this situation
|
|
|
|
if(A->ID0 == IDENT_BASE_DIR && A->ID1 == IDENT_SEARCH_LOCATION)
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[IDENT_GLOBAL_SEARCH_DIR].String);
|
|
|
|
}
|
|
|
|
PrintStringC(CS_RED, Wrap0("]"));
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintVariants(uint64_t V, colour_code ColourCode, string Margin)
|
|
|
|
{
|
|
|
|
int TermCols = GetTerminalColumns();
|
|
|
|
int AvailableColumnsForValue = TermCols - Margin.Length;
|
|
|
|
int RunningAvailableColumns = TermCols - Margin.Length;
|
|
|
|
PrintString(Margin);
|
|
|
|
bool NeedsSpacing = FALSE;
|
|
|
|
if(V)
|
|
|
|
{
|
|
|
|
for(int VariantShifterIndex = 0; VariantShifterIndex < AVS_COUNT; ++VariantShifterIndex)
|
|
|
|
{
|
|
|
|
if(V & (1 << VariantShifterIndex))
|
|
|
|
{
|
|
|
|
char *String = ArtVariantStrings[VariantShifterIndex];
|
|
|
|
int Length = StringLength(String);
|
|
|
|
if(RunningAvailableColumns - Length >= 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", NeedsSpacing ? " " : "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
PrintString(Margin);
|
|
|
|
NeedsSpacing = FALSE;
|
|
|
|
RunningAvailableColumns = AvailableColumnsForValue;
|
|
|
|
}
|
|
|
|
PrintC(ColourCode, String);
|
|
|
|
RunningAvailableColumns -= Length + NeedsSpacing;
|
|
|
|
NeedsSpacing = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW, "[unset]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintVariantInconsistencies(memory_book *VariantStrings)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < VariantStrings->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
variant_string *ThisVariantsString = GetPlaceInBook(VariantStrings, i);
|
|
|
|
if(ThisVariantsString->Variants.ItemCount > 1)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
ConfigError(0, 0, S_ERROR, "Sprite has inconsistently set variants ", &ThisVariantsString->Path);
|
|
|
|
for(int j = 0; j < ThisVariantsString->Variants.ItemCount; ++j)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
string Margin = Wrap0(" ");
|
2020-05-24 23:26:13 +00:00
|
|
|
variant V = *(variant *)GetPlaceInBook(&ThisVariantsString->Variants, j);
|
2020-05-09 17:33:25 +00:00
|
|
|
PrintVariants(V, j % 2 ? CS_CYAN_BOLD : CS_YELLOW_BOLD, Margin);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeAssociations(config_string_associations *A)
|
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < A->Associations.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *This = GetPlaceInBook(&A->Associations, i);
|
|
|
|
FreeBook(&This->Projects);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(&A->Associations);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeVariants(memory_book *VariantStrings)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < VariantStrings->ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
variant_string *This = GetPlaceInBook(VariantStrings, i);
|
|
|
|
FreeBook(&This->Variants);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
FreeBook(VariantStrings);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeVerifiers(config_verifiers *Verifiers)
|
|
|
|
{
|
2020-05-17 21:50:28 +00:00
|
|
|
FreeAssociations(&Verifiers->BaseDirAndSearchLocation);
|
|
|
|
FreeAssociations(&Verifiers->BaseDirAndPlayerLocation);
|
2020-05-09 17:33:25 +00:00
|
|
|
FreeAssociations(&Verifiers->HMMLDirs);
|
|
|
|
FreeVariants(&Verifiers->VariantStrings);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintLogLevel(char *Title, log_level Level, char *Delimiter, uint64_t Indentation, bool AppendNewline)
|
|
|
|
{
|
|
|
|
Indent(Indentation);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[IDENT_LOG_LEVEL].String);
|
|
|
|
fprintf(stderr, "%s", Delimiter);
|
|
|
|
PrintC(CS_GREEN_BOLD, LogLevelStrings[Level]);
|
|
|
|
if(AppendNewline) { fprintf(stderr, "\n"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *UpperLeftCorner;
|
|
|
|
char *UpperLeft;
|
|
|
|
char *Horizontal;
|
|
|
|
char *UpperRight;
|
|
|
|
char *Vertical;
|
|
|
|
char *LowerLeftCorner;
|
|
|
|
char *LowerLeft;
|
|
|
|
char *Margin;
|
|
|
|
char *Delimiter;
|
|
|
|
char *Separator;
|
|
|
|
} typography;
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintVerticals(typography *T, int Count)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < Count; ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", T->Vertical);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CarriageReturn(typography *T, int VerticalsRequired)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
PrintVerticals(T, VerticalsRequired);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
TypesetIconType(typography *T, uint8_t Generation, icon_type Type, bool PrependNewline, bool AppendNewline)
|
|
|
|
{
|
|
|
|
uint64_t Result = 0;
|
|
|
|
|
|
|
|
// TODO(matt): Implement me, please!
|
|
|
|
|
|
|
|
//CarriageReturn(T, Generation);
|
|
|
|
//fprintf(stderr, "%s", T.Margin);
|
|
|
|
#if 0
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[IDENT_ICON_TYPE].String);
|
|
|
|
fprintf(stderr, "%s", T.Delimiter);
|
|
|
|
PrintC(CS_GREEN_BOLD, IconTypeStrings[Type]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(PrependNewline)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
++Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
config_identifier_id Key = IDENT_ICON_TYPE;
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[Key].String);
|
|
|
|
fprintf(stderr, "%s", T->Delimiter);
|
|
|
|
if(Type == IT_DEFAULT_UNSET)
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW, "[unset]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintStringC(CS_GREEN_BOLD, Wrap0(IconTypeStrings[Type]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(AppendNewline)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
++Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TypesetVariants(typography *T, uint8_t Generation, config_identifier_id Key, uint64_t Value, int AvailableColumns, uint8_t *RowsRequired, bool PrependNewline, bool AppendNewline)
|
|
|
|
{
|
|
|
|
// NOTE(matt): RowsRequired is a value passed only by PrintSupport().
|
|
|
|
if(PrependNewline)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
if(RowsRequired) { --*RowsRequired; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RowsRequired)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? T->LowerLeft : T->Vertical, T->Margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
|
|
|
|
int CharactersInKeyPlusDelimiter = StringLength(ConfigIdentifiers[Key].String) + StringLength(T->Delimiter);
|
|
|
|
int AvailableColumnsForValue = AvailableColumns - CharactersInKeyPlusDelimiter;
|
|
|
|
int RunningAvailableColumns = AvailableColumnsForValue;
|
|
|
|
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[Key].String);
|
|
|
|
fprintf(stderr, "%s", T->Delimiter);
|
|
|
|
|
|
|
|
bool NeedsSpacing = FALSE;
|
|
|
|
if(Value)
|
|
|
|
{
|
|
|
|
for(int VariantShifterIndex = 0; VariantShifterIndex < AVS_COUNT; ++VariantShifterIndex)
|
|
|
|
{
|
|
|
|
if(Value & (1 << VariantShifterIndex))
|
|
|
|
{
|
|
|
|
char *String = ArtVariantStrings[VariantShifterIndex];
|
|
|
|
int Length = StringLength(String);
|
|
|
|
if(RunningAvailableColumns - Length >= 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", NeedsSpacing ? " " : "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
if(RowsRequired)
|
|
|
|
{
|
|
|
|
--*RowsRequired;
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? T->LowerLeft : T->Vertical, T->Margin);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
for(int i = 0; i < CharactersInKeyPlusDelimiter; ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
}
|
|
|
|
NeedsSpacing = FALSE;
|
|
|
|
RunningAvailableColumns = AvailableColumnsForValue;
|
|
|
|
}
|
|
|
|
PrintC(CS_GREEN_BOLD, String);
|
|
|
|
RunningAvailableColumns -= Length + NeedsSpacing;
|
|
|
|
NeedsSpacing = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW, "[unset]");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(AppendNewline)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintMedium(typography *T, medium *M, char *Delimiter, uint64_t Indentation, bool AppendNewline)
|
|
|
|
{
|
|
|
|
PrintStringC(CS_BLUE_BOLD, M->ID);
|
|
|
|
if(M->Hidden)
|
|
|
|
{
|
|
|
|
PrintC(CS_BLACK_BOLD, " [hidden]");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s", Delimiter);
|
|
|
|
PrintStringC(CS_MAGENTA, M->Name);
|
|
|
|
fprintf(stderr, " (");
|
|
|
|
if(M->Icon.Length > 0)
|
|
|
|
{
|
|
|
|
PrintStringI(M->Icon, Indentation);
|
|
|
|
}
|
|
|
|
if(M->IconNormal.Length > 0)
|
|
|
|
{
|
|
|
|
PrintStringI(M->IconNormal, Indentation);
|
|
|
|
}
|
|
|
|
if(M->IconFocused.Length > 0)
|
|
|
|
{
|
|
|
|
PrintStringI(M->IconFocused, Indentation);
|
|
|
|
}
|
|
|
|
TypesetIconType(T, Indentation, M->IconType, FALSE, AppendNewline);
|
|
|
|
TypesetVariants(T, Indentation, IDENT_ICON_VARIANTS, M->IconVariants, 0, 0, FALSE, AppendNewline);
|
|
|
|
fprintf(stderr, ")");
|
|
|
|
if(AppendNewline)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintSupport(support *S, typography *Typography, int IndentationLevel, uint8_t *RowsRequired)
|
|
|
|
{
|
|
|
|
bool ShouldFillSyntax = FALSE;
|
|
|
|
config_pair ID = { .Key = IDENT_SUPPORT, .Value = S->ID };
|
|
|
|
fprintf(stderr, "%s%s", *RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical, Typography->Margin);
|
|
|
|
PrintPair(&ID, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--*RowsRequired;
|
|
|
|
if(S->URL.Length > 0)
|
|
|
|
{
|
|
|
|
config_pair URL = { .Key = IDENT_URL, .Value = S->URL };
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical, Typography->Margin);
|
|
|
|
PrintPair(&URL, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--*RowsRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(S->Icon.Length > 0)
|
|
|
|
{
|
|
|
|
config_pair Icon = { .Key = IDENT_ICON, .Value = S->Icon };
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical, Typography->Margin);
|
|
|
|
PrintPair(&Icon, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--*RowsRequired;
|
|
|
|
}
|
|
|
|
if(S->IconNormal.Length > 0)
|
|
|
|
{
|
|
|
|
config_pair IconNormal = { .Key = IDENT_ICON_NORMAL, .Value = S->IconNormal };
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical, Typography->Margin);
|
|
|
|
PrintPair(&IconNormal, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--*RowsRequired;
|
|
|
|
}
|
|
|
|
if(S->IconFocused.Length > 0)
|
|
|
|
{
|
|
|
|
config_pair IconFocused = { .Key = IDENT_ICON_FOCUSED, .Value = S->IconFocused };
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical, Typography->Margin);
|
|
|
|
PrintPair(&IconFocused, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--*RowsRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
// TODO(matt): FIX ME
|
|
|
|
fprintf(stderr, "%s%s ", *RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical, Typography->Margin);
|
|
|
|
*RowsRequired -= TypesetIconType(Typography, IndentationLevel, S->IconType, FALSE, TRUE);
|
|
|
|
uint8_t StartingColumn = 4;
|
|
|
|
uint64_t AvailableColumns = GetTerminalColumns() - StartingColumn;
|
|
|
|
TypesetVariants(Typography, IndentationLevel, IDENT_ICON_VARIANTS, S->IconVariants, AvailableColumns, RowsRequired, FALSE, TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
GetRowsRequiredForVariants(typography *T, config_identifier_id Key, uint64_t Value, int AvailableColumns)
|
|
|
|
{
|
|
|
|
int CharactersInKeyPlusDelimiter = StringLength(ConfigIdentifiers[Key].String) + StringLength(T->Delimiter);
|
|
|
|
int AvailableColumnsForValue = AvailableColumns - CharactersInKeyPlusDelimiter;
|
|
|
|
int RunningAvailableColumns = AvailableColumnsForValue;
|
|
|
|
|
|
|
|
uint8_t Result = 1;
|
|
|
|
bool NeedsSpacing = FALSE;
|
|
|
|
for(int VariantShifterIndex = 0; VariantShifterIndex < AVS_COUNT; ++VariantShifterIndex)
|
|
|
|
{
|
|
|
|
if(Value & (1 << VariantShifterIndex))
|
|
|
|
{
|
|
|
|
char *String = ArtVariantStrings[VariantShifterIndex];
|
|
|
|
int Length = StringLength(String);
|
|
|
|
if(!(RunningAvailableColumns - Length >= 0))
|
|
|
|
{
|
|
|
|
++Result;
|
|
|
|
NeedsSpacing = FALSE;
|
|
|
|
RunningAvailableColumns = AvailableColumnsForValue;
|
|
|
|
}
|
|
|
|
RunningAvailableColumns -= Length + NeedsSpacing;
|
|
|
|
NeedsSpacing = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
GetRowsRequiredForPersonInfo(typography *T, person *P)
|
|
|
|
{
|
|
|
|
uint8_t RowsRequired = 0;
|
|
|
|
|
|
|
|
if(P->Name.Length > 0) { ++RowsRequired; }
|
|
|
|
if(P->Homepage.Length > 0) { ++RowsRequired; }
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < P->Support.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
++RowsRequired;
|
2020-05-15 01:35:55 +00:00
|
|
|
support *This = GetPlaceInBook(&P->Support, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(This->URL.Length > 0) { ++RowsRequired; }
|
|
|
|
if(This->Icon.Length > 0) { ++RowsRequired; }
|
|
|
|
if(This->IconNormal.Length > 0) { ++RowsRequired; }
|
|
|
|
if(This->IconFocused.Length > 0) { ++RowsRequired; }
|
|
|
|
++RowsRequired; // NOTE(matt): For TypesetIconType()
|
|
|
|
int StartingColumn = 4;
|
|
|
|
RowsRequired += GetRowsRequiredForVariants(T, IDENT_ICON_VARIANTS, This->IconVariants, GetTerminalColumns() - StartingColumn);
|
|
|
|
}
|
|
|
|
return RowsRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintPerson(person *P, typography *Typography)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
bool HaveInfo = P->Name.Length > 0 || P->Homepage.Length > 0 || P->Support.ItemCount > 0;
|
2020-05-09 17:33:25 +00:00
|
|
|
fprintf(stderr, "\n"
|
|
|
|
"%s%s%s%s%s ", HaveInfo ? Typography->UpperLeftCorner : Typography->UpperLeft,
|
|
|
|
Typography->Horizontal, Typography->Horizontal, Typography->Horizontal, Typography->UpperRight);
|
|
|
|
PrintStringC(CS_GREEN_BOLD, P->ID);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
uint8_t RowsRequired = GetRowsRequiredForPersonInfo(Typography, P);
|
|
|
|
|
|
|
|
int IndentationLevel = 0;
|
|
|
|
bool ShouldFillSyntax = FALSE;
|
|
|
|
if(P->Name.Length > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s ", RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical);
|
|
|
|
config_pair Name = { .Key = IDENT_NAME, .Value = P->Name }; PrintPair(&Name, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--RowsRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(P->Homepage.Length > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s ", RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical);
|
|
|
|
config_pair Homepage = { .Key = IDENT_HOMEPAGE, .Value = P->Homepage }; PrintPair(&Homepage, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--RowsRequired;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < P->Support.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PrintSupport(GetPlaceInBook(&P->Support, i), Typography, IndentationLevel, &RowsRequired);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
uint8_t
|
|
|
|
GetRowsRequiredForRoleInfo(role *R)
|
|
|
|
{
|
|
|
|
uint8_t RowsRequired = 0;
|
|
|
|
if(R->Name.Length > 0) { ++RowsRequired; }
|
|
|
|
if(R->Plural.Length > 0) { ++RowsRequired; }
|
|
|
|
int NonSpeakingLines = 1;
|
|
|
|
RowsRequired += NonSpeakingLines;
|
|
|
|
return RowsRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintRole(role *R, typography *Typography)
|
|
|
|
{
|
|
|
|
bool HaveInfo = R->Name.Length > 0 || R->Plural.Length > 0;
|
|
|
|
fprintf(stderr, "\n"
|
|
|
|
"%s%s%s%s%s ", HaveInfo ? Typography->UpperLeftCorner : Typography->UpperLeft,
|
|
|
|
Typography->Horizontal, Typography->Horizontal, Typography->Horizontal, Typography->UpperRight);
|
|
|
|
PrintStringC(CS_GREEN_BOLD, R->ID);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
uint8_t RowsRequired = GetRowsRequiredForRoleInfo(R);
|
|
|
|
|
|
|
|
int IndentationLevel = 0;
|
|
|
|
bool ShouldFillSyntax = FALSE;
|
|
|
|
if(R->Name.Length > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s ", RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical);
|
|
|
|
config_pair Name = { .Key = IDENT_NAME, .Value = R->Name }; PrintPair(&Name, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--RowsRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(R->Plural.Length > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s ", RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical);
|
|
|
|
config_pair Plural = { .Key = IDENT_PLURAL, .Value = R->Plural }; PrintPair(&Plural, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--RowsRequired;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s ", RowsRequired == 1 ? Typography->LowerLeft : Typography->Vertical);
|
|
|
|
config_bool_pair NonSpeaking = { .Key = IDENT_NON_SPEAKING, .Value = R->NonSpeaking }; PrintBoolPair(&NonSpeaking, Typography->Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
--RowsRequired;
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
|
|
|
PrintLineage(string Lineage, bool AppendNewline)
|
|
|
|
{
|
|
|
|
string Parent = StripComponentFromPath(Lineage);
|
|
|
|
PrintStringC(CS_BLACK_BOLD, Parent);
|
|
|
|
if(Parent.Length > 0)
|
|
|
|
{
|
|
|
|
PrintC(CS_BLACK_BOLD, "/");
|
|
|
|
}
|
|
|
|
string Us = GetFinalComponent(Lineage);
|
|
|
|
PrintStringC(CS_BLUE_BOLD, Us);
|
|
|
|
if(AppendNewline) { fprintf(stderr, "\n"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
GetColumnsRequiredForMedium(medium *M, typography *T)
|
|
|
|
{
|
|
|
|
uint8_t Result = M->ID.Length + StringLength(T->Delimiter) + M->Name.Length + StringLength(" (") + M->Icon.Length + StringLength(")");
|
|
|
|
if(M->Hidden) { Result += StringLength(" [hidden]"); }
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle(char *Text, typography *T, uint8_t Generation, int AvailableColumns,
|
|
|
|
int64_t SectionItemCount /* NOTE(matt): Use any non-0 when the section is known to have content */)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
char *LeftmostChar = "╾";
|
|
|
|
char *InnerChar = "─";
|
|
|
|
char *RightmostChar = "╼";
|
|
|
|
|
|
|
|
int LeftmostCharLength = 1;
|
|
|
|
int SpacesRequired = 2;
|
|
|
|
int RightmostCharLength = 1;
|
|
|
|
int InnerCharsRequired = AvailableColumns - LeftmostCharLength - StringLength(Text) - RightmostCharLength - SpacesRequired;
|
|
|
|
int LeftCharsRequired = 4;
|
|
|
|
int RightCharsRequired = InnerCharsRequired - LeftCharsRequired;
|
|
|
|
fprintf(stderr, "%s", LeftmostChar);
|
|
|
|
for(int i = 0; i < LeftCharsRequired; ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", InnerChar);
|
|
|
|
}
|
|
|
|
fprintf(stderr, " %s ", Text);
|
|
|
|
for(int i = 0; i < RightCharsRequired; ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", InnerChar);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s", RightmostChar);
|
2021-05-30 18:39:47 +00:00
|
|
|
if(SectionItemCount == 0)
|
|
|
|
{
|
|
|
|
//fprintf(stderr, "\n");
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintMedia(project *P, typography *T, uint8_t Generation, int AvailableColumns)
|
|
|
|
{
|
|
|
|
int IndentationLevel = 0;
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle("Media", T, Generation, AvailableColumns, P->Medium.ItemCount);
|
2020-05-09 17:33:25 +00:00
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
//AvailableColumns -= Generation + 1;
|
|
|
|
int RunningAvailableColumns = AvailableColumns;
|
2020-05-15 01:35:55 +00:00
|
|
|
medium *This = GetPlaceInBook(&P->Medium, 0);
|
|
|
|
int ColumnsRequired = GetColumnsRequiredForMedium(This, T);
|
2020-05-09 17:33:25 +00:00
|
|
|
if(ColumnsRequired <= RunningAvailableColumns)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
PrintMedium(T, This, T->Delimiter, IndentationLevel, FALSE);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
RunningAvailableColumns -= ColumnsRequired;
|
|
|
|
int StringLengthOfSpacePlusSeparator = 2;
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 1; i < P->Medium.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
This = GetPlaceInBook(&P->Medium, i);
|
2020-05-09 17:33:25 +00:00
|
|
|
ColumnsRequired = GetColumnsRequiredForMedium(This, T);
|
|
|
|
if(RunningAvailableColumns >= StringLengthOfSpacePlusSeparator)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " %s", T->Separator);
|
|
|
|
RunningAvailableColumns -= StringLengthOfSpacePlusSeparator;
|
|
|
|
|
|
|
|
if(ColumnsRequired + 1 <= RunningAvailableColumns)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
--RunningAvailableColumns;
|
|
|
|
PrintMedium(T, This, T->Delimiter, IndentationLevel, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
RunningAvailableColumns = AvailableColumns;
|
|
|
|
PrintMedium(T, This, T->Delimiter, IndentationLevel, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
RunningAvailableColumns = AvailableColumns;
|
|
|
|
fprintf(stderr, "%s ", T->Separator);
|
|
|
|
RunningAvailableColumns -= StringLengthOfSpacePlusSeparator;
|
|
|
|
PrintMedium(T, This, T->Delimiter, IndentationLevel, FALSE);
|
|
|
|
}
|
|
|
|
RunningAvailableColumns -= ColumnsRequired;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
void
|
|
|
|
PrintCredits(config *C, project *P, typography *T, uint8_t Generation, int IndentationLevel, int AvailableColumns)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < C->Role.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
role *Role = GetPlaceInBook(&C->Role, i);
|
|
|
|
int CreditCount = 0;
|
|
|
|
for(int j = 0; j < P->Credit.ItemCount; ++j)
|
|
|
|
{
|
|
|
|
credit *Credit = GetPlaceInBook(&P->Credit, j);
|
|
|
|
if(Role == Credit->Role)
|
|
|
|
{
|
|
|
|
++CreditCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CreditCount > 0)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
int Alignment = 0;
|
|
|
|
Alignment += fprintf(stderr, "%s", T->Margin);
|
|
|
|
if(CreditCount == 1)
|
|
|
|
{
|
|
|
|
Alignment += PrintStringC(CS_YELLOW_BOLD, Role->Name.Length ? Role->Name : Role->ID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(Role->Plural.Length > 0)
|
|
|
|
{
|
|
|
|
Alignment += PrintStringC(CS_YELLOW_BOLD, Role->Plural);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Alignment += PrintStringC(CS_YELLOW_BOLD, Role->Name.Length ? Role->Name : Role->ID);
|
|
|
|
Alignment += PrintStringC(CS_YELLOW_BOLD, Wrap0("s"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Alignment += fprintf(stderr, "%s", T->Delimiter);
|
|
|
|
bool Printed = FALSE;
|
|
|
|
for(int j = 0; j < P->Credit.ItemCount; ++j)
|
|
|
|
{
|
|
|
|
credit *Credit = GetPlaceInBook(&P->Credit, j);
|
|
|
|
if(Role == Credit->Role)
|
|
|
|
{
|
|
|
|
if(Printed)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
AlignText(Alignment);
|
|
|
|
}
|
|
|
|
PrintStringC(CS_GREEN_BOLD, Credit->Person->Name.Length ? Credit->Person->Name : Credit->Person->ID);
|
|
|
|
Printed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:33:25 +00:00
|
|
|
void
|
|
|
|
TypesetPair(typography *T, uint8_t Generation, config_identifier_id Key, string Value, int AvailableColumns)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
|
|
|
|
int CharactersInKeyPlusDelimiter = StringLength(ConfigIdentifiers[Key].String) + StringLength(T->Delimiter);
|
|
|
|
int AvailableColumnsForValue = AvailableColumns - CharactersInKeyPlusDelimiter;
|
|
|
|
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[Key].String);
|
|
|
|
fprintf(stderr, "%s", T->Delimiter);
|
|
|
|
|
|
|
|
int CharactersToWrite = Value.Length;
|
|
|
|
if(Value.Length > 0)
|
|
|
|
{
|
|
|
|
string Pen = { .Base = Value.Base + Value.Length - CharactersToWrite,
|
|
|
|
.Length = MIN(Value.Length, AvailableColumnsForValue) };
|
|
|
|
PrintStringC(CS_GREEN_BOLD, Pen);
|
|
|
|
CharactersToWrite -= Pen.Length;
|
|
|
|
while(CharactersToWrite > 0)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
for(int i = 0; i < CharactersInKeyPlusDelimiter; ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
string Pen = { .Base = Value.Base + Value.Length - CharactersToWrite,
|
|
|
|
.Length = MIN(CharactersToWrite, AvailableColumnsForValue) };
|
|
|
|
PrintStringC(CS_GREEN_BOLD, Pen);
|
|
|
|
CharactersToWrite -= Pen.Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintC(CS_YELLOW, "[unset]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TypesetBool(typography *T, uint8_t Generation, config_identifier_id Key, bool Value)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
config_bool_pair Pair = { .Key = Key, .Value = Value };
|
|
|
|
bool ShouldFillSyntax = FALSE;
|
|
|
|
PrintBoolPair(&Pair, T->Delimiter, ShouldFillSyntax, 0, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TypesetGenre(typography *T, uint8_t Generation, genre G)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[IDENT_GENRE].String);
|
|
|
|
fprintf(stderr, "%s", T->Delimiter);
|
|
|
|
PrintC(CS_GREEN_BOLD, GenreStrings[G]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TypesetNumberingScheme(typography *T, uint8_t Generation, numbering_scheme N)
|
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
PrintC(CS_YELLOW_BOLD, ConfigIdentifiers[IDENT_NUMBERING_SCHEME].String);
|
|
|
|
fprintf(stderr, "%s", T-> Delimiter);
|
|
|
|
PrintC(CS_GREEN_BOLD, NumberingSchemeStrings[N]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintProject(config *C, project *P, typography *T, int Ancestors, int IndentationLevel, int TerminalColumns)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
int Generation = Ancestors + 1;
|
|
|
|
CarriageReturn(T, Ancestors);
|
|
|
|
|
|
|
|
fprintf(stderr, "%s%s%s%s%s ", T->UpperLeftCorner,
|
|
|
|
T->Horizontal, T->Horizontal, T->Horizontal, T->UpperRight);
|
|
|
|
PrintLineage(P->Lineage, FALSE);
|
|
|
|
|
|
|
|
int CharactersInMargin = 1;
|
|
|
|
int AvailableColumns = TerminalColumns - (Generation + CharactersInMargin);
|
2020-05-15 01:35:55 +00:00
|
|
|
if(P->Medium.ItemCount > 0)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
PrintMedia(P, T, Generation, AvailableColumns);
|
|
|
|
}
|
|
|
|
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle("Settings", T, Generation, AvailableColumns, -1);
|
2020-05-09 17:33:25 +00:00
|
|
|
|
|
|
|
TypesetPair(T, Generation, IDENT_TITLE, P->Title, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_HTML_TITLE, P->HTMLTitle, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_DEFAULT_MEDIUM, P->DefaultMedium ? P->DefaultMedium->ID : EmptyString(), AvailableColumns);
|
|
|
|
|
|
|
|
TypesetPair(T, Generation, IDENT_UNIT, P->Unit, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_HMML_DIR, P->HMMLDir, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_TEMPLATES_DIR, P->TemplatesDir, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_SEARCH_TEMPLATE, P->SearchTemplatePath, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_PLAYER_TEMPLATE, P->PlayerTemplatePath, AvailableColumns);
|
|
|
|
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
TypesetPair(T, Generation, IDENT_BASE_DIR, P->BaseDir, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_BASE_URL, P->BaseURL, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_SEARCH_LOCATION, P->SearchLocation, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_PLAYER_LOCATION, P->PlayerLocation, AvailableColumns);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-09 17:33:25 +00:00
|
|
|
TypesetPair(T, Generation, IDENT_STREAM_USERNAME, P->StreamUsername, AvailableColumns);
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
TypesetPair(T, Generation, IDENT_VOD_PLATFORM, P->VODPlatform, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_THEME, P->Theme, AvailableColumns);
|
|
|
|
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
TypesetPair(T, Generation, IDENT_ART, P->Art, AvailableColumns);
|
|
|
|
TypesetVariants(T, Generation, IDENT_ART_VARIANTS, P->ArtVariants, AvailableColumns, 0, TRUE, FALSE);
|
|
|
|
TypesetPair(T, Generation, IDENT_ICON, P->Icon, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_ICON_NORMAL, P->IconNormal, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_ICON_FOCUSED, P->IconFocused, AvailableColumns);
|
|
|
|
TypesetPair(T, Generation, IDENT_ICON_DISABLED, P->IconDisabled, AvailableColumns);
|
|
|
|
TypesetIconType(T, Generation, P->IconType, TRUE, FALSE);
|
|
|
|
TypesetVariants(T, Generation, IDENT_ICON_VARIANTS, P->IconVariants, AvailableColumns, 0, TRUE, FALSE);
|
|
|
|
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
TypesetGenre(T, Generation, P->Genre);
|
|
|
|
TypesetNumberingScheme(T, Generation, P->NumberingScheme);
|
|
|
|
TypesetBool(T, Generation, IDENT_IGNORE_PRIVACY, P->IgnorePrivacy);
|
|
|
|
TypesetBool(T, Generation, IDENT_SINGLE_BROWSER_TAB, P->SingleBrowserTab);
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
TypesetPair(T, Generation, IDENT_OWNER, P->Owner ? P->Owner->ID : Wrap0(""), AvailableColumns);
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
#else
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < P->Indexer.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
person **Indexer = GetPlaceInBook(&P->Indexer, i);
|
|
|
|
TypesetPair(T, Generation, IDENT_INDEXER, (*Indexer)->ID, AvailableColumns);
|
|
|
|
}
|
|
|
|
for(int i = 0; i < P->CoHost.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
person **CoHost = GetPlaceInBook(&P->CoHost, i);
|
|
|
|
TypesetPair(T, Generation, IDENT_COHOST, (*CoHost)->ID, AvailableColumns);
|
|
|
|
}
|
|
|
|
for(int i = 0; i < P->Guest.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
person **Guest = GetPlaceInBook(&P->Guest, i);
|
|
|
|
TypesetPair(T, Generation, IDENT_GUEST, (*Guest)->ID, AvailableColumns);
|
|
|
|
}
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
PrintTitle("Credits", T, Generation, AvailableColumns, P->Credit.ItemCount);
|
|
|
|
if(P->Credit.ItemCount > 0)
|
|
|
|
{
|
|
|
|
PrintCredits(C, P, T, Generation, IndentationLevel, AvailableColumns);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
|
|
|
PrintC(CS_YELLOW, "[none]");
|
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-15 01:35:55 +00:00
|
|
|
if(P->Child.ItemCount)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
CarriageReturn(T, Generation);
|
|
|
|
fprintf(stderr, "%s", T->Margin);
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle("Children", T, Generation, AvailableColumns, -1);
|
2020-05-09 17:33:25 +00:00
|
|
|
++Ancestors;
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < P->Child.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintProject(C, GetPlaceInBook(&P->Child, i), T, Ancestors, IndentationLevel, TerminalColumns);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
--Ancestors;
|
|
|
|
}
|
|
|
|
CarriageReturn(T, Ancestors);
|
|
|
|
fprintf(stderr, "%s%s%s%s%s ", T->LowerLeftCorner,
|
|
|
|
T->Horizontal, T->Horizontal, T->Horizontal, T->UpperRight);
|
|
|
|
PrintLineage(P->Lineage, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintConfig(config *C, bool ShouldClearTerminal)
|
|
|
|
{
|
|
|
|
if(C)
|
|
|
|
{
|
|
|
|
int TermCols = GetTerminalColumns();
|
|
|
|
if(ShouldClearTerminal) { ClearTerminal(); }
|
|
|
|
typography Typography =
|
|
|
|
{
|
|
|
|
.UpperLeftCorner = "┌",
|
|
|
|
.UpperLeft = "╾",
|
|
|
|
.Horizontal = "─",
|
|
|
|
.UpperRight = "╼",
|
|
|
|
.Vertical = "│",
|
|
|
|
.LowerLeftCorner = "└",
|
|
|
|
.LowerLeft = "╽",
|
|
|
|
.Margin = " ",
|
|
|
|
.Delimiter = ": ",
|
|
|
|
.Separator = "•",
|
|
|
|
};
|
|
|
|
|
|
|
|
// separate
|
|
|
|
fprintf(stderr, "\n");
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle("Global Settings", &Typography, 0, TermCols, -1);
|
2020-05-09 17:33:25 +00:00
|
|
|
int IndentationLevel = 0;
|
|
|
|
|
|
|
|
int AvailableColumns = TermCols - StringLength(Typography.Margin);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_DB_LOCATION, C->DatabaseLocation, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_CACHE_DIR, C->CacheDir, AvailableColumns);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
TypesetPair(&Typography, 0, IDENT_GLOBAL_TEMPLATES_DIR, C->GlobalTemplatesDir, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_GLOBAL_SEARCH_TEMPLATE, C->GlobalSearchTemplatePath, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_GLOBAL_SEARCH_DIR, C->GlobalSearchDir, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_GLOBAL_SEARCH_URL, C->GlobalSearchURL, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_GLOBAL_THEME, C->GlobalTheme, AvailableColumns);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
TypesetPair(&Typography, 0, IDENT_ASSETS_ROOT_DIR, C->AssetsRootDir, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_ASSETS_ROOT_URL, C->AssetsRootURL, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_CSS_PATH, C->CSSDir, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_IMAGES_PATH, C->ImagesDir, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_JS_PATH, C->JSDir, AvailableColumns);
|
|
|
|
TypesetPair(&Typography, 0, IDENT_QUERY_STRING, C->QueryString, AvailableColumns);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n"
|
|
|
|
"\n"
|
|
|
|
"%s", Typography.Margin);
|
|
|
|
bool ShouldFillSyntax = FALSE;
|
|
|
|
PrintBool("Respecting Privacy (derived from projects)", C->RespectingPrivacy, Typography.Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
fprintf(stderr, "%s", Typography.Margin);
|
|
|
|
int SecondsPerMinute = 60;
|
|
|
|
config_int_pair PrivacyCheckInterval = { .Key = IDENT_PRIVACY_CHECK_INTERVAL, .Value = C->PrivacyCheckInterval / SecondsPerMinute }; PrintIntPair(&PrivacyCheckInterval, Typography.Delimiter, ShouldFillSyntax, IndentationLevel, FALSE, TRUE);
|
|
|
|
fprintf(stderr, "%s", Typography.Margin);
|
|
|
|
PrintLogLevel(ConfigIdentifiers[IDENT_LOG_LEVEL].String, C->LogLevel, Typography.Delimiter, IndentationLevel, TRUE);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle("People", &Typography, 0, TermCols, C->Person.ItemCount);
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < C->Person.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintPerson(GetPlaceInBook(&C->Person, i), &Typography);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
PrintTitle("Roles", &Typography, 0, TermCols, C->Role.ItemCount);
|
|
|
|
for(int i = 0; i < C->Role.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
PrintRole(GetPlaceInBook(&C->Role, i), &Typography);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintTitle("Projects", &Typography, 0, TermCols, -1);
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < C->Project.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2021-05-30 18:39:47 +00:00
|
|
|
PrintProject(C, GetPlaceInBook(&C->Project, i), &Typography, 0, IndentationLevel, TermCols);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FreeProject(project *P)
|
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeBook(&P->Medium);
|
2021-05-30 18:39:47 +00:00
|
|
|
#if(HMMLIB_MAJOR_VERSION == 2)
|
|
|
|
FreeBook(&P->Credit);
|
|
|
|
#else
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeBook(&P->Indexer);
|
|
|
|
FreeBook(&P->Guest);
|
|
|
|
FreeBook(&P->CoHost);
|
2021-05-30 18:39:47 +00:00
|
|
|
#endif
|
2020-05-15 01:35:55 +00:00
|
|
|
for(int i = 0; i < P->Child.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeProject(GetPlaceInBook(&P->Child, i));
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeBook(&P->Child);
|
2020-05-09 17:33:25 +00:00
|
|
|
FreeTemplate(&P->SearchTemplate);
|
|
|
|
FreeTemplate(&P->PlayerTemplate);
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
// NOTE(matt): Making this a #define permits Free() to null out the incoming C
|
|
|
|
#define FreeConfig(C)\
|
|
|
|
{\
|
|
|
|
if(C)\
|
|
|
|
{\
|
|
|
|
for(int i = 0; i < C->Person.ItemCount; ++i)\
|
|
|
|
{\
|
|
|
|
person *Person = GetPlaceInBook(&C->Person, i);\
|
|
|
|
FreeBook(&Person->Support);\
|
|
|
|
}\
|
|
|
|
FreeBook(&C->Person);\
|
2021-05-30 18:39:47 +00:00
|
|
|
FreeBook(&C->Role);\
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < C->Project.ItemCount; ++i)\
|
|
|
|
{\
|
|
|
|
FreeProject(GetPlaceInBook(&C->Project, i));\
|
|
|
|
}\
|
|
|
|
FreeBook(&C->Project);\
|
|
|
|
FreeBook(&C->ResolvedVariables);\
|
|
|
|
FreeTemplate(&C->SearchTemplate);\
|
|
|
|
\
|
|
|
|
Free(C);\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
|
|
|
|
config_verifiers
|
|
|
|
InitVerifiers(void)
|
|
|
|
{
|
|
|
|
config_verifiers Result = {};
|
2020-06-24 12:29:18 +00:00
|
|
|
Result.VariantStrings = InitBook(MBT_VARIANT_STRING, 8);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
Result.HMMLDirs.ID0 = IDENT_HMML_DIR;
|
2020-06-24 12:29:18 +00:00
|
|
|
Result.HMMLDirs.Associations = InitBook(MBT_CONFIG_STRING_ASSOCIATION, 8);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
Result.BaseDirAndSearchLocation.ID0 = IDENT_BASE_DIR;
|
|
|
|
Result.BaseDirAndSearchLocation.ID1 = IDENT_SEARCH_LOCATION;
|
2020-06-24 12:29:18 +00:00
|
|
|
Result.BaseDirAndSearchLocation.Associations = InitBook(MBT_CONFIG_STRING_ASSOCIATION, 8);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
Result.BaseDirAndPlayerLocation.ID0 = IDENT_BASE_DIR;
|
|
|
|
Result.BaseDirAndPlayerLocation.ID1 = IDENT_PLAYER_LOCATION;
|
2020-06-24 12:29:18 +00:00
|
|
|
Result.BaseDirAndPlayerLocation.Associations = InitBook(MBT_CONFIG_STRING_ASSOCIATION, 8);
|
2020-05-24 23:26:13 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
bool
|
|
|
|
IsPositioned(config_int_pair *Position)
|
|
|
|
{
|
|
|
|
return Position && Position->Value != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PositionRolesInConfig(config *C, resolution_errors *E, config_verifiers *V, scope_tree *S)
|
|
|
|
{
|
|
|
|
memory_book RolesStaging = InitBookOfPointers(MBT_SCOPE_TREE_PTR, 4);
|
|
|
|
for(int i = 0; i < S->Trees.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
scope_tree *Tree = GetPlaceInBook(&S->Trees, i);
|
|
|
|
if(Tree->ID.Key == IDENT_ROLE)
|
|
|
|
{
|
|
|
|
scope_tree **This = MakeSpaceInBook(&RolesStaging);
|
|
|
|
*This = Tree;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int SlotCount = RolesStaging.ItemCount;
|
|
|
|
scope_tree *RoleSlot[SlotCount];
|
|
|
|
Clear(RoleSlot, sizeof(scope_tree *) * SlotCount);
|
|
|
|
for(int i = 0; i < SlotCount; ++i)
|
|
|
|
{
|
|
|
|
scope_tree **Role = GetPlaceInBook(&RolesStaging, i);
|
|
|
|
config_int_pair *Position = GetIntPair(*Role, IDENT_POSITION);
|
|
|
|
if(IsPositioned(Position))
|
|
|
|
{
|
|
|
|
int TargetPos;
|
|
|
|
if(Position->Value < 0)
|
|
|
|
{
|
|
|
|
TargetPos = SlotCount + Position->Value;
|
|
|
|
Clamp(0, TargetPos, SlotCount - 1);
|
|
|
|
while(RoleSlot[TargetPos] && TargetPos > 0)
|
|
|
|
{
|
|
|
|
--TargetPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(RoleSlot[TargetPos] && TargetPos < SlotCount - 1)
|
|
|
|
{
|
|
|
|
++TargetPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(Position->Value > 0)
|
|
|
|
{
|
|
|
|
TargetPos = Position->Value - 1;
|
|
|
|
Clamp(0, TargetPos, SlotCount - 1);
|
|
|
|
while(RoleSlot[TargetPos] && TargetPos < SlotCount - 1)
|
|
|
|
{
|
|
|
|
++TargetPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(RoleSlot[TargetPos] && TargetPos > 0)
|
|
|
|
{
|
|
|
|
--TargetPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RoleSlot[TargetPos] = *Role;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < SlotCount; ++i)
|
|
|
|
{
|
|
|
|
scope_tree **Role = GetPlaceInBook(&RolesStaging, i);
|
|
|
|
config_int_pair *Position = GetIntPair(*Role, IDENT_POSITION);
|
|
|
|
if(!IsPositioned(Position))
|
|
|
|
{
|
|
|
|
for(int j = 0; j < SlotCount; ++j)
|
|
|
|
{
|
|
|
|
if(!RoleSlot[j])
|
|
|
|
{
|
|
|
|
RoleSlot[j] = *Role;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < SlotCount; ++i)
|
|
|
|
{
|
|
|
|
PushRoleOntoConfig(C, E, V, RoleSlot[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeBook(&RolesStaging);
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
config *
|
|
|
|
ResolveVariables(scope_tree *S)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
Assert(LOG_COUNT == ArrayCount(LogLevelStrings));
|
|
|
|
config *Result = calloc(1, sizeof(config));
|
2020-06-24 12:29:18 +00:00
|
|
|
Result->ResolvedVariables = InitBookOfStrings(Kilobytes(1));
|
|
|
|
Result->Person = InitBook(MBT_PERSON, 8);
|
2021-05-30 18:39:47 +00:00
|
|
|
Result->Role = InitBook(MBT_ROLE, 4);
|
2020-06-24 12:29:18 +00:00
|
|
|
Result->Project = InitBook(MBT_PROJECT, 8);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
resolution_errors Errors = {};
|
2020-06-24 12:29:18 +00:00
|
|
|
Errors.Warnings = InitBook(MBT_RESOLUTION_ERROR, 16);
|
|
|
|
Errors.Errors = InitBook(MBT_RESOLUTION_ERROR, 16);
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
config_verifiers Verifiers = InitVerifiers();
|
|
|
|
|
|
|
|
for(int i = 0; i < S->Pairs.ItemCount; ++i)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
config_pair *Pair = GetPlaceInBook(&S->Pairs, i);
|
2020-06-24 12:29:18 +00:00
|
|
|
string Filepath = Wrap0(Pair->Position.Filename);
|
2020-05-24 23:26:13 +00:00
|
|
|
switch(Pair->Key)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
case IDENT_DB_LOCATION:
|
|
|
|
{ Result->DatabaseLocation = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS); } break;
|
|
|
|
case IDENT_GLOBAL_SEARCH_DIR:
|
|
|
|
{
|
|
|
|
Result->GlobalSearchDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS);
|
|
|
|
if(Result->GlobalSearchDir.Length > MAX_BASE_DIR_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->GlobalSearchDir, MAX_BASE_DIR_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_GLOBAL_SEARCH_URL:
|
|
|
|
{
|
|
|
|
Result->GlobalSearchURL = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS);
|
|
|
|
if(Result->GlobalSearchURL.Length > MAX_BASE_URL_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->GlobalSearchURL, MAX_BASE_URL_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_GLOBAL_TEMPLATES_DIR:
|
|
|
|
{ Result->GlobalTemplatesDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS); } break;
|
|
|
|
case IDENT_GLOBAL_SEARCH_TEMPLATE:
|
|
|
|
{ Result->GlobalSearchTemplatePath = StripSlashes(ResolveString(Result, &Errors, S, Pair, FALSE), P_REL); } break;
|
|
|
|
case IDENT_GLOBAL_THEME:
|
|
|
|
{
|
|
|
|
Result->GlobalTheme = ResolveString(Result, &Errors, S, Pair, FALSE);
|
|
|
|
if(Result->GlobalTheme.Length > MAX_THEME_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->GlobalTheme, MAX_THEME_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_ASSETS_ROOT_DIR:
|
|
|
|
{
|
|
|
|
Result->AssetsRootDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS);
|
|
|
|
if(Result->AssetsRootDir.Length > MAX_ROOT_DIR_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->AssetsRootDir, MAX_ROOT_DIR_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_ASSETS_ROOT_URL:
|
|
|
|
{
|
|
|
|
Result->AssetsRootURL = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS);
|
|
|
|
if(Result->AssetsRootURL.Length > MAX_ROOT_URL_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->AssetsRootURL, MAX_ROOT_URL_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_CSS_PATH:
|
|
|
|
{
|
|
|
|
Result->CSSDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, FALSE), P_REL);
|
|
|
|
if(Result->CSSDir.Length > MAX_RELATIVE_ASSET_LOCATION_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->CSSDir, MAX_RELATIVE_ASSET_LOCATION_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_IMAGES_PATH:
|
|
|
|
{
|
|
|
|
Result->ImagesDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, FALSE), P_REL);
|
|
|
|
if(Result->ImagesDir.Length > MAX_RELATIVE_ASSET_LOCATION_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->ImagesDir, MAX_RELATIVE_ASSET_LOCATION_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_JS_PATH:
|
|
|
|
{
|
|
|
|
Result->JSDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, FALSE), P_REL);
|
|
|
|
if(Result->JSDir.Length > MAX_RELATIVE_ASSET_LOCATION_LENGTH)
|
|
|
|
{
|
2020-06-24 12:29:18 +00:00
|
|
|
ConfigErrorSizing(&Filepath, Pair->Position.LineNumber, Pair->Key,
|
2020-05-24 23:26:13 +00:00
|
|
|
&Result->JSDir, MAX_RELATIVE_ASSET_LOCATION_LENGTH);
|
|
|
|
PushError(&Errors, S_ERROR, 0, Pair->Key);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case IDENT_QUERY_STRING:
|
|
|
|
{ Result->QueryString = ResolveString(Result, &Errors, S, Pair, FALSE); } break;
|
|
|
|
case IDENT_CACHE_DIR:
|
|
|
|
{ Result->CacheDir = StripSlashes(ResolveString(Result, &Errors, S, Pair, TRUE), P_ABS); } break;
|
|
|
|
default: break;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SecondsPerMinute = 60;
|
|
|
|
for(int i = 0; i < S->IntPairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_int_pair *IntPair = GetPlaceInBook(&S->IntPairs, i);
|
|
|
|
switch(IntPair->Key)
|
|
|
|
{
|
|
|
|
case IDENT_PRIVACY_CHECK_INTERVAL:
|
|
|
|
{ Result->PrivacyCheckInterval = SecondsPerMinute * IntPair->Value; } break;
|
|
|
|
case IDENT_LOG_LEVEL:
|
|
|
|
{ Result->LogLevel = IntPair->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 12:29:18 +00:00
|
|
|
for(int i = 0; i < S->BoolPairs.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
config_bool_pair *BoolPair = GetPlaceInBook(&S->BoolPairs, i);
|
|
|
|
switch(BoolPair->Key)
|
|
|
|
{
|
|
|
|
case IDENT_SUPPRESS_PROMPTS:
|
|
|
|
{ Result->SuppressingPrompts = BoolPair->Value; } break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < S->Trees.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
scope_tree *Tree = GetPlaceInBook(&S->Trees, i);
|
|
|
|
if(Tree->ID.Key == IDENT_PERSON)
|
|
|
|
{
|
|
|
|
PushPersonOntoConfig(Result, &Errors, &Verifiers, Tree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:39:47 +00:00
|
|
|
PositionRolesInConfig(Result, &Errors, &Verifiers, S);
|
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
for(int i = 0; i < S->Trees.ItemCount; ++i)
|
|
|
|
{
|
|
|
|
scope_tree *Tree = GetPlaceInBook(&S->Trees, i);
|
|
|
|
if(Tree->ID.Key == IDENT_PROJECT)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
2020-05-24 23:26:13 +00:00
|
|
|
PushProjectOntoConfig(Result, &Errors, &Verifiers, Tree);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
}
|
2020-05-09 17:33:25 +00:00
|
|
|
|
2020-05-24 23:26:13 +00:00
|
|
|
config_string_association *BaseDirAndSearchLocation = GetGlobalPathAssociation(&Verifiers.BaseDirAndSearchLocation, Result->GlobalSearchDir);
|
|
|
|
if(BaseDirAndSearchLocation)
|
|
|
|
{
|
|
|
|
PushError(&Errors, S_ERROR, 0, IDENT_GLOBAL_SEARCH_DIR);
|
|
|
|
AddProjectToAssociation(BaseDirAndSearchLocation, 0);
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
2020-05-24 23:26:13 +00:00
|
|
|
|
|
|
|
// TODO(matt): Mandate that, if a GlobalSearchDir or GlobalSearchURL is set, then both must be set
|
|
|
|
if(!Result->GlobalTheme.Length)
|
|
|
|
{
|
|
|
|
ConfigErrorUnset(IDENT_GLOBAL_THEME);
|
|
|
|
PushError(&Errors, S_ERROR, 0, IDENT_GLOBAL_THEME);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Errors.Errors.ItemCount > 0)
|
|
|
|
{
|
|
|
|
PrintAssociationClashes(&Verifiers.HMMLDirs);
|
|
|
|
PrintAssociationClashes(&Verifiers.BaseDirAndSearchLocation);
|
|
|
|
PrintAssociationClashes(&Verifiers.BaseDirAndPlayerLocation);
|
|
|
|
PrintVariantInconsistencies(&Verifiers.VariantStrings);
|
|
|
|
FreeConfig(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeVerifiers(&Verifiers);
|
|
|
|
FreeErrors(&Errors);
|
|
|
|
|
|
|
|
return Result;
|
2020-05-09 17:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config *
|
2020-05-15 01:35:55 +00:00
|
|
|
ParseConfig(string Path, memory_book *TokensList)
|
2020-05-09 17:33:25 +00:00
|
|
|
{
|
|
|
|
//PrintFunctionName("ParseConfig()");
|
2020-05-24 23:26:13 +00:00
|
|
|
_memory_book(config_type_spec) TypeSpecs = InitTypeSpecs();
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
MEM_LOOP_PRE_FREE("InitTypeSpecs")
|
|
|
|
FreeTypeSpecs(&TypeSpecs);
|
|
|
|
MEM_LOOP_PRE_WORK()
|
|
|
|
TypeSpecs = InitTypeSpecs();
|
|
|
|
MEM_LOOP_POST("InitTypeSpecs")
|
|
|
|
#endif
|
2020-05-09 17:33:25 +00:00
|
|
|
config *Result = 0;
|
|
|
|
tokens *T = Tokenise(TokensList, Path);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
MEM_LOOP_PRE_FREE("Tokenise")
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeTokensList(TokensList);
|
2020-05-09 17:33:25 +00:00
|
|
|
//FreeAndResetCount(WatchHandles.Handle, WatchHandles.Count);
|
|
|
|
MEM_LOOP_PRE_WORK()
|
2020-05-15 01:35:55 +00:00
|
|
|
T = Tokenise(TokensList, Path);
|
2020-05-09 17:33:25 +00:00
|
|
|
MEM_LOOP_POST("Tokenise")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(T)
|
|
|
|
{
|
2020-05-30 17:12:54 +00:00
|
|
|
scope_tree *ScopeTree = InitRootScopeTree();
|
2020-05-09 17:33:25 +00:00
|
|
|
SetTypeSpec(ScopeTree, &TypeSpecs);
|
|
|
|
SetDefaults(ScopeTree, &TypeSpecs);
|
|
|
|
ScopeTree = ScopeTokens(ScopeTree, TokensList, T, &TypeSpecs, 0);
|
|
|
|
|
|
|
|
// TODO(matt): Mem testing
|
|
|
|
//
|
|
|
|
#if 0
|
|
|
|
MEM_LOOP_PRE_FREE("ScopeTree")
|
|
|
|
FreeScopeTree(ScopeTree);
|
2020-05-15 01:35:55 +00:00
|
|
|
FreeTokensList(TokensList);
|
2020-05-09 17:33:25 +00:00
|
|
|
MEM_LOOP_PRE_WORK()
|
2020-05-15 01:35:55 +00:00
|
|
|
T = Tokenise(TokensList, Path);
|
2020-05-30 17:12:54 +00:00
|
|
|
ScopeTree = InitRootScopeTree();
|
2020-05-09 17:33:25 +00:00
|
|
|
SetTypeSpec(ScopeTree, &TypeSpecs);
|
|
|
|
SetDefaults(ScopeTree, &TypeSpecs);
|
2020-05-15 01:35:55 +00:00
|
|
|
ScopeTree = ScopeTokens(ScopeTree, TokensList, T, &TypeSpecs, 0);
|
2020-05-09 17:33:25 +00:00
|
|
|
MEM_LOOP_POST("ScopeTree")
|
|
|
|
#endif
|
|
|
|
//
|
|
|
|
////
|
|
|
|
|
|
|
|
//PrintScopeTree(ScopeTree);
|
|
|
|
if(ScopeTree)
|
|
|
|
{
|
|
|
|
//PrintC(CS_GREEN, "Resolving scope tree\n");
|
|
|
|
Result = ResolveVariables(ScopeTree);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
MEM_LOOP_PRE_FREE("ResolveVariables")
|
|
|
|
FreeConfig(Result);
|
|
|
|
MEM_LOOP_PRE_WORK()
|
|
|
|
Result = ResolveVariables(ScopeTree);
|
|
|
|
MEM_LOOP_POST("ResolveVariables")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FreeScopeTree(ScopeTree);
|
|
|
|
}
|
|
|
|
FreeTokensList(TokensList);
|
|
|
|
}
|
|
|
|
FreeTypeSpecs(&TypeSpecs);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// config
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int
|
|
|
|
main(int ArgC, char **Args)
|
|
|
|
{
|
|
|
|
//fprintf(stderr, "%s\n", ConfigFile.Buffer.Location);
|
|
|
|
config_type_specs TypeSpecs = InitTypeSpecs();
|
|
|
|
|
|
|
|
config *Config = ParseConfig(&TypeSpecs, Wrap0("cinera.conf"));
|
|
|
|
if(Config)
|
|
|
|
{
|
|
|
|
//PrintConfig(Config);
|
|
|
|
FreeConfig(Config);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeTypeSpecs(&TypeSpecs);
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
#endif
|