File: tracks.c

package info (click to toggle)
libnjb 1.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,952 kB
  • ctags: 643
  • sloc: ansic: 10,718; sh: 7,926; makefile: 220
file content (82 lines) | stat: -rw-r--r-- 1,522 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <string.h>
#include <libnjb.h>
#include <getopt.h>

extern int njb_error;

int main (int argc, char **argv)
{
	njb_t njbs[NJB_MAX_DEVICES], *njb;
	extern char *optarg;
	int opt;
	int n, debug, rc = 1;
	songid_t *songtag;
	char *lang;

	debug= 0;
	while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
		switch (opt) {
		case 'D':
			debug= atoi(optarg);
			break;
		default:
			fprintf(stderr, "usage: tracks [ -D debuglvl ]\n");
			return 1;
		}
	}

	if ( debug ) NJB_Set_Debug(debug);

	/*
	 * Check environment variables $LANG and $LC_CTYPE
	 * to see if we want to support UTF-8 unicode
	 * $LANG = "xx_XX.UTF-8" or $LC_CTYPE = "?"
	 * trigger unicode support.
	 */
	lang = getenv("LANG");
	if (lang != NULL) {
	  if (strlen(lang) > 5) {
	    if (!strcmp(&lang[strlen(lang)-5], "UTF-8")) {
	       NJB_Set_Unicode(NJB_UC_UTF8);
	    }
	  }
	}

	if ( NJB_Discover(njbs, 0, &n) == -1 ) njb_error_dump(stderr);

	if ( n == 0 ) {
		fprintf(stderr, "no NJB devices found\n");
		return 0;
	} 

	njb= njbs;

	if ( NJB_Open(njb) == -1 ) {
		njb_error_dump(stderr);
		return 1;
	}

	if ( NJB_Capture(njb) == -1 ) {
		njb_error_dump(stderr);
		goto err1;
	}

	n = 0;
	NJB_Reset_Get_Track_Tag(njb);
	while ( (songtag= NJB_Get_Track_Tag(njb)) ) {
		songid_dump(songtag, stdout);
		songid_destroy(songtag);
		printf("----------------------------------\n");
		n ++;
	}
	if ( njb_error != EO_EOM ) njb_error_dump(stderr);
	printf("In total: %u tracks.\n", n);

	NJB_Release(njb);
	rc = 0;

err1:
	NJB_Close(njb);
	return rc;
}