version 0.45 master v0.45
authorAntoine Jacquet <royale@zerezo.com>
Mon, 6 Jan 2025 11:50:14 +0000 (12:50 +0100)
committerAntoine Jacquet <royale@zerezo.com>
Mon, 6 Jan 2025 11:50:14 +0000 (12:50 +0100)
ChangeLog
configure
configure.in
fapg.c

index d72db84..490a059 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 Change log file for FAPG
 
+version 0.45   (2025-01-06) (by Petter Reinholdtsen)
+       * remove use of PATH_MAX to build on Hurd
+
+version 0.44   (2023-01-15) (by Andreas Neuper)
+       * add UTF-16 support
+
+version 0.43   (2020-03-27) (by François Revol)
+       * parse ID3v2.3 TLEN as a fallback for duration detection
+       * don't skip printing EXTINF for unknown durations
+
 version 0.42   (2015-02-02)
        * unescaped character in man page (patch by Kumar Appaiah)
        * security flaws in FAPG 0.41 and related patches (patch by Sebastian Pipping)
index 3e719cc..5fff737 100755 (executable)
--- a/configure
+++ b/configure
@@ -2060,7 +2060,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE=fapg
- VERSION=0.42
+ VERSION=0.45
 
 
 cat >>confdefs.h <<_ACEOF
index a9f8f0e..8124fd3 100644 (file)
@@ -1,7 +1,7 @@
 # Process this file with autoconf to produce a configure script.
 AC_PREREQ(2.61)
 AC_INIT(fapg.c)
-AM_INIT_AUTOMAKE(fapg, 0.42)
+AM_INIT_AUTOMAKE(fapg, 0.45)
 
 AC_PROG_INSTALL
 AC_PROG_CC
diff --git a/fapg.c b/fapg.c
index bd2b3f0..d205eec 100644 (file)
--- a/fapg.c
+++ b/fapg.c
@@ -44,8 +44,9 @@
 #define MP3_BASE 1024
 #define OGG_BASE 1024*10
 #define MAX 1024*250            /* 250ko for ID3 with JPEG images in it */
+#define MAX_ITEM 1024
 
-#define FORMAT_M3U 0
+#define FORMAT_M3U 0  /* "0" is not a good choice for debugging, but OK for a default */
 #define FORMAT_PLS 1
 #define FORMAT_HTML 2
 #define FORMAT_RSS 3
@@ -74,9 +75,9 @@ unsigned char buffer[MAX];
 
 int counter = 0;
 
-unsigned char artist[1024];
-unsigned char title[1024];
-unsigned char genrebuf[1024];
+unsigned char artist[MAX_ITEM];
+unsigned char title[MAX_ITEM];
+unsigned char genrebuf[MAX_ITEM];
 unsigned char genre = 0;
 int duration;
 #define MP2ENC 1
@@ -259,6 +260,23 @@ void mywebputstr(const char *c)
     }
 }
 
+void utf16toutf8(char *c,int n)
+{
+    /* check whether the we need to convert UTF-16 to UTF-8 strings */
+    if ( ( c[0] != '\377' ) || ( c[1] != '\376' ) ) { return; }
+    /* only continue here, if the first 2 letters are 0xfffe *
+     * c references an UTF-16 input, where latin letters are *
+     * separated by zero bytes, which we need to eliminate   */
+    int i=0; --n;
+    for(int j=2; (j<n) && (j<MAX_ITEM); j++ ) {
+      if( isprint(c[j]) ) { /* this is not perfect ! */
+            c[i++]=c[j];
+    }   }   c[i+1]=c[i]='\0';
+    /* the index i follows the zero-terminated "string" *
+     * now the read buffer is modified, not the file    */
+    return;
+}
+
 void myplaputstr(const char *c)
 {
     while(*c != 0) {
@@ -692,7 +710,7 @@ void parse_mp3(unsigned char *file)
         fprintf(stderr, "Debug >> parsing mp3 : %s\n", file);
 
     /* read header */
-    if((fic = fopen(file, "r")) == NULL) {
+    if((fic = fopen(file, "rb")) == NULL) {
         fprintf(stderr, "Warning >> can't open file : %s\n", file);
         return;
     }
@@ -732,10 +750,12 @@ void parse_mp3(unsigned char *file)
                 if(*c == 0)
                     break;
                 if(strncmp(c, "TT2", 3) == 0) {
+                    utf16toutf8(c+7,size);
                     strncpy(title, c + 7, size - 1);
                     title[size - 1] = '\0';
                 }
                 if(strncmp(c, "TP1", 3) == 0) {
+                    utf16toutf8(c+7,size);
                     strncpy(artist, c + 7, size - 1);
                     artist[size - 1] = '\0';
                 }
@@ -755,10 +775,12 @@ void parse_mp3(unsigned char *file)
                 if(*c == 0)
                     break;
                 if(strncmp(c, "TIT2", 4) == 0) {
+                    utf16toutf8(c+11,size);
                     strncpy(title, c + 11, size - 1);
                     title[size - 1] = '\0';
                 }
                 if(strncmp(c, "TPE1", 4) == 0) {
+                    utf16toutf8(c+11,size);
                     strncpy(artist, c + 11, size - 1);
                     artist[size - 1] = '\0';
                 }
@@ -1462,7 +1484,7 @@ void parse_directory(unsigned char *path, unsigned char * original_path)
 {
     int i, n;
     struct dirent **namelist;
-    unsigned char newpath[PATH_MAX];
+    unsigned char *newpath = NULL;
     struct stat infos;
 
     if(debug)
@@ -1482,10 +1504,14 @@ void parse_directory(unsigned char *path, unsigned char * original_path)
         return;
     }
     for(i = 0; i < n; i++) {
-        snprintf(newpath, PATH_MAX, "%s/%s", path, namelist[i]->d_name);
+        int pathlen = strlen(path)+strlen(namelist[i]->d_name)+2;
+        newpath = malloc(pathlen);
+        snprintf(newpath, pathlen, "%s/%s", path, namelist[i]->d_name);
 
         if(stat(newpath, &infos) != 0) {
             fprintf(stderr, "Warning >> can't stat entry : %s\n", newpath);
+            free(newpath);
+            newpath = NULL;
             continue;
         }
         if(recursive && S_ISDIR(infos.st_mode)
@@ -1499,6 +1525,8 @@ void parse_directory(unsigned char *path, unsigned char * original_path)
         }
         free(namelist[i]);
     }
+    newpath = NULL;
+    free(newpath);
     free(namelist);
 }
 
@@ -1582,13 +1610,17 @@ int main(int argc, char **argv)
         sprintf(pwd, "%s/", pwd_source);
         
         if(fromstdin) {
-            unsigned char path[PATH_MAX];
+            char *path = NULL;
             int i;
-            while(fgets(path, PATH_MAX, stdin)) {
-                for(i = 0; i < PATH_MAX; i++)
+            size_t pathlen;
+
+            while(-1 != getline(&path, &pathlen, stdin)) {
+                for(i = 0; i < pathlen; i++)
                     if(path[i] == '\r' || path[i] == '\n')
                         path[i] = '\0';
                 if (i <= 0) {
+                    free(path);
+                    path = NULL;
                     continue;
                 }
 
@@ -1598,6 +1630,8 @@ int main(int argc, char **argv)
                 }
 
                 parse_directory(path, pwd);
+                free(path);
+                path = NULL;
             }
         } else
             for(; optind < argc; optind++) {