cinera: Code clean-up

• Make vod_platform an enum
• Unionise config_int_pair and config_bool_pair in config_pair
This commit is contained in:
Matt Mascarenhas 2021-06-17 13:32:53 +01:00
parent 744515dac4
commit e39a09c0ad
2 changed files with 351 additions and 410 deletions

View File

@ -23,7 +23,7 @@ typedef struct
version CINERA_APP_VERSION = {
.Major = 0,
.Minor = 8,
.Patch = 22
.Patch = 23
};
#include <stdarg.h> // NOTE(matt): varargs
@ -69,6 +69,9 @@ typedef uint64_t bool;
#define TRUE 1
#define FALSE 0
#define SECONDS_PER_HOUR 3600
#define SECONDS_PER_MINUTE 60
#define enum8(type) int8_t
#define enum16(type) int16_t
#define enum32(type) int32_t
@ -2407,6 +2410,54 @@ GetIconTypeFromString(string *Filename, token *T)
return NS_COUNT;
}
char *VODPlatformStrings[] =
{
0,
"youtube",
};
typedef enum
{
VP_DEFAULT_UNSET,
VP_YOUTUBE,
VP_COUNT,
} vod_platform;
vod_platform
GetVODPlatformFromString(string *Filename, token *T)
{
for(int i = 0; i < VP_COUNT; ++i)
{
if(!StringsDifferLv0(T->Content, VODPlatformStrings[i])) { return i; }
}
ConfigError(Filename, T->LineNumber, S_ERROR, "Unknown vod_platform: ", &T->Content);
fprintf(stderr, " Valid vod_platforms:\n");
int FirstValidVODPlatform = 1;
for(int i = FirstValidVODPlatform; i < VP_COUNT; ++i)
{
fprintf(stderr, " %s\n", VODPlatformStrings[i]);
}
return VP_COUNT;
}
vod_platform
GetVODPlatform(string VODPlatform)
{
for(int i = 0; i < VP_COUNT; ++i)
{
if(!StringsDifferLv0(VODPlatform, VODPlatformStrings[i])) { return i; }
}
return VP_COUNT;
}
bool
IsValidVODPlatform(vod_platform V)
{
return V > VP_DEFAULT_UNSET && V < VP_COUNT;
}
// DBVersion 1
typedef struct { unsigned int DBVersion; version AppVersion; version HMMLVersion; unsigned int EntryCount; } db_header1;
typedef struct { int Size; char BaseFilename[32]; } db_entry1;
@ -3249,7 +3300,7 @@ typedef struct
char URLSearch[MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH];
char URLPlayer[MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH + 1 + MAX_BASE_FILENAME_LENGTH];
char VideoID[MAX_VOD_ID_LENGTH];
char VODPlatform[16];
vod_platform VODPlatform;
} buffers;
rc
@ -4148,9 +4199,6 @@ InitTemplate(template *Template, string Location, template_type Type)
Template->Metadata.NavBuffer = InitBook(sizeof(navigation_buffer), 4);
}
#define SECONDS_PER_HOUR 3600
#define SECONDS_PER_MINUTE 60
v3
V3(int A, int B, int C)
{
@ -9156,13 +9204,13 @@ ExamineDB(void)
DeclaimMenuBuffers(&MenuBuffers)
bool
VideoIsPrivate(string VODPlatform, char *VideoID)
VideoIsPrivate(vod_platform VODPlatform, char *VideoID)
{
// TODO(matt): Redo this to only return once, at the end
// NOTE(matt): Currently only supports YouTube
// NOTE(matt): Stack-string
if(StringsMatch(Wrap0("youtube"), VODPlatform))
if(VODPlatform == VP_YOUTUBE)
{
char Message[128];
CopyString(Message, sizeof(Message), "%sChecking%s privacy status of: https://youtube.com/watch?v=%s", ColourStrings[CS_ONGOING], ColourStrings[CS_END], VideoID);
@ -10240,7 +10288,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
Clear(CollationBuffers->Title, sizeof(CollationBuffers->Title));
Clear(CollationBuffers->URLPlayer, sizeof(CollationBuffers->URLPlayer));
Clear(CollationBuffers->URLSearch, sizeof(CollationBuffers->URLSearch));
Clear(CollationBuffers->VODPlatform, sizeof(CollationBuffers->VODPlatform));
CollationBuffers->VODPlatform = VP_DEFAULT_UNSET;
// TODO(matt): A "MakeString0OnStack()" sort of function?
// NOTE(matt): Stack-string
@ -10342,24 +10390,30 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
CopyString(CollationBuffers->VideoID, sizeof(CollationBuffers->VideoID), "%s", HMML.metadata.id);
}
string VODPlatform = {};
vod_platform VODPlatform = VP_DEFAULT_UNSET;
if(HMML.metadata.vod_platform)
{
VODPlatform = Wrap0(HMML.metadata.vod_platform);
VODPlatform = GetVODPlatform(Wrap0(HMML.metadata.vod_platform));
}
else if(CurrentProject->VODPlatform.Length > 0)
if(!IsValidVODPlatform(VODPlatform) && IsValidVODPlatform(CurrentProject->VODPlatform))
{
VODPlatform = CurrentProject->VODPlatform;
}
if(VODPlatform.Length == 0)
if(!IsValidVODPlatform(VODPlatform))
{
IndexingError(FilepathL, 0, S_ERROR, "The [video] node lacks an \"vod_platform\"", 0);
IndexingError(FilepathL, 0, S_ERROR, "The [video] node lacks a valid \"vod_platform\"", 0);
fprintf(stderr, " Valid vod_platforms:\n");
int FirstValidVODPlatform = 1;
for(int i = FirstValidVODPlatform; i < VP_COUNT; ++i)
{
fprintf(stderr, " %s\n", VODPlatformStrings[i]);
}
Result = RC_ERROR_HMML;
}
else
{
CopyString(CollationBuffers->VODPlatform, sizeof(CollationBuffers->VODPlatform), "%s", HMML.metadata.vod_platform);
CollationBuffers->VODPlatform = VODPlatform;
}
buffer URLPlayer = {};
@ -11627,7 +11681,7 @@ BuffersToHTML(config *C, project *Project, buffers *CollationBuffers, template *
}
break;
case TAG_VIDEO_ID: CopyStringToBufferNoFormat(&Master, Wrap0i(CollationBuffers->VideoID, sizeof(CollationBuffers->VideoID))); break;
case TAG_VOD_PLATFORM: CopyStringToBufferNoFormat(&Master, Wrap0i(CollationBuffers->VODPlatform, sizeof(CollationBuffers->VODPlatform))); break;
case TAG_VOD_PLATFORM: CopyStringToBufferNoFormat(&Master, Wrap0(VODPlatformStrings[CollationBuffers->VODPlatform])); break;
case TAG_SEARCH:
{
/* */ MEM_TEST_MID("BuffersToHTML()");

File diff suppressed because it is too large Load Diff