Esempio n. 1
0
File: astil.c Progetto: epi/asap
static int ASTILCover_ParseTimestamp(const char *s, int *pos)
{
	int minutes = ASTIL_ParseInt(s, pos);
	if (minutes >= 0 && s[(*pos)++] == ':') {
		int seconds = ASTIL_ParseInt(s, pos);
		if (seconds >= 0)
			return 60 * minutes + seconds;
	}
	return -1;
}
Esempio n. 2
0
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;
}