version 0.33
[FAPG] / fapg.c
diff --git a/fapg.c b/fapg.c
index adf89ee..b800d76 100644 (file)
--- a/fapg.c
+++ b/fapg.c
@@ -1,5 +1,5 @@
 /*
- * FAPG version 0.21
+ * FAPG version 0.33
  *
  * FAPG means Fast Audio Playlist Generator.
  * It is a tool to generate list of audio files (Wav, MP3, Ogg, etc)
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <string.h>
+#include <strings.h>
 #include <limits.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <assert.h>
+#include "genres.h"
 
 #define MP3_BASE 1024
 #define OGG_BASE 1024*10
 
 int debug=0;
 int format=0; /* 0 = m3u ; 1 = pls ; 2 = html */
-unsigned char *prefix="";
+char *genrelist=NULL;
+char *prefix="";
 int recursive=0;
+int avoidhlinked=0;
 int separator='/';
 int skip=0;
 int windows=0;
-unsigned char *eol="\n";
-unsigned char buffer[MAX];
+char *eol="\n";
+char buffer[MAX];
 
 int counter=0;
 
-unsigned char artist[1024];
-unsigned char title[1024];
+char artist[1024];
+char title[1024];
+char genrebuf[1024];
+char genre=0;
 int duration;
 
-unsigned char unix2dos[256]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,70,35,36,37,38,39,40,41,82,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,84,59,36,61,65,71,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,36,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,36,125,126,127,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,131,225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187,166,166,166,166,166,193,194,192,169,166,166,43,43,162,165,43,43,45,45,43,45,43,227,195,43,43,45,45,166,45,43,164,240,208,202,203,200,105,205,206,207,43,43,166,220,166,204,175,211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180,173,177,61,190,182,167,247,184,176,168,183,185,179,178,166,160};
+char unix2dos[256]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,70,35,36,37,38,39,40,41,82,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,84,59,36,61,65,71,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,36,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,36,125,126,127,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,131,225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187,166,166,166,166,166,193,194,192,169,166,166,43,43,162,165,43,43,45,45,43,45,43,227,195,43,43,45,45,166,45,43,164,240,208,202,203,200,105,205,206,207,43,43,166,220,166,204,175,211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180,173,177,61,190,182,167,247,184,176,168,183,185,179,178,166,160};
 
 void usage()
 {
-  fprintf(stderr,"Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n");
+  fprintf(stderr,"Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-g|--genre=#:#:...] [-n|--nohardlink] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-x|--exclude=#:#:...] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n");
   exit(1);
 }
 
 void parse_options(int argc,char **argv)
 {
-  static char const short_options[]="bdf:o:p:rw";
+  static char const short_options[]="bdf:g:lo:np:rwx:";
   static struct option long_options[]=
   {
     {"backslash",no_argument,NULL,'b'},
     {"debug",no_argument,NULL,'d'},
     {"format",required_argument,NULL,'f'},
+    {"genre",required_argument,NULL,'g'},
+    {"nohardlink",no_argument,NULL,'n'},
     {"output",required_argument,NULL,'o'},
     {"prefix",required_argument,NULL,'p'},
     {"recursive",no_argument,NULL,'r'},
-    {"windows",no_argument,NULL,'w'}
+    {"windows",no_argument,NULL,'w'},
+    {"exclude",required_argument,NULL,'x'}
   };
   int c;
   int option_index=0;
@@ -95,6 +105,23 @@ void parse_options(int argc,char **argv)
         if (strcmp(optarg,"html")==0) format=2; else
         usage();
         break;
+      case 'g':
+        if (genrelist==NULL) genrelist=calloc(257,sizeof(char)); /* allow multiple includes/excludes */
+        if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); }
+        else
+        {
+          int n=0; 
+          while (n<strlen(optarg))
+          {
+            if (debug) fprintf(stderr,"Debug >> genrelist entry activting : %d\n",atoi(&optarg[n]));
+            genrelist[atoi(&optarg[n])]=1;
+            while (isdigit(optarg[n++]));
+          }
+        }
+        break;
+      case 'n':
+        avoidhlinked=1;
+        break;
       case 'o':
         close(1);
         if (fopen(optarg,"w")==NULL) { fprintf(stderr,"Error >> unable to open output file : %s\n",optarg); exit(2); }
@@ -110,13 +137,42 @@ void parse_options(int argc,char **argv)
         windows=1;
         eol="\r\n";
         break;
+      case 'x':
+        if (genrelist==NULL) /* allow multiple includes/excludes - not recommended (confusing) but possible */
+        {
+          int n=0; 
+          genrelist=calloc(257,sizeof(char));
+          while (n<256) genrelist[n++]=1;
+        }
+        if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); }
+        else
+        {
+          int n=0; 
+          while (n<strlen(optarg))
+          {
+            if (debug) fprintf(stderr,"Debug >> genrelist entry activting : %d\n",atoi(&optarg[n]));
+            genrelist[atoi(&optarg[n])]=0;
+            while (isdigit(optarg[n++]));
+          }
+        }
+        break;
       default:
         usage();
     }
   }
+  if (genrelist==NULL)
+  {
+    genrelist=calloc(257,sizeof(char));
+    if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); }
+    else
+    { 
+      int n=0; 
+      while (n<256) genrelist[n++]=1;
+    }
+  }
 }
 
-void parse_mp3(unsigned char *file)
+void parse_mp3(char *file)
 {
   int bitrates[2][3][15]=
     {{{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448},
@@ -126,9 +182,11 @@ void parse_mp3(unsigned char *file)
       {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
       {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}}};
   FILE *fic;
-  unsigned char *c;
+  char *c;
   int lus;
 
+  genre=0;
+  genrebuf[0]=0;
   if (debug) fprintf(stderr,"Debug >> parsing mp3 : %s\n",file);
 
   /* read header */
@@ -172,6 +230,13 @@ void parse_mp3(unsigned char *file)
         strncpy(artist,c+7,size-1);
         artist[size-1]='\0';
       }
+      if (strncmp(c,"TCO",3)==0)
+      {
+        /* strncpy(genrebuf,c+7,size-1);*/
+        /* genrebuf[size-1]='\0'; */
+        /* genre=atoi(&genrebuf[1]); */
+        genre=atoi(c+8);
+      }
       c+=size+6;
     }
     if (version==3 || version==4) while (c<buffer+size)
@@ -188,13 +253,20 @@ void parse_mp3(unsigned char *file)
         strncpy(artist,c+11,size-1);
         artist[size-1]='\0';
       }
+      if (strncmp(c,"TCON",4)==0)
+      {
+        /* strncpy(genrebuf,c+11,size-1); */
+        /* genrebuf[size-1]='\0'; */
+        /* genre=atoi(&genrebuf[1]); */
+        genre=atoi(c+12);
+      }
       c+=size+10;
     }
   }
   
   while (c<buffer+lus-10)
   {
-    if (*c==0xFF && (*(c+1)&0xF0)==0xF0)
+    if ((unsigned char)*c==0xFF && ((unsigned char)*(c+1)&0xF0)==0xF0)
     {
       int version;
       int lay;
@@ -234,16 +306,21 @@ void parse_mp3(unsigned char *file)
       artist[30]='\0';
       c=artist+29;
       while (c>artist && *c==' ') *(c--)='\0';
+      /* strncpy(album,buffer+65,30); */
+      /* strncpy(year,buffer+97,4); */
+      /* strncpy(comment,buffer+101,30); */
+      /* strncpy(genrebuf,buffer+127,1); genre[1]=0; */
+      genre=buffer[127];
     }
   }
 
   fclose(fic);
 }  
 
-void parse_ogg(unsigned char *file)
+void parse_ogg(char *file)
 {
   FILE *fic;
-  unsigned char *c;
+  char *c;
   int lus;
   int sample_rate;
   int samples;
@@ -267,20 +344,37 @@ void parse_ogg(unsigned char *file)
   while (c<buffer+lus-10)
   {
     int size;
-    if (strncmp(c,"TITLE=",6)==0)
+    if (strncasecmp(c,"TITLE=",6)==0)
     {
       size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24);
       strncpy(title,c+6,size-6);
       title[size-6]='\0';
       c+=size;
     }
-    if (strncmp(c,"ARTIST=",7)==0)
+    if (strncasecmp(c,"ARTIST=",7)==0)
     {
       size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24);
       strncpy(artist,c+7,size-7);
       artist[size-7]='\0';
       c+=size;
     }
+    if (strncasecmp(c,"GENRE=",6)==0)
+    {
+      static int i=0;
+      size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24);
+      strncpy(genrebuf,c+6,size-6);
+      genrebuf[size-6]='\0';
+      c+=size;
+      for(i=0;i<ID3_NR_OF_V1_GENRES;i++)
+      {
+        if (strcasecmp(ID3_v1_genre_description[i],genrebuf)==0)
+        {
+          genre=i;
+          break;
+        }
+        if (i==ID3_NR_OF_V1_GENRES) genre=0;
+      }
+    }
     c++;
   }
   
@@ -298,12 +392,162 @@ void parse_ogg(unsigned char *file)
   fclose(fic);
 }
 
-void parse_directory(unsigned char *path)
+void parse_mpc(char *file)
+{
+  FILE *fic;
+  char *c;
+  int lus;
+  int sample_rates[4]={44100,48000,37800,32000};
+  int frame_count;
+  int size,items;
+  int i;
+
+  if (debug) fprintf(stderr,"Debug >> parsing mpc : %s\n",file);
+
+  /* read header */
+  if ((fic=fopen(file,"r"))==NULL) { fprintf(stderr,"Warning >> can't open file : %s\n",file); return; }
+  lus=fread(buffer,1,12,fic);
+
+  /* try Musepack */
+  if (buffer[0]!='M' && buffer[1]!='P' && buffer[2]!='+')
+  {
+    fprintf(stderr,"Warning >> not a Musepack header : %s\n",file);
+    return;
+  }
+  
+  /* only version 7 */
+  if (buffer[3]!=7)
+  {
+    fprintf(stderr,"Warning >> only Musepack SV7 supported : %s\n",file);
+    return;
+  }
+  
+  /* duration */
+  c=buffer+4;
+  frame_count=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
+  c+=5;
+  duration=frame_count*1152/sample_rates[*c&3];
+  
+  /* try APETAGEX footer */
+  fseek(fic,-32,SEEK_END);
+  lus=fread(buffer,1,32,fic);
+  if (lus==32 && strncmp(buffer,"APETAGEX",8)==0)
+  {
+    c=buffer+12;
+    size=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
+    size+=32;
+    c+=4;
+    items=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
+    fseek(fic,-size,SEEK_END);
+    lus=fread(buffer,1,size,fic);
+    if (lus==size && strncmp(buffer,"APETAGEX",8)==0)
+    {
+      c=buffer+32;
+      while (items--)
+      {
+        size=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
+        c+=8;
+        if (strcasecmp(c,"TITLE")==0)
+        {
+          strncpy(title,c+6,size);
+          title[size]='\0';
+        }
+        if (strcasecmp(c,"ARTIST")==0)
+        {
+          strncpy(artist,c+7,size);
+          artist[size]='\0';
+        }
+        if (strcasecmp(c,"GENRE")==0)
+        {
+          for(i=0;i<ID3_NR_OF_V1_GENRES;i++)
+          {
+            strncpy(genrebuf,c+6,size);
+            genrebuf[size]='\0';
+            if (strcasecmp(ID3_v1_genre_description[i],genrebuf)==0)
+            {
+              genre=i;
+              break;
+            }
+            if (i==ID3_NR_OF_V1_GENRES) genre=0;
+          }
+        }
+        c+=strlen(c)+1+size;
+      }
+    }
+  }
+
+  fclose(fic);
+}
+
+#define FSN  8
+#define MAXINO  (1<<22)
+#define INOTYP  unsigned long
+#define regbit_qry(x,y)  ( x[( (y) / sizeof(INOTYP) )]  &  1<<( (y) % sizeof(INOTYP) ) )
+#define regbit_set(x,y)  ( x[( (y) / sizeof(INOTYP) )]  |=  1<<( (y) % sizeof(INOTYP) ) )
+
+int hlink_check(struct stat*info)
+{
+  /*
+   * for speed this subroutine should only be called
+   * - if the file has more than one hardlink
+   * - if the file is a resolved softlink
+   */
+  /* the persistent variables */
+  static INOTYP *list[FSN];
+  static dev_t name[FSN];
+  /* some temporary variables */
+  int fsn, is_registered=0;
+
+  /* assertions - in case parameters are lowered for less memory usage */
+  assert(fsn<FSN);
+  assert((info->st_ino)/sizeof(INOTYP)<MAXINO);
+  
+  /* search which internal registration number is used for this filesystem */
+  for( fsn=0; (name[fsn]!=(info->st_dev)) && (name[fsn]!=0) ; fsn++);
+
+  /* if file system is not registered yet, do it and leave */
+  if( name[fsn] == 0 ) 
+  {
+    name[fsn] = (info->st_dev);  
+    /* provide space for the bitmap that maps the inodes of this file system */
+    list[fsn] = (INOTYP*)calloc(MAXINO,sizeof(INOTYP));
+    /* no comparison is needed in empty lists ... return */
+    if(debug) fprintf(stderr, "Debug >> Linked >> Init List %04x @mem %04lx\n", (int)name[fsn], (long)&list[fsn] );
+  } else
+  {
+    /* this looks more complicated than it really is */
+    /* the idea is very simple: 
+     *  provide a bitmap that maps all inodes of a file system
+     *  to mark all files that have already been visited.
+     *  If it is already visited, do not add it to the playlist
+     */
+    /*
+     * The difficulty is as follows:
+     *   struct inode_bitmap { char registered:1; } bitmap[1<<MAXINO];
+     * would be byte-aligned and would allocate at least eight times the needed space.
+     * Feel free to change the definitions that are involved here, if you know better.
+     */
+    if(  regbit_qry( list[fsn], (info->st_ino) ) ) is_registered=1;
+    else regbit_set( list[fsn], (info->st_ino) );
+    /*
+     * the debug expression is more complicated then the working stuff
+     */
+    if(debug)
+      fprintf(stderr, "Debug >> Linked >> DEV %04x INO %06x => "
+    "list[%02x][%04x] = %04x & %04x --> %s registered\n",
+    (int)info->st_dev, (int)info->st_ino, fsn, (int)((info->st_ino)/sizeof(INOTYP)),
+          (int)list[fsn][(info->st_ino)/sizeof(INOTYP)],
+    1<<((info->st_ino)%sizeof(INOTYP)), is_registered?"Already":"Not" );
+  }
+  return is_registered;
+}
+
+void parse_directory(char *path)
 {
   int i,n;
   struct dirent **namelist;
-  unsigned char newpath[PATH_MAX];
-  unsigned char *c;
+  char newpath[PATH_MAX];
+  char *c;
   struct stat infos;
 
   void print_faketitle()
@@ -313,14 +557,24 @@ void parse_directory(unsigned char *path)
     while (c<newpath+strlen(newpath)-5)
     {
       c++;
-      if (*c=='_') putchar(' '); else if (windows) putchar(unix2dos[*c]); else putchar(*c);
+      if (*c=='_') putchar(' '); else if (windows) putchar(unix2dos[(int)*c]); else putchar(*c);
     }
   }
   
   void print_path()
   {
+    char last=0;
     printf(prefix);
-    for (c=newpath+skip;*c!='\0';c++) if (*c=='/') putchar(separator); else if (windows) putchar(unix2dos[*c]); else putchar(*c);
+    c=newpath+skip;
+    /* remove leading "./" when parsing current directory */
+    if (*c=='.' && *(c+1)=='/') { c+=2; last='/'; }
+    for (;*c!='\0';c++)
+    {
+      /* remove double "//" when parsing a directory ending with a "/" */
+      if (last=='/' && *c=='/') continue;
+      last=*c;
+      if (*c=='/') putchar(separator); else if (windows) putchar(unix2dos[(int)*c]); else putchar(*c);
+    }
   }
 
   if (debug) fprintf(stderr,"Debug >> parsing directory : %s\n",path);
@@ -330,19 +584,23 @@ void parse_directory(unsigned char *path)
     sprintf(newpath,"%s/%s",path,namelist[i]->d_name);
     if (stat(newpath,&infos)!=0) { fprintf(stderr,"Warning >> can't stat file : %s\n",newpath); continue; }
     if (recursive && S_ISDIR(infos.st_mode) && strcmp(namelist[i]->d_name,".")!=0 && strcmp(namelist[i]->d_name,"..")!=0) parse_directory(newpath);
-    if (S_ISREG(infos.st_mode))
+    /* hlink_check() might be applied more selective ... avoidhlink is only a simple prereq */
+    if (S_ISREG(infos.st_mode) && ! ( avoidhlinked && hlink_check(&infos) ) )
     {
-      unsigned char ext[5];
+      char ext[5];
       int j;
       for (j=0;j<5;j++) ext[j]=tolower(namelist[i]->d_name[strlen(namelist[i]->d_name)-4+j]);
       artist[0]='\0';
       title[0]='\0';
       duration=-2;
+      if (strcmp(".mp2",ext)==0) { duration=-1; parse_mp3(newpath); }
       if (strcmp(".mp3",ext)==0) { duration=-1; parse_mp3(newpath); }
+      if (strcmp(".mpc",ext)==0) { duration=-1; parse_mpc(newpath); }
+      if (strcmp(".mp+",ext)==0) { duration=-1; parse_mpc(newpath); }
       if (strcmp(".ogg",ext)==0) { duration=-1; parse_ogg(newpath); }
       if (strcmp(".wav",ext)==0) { duration=-1; /* parse_wav(newpath); */ }
       
-      if (duration!=-2) /* is it an audio file ? */
+      if (duration!=-2 && genrelist[(int)genre]) /* is it an audio file ? */
       {
         counter++;
         switch (format)
@@ -391,10 +649,10 @@ int main(int argc,char **argv)
       printf("#EXTM3U%s",eol);
       break;
     case 1:
-      printf("[playlist]%s,eol");
+      printf("[playlist]%s",eol);
       break;
     case 2:
-      printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">%s%s<html>%s%s<head>%s<title>Playlist generated by FAPG 0.21</title>%s<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />%s<style type=\"text/css\">%s<!--%s%sbody,td,tr {%s font-family: Verdana, Arial, Helvetica, sans-serif;%s  font-size: 12px;%s  color: #000000;%s}%s%sbody {%s  background: #ffffff;%s}%s%sth {%s  text-align: center;%s  background: #ffcccc;%s  padding-left: 15px;%s  padding-right: 15px;%s  border: 1px #dd8888 solid;%s}%s%std {%s  text-align: center;%s  background: #eeeeee;%s  padding-left: 15px;%s  padding-right: 15px;%s  border: 1px #cccccc solid;%s}%s%sh1 {%s  font-size: 25px;%s}%s%sp {%s  font-size: 10px;%s}%s%sa {%s  color: #993333;%s  text-decoration: none;%s}%s%sa:hover {%s text-decoration: underline;%s}%s%s-->%s</style>%s</head>%s%s<body>%s%s<h1>Playlist</h1>%s%s<table>%s<tr><th>Entry</th><th>Artist</th><th>Title</th><th>Length</th></tr>%s",eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol);
+      printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">%s%s<html>%s%s<head>%s<title>Playlist generated by FAPG 0.33</title>%s<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />%s<style type=\"text/css\">%s<!--%s%sbody,td,tr {%s font-family: Verdana, Arial, Helvetica, sans-serif;%s  font-size: 12px;%s  color: #000000;%s}%s%sbody {%s  background: #ffffff;%s}%s%sth {%s  text-align: center;%s  background: #ffcccc;%s  padding-left: 15px;%s  padding-right: 15px;%s  border: 1px #dd8888 solid;%s}%s%std {%s  text-align: center;%s  background: #eeeeee;%s  padding-left: 15px;%s  padding-right: 15px;%s  border: 1px #cccccc solid;%s}%s%sh1 {%s  font-size: 25px;%s}%s%sp {%s  font-size: 10px;%s}%s%sa {%s  color: #993333;%s  text-decoration: none;%s}%s%sa:hover {%s text-decoration: underline;%s}%s%s-->%s</style>%s</head>%s%s<body>%s%s<h1>Playlist</h1>%s%s<table>%s<tr><th>Entry</th><th>Artist</th><th>Title</th><th>Length</th></tr>%s",eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol);
       break;
   }
   for (;optind<argc;optind++)
@@ -408,8 +666,9 @@ int main(int argc,char **argv)
       printf("NumberOfEntries=%d%sVersion=2%s",counter,eol,eol);
       break;
     case 2:
-      printf("</table>%s%s<p>Playlist generated by <a href=\"http://royale.zerezo.com/fapg/\">FAPG 0.21</a></p>%s%s</body>%s%s</html>",eol,eol,eol,eol,eol,eol);
+      printf("</table>%s%s<p>Playlist generated by <a href=\"http://royale.zerezo.com/fapg/\">FAPG 0.33</a></p>%s%s</body>%s%s</html>",eol,eol,eol,eol,eol,eol);
       break;
   }
+  if (genrelist) free(genrelist);
   exit(0);
 }