177
174
DEBUGCODE { fprintf(stderr, "script_path is: %s\n", script_path); }
180
/* FIXME looks like a place for scandir() - or our own w32_scandir() */
181
177
/* create a list of all the .xml files */
183
script_dir = opendir(script_path);
187
script_file = readdir(script_dir);
191
/* must have at least '.xml' at the end */
192
if (strlen(script_file->d_name) < 5)
195
/* Don't show project info file: */
196
if (strcmp(script_file->d_name, "projectInfo.xml") == 0)
199
if (strcmp(&script_file->d_name[strlen(script_file->d_name) - 4],".xml"))
202
sprintf(script_filenames[num_scripts], "%s", script_file->d_name);
204
DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n",
205
num_scripts, script_filenames[num_scripts]); }
207
} while (1); /* Leave loop when readdir() returns NULL */
209
closedir(script_dir);
178
num_scripts = scandir(script_path, &script_list_dirents, is_xml_file, alphasort);
180
for (scriptIterator = 0, scripts = 0;
181
scriptIterator < num_scripts && scripts < MAX_LESSONS;
184
/* Copy over the filename: */
185
nchars = snprintf(script_filenames[scripts], FNLEN, "%s",
186
script_list_dirents[scriptIterator]->d_name);
188
/* Skip (actually clobber) any invalid or undesired files: */
189
if (nchars < 0 || nchars >= FNLEN)
191
/* Don't show project info file or instructions files */
192
if (strcmp(script_filenames[scripts], "projectInfo.xml") == 0 ||
193
strcmp(script_filenames[scripts], "laser.xml") == 0 ||
194
strcmp(script_filenames[scripts], "cascade.xml") == 0)
199
fprintf(stderr, "Found script file %d:\t%s\n", scripts, script_filenames[scripts]);
202
/* Increment the iterator for correctly-parsed lesson files */
208
fprintf(stderr, "Before undesired files screened out:\n");
209
for(i = 0; i < num_scripts; i++)
210
fprintf(stderr, "script %d filename: %s\n", i,
211
script_list_dirents[i]->d_name);
212
fprintf(stderr, "After undesired files screened out:\n");
213
for(i = 0; i < scripts; i++)
214
fprintf(stderr, "script %d filename: %s\n", i,
215
script_filenames[i]);
219
/* Now free the individual dirents. We do this on a second pass */
220
/* because of the "continue" approach used to error handling. */
221
for (scriptIterator = 0; scriptIterator < num_scripts; scriptIterator++)
222
free(script_list_dirents[scriptIterator]);
223
free(script_list_dirents);
225
/* Adjust num_scripts for any skipped files: */
226
num_scripts = scripts;
228
//START OF OLD IMPLEMENTATION
230
// script_dir = opendir(script_path);
233
// script_file = readdir(script_dir);
237
// /* must have at least '.xml' at the end */
238
// if (strlen(script_file->d_name) < 5)
241
// /* Don't show project info file or instructions files */
242
// if (strcmp(script_file->d_name, "projectInfo.xml") == 0 ||
243
// strcmp(script_file->d_name, "laser.xml") == 0 ||
244
// strcmp(script_file->d_name, "cascade.xml") == 0)
248
// if (strcmp(&script_file->d_name[strlen(script_file->d_name) - 4],".xml"))
251
// sprintf(script_filenames[num_scripts], "%s", script_file->d_name);
253
// DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n",
254
// num_scripts, script_filenames[num_scripts]); }
256
// } while (1); /* Leave loop when readdir() returns NULL */
258
// closedir(script_dir);
260
// END OF OLD IMPLEMENTATION
211
264
DEBUGCODE { fprintf(stderr, "Found %d . xml file(s) in script dir\n", num_scripts); }
542
602
if (fscanf_result == EOF)
605
if (strncmp("<!--", str, 4) == 0)
607
/* -- comment section found, ignore everything until comment close -- */
613
// search the current line for comment end
614
for ( tmpStr = str; strlen(tmpStr) >= 3 && !found; tmpStr++ )
616
if (strncmp("-->",tmpStr, 3) == 0)
618
// move past the comment end tag
624
// if the comment end was not found get another line
627
fscanf_result = fscanf(f, "%[^\n]\n", str);
631
// we did find the end of the comment
635
if (strlen(tmpStr) > 0)
637
// copy the rest of the line into str for processing
638
strncpy(str, tmpStr, strlen(tmpStr));
639
str[strlen(tmpStr)] = '\0';
643
// str needs another line, this one is used up
644
fscanf_result = fscanf(f, "%[^\n]\n", str);
648
// if the next line is a comment, start all over again
649
if (fscanf_result != EOF && strncmp("<!--", str, 4) == 0)
655
} while ( fscanf_result != EOF && !found );
657
/* -- if we reached the end of the file and saw no close to the comment, generate a warning -- */
658
if ( !found && fscanf_result == EOF )
660
fprintf(stderr, "XML Warning: End of file reached looking for the end of a comment.\n");
664
/* -- don't continue processing if at EOF -- */
665
if (fscanf_result == EOF)
545
671
if (strncmp("<script", str, 7) == 0)
547
673
/* -- allocate space for the lesson info -- */
874
else if (strncmp("<bkgd", str, 5) == 0)
879
"CRITICAL XML ERROR: <bkgd> should be in a <page> in file %s line (todo)",
882
return 0; //Return control to the main program for a clean exit
885
if (curPage->items == NULL)
887
curItem = (itemType*)calloc(1, sizeof(itemType));
888
curPage->items = curItem;
892
curItem->next = (itemType*)calloc(1, sizeof(itemType));
893
curItem = curItem->next;
896
curItem->type = itemBKGD;
897
curItem->x = curItem->y = -1;
900
for (i = 6; i < strlen(str); i++)
902
if ((str[i] == 's') && strncmp("src", &str[i], 3) == 0)
903
curItem->data = get_quote(&str[i + 3]);
743
907
else if (strncmp("<wav", str, 4) == 0)
745
909
if (curPage == NULL)
965
1136
if (curPage->background)
967
1138
SDL_Surface* img = LoadImage(curPage->background, IMG_ALPHA|IMG_NOT_REQUIRED);
968
SDL_BlitSurface(img, NULL, screen, NULL);
1140
/* hack: since this is the background it needs to scale when in fullscreen
1141
* but shouldn't every image scale when in fullscreen? assuming svg is for that... -MDT */
1142
if (settings.fullscreen)
1144
SDL_Surface* fsimg = zoom(img, fs_res_x, fs_res_y);
1145
SDL_BlitSurface(fsimg, NULL, screen, NULL);
1146
SDL_FreeSurface(fsimg);
1150
SDL_BlitSurface(img, NULL, screen, NULL);
969
1153
SDL_FreeSurface(img);
971
1156
else if (curScript->background)
973
1158
SDL_Surface* img = LoadImage(curScript->background, IMG_ALPHA|IMG_NOT_REQUIRED);
974
SDL_BlitSurface(img, NULL, screen, NULL);
1160
/* hack: since this is the background it needs to scale when in fullscreen -MDT */
1161
if (settings.fullscreen)
1163
SDL_Surface* fsimg = zoom(img, fs_res_x, fs_res_y);
1164
SDL_BlitSurface(fsimg, NULL, screen, NULL);
1165
SDL_FreeSurface(fsimg);
1169
SDL_BlitSurface(img, NULL, screen, NULL);
975
1172
SDL_FreeSurface(img);