Shayan's Software & Technology

My adventure as a Software Engineer continues..,

WebVTT 0.3 Release


I have chosen to build the error handling functionality for the parser. This functionality includes the ability to log errors while the parser is parsing cue text. The error log can also be used to catalog any system logic errors that might occur. There is an array of common errors that stores common error messages. The error messages are enumerated to represent errors that reflect the error message. My struct uses this functionality already present in the parser to create an error structure and pack it into a struct.


This is the home of the error structure. There have been numerous changes to this structure since the last release. here they are:

– text files are no longer handled in the error structure because the cue text parser only receives a raw cue text structure in the form form of a buffer to parse.

– types are no longer primitive due to less reliance on the standard libraries and more reliance on the vttlibrary,

/* Represents an Error Logging Type and follows GNU style error logging standards:
 * These error standards are followed for source files and webVTT files.

typedef struct {

char *error_message;
 webvtt_uint webvtt_line_number;
 webvtt_uint webvtt_column;

} vtt_error_t;

/* Forward declaration of the webvtt_parser_t struct */
typedef struct webvtt_parser_t *webvtt_parser;

 * Error functions.
 * These functions are used when the DEBUG_MODE is set.
 * Create an Error instance and populate it with error information and add to the list.
 * takes in vtt file name and the line the error occured on.
void create_error(webvtt_parser self, webvtt_error err);

 * Add an Error object to the end of the list.
void add_to_error_list(webvtt_parser self, vtt_error_t *error);

 * This function is meant to be called at the end of parser execution for displaying error information.
 * It also Formats and writes out errors to a log file called errorlog.txt.
 * Deallocate error object as its elements are written to the file and to stderr
void print_error_list(webvtt_parser self);

 * Destroy an Error Objects and list
void destroy_error_list(webvtt_parser self);



The implementations of error functions have changed to reflect the nature of some of the components available in the new c-parser.

void create_error(webvtt_parser self, webvtt_error err) {
 * Create and initialize the error structure.
 * Error messages are represented with ASCII character strings
 const char *err_message = webvtt_strerror(err);
 /* check to see if an associated error message was found */
 if (err_message != "\0") {
 vtt_error_t *er = (vtt_error_t *)malloc(sizeof(vtt_error_t));
 er->error_message = (char *)malloc(sizeof(char) * strlen(err_message));
 er->error_message = (char *)err_message;

er->webvtt_line_number = self->line;
 er->webvtt_column = self->column;

/* Add to the end of the error array. */
 add_to_error_list(self, er);

void add_to_error_list(webvtt_parser self, vtt_error_t *er) {
 /* Make use of the first allocated element before reallocating. */
 if(self->error_list_size == 0)
 self->error_list[0] = *er;
 else {
 self->error_list = (vtt_error_t*)realloc(self->error_list, sizeof(vtt_error_t) + sizeof(self->error_list));
 self->error_list[self->error_list_size] = *er;
 /* free the dynamically allocated vtt_error_t instance (was allocated in create_error func) */

/* Prints errors stored int he webvtt_parser structure to standard error. */
void print_error_list(webvtt_parser self) {
 webvtt_uint i;
 for ( i = 0; i < self->error_list_size; i++) {
 /* print to stderr */
 fprintf(stderr, "Error Message: %s Line: %d Column: %d\n",
 self->error_list[i].error_message, self->error_list[i].webvtt_line_number, self->error_list[i].webvtt_column);

/* Destroys the webvtt error list in the webvtt_parser object and it's contents */

void destroy_error_list(webvtt_parser self){
 if (self->error_list){
 webvtt_uint i;
 for(i = 0; i > self->error_list_size; i++) {
 /* Deallocate the current Error Object in the list. */
 self->error_list_size = 0;


The error struct list resides in the webvtt_parser structure. This is where the parser can store an error as it occurs and continue on parsing the vtt file.

 webvtt_uint state;
 webvtt_uint bytes; /* number of bytes read. */
 webvtt_uint line;
 webvtt_uint column;
 webvtt_cue_fn_ptr read;
 webvtt_error_fn_ptr error;
 void *userdata;
 webvtt_bool mode;
 webvtt_bool finish;
 webvtt_uint flags;
 * Current cue
 webvtt_cue cue;

 * line
 int truncate;
 webvtt_uint line_pos;
 webvtt_bytearray line_buffer;

 * tokenizer
 webvtt_uint tstate;
 webvtt_uint token_pos;
 webvtt_byte token[0x100];

 * Error Object List
 vtt_error_t* error_list;
 webvtt_uint error_list_size;





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: