version 0.36 (by Hank Barta)
[FAPG] / fapg.c
diff --git a/fapg.c b/fapg.c
index 19eb30a..0ec3835 100644 (file)
--- a/fapg.c
+++ b/fapg.c
@@ -1,7 +1,3 @@
-/*
- *              FAPG
- */
-#define VERSION "0.35"
 /*
  * FAPG means Fast Audio Playlist Generator.
  * It is a tool to generate list of audio files (Wav, MP3, Ogg, etc)
@@ -42,6 +38,7 @@
 #include <assert.h>
 #include "genres.h"
 
+#define VERSION "0.36"
 #define MP3_BASE 1024
 #define OGG_BASE 1024*10
 #define MAX 1024*200            /* 200ko for ID3 with JPEG images in it */
@@ -220,12 +217,18 @@ unsigned char *iso2web[256] = {
 void usage()
 {
     fprintf(stderr,
-            "Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss] [-g|--genre=#:#:...] [-n|--nohardlink] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-c|--command=<intern|....>] [-x|--exclude=#:#:...] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n");
+            "Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss|pla] [-g|--genre=#:#:...] [-n|--nohardlink] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-c|--command=<intern|....>] [-x|--exclude=#:#:...] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n");
     exit(1);
 }
 
 #define mywebputchar(x) { fputs(iso2web[(unsigned char)winorunix[(unsigned char)x]], stdout); }
 #define    myputchar(x) { putchar(basemap[(unsigned char)winorunix[(unsigned char)x]]); }
+/* #define    myplaputchar(x) { putchar(basemap[(unsigned char)winorunix[(unsigned char)x]]);putchar('\0');} */
+void myplaputchar(const char x)
+{
+    putchar(basemap[(unsigned char)winorunix[(unsigned char)x]]);
+    putchar('\0');
+}
 
 void mywebputstr(const char *c)
 {
@@ -235,6 +238,20 @@ void mywebputstr(const char *c)
     }
 }
 
+void myplaputstr(const char *c)
+{
+    while(*c != 0) {
+        if( *c == '/')
+            myplaputchar('\\'); /* translate slash to backslash */
+        else
+            myplaputchar(*c);
+        c++;
+        /* remove multiple slashes "//" when parsing a directory ending with a "/" */
+        while(*c == '/' && c[1] == '/')
+            c++;
+    }
+}
+
 void myputstr(const char *c)
 {
     while(*c != 0) {
@@ -381,6 +398,8 @@ void parse_options(int argc, char **argv)
                 format = 2;
             else if(strcmp(optarg, "rss") == 0)
                 format = 3;
+            else if(strcmp(optarg, "pla") == 0)
+                format = 4;
             else
                 usage();
             break;
@@ -920,6 +939,7 @@ void parse_file(unsigned char *newpath)
         // there are no tag infos read
         // use file name to state substitute it
         char *c = strrchr(newpath, separator);
+       if (c == NULL) c = newpath;
         strcpy(artist, ++c);
         // arbitrarily use the first '-'
         // to separate artist and title
@@ -1017,6 +1037,11 @@ void parse_file(unsigned char *newpath)
                 printf("\t</item>%s", eol);
             }
             break;
+        case 4: // printing output for Sansa players
+            myplaputstr("HARP, ");
+            myplaputstr(newpath);
+            myplaputstr(eol);
+            break;
         }
     }
 }
@@ -1113,6 +1138,11 @@ int main(int argc, char **argv)
             basemap = noand;
         }
         break;
+    case 4: 
+        {
+            eol = "\r\n";
+            myplaputstr( "PLP PLAYLIST\r\nVERSION 1.20\r\n\r\n" );
+        }
     }
     for(; optind < argc; optind++) {
         parse_directory(argv[optind]);