Add realclean target
[jelmer/ptabtools.git] / ptbinfo.c
1 /*
2         (c) 2004: Jelmer Vernooij <jelmer@samba.org>
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <stdio.h>
20 #include <errno.h>
21 #include <popt.h>
22 #include "dlinklist.h"
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #ifdef HAVE_STDINT_H
29 #  include <stdint.h>
30 #endif
31
32 #include "ptb.h"
33
34 #define COND_PRINTF(desc,field) if(field) printf("%s: %s\n", desc, field);
35
36 void write_praudio_info(struct ptb_hdr *hdr)
37 {
38         printf("Audio Type: ");
39         switch(hdr->class_info.song.release_info.pr_audio.type)
40         { 
41         case AUDIO_TYPE_SINGLE: printf("Single\n"); break;
42         case AUDIO_TYPE_EP: printf("EP\n"); break;
43         case AUDIO_TYPE_ALBUM: printf("Album\n"); break;
44         case AUDIO_TYPE_DOUBLE_ALBUM: printf("Double Album\n"); break;
45         case AUDIO_TYPE_TRIPLE_ALBUM: printf("Triple Album\n"); break;
46         case AUDIO_TYPE_BOXSET: printf("Boxset\n"); break;
47         }
48         COND_PRINTF("Album Title", hdr->class_info.song.release_info.pr_audio.album_title);
49         printf("Year: %d\n", hdr->class_info.song.release_info.pr_audio.year);
50         printf("Live recording? %s\n", hdr->class_info.song.release_info.pr_audio.is_live_recording?"Yes":"No");
51 }
52
53 void write_prvideo_info(struct ptb_hdr *hdr)
54 {
55         COND_PRINTF("Video Title", hdr->class_info.song.release_info.pr_video.video_title);
56         printf("Year: %d\n", hdr->class_info.song.release_info.pr_video.year);
57         printf("Live recording? %s\n", hdr->class_info.song.release_info.pr_video.is_live_recording?"Yes":"No");
58 }
59
60 void write_bootleg_info(struct ptb_hdr *hdr)
61 {
62         COND_PRINTF("Bootleg Title", hdr->class_info.song.release_info.bootleg.title);
63         printf("Date: %d-%d-%d\n", 
64                    hdr->class_info.song.release_info.bootleg.day,
65                    hdr->class_info.song.release_info.bootleg.month,
66                    hdr->class_info.song.release_info.bootleg.year);
67 }
68
69 void write_song_info(struct ptb_hdr *hdr)
70 {
71         COND_PRINTF("Title", hdr->class_info.song.title);
72         COND_PRINTF("Artist", hdr->class_info.song.artist);
73         COND_PRINTF("Words By", hdr->class_info.song.words_by);
74         COND_PRINTF("Music By", hdr->class_info.song.music_by);
75         COND_PRINTF("Arranged By", hdr->class_info.song.arranged_by);
76         COND_PRINTF("Guitar Transcribed By", hdr->class_info.song.guitar_transcribed_by);
77         COND_PRINTF("Bass Transcribed By", hdr->class_info.song.bass_transcribed_by);
78         if(hdr->class_info.song.lyrics) 
79                 printf("Lyrics\n----------\n%s\n\n", hdr->class_info.song.lyrics);
80         COND_PRINTF("Copyright", hdr->class_info.song.copyright);
81
82         printf("Release type: ");
83         switch(hdr->class_info.song.release_type) {
84         case RELEASE_TYPE_PR_AUDIO:
85                 printf("Public Release (Audio)\n");
86                 write_praudio_info(hdr);
87                 break;
88         case RELEASE_TYPE_PR_VIDEO:
89                 printf("Public Release (Video)\n");
90                 write_prvideo_info(hdr);
91                 break;
92         case RELEASE_TYPE_BOOTLEG:
93                 printf("Bootleg\n");
94                 write_bootleg_info(hdr);
95                 break;
96         case RELEASE_TYPE_UNRELEASED:
97                 printf("Unreleased\n");
98                 break;
99         }
100 }
101
102 void write_lesson_info(struct ptb_hdr *hdr)
103 {
104         COND_PRINTF("Title", hdr->class_info.lesson.title);
105         COND_PRINTF("Artist", hdr->class_info.lesson.artist);
106         printf("Style: %d\n", hdr->class_info.lesson.style);
107         printf("Level: ");
108         switch(hdr->class_info.lesson.level) {
109         case LEVEL_BEGINNER: printf("Beginner"); break;
110         case LEVEL_INTERMEDIATE: printf("Intermediate"); break;
111         case LEVEL_ADVANCED: printf("Advanced"); break;
112         }
113         COND_PRINTF("Author", hdr->class_info.lesson.author);
114         COND_PRINTF("Copyright", hdr->class_info.lesson.copyright);
115 }
116
117 int main(int argc, const char **argv) 
118 {
119         struct ptbf *ret;
120         int debugging = 0;
121         int c, tmp1, tmp2;
122         int version = 0;
123         poptContext pc;
124         struct poptOption options[] = {
125                 POPT_AUTOHELP
126                 {"debug", 'd', POPT_ARG_NONE, &debugging, 0, "Turn on debugging output" },
127                 {"version", 'v', POPT_ARG_NONE, &version, 'v', "Show version information" },
128                 POPT_TABLEEND
129         };
130
131         pc = poptGetContext(argv[0], argc, argv, options, 0);
132         poptSetOtherOptionHelp(pc, "file.ptb");
133         while((c = poptGetNextOpt(pc)) >= 0) {
134                 switch(c) {
135                 case 'v':
136                         printf("ptbinfo Version "PACKAGE_VERSION"\n");
137                         printf("(C) 2004 Jelmer Vernooij <jelmer@samba.org>\n");
138                         exit(0);
139                         break;
140                 }
141         }
142                         
143         ptb_set_debug(debugging);
144         ptb_set_asserts_fatal(0);
145         
146         if(!poptPeekArg(pc)) {
147                 poptPrintUsage(pc, stderr, 0);
148                 return -1;
149         }
150         ret = ptb_read_file(poptGetArg(pc));
151         
152         if(!ret) {
153                 perror("Read error: ");
154                 return -1;
155         } 
156
157         printf("File type: ");
158         switch(ret->hdr.classification) {
159         case CLASSIFICATION_SONG: 
160                 printf("Song\n");
161                 write_song_info(&ret->hdr);
162                 break;
163         case CLASSIFICATION_LESSON:
164                 printf("Lesson\n");
165                 write_lesson_info(&ret->hdr);
166                 break;
167         default: 
168                 printf("Unknown\n");
169                 break;
170         }
171
172         DLIST_LEN(ret->instrument[0].sections, tmp1, struct ptb_section *);
173         DLIST_LEN(ret->instrument[1].sections, tmp2, struct ptb_section *);
174         printf("Number of sections: \tRegular: %d Bass: %d\n", tmp1, tmp2);
175
176         DLIST_LEN(ret->instrument[0].guitars, tmp1, struct ptb_guitar *);
177         DLIST_LEN(ret->instrument[1].guitars, tmp2, struct ptb_guitar *);
178
179         printf("Number of guitars: \tRegular: %d Bass: %d\n", tmp1, tmp2);
180
181         return (ret?0:1);
182 }