diff --git a/cinera/cinera.c b/cinera/cinera.c index d45ba56..c3e9530 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -23,7 +23,7 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 10, - .Patch = 19 + .Patch = 20 }; #define __USE_XOPEN2K8 // NOTE(matt): O_NOFOLLOW @@ -1451,6 +1451,7 @@ file credits this person for the entire project, but indexers may \"uncredit\" p file credits this person for the entire project, but indexers may \"uncredit\" people in the [video] node of a HMML file." }, { "css_path", "Path relative to assets_root_dir and assets_root_url where CSS files are located." }, { "db_location", "Absolute file path where the database file resides. If you run multiple instances of Cinera on the same machine, please ensure this db_location differs between them." }, + { "default_cc_lang", "The ISO 639-1 language code of the closed captions to enable by default. May be overridden by setting the cc_lang in the video node of an HMML file." }, { "default_medium", "The ID of a medium (see also medium) which will be the default for the project. May be overridden by setting the medium in the video node of an HMML file." }, { "deny", "See allow." }, { "deny_bespoke_templates", "Indexers may use the \"template\" attribute in the video node of an .hmml file to set a bespoke template for that entry, superseding any configured player_template. Setting \"deny_bespoke_templates\" to true prevents this." }, @@ -1586,6 +1587,7 @@ typedef enum IDENT_CREDIT, IDENT_CSS_PATH, IDENT_DB_LOCATION, + IDENT_DEFAULT_CC_LANG, IDENT_DEFAULT_MEDIUM, IDENT_DENY, IDENT_DENY_BESPOKE_TEMPLATES, @@ -1963,18 +1965,14 @@ ConfigError(string *Filename, uint64_t LineNumber, severity Severity, char *Mess void ConfigErrorField(string *Filename, uint64_t LineNumber, severity Severity, config_identifier_id FieldID, - char *Message, string *Received) + string *Received, char *Message) { ErrorFilenameAndLineNumber(Filename, LineNumber, Severity, ED_CONFIG); fprintf(stderr, - "Faulty %s%s%s %s", + "%s%s%s value %s%.*s%s %s\n", ColourStrings[CS_YELLOW_BOLD], ConfigIdentifiers[FieldID].String, ColourStrings[CS_END], + ColourStrings[CS_MAGENTA_BOLD], (int)Received->Length, Received->Base, ColourStrings[CS_END], Message); - if(Received) - { - PrintStringC(CS_MAGENTA_BOLD, *Received); - } - fprintf(stderr, "\n"); } void @@ -2139,6 +2137,25 @@ IndexingErrorClash(string *Filename, uint64_t LineNumber, severity Severity, cha fprintf(stderr, "\n"); } +void +PrintValidLanguageCodeChars(void) +{ + fprintf(stderr, + " Valid characters:\n" + " a to z\n" + " A to Z\n" + " 0 to 9\n" + " - (hyphen)\n"); +} + +void +IndexingErrorInvalidLanguageCode(string *Filename, uint64_t LineNumber, char *Key, string Received) +{ + ErrorFilenameAndLineNumber(Filename, LineNumber, S_ERROR, ED_INDEXING); + fprintf(stderr, "%s value %s%.*s%s contains invalid character(s)\n", + Key, ColourStrings[CS_MAGENTA_BOLD], (int)Received.Length, Received.Base, ColourStrings[CS_END]); +} + void IndexingErrorInvalidSubstring(string *Filename, uint64_t LineNumber, char *Key, string Received, string InvalidSubstring) { @@ -2481,6 +2498,23 @@ IsValidIdentifierCharacter(char C) return ((C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') || C == '_' || C == '-'); } +bool +IsValidLanguageCode(string S) +{ + // TODO(matt): Add an upper limit to the length + bool Result = TRUE; + for(int i = 0; i < S.Length; ++i) + { + char C = S.Base[i]; + if(!((C >= '0' && C <= '9') || (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') || C == '-')) + { + Result = FALSE; + break; + } + } + return Result; +} + bool IsNumber(char C) { @@ -11054,6 +11088,18 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF } } + string CCLang = CurrentProject->DefaultCCLang; + if(HMML.metadata.cc_lang) + { + CCLang = Wrap0(HMML.metadata.cc_lang); + if(!IsValidLanguageCode(CCLang)) + { + IndexingErrorInvalidLanguageCode(&FilepathL, 0, "cc_lang", CCLang); + PrintValidLanguageCodeChars(); + Result = RC_ERROR_HMML; + } + } + string OutputLocation = {}; if(!HMML.metadata.output) { @@ -11230,8 +11276,17 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF CopyStringToBuffer(&PlayerBuffers.Main, "