More header parsing
authorJelmer Vernooij <jelmer@samba.org>
Fri, 7 May 2004 04:43:39 +0000 (05:43 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 7 May 2004 04:43:39 +0000 (05:43 +0100)
Makefile
ptb.c
ptb.h

index 5384c05adaca46fb22796010e17d4c9a668e68c4..5c593c29b3ff125c19026b85f4fb806a3bd122e5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,4 +21,4 @@ ptbtest: $(PTBTEST_OBJS)
        $(CC) -o $@ $(PTBTEST_OBJS) `pkg-config --libs glib-2.0`
 
 clean: 
-       rm -f *,o core $(PROGS)
+       rm -f *.o core $(PROGS)
diff --git a/ptb.c b/ptb.c
index 7f50b53616b83fc3e9922e286da42d54478c6146..51e66588617892fe3ede3697c994142d142aa965 100644 (file)
--- a/ptb.c
+++ b/ptb.c
@@ -76,33 +76,70 @@ static int ptb_read_header(int fd, struct ptb_hdr *hdr)
        if(strcmp(id, "ptab")) return -1;
 
        read(fd, &hdr->version, 2);
-       
-       /* FIXME: 0000 / 0003 */
-       read(fd, unknown, 2);
-//     fprintf(stderr, "%s: %02x %02x : %lx\n", debug_filename, unknown[0], unknown[1], *((guint16 *)unknown));
-       ptb_read_string(fd, &hdr->title);
-       ptb_read_string(fd, &hdr->artist);
-
-       /* FIXME: REcord type ? */
-       read(fd, unknown, 2);
-//     fprintf(stderr, "%s: %02x %02x : %lx\n", debug_filename, unknown[0], unknown[1], *((guint16 *)unknown));
-       ptb_read_string(fd, &hdr->album);
-       
-       /* d4 0700 00 */
-       read(fd, unknown, 4);
-       ptb_read_string(fd, &hdr->music_by);
-       ptb_read_string(fd, &hdr->words_by);
-       ptb_read_string(fd, &hdr->arranged_by);
-       ptb_read_string(fd, &hdr->guitar_transcribed_by);
-       ptb_read_string(fd, &hdr->bass_transcribed_by);
-       ptb_read_string(fd, &hdr->lyrics);
-       ptb_read_string(fd, &hdr->copyright);
+
+       read(fd, &hdr->classification, 1);
+
+       switch(hdr->classification) {
+       case CLASSIFICATION_SONG:
+       read(fd, unknown, 1); /* FIXME */
+       ptb_read_string(fd, &hdr->class_info.song.title);
+       ptb_read_string(fd, &hdr->class_info.song.artist);
+
+       read(fd, &hdr->class_info.song.release_type, 1);
+
+       switch(hdr->class_info.song.release_type) {
+       case RELEASE_TYPE_PR_AUDIO:
+       read(fd, &hdr->class_info.song.release_info.pr_audio.type, 1);
+       ptb_read_string(fd, &hdr->class_info.song.release_info.pr_audio.album_title);
+       read(fd, &hdr->class_info.song.release_info.pr_audio.year, 2);
+       read(fd, &hdr->class_info.song.release_info.pr_audio.is_live_recording, 1);
+       break;
+       case RELEASE_TYPE_PR_VIDEO:
+       ptb_read_string(fd, &hdr->class_info.song.release_info.pr_video.video_title);
+       read(fd, &hdr->class_info.song.release_info.pr_video.is_live_recording, 1);
+       break;
+       case RELEASE_TYPE_BOOTLEG:
+               ptb_read_string(fd, &hdr->class_info.song.release_info.bootleg.title);
+               read(fd, &hdr->class_info.song.release_info.bootleg.day, 2);
+               read(fd, &hdr->class_info.song.release_info.bootleg.month, 2);
+               read(fd, &hdr->class_info.song.release_info.bootleg.year, 2);
+               break;
+       case RELEASE_TYPE_UNRELEASED:
+       break;
+
+       default:
+               fprintf(stderr, "Unknown release type: %d\n", hdr->class_info.song.release_type);
+               break;
+       }
+
+       read(fd, &hdr->class_info.song.is_original_author_unknown, 1);
+       ptb_read_string(fd, &hdr->class_info.song.music_by);
+       ptb_read_string(fd, &hdr->class_info.song.words_by);
+       ptb_read_string(fd, &hdr->class_info.song.arranged_by);
+       ptb_read_string(fd, &hdr->class_info.song.guitar_transcribed_by);
+       ptb_read_string(fd, &hdr->class_info.song.bass_transcribed_by);
+       ptb_read_string(fd, &hdr->class_info.song.lyrics);
+       ptb_read_string(fd, &hdr->class_info.song.copyright);
        ptb_read_string(fd, &hdr->guitar_notes);
        ptb_read_string(fd, &hdr->bass_notes);
+       ptb_read_string(fd, &hdr->drum_notes);
+       break;
+       case CLASSIFICATION_LESSON:
+       ptb_read_string(fd, &hdr->class_info.lesson.title);
+       ptb_read_string(fd, &hdr->class_info.lesson.artist);
+       read(fd, &hdr->class_info.lesson.style, 2);
+       read(fd, &hdr->class_info.lesson.level, 1);
+       ptb_read_string(fd, &hdr->class_info.lesson.author);
+       ptb_read_string(fd, &hdr->guitar_notes);
+       ptb_read_string(fd, &hdr->class_info.lesson.copyright);
+       read(fd, unknown, 2); /* FIXME */
+       break;
+
+       default:
+       fprintf(stderr, "Unknown classification: %d\n", hdr->classification);
+       break;
 
-       /* FIXME Integer indicating something ? */
-       read(fd, unknown, 2);
-//     fprintf(stderr, "%s: %02x %02x : %lx\n", debug_filename, unknown[0], unknown[1], *((guint16 *)unknown));
+       }
 
        /* This should be 0xffff, ending the header */
        read(fd, &header_end, 2);
@@ -129,8 +166,6 @@ struct ptbf *ptb_read_file(const char *file, struct ptb_section *sections)
                return NULL;
        }
 
-       debugging = 1;
-
        while(lseek(bf->fd, 0, SEEK_CUR) < bf->st_buf.st_size) {
                guint16 unknownval;
                guint16 l;
diff --git a/ptb.h b/ptb.h
index 90459935fe65d89252db8e2e7b1f6a983145371d..9acd7ff5a5cc87555b3299678a8a7c67b6f33feb 100644 (file)
--- a/ptb.h
+++ b/ptb.h
@@ -1,20 +1,20 @@
 /*
-       (c) 2004 Jelmer Vernooij <jelmer@samba.org>
+   (c) 2004 Jelmer Vernooij <jelmer@samba.org>
 
-       This program is free software; you can redistribute it and/or modify
-       it under the terms of the GNU General Public License as published by
-       the Free Software Foundation; either version 2 of the License, or
-       (at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-       GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-       You should have received a copy of the GNU General Public License
-       along with this program; if not, write to the Free Software
-       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   */
 
 #ifndef __PTB_H__
 #define __PTB_H__
 #include <glib.h>
 
 struct ptb_hdr {
-       char *title;
-       char *artist;
-       char *album;
-       char *words_by;
-       char *music_by;
-       char *arranged_by;
-       char *guitar_transcribed_by;
-       char *bass_transcribed_by;
-       char *lyrics;
+       enum { CLASSIFICATION_SONG = 0, CLASSIFICATION_LESSON} classification;
+
+       union {
+               struct {
+                       enum { RELEASE_TYPE_PR_AUDIO = 0, RELEASE_TYPE_PR_VIDEO, RELEASE_TYPE_BOOTLEG, RELEASE_TYPE_UNRELEASED } release_type;
+
+                       union {
+                               struct {
+                                       enum { AUDIO_TYPE_SINGLE = 0, AUDIO_TYPE_EP, AUDIO_TYPE_ALBUM, AUDIO_TYPE_DOUBLE_ALBUM, AUDIO_TYPE_TRIPLE_ALBUM, AUDIO_TYPE_BOXSET } type;
+                                       char *album_title;
+                                       guint16 year;
+                                       guint8 is_live_recording;
+                               } pr_audio;
+                               struct {
+                                       char *video_title;
+                                       guint16 year;
+                                       guint8 is_live_recording;
+                               } pr_video;
+                               struct {
+                                       char *title;
+                                       guint16 day;
+                                       guint16 month;
+                                       guint16 year;
+                               } bootleg;
+                               struct {
+                               } unreleased;
+                       } release_info;
+                       guint8 is_original_author_unknown;
+                       char *title;
+                       char *artist;
+                       char *words_by;
+                       char *music_by;
+                       char *arranged_by;
+                       char *guitar_transcribed_by;
+                       char *bass_transcribed_by;
+                       char *lyrics;
+                       char *copyright;
+               } song;
+
+               struct  {
+                       char *title;
+                       char *artist;
+                       guint16 style;
+                       enum { LEVEL_BEGINNER = 0, LEVEL_INTERMEDIATE, LEVEL_ADVANCED} level;
+                       char *author;
+                       char *copyright;
+               } lesson;
+       } class_info;
+
        char *guitar_notes;
        char *bass_notes;
-       char *copyright;
+       char *drum_notes;
        guint16 version;
 };
 
 struct ptb_chord {
-       
+
        struct ptb_chord *next;
 };
 
@@ -60,8 +100,8 @@ struct ptbf {
 };
 
 struct ptb_section {
-    char *name;
-    int (*handler) (struct ptbf *, const char *section);
+       char *name;
+       int (*handler) (struct ptbf *, const char *section);
 };
 
 extern struct ptb_section default_sections[];