/* input.c */ #include #include #include #include #include #include #include "globals.h" extern int prepare_subtitle (char *, Image **, Image **); /* * add Input to the list of Inputs */ Input ** add_input (Input **input, struct timeval tv, Image *image) { *input = (Input *) malloc (sizeof (Input)); (*input)->time = TIMEVAL_IN_USEC (tv); (*input)->image = image; (*input)->x = (win_width - image->width)/2; (*input)->y = (win_height - image->height)/2; (*input)->next = (Input *) NULL; return &((*input)->next); } /* * takes a string of three numbers separated by colons, i.e. 00:00:00.00 * The last number can be floatinf point. The three numbers are separated * and and recombined in the form of the timeval structure. * This structure is returned. */ struct timeval ascii_to_timeval (char *ascii) { char *temp, *ptr, **next; struct timeval tv; char colon [] = ":"; long hr, min; double fsec, sec, usec; ptr = ascii; next = &ptr; temp = strsep (next, colon); hr = atol (temp); temp = strsep (next, colon); min = atol (temp); fsec = (double) atof (*next); usec = 1000000 * modf (fsec, &sec); tv.tv_sec = (long) ((hr * 60 * 60) + (min * 60) + sec); tv.tv_usec = (long) usec; return tv; } /* * Read in the input file and place Inputs into an unsorted linked list. */ void read_inputs (Input **ptr) { int length; char *string_ptr, string [MAX_STRING_SIZE]; char **next, *start, *end; const char whitespace [] = " \f\r\t\v"; Image *put, *clear; while ( fgets (string, sizeof (string), stdin) ) { length = strlen (string); string [length-1] = (char) NULL; string_ptr = string; next = &string_ptr; start = strsep (next, whitespace); end = strsep (next, whitespace); prepare_subtitle (*next, &put, &clear); ptr = add_input (ptr, ascii_to_timeval (start), put); ptr = add_input (ptr, ascii_to_timeval (end), clear); } }