cibool ASTIL_Load(ASTIL *self, const char *filename, int song) { int lastSlash = ASTIL_FindPreviousSlash(filename, strlen(filename)); int rootSlash; FILE *fp; char line[ASTIL_MAX_TEXT_LENGTH + 1]; self->nCovers = 0; self->stilFilename[0] = '\0'; self->title[0] = '\0'; self->author[0] = '\0'; self->directoryComment[0] = '\0'; self->fileComment[0] = '\0'; self->songComment[0] = '\0'; if (lastSlash < 0 || lastSlash >= FILENAME_MAX - 14) /* strlen("/Docs/STIL.txt") */ return FALSE; memcpy(self->stilFilename, filename, lastSlash + 1); for (rootSlash = lastSlash; ; rootSlash = ASTIL_FindPreviousSlash(filename, rootSlash)) { if (rootSlash < 0) { self->stilFilename[0] = '\0'; return FALSE; } strcpy(self->stilFilename + rootSlash + 1, "Docs/STIL.txt"); self->stilFilename[rootSlash + 5] = self->stilFilename[rootSlash]; /* copy dir separator - slash or backslash */ fp = fopen(self->stilFilename, "rb"); if (fp != NULL) break; strcpy(self->stilFilename + rootSlash + 1, "STIL.txt"); fp = fopen(self->stilFilename, "rb"); if (fp != NULL) break; } self->isUTF8 = ASTIL_ReadUTF8BOM(fp); while (ASTIL_ReadLine(fp, line) >= 0) { int len = ASTIL_MatchFilename(line, filename + rootSlash); if (len == -1) { ASTIL_ReadComment(fp, line, self->fileComment); if (line[0] == '(' && line[1] == '#') { do { int i = 2; if (ASTIL_ParseInt(line, &i) - 1 == song && line[i] == ')' && line[i + 1] == '\0') { ASTIL_ReadComment(fp, line, self->songComment); ASTIL_ReadStilBlock(self, fp, line); break; } } while (ASTIL_ReadUntilSongNo(fp, line)); } else ASTIL_ReadStilBlock(self, fp, line); break; } if (len == lastSlash - rootSlash + 1 && line[len] == '\0') ASTIL_ReadComment(fp, line, self->directoryComment); } fclose(fp); return TRUE; }
static void ASTILCover_Load(ASTILCover *self, FILE *fp, char *line) { const char *ts; self->startSeconds = -1; self->endSeconds = -1; ts = strrchr(line, '('); if (ts != NULL) { int i = ts - line + 1; int startSeconds = ASTILCover_ParseTimestamp(line, &i); int endSeconds = -1; if (startSeconds >= 0 && line[i] == '-') { i++; endSeconds = ASTILCover_ParseTimestamp(line, &i); } if (line[i] == ')' && line[i + 1] == '\0') { int len = ts - line; if (line[len - 1] == ' ') len--; line[len] = '\0'; self->startSeconds = startSeconds; self->endSeconds = endSeconds; } } ASTILCover_SetText(self->titleAndSource, line + 9); self->artist[0] = '\0'; self->comment[0] = '\0'; if (ASTIL_ReadLine(fp, line) >= 9 && memcmp(line, " ARTIST: ", 9) == 0) { ASTILCover_SetText(self->artist, line + 9); ASTIL_ReadComment(fp, line, self->comment); } }