/* reads a SMIL presentation and stores the media objects in nodes */ #ifndef __SMILTOSTRUCT_H #define __SMILTOSTRUCT_H #include #include #include #include #define SIZE 100 //holds the info on a media object typedef struct node { char name[SIZE]; char keywords[SIZE]; char subsection[SIZE]; char url[SIZE]; char level[SIZE]; struct node *next; } node; //pointers to different types of nodes typedef struct tagstructure { struct node *ts; struct node *as; struct node *vs; struct node *is; } tagstructure; //reads in SMIL file and converts objects to nodes tagstructure *conversion(char *filename) { tagstructure *tags; //pointer to all nodes node *active, //current ncde *head; //head of current node list char temp[80], temp2[10], //temporary chars for holding params, values, tags, etc. key[100], //temporary chars for holding keywords url[100]; //temporary chars for holding a url int ch, //current character cat, //tells which param we are dealing with i, //lcv ch2, //temporary char j; //lcv FILE *file1; //pointer to file to read from if ((file1 = fopen(filename, "r")) == NULL) { printf("Error opening file for input!\n"); exit(0); } tags = malloc(sizeof(tagstructure)); tags->ts = NULL; tags->as = NULL; tags->vs = NULL; tags->is = NULL; for (;;) { ch = fgetc(file1); if (ch == EOF) break; if(ch == '/') { ch = fgetc(file1); ch = fgetc(file1); } if (!isspace(ch)) { if (ch == '<') { ch = fgetc(file1); i = 0; while((ch != ' ')&&(ch != EOF)&&(ch != '\n')) { temp[i] = ch; ch = fgetc(file1); i++; } temp[i] = '\0'; if (strcmp(temp, "text") == 0) //found a text object { active = tags->ts; if(active == NULL) { tags->ts = malloc(sizeof(node)); tags->ts->next = NULL; active = tags->ts; } else { while(active->next != NULL) active = active->next; active->next = malloc(sizeof(node)); active = active->next; active->next = NULL; } head = tags->ts; } else if (strcmp(temp, "audio") == 0) { //found an audio object active = tags->as; if(active == NULL) { tags->as = malloc(sizeof(node)); tags->as->next = NULL; active = tags->as; } else { while(active->next != NULL) active = active->next; active->next = malloc(sizeof(node)); active = active->next; active->next = NULL; } head = tags->as; } else if (strcmp(temp, "video") == 0) { //found a video object active = tags->vs; if(active == NULL) { tags->vs = malloc(sizeof(node)); tags->vs->next = NULL; active = tags->vs; } else { while(active->next != NULL) active = active->next; active->next = malloc(sizeof(node)); active = active->next; active->next = NULL; } head = tags->vs; } else if (strcmp(temp, "img") == 0) { //found an img object active = tags->is; if(active == NULL) { tags->is = malloc(sizeof(node)); tags->is->next = NULL; active = tags->is; } else { while(active->next != NULL) active = active->next; active->next = malloc(sizeof(node)); active = active->next; active->next = NULL; } head = tags->is; } else if(temp[i-1] != '>') { ch = fgetc(file1); while(ch != '>') ch = fgetc(file1); ch = fgetc(file1); } } else //found a parameter { i = 0; while (ch != '=') { temp[i++] = ch; ch = fgetc(file1); } temp[i] = '\0'; if (strcmp(temp, "src") == 0) cat = 1; else if (strcmp(temp, "abstract") == 0) cat = 2; else if (strcmp(temp, "title") == 0) cat = 3; else if (strcmp(temp, "alt") == 0) cat = 4; else if (strcmp(temp, "id") == 0) cat = 5; ch = fgetc(file1); ch = fgetc(file1); i = 0; while (ch != '"') { if (ch != '\n') temp[i++] = ch; else temp[i++] = ' '; ch = fgetc(file1); } temp[i] = '\0'; if (head == tags->ts) { if(cat == 4) { ch2 = temp[0]; i = 0; while(ch2 != '*') { key[i] = ch2; ch2 = temp[i++]; } key[i] = '\0'; j = 0; i++; ch2 = temp[i]; while(ch2 != '\0') { url[j++] = ch2; ch2 = temp[++i]; } url[j] = '\0'; strcpy(active->url, url); strcpy(active->keywords, key); } else if(cat != 1) { switch (cat) { case 2: strcpy(active->subsection, temp); break; case 3: strcpy(active->name, temp); break; case 5: ch = temp[2]; i = 2; j =0; while(ch != '\0') { temp2[j++] = ch; ch = temp[++i]; } temp2[j] = '\0'; strcpy(active->level,temp2); } } cat = -1; } else { switch (cat) { case 1: strcpy(active->url, temp); break; case 2: strcpy(active->subsection, temp); break; case 3: strcpy(active->name, temp); break; case 4: strcpy(active->keywords, temp); break; case 5: ch = temp[2]; i = 2; j = 0; while(ch != '\0') { temp2[j++] = ch; ch = temp[++i]; } temp2[j] = '\0'; strcpy(active->level,temp2); } cat = -1; } } } } close(file1); return tags; } #endif