2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)auinfo.c 1.23 04/03/01 Copyright 1998-2004 J. Schilling */
15 * Copyright (c) 1998-2004 J. Schilling
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2
20 * as published by the Free Software Foundation.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along with
28 * this program; see the file COPYING. If not, write to the Free Software
29 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
49 BOOL auinfosize(char *name, track_t *trackp);
50 void auinfo(char *name, int track, track_t *trackp);
51 textptr_t *gettextptr(int track, track_t *trackp);
52 static char *savestr(char *name);
53 static char *readtag(char *name);
54 static char *readtstr(char *name);
55 void setmcn(char *mcn, track_t *trackp);
56 static void isrc_illchar(char *isrc, int c);
57 void setisrc(char *isrc, track_t *trackp);
58 void setindex(char *tindex, track_t *trackp);
62 main(int argc, char *argv[])
64 /* auinfo("/etc/default/cdrecord");*/
65 /* auinfo("/mnt2/CD3/audio_01.inf");*/
66 auinfo("/mnt2/CD3/audio_01.wav");
71 auinfosize(char *name, track_t *trackp)
80 if (!is_audio(trackp))
83 if ((trackp->flags & TI_USEINFO) == 0)
86 if ((p = strrchr(name, '.')) == NULL)
88 if (!streql(p, ".inf") && !streql(p, ".INF"))
92 * First check if a bad guy tries to call auinfosize()
93 * while STDIN_FILENO is a TTY.
95 if (isatty(STDIN_FILENO)) {
97 "WARNING: Stdin is connected to a terminal.\n");
101 if (stat(name, &sb) < 0) /* *.inf file not found */
104 if (sb.st_size > 10000) /* Too large for a *.inf file */
107 if (cfg_open(name) < 0) /* Cannot open *.inf file */
110 tlp = p = readtag("Tracklength");
111 if (p == NULL) { /* Tracklength= Tag not found */
113 "WARNING: %s does not contain a 'Tracklength=' tag.\n",
120 if (*p != '\0' && *p != ',') {
122 "WARNING: %s: 'Tracklength=' contains illegal parameter '%s'.\n",
129 p = astol(p, &nsamples);
132 "WARNING: %s: 'Tracklength=' contains illegal parameter '%s'.\n",
137 tracksize = (secs * 2352) + (nsamples * 4);
139 fprintf(stderr, "%s: Tracksize %lld bytes (%ld sectors, %ld samples)\n",
140 name, tracksize, secs, nsamples);
142 trackp->itracksize = tracksize;
148 auinfo(char *name, int track, track_t *trackp)
152 track_t *tp = &trackp[track];
156 BOOL isdao = !is_tao(&trackp[0]);
158 strncpy(infname, name, sizeof (infname)-1);
159 infname[sizeof (infname)-1] = '\0';
160 p = strrchr(infname, '.');
161 if (p != 0 && &p[4] < &name[sizeof (infname)]) {
162 strcpy(&p[1], "inf");
165 if (cfg_open(infname) == 0) {
167 p = readtstr("CDINDEX_DISCID");
168 p = readtag("CDDB_DISKID");
172 setmcn(p, &trackp[0]);
173 txp = gettextptr(0, trackp); /* MCN is isrc for trk 0*/
174 txp->tc_isrc = savestr(p);
179 setisrc(p, &trackp[track]);
180 txp = gettextptr(track, trackp);
181 txp->tc_isrc = savestr(p);
184 p = readtstr("Albumperformer");
186 txp = gettextptr(0, trackp); /* Album perf. in trk 0*/
187 txp->tc_performer = savestr(p);
189 p = readtstr("Performer");
191 txp = gettextptr(track, trackp);
192 txp->tc_performer = savestr(p);
194 p = readtstr("Albumtitle");
196 txp = gettextptr(0, trackp); /* Album title in trk 0*/
197 txp->tc_title = savestr(p);
199 p = readtstr("Tracktitle");
201 txp = gettextptr(track, trackp);
202 txp->tc_title = savestr(p);
204 p = readtstr("Songwriter");
206 txp = gettextptr(track, trackp);
207 txp->tc_songwriter = savestr(p);
209 p = readtstr("Composer");
211 txp = gettextptr(track, trackp);
212 txp->tc_composer = savestr(p);
214 p = readtstr("Arranger");
216 txp = gettextptr(track, trackp);
217 txp->tc_arranger = savestr(p);
219 p = readtstr("Message");
221 txp = gettextptr(track, trackp);
222 txp->tc_message = savestr(p);
224 p = readtstr("Diskid");
226 txp = gettextptr(0, trackp); /* Disk id is in trk 0*/
227 txp->tc_title = savestr(p);
229 p = readtstr("Closed_info");
231 txp = gettextptr(track, trackp);
232 txp->tc_closed_info = savestr(p);
235 p = readtag("Tracknumber");
239 p = readtag("Trackstart");
243 if (track == 1 && tno == 1 && l > 0) {
244 trackp[1].pregapsize = 150 + l;
245 printf("Track1 Start: '%s' (%ld)\n", p, l);
249 p = readtag("Tracklength");
251 p = readtag("Pre-emphasis");
253 if (strncmp(p, "yes", 3) == 0) {
254 tp->flags |= TI_PREEMP;
255 if ((tp->tracktype & TOC_MASK) == TOC_DA)
256 tp->sectype = SECT_AUDIO_PRE;
258 } else if (strncmp(p, "no", 2) == 0) {
259 tp->flags &= ~TI_PREEMP;
260 if ((tp->tracktype & TOC_MASK) == TOC_DA)
261 tp->sectype = SECT_AUDIO_NOPRE;
265 p = readtag("Channels");
266 p = readtag("Copy_permitted");
269 * -useinfo always wins
271 tp->flags &= ~(TI_COPY|TI_SCMS);
273 if (strncmp(p, "yes", 3) == 0)
274 tp->flags |= TI_COPY;
275 else if (strncmp(p, "no", 2) == 0)
276 tp->flags |= TI_SCMS;
277 else if (strncmp(p, "once", 2) == 0)
278 tp->flags &= ~(TI_COPY|TI_SCMS);
280 p = readtag("Endianess");
281 p = readtag("Index");
282 if (p && *p && isdao)
283 setindex(p, &trackp[track]);
285 p = readtag("Index0");
293 trackp[track+1].pregapsize = 0;
295 ts = tp->itracksize / tp->isecsize;
298 trackp[track+1].pregapsize = ps;
306 gettextptr(int track, track_t *trackp)
308 register textptr_t *txp;
310 txp = (textptr_t *)trackp[track].text;
312 txp = malloc(sizeof (textptr_t));
314 comerr("Cannot malloc CD-Text structure.\n");
315 fillbytes(txp, sizeof (textptr_t), '\0');
316 trackp[track].text = txp;
326 ret = malloc(strlen(str)+1);
330 comerr("Cannot malloc auinfo string.\n");
341 printf("%s '%s'\n", name, p);
352 if (p && *p == '\'') {
356 while (p2 > p && *p2 != '\'')
360 printf("%s '%s'\n", name, p);
366 * Media catalog number is a 13 digit number.
369 setmcn(char *mcn, track_t *trackp)
373 if (strlen(mcn) != 13)
374 comerrno(EX_BAD, "MCN '%s' has illegal length.\n", mcn);
376 for (p = mcn; *p; p++) {
377 if (*p < '0' || *p > '9')
378 comerrno(EX_BAD, "MCN '%s' contains illegal character '%c'.\n", mcn, *p);
385 printf("Track %d MCN: '%s'\n", (int)trackp->trackno, trackp->isrc);
388 static char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
391 isrc_illchar(char *isrc, int c)
393 errmsgno(EX_BAD, "ISRC '%s' contains illegal character '%c'.\n", isrc, c);
399 * Country code 'C' (alpha) 2 Bytes
400 * Owner code 'O' (alphanumeric) 3 Bytes
401 * Year of record 'Y' (numeric) 2 Bytes
402 * Serial number 'S' (numeric) 5 Bytes
407 setisrc(char *isrc, track_t *trackp)
415 if ((len = strlen(isrc)) != 12) {
416 for (p = isrc, i = 0; *p; p++) {
420 if (((len - i) != 12) || i > 3)
421 comerrno(EX_BAD, "ISRC '%s' has illegal length.\n", isrc);
427 for (p = isrc, ip = ibuf, i = 0; i < 2; p++, i++) {
429 if (!strchr(upper, *p)) {
432 * Flag numbers but accept them.
434 isrc_illchar(isrc, *p);
435 if (*p >= '0' && *p <= '9')
446 for (i = 0; i < 3; p++, i++) {
448 if (strchr(upper, *p))
450 if (*p >= '0' && *p <= '9')
458 * The Year and the recording number (2 + 5 numbers).
460 for (i = 0; i < 7; p++, i++) {
462 if (*p >= '0' && *p <= '9')
464 if (*p == '-' && i == 2) {
477 printf("Track %d ISRC: '%s'\n", (int)trackp->trackno, trackp->isrc);
480 isrc_illchar(isrc, *p);
485 setindex(char *tindex, track_t *trackp)
493 idxlist = malloc(100*sizeof (long));
499 if (*p != '\0' && *p != ' ' && *p != '\t' && *p != ',')
503 comerrno(EX_BAD, "Too many indices for track %d\n", (int)trackp->trackno);
507 while (*p == ' ' || *p == '\t')
513 printf("Track %d %d Index: '%s'\n", (int)trackp->trackno, i, tindex);
516 for (i = 0; i <= nindex; i++)
517 printf("%d: %ld\n", i, idxlist[i]);
520 trackp->nindex = nindex;
521 trackp->tindex = idxlist;
524 comerrno(EX_BAD, "Index '%s' contains illegal character '%c'.\n", tindex, *p);