files.c

00001 #include "common.h"
00002 #include <string.h>
00003 
00004 static void datafile_dump (njb_datafile_t *df, FILE *fp)
00005 {
00006   u_int64_t size = df->filesize;
00007   
00008   fprintf(fp, "File ID  : %u\n", df->dfid);
00009   fprintf(fp, "Filename : %s\n", df->filename);
00010   if (df->folder != NULL) {
00011     fprintf(fp, "Folder   : %s\n", df->folder);
00012   }
00013   fprintf(fp, "Fileflags: %08X\n", df->flags);
00014 #ifdef __WIN32__
00015   fprintf(fp, "Size :     %I64u bytes\n", size);
00016 #else
00017   fprintf(fp, "Size :     %llu bytes\n", size);
00018 #endif
00019 }
00020 
00021 int main (int argc, char **argv)
00022 {
00023   njb_t njbs[NJB_MAX_DEVICES], *njb;
00024   extern char *optarg;
00025   int opt;
00026   int n, debug;
00027   njb_datafile_t *filetag;
00028   char *lang;
00029   
00030   debug= 0;
00031   while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
00032     switch (opt) {
00033     case 'D':
00034       debug= atoi(optarg);
00035       break;
00036     default:
00037       fprintf(stderr, "usage: tracks [ -D debuglvl ]\n");
00038       return 1;
00039     }
00040   }
00041   
00042   if ( debug ) NJB_Set_Debug(debug);
00043   
00044   /*
00045    * Check environment variables $LANG and $LC_CTYPE
00046    * to see if we want to support UTF-8 unicode
00047    * $LANG = "xx_XX.UTF-8" or $LC_CTYPE = "?"
00048    * trigger unicode support.
00049    */
00050   lang = getenv("LANG");
00051   if (lang != NULL) {
00052     if (strlen(lang) > 5) {
00053       if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
00054         NJB_Set_Unicode(NJB_UC_UTF8);
00055       }
00056     }
00057   }
00058 
00059   if (NJB_Discover(njbs, 0, &n) == -1) {
00060     fprintf(stderr, "could not locate any jukeboxes\n");
00061     return 1;
00062   }
00063   
00064   if ( n == 0 ) {
00065     fprintf(stderr, "no NJB devices found\n");
00066     return 0;
00067   } 
00068   
00069   njb = njbs;
00070   
00071   if ( NJB_Open(njb) == -1 ) {
00072     NJB_Error_Dump(njb, stderr);
00073     return 1;
00074   }
00075   
00076   if ( NJB_Capture(njb) == -1 ) {
00077     NJB_Error_Dump(njb, stderr);
00078     return 1;
00079   }
00080   
00081   NJB_Reset_Get_Datafile_Tag(njb);
00082   while ( (filetag = NJB_Get_Datafile_Tag (njb)) ) {
00083     datafile_dump(filetag, stdout);
00084     printf("----------------------------------\n");
00085     NJB_Datafile_Destroy(filetag);
00086   }
00087 
00088   /* Dump any pending errors */
00089   if (NJB_Error_Pending(njb)) {
00090     NJB_Error_Dump(njb, stderr);
00091   }
00092   
00093   NJB_Release(njb);
00094   
00095   NJB_Close(njb);
00096   return 0;
00097 }
00098 

Generated on Mon Sep 11 00:52:12 2006 for libnjb by  doxygen 1.4.7