X-Git-Url: http://royale.zerezo.com/git/?p=FAPG;a=blobdiff_plain;f=fapg.c;fp=fapg.c;h=8a6667d848eccef1649b746bbfe80472357bb149;hp=e75235ed9bca7c2ba7cece1fab4dfe73b5208fe4;hb=ff081934d3f79e659ca14c93b147028b59880ee8;hpb=eb987a9f4940f5143602e2ef7138550d0263ae40 diff --git a/fapg.c b/fapg.c index e75235e..8a6667d 100644 --- a/fapg.c +++ b/fapg.c @@ -1,5 +1,5 @@ /* - * FAPG version 0.30 + * FAPG version 0.31 * * FAPG means Fast Audio Playlist Generator. * It is a tool to generate list of audio files (Wav, MP3, Ogg, etc) @@ -36,6 +36,7 @@ #include #include #include +#include #include "genres.h" #define MP3_BASE 1024 @@ -47,6 +48,7 @@ int format=0; /* 0 = m3u ; 1 = pls ; 2 = html */ char *genrelist=NULL; unsigned char *prefix=""; int recursive=0; +int avoidhlinked=0; int separator='/'; int skip=0; int windows=0; @@ -65,19 +67,20 @@ unsigned char unix2dos[256]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,2 void usage() { - fprintf(stderr,"Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-g|--genre=#:#:...] [-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"); + 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:g:o:p:rwx:"; + 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'}, @@ -116,6 +119,9 @@ void parse_options(int argc,char **argv) } } 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); } @@ -473,6 +479,69 @@ void parse_mpc(unsigned char *file) 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(fsnst_ino)/sizeof(INOTYP)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<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(unsigned char *path) { int i,n; @@ -505,7 +574,8 @@ 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]; int j; @@ -572,7 +642,7 @@ int main(int argc,char **argv) printf("[playlist]%s",eol); break; case 2: - printf("%s%s%s%s%sPlaylist generated by FAPG 0.30%s%s%s%s%s%s%s

Playlist

%s%s%s%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("%s%s%s%s%sPlaylist generated by FAPG 0.31%s%s%s%s%s%s%s

Playlist

%s%s
EntryArtistTitleLength
%s%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%s%s

Playlist generated by FAPG 0.30

%s%s%s%s",eol,eol,eol,eol,eol,eol); + printf("
EntryArtistTitleLength
%s%s

Playlist generated by FAPG 0.31

%s%s%s%s",eol,eol,eol,eol,eol,eol); break; } if (genrelist) free(genrelist);