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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
/* "info.c" copyright 1994 thomas insel
* copyright 1995 sven oliver moll */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#ifdef sun
# include <sundev/srreg.h>
#elif defined linux
# include <linux/cdrom.h>
#else
# error Please fix includes for your system in info.c
#endif
#include "config.h"
#include "database.h"
#include "hardware.h"
#include "info.h"
#include "main.h"
#ifdef CDCTRL
char caBuff[(BUFSIZ > (20 + 8*100)) ? BUFSIZ : (20 + 8*100)];
#endif
/************************************************************************/
/* Procedure: tracks_line
* Purpose: to display a line of info on a CD-ROM track
*
* Inputs: hardware info
* Outputs: to temp string
* Returns: pointer to temp string
* Notes:
* 1.
*/
/************************************************************************/
char *
tracks_line(cdhw_t *hw)
{
int i;
#ifdef CDCTRL
char *tempstr = &caBuff[0];
#else
char *tempstr = (char *)malloc(20 + 8*hw->tochdr.cdth_trk1);
#endif
sprintf(tempstr, "tracks %u ", hw->tochdr.cdth_trk1);
for (i=hw->tochdr.cdth_trk0; i<=hw->tochdr.cdth_trk1; i++)
sprintf(tempstr + strlen(tempstr), "%u ",
hw->tocentries[i-1].cdte_addr.msf.minute*4500 +
hw->tocentries[i-1].cdte_addr.msf.second*75 +
hw->tocentries[i-1].cdte_addr.msf.frame );
sprintf(tempstr + strlen(tempstr), "%u",
hw->tocentries[hw->tochdr.cdth_trk1].cdte_addr.msf.minute*60 +
hw->tocentries[hw->tochdr.cdth_trk1].cdte_addr.msf.second);
return tempstr;
}
/************************************************************************/
/* Procedure: check_disc
* Purpose: to check the disc for mounted, data, and no disc
*
* Inputs: program name, CD file des., CD file des., pointer to flag,
* device of CDROM
* Outputs: debug to stdout, error to stdout
* Returns: pointer to HW structure
* Notes:
* 1.
*/
/************************************************************************/
cdhw_t *check_disc (char *progname, int cdfile, int docr, int *piF,
char *cddevice)
{
cdhw_t *hw;
/* get hardware info */
hw = read_hw(progname, cdfile, cddevice);
/* check if NO CDROM */
if ((hw->iStatus == CD_STATUS_NO_CD) ||
(hw->iStatus == CD_STATUS_REMOVED)) {
printf ("nodisc");
DoCr (docr);
*piF = FALSE;
} else {
/* check if mounted */
if (hw->iStatus == CD_STATUS_MOUNTED) {
printf ("mounted");
DoCr (docr);
*piF = FALSE;
} else {
/* if data disc, print msg */
if (hw->iStatus == CD_STATUS_DATA_DISC) {
printf ("datadisc %d track%c", hw->iData, (hw->iData>1)?'s':' ');
DoCr (docr);
*piF = FALSE;
} else {
*piF = TRUE;
}
}
}
return (hw);
}
/************************************************************************/
/* Procedure: do_info
* Purpose: to print info on a CD-ROM
*
* Inputs: name of program, cd file descriptior, info level, CR flag,
* device of CDROM
* Outputs: to stdout/stderr
* Returns: n/a
* Notes:
* 1.
*/
/************************************************************************/
void do_info(char *progname, int cdfile, int info,
char *cddevice, int docr)
{
cdhw_t *hw = NULL;
int iTemp;
#ifdef DEBUG1
fprintf (stderr,"do_info: skipped, progname=%s, cdfile=%d, info=%d, hw=0x%lx\n",
progname, cdfile, info, hw);
return;
#endif
hw = check_disc (progname, cdfile, docr, &iTemp, cddevice);
if (iTemp == TRUE) {
/* hw = read_hw(progname, cdfile, cd_device); */
/* if ((hw->iStatus == CD_STATUS_NO_CD) || */
/* (hw->iStatus == CD_STATUS_REMOVED)) { */
/* printf ("nodisc"); */
/* DoCr (docr); */
/* } else if (hw->iStatus == CD_STATUS_MOUNTED) { */
/* printf ("mounted"); */
/* DoCr (docr); */
/* } else { */
#ifdef DEBUG
fprintf (stderr,"do_info: called, progname=%s, cdfile=%d, info=%d, hw=%lx\n",
progname, cdfile, info, (long)hw);
#endif
/* audio status */
if ((info == I_AUDIOSTATUS) || (info == I_DISP_ALL)) {
switch (hw->subchnl.cdsc_audiostatus) {
case CDROM_AUDIO_INVALID:
printf("invalid ");
break;
case CDROM_AUDIO_PLAY:
printf("play ");
break;
case CDROM_AUDIO_PAUSED:
printf("paused ");
break;
case CDROM_AUDIO_COMPLETED:
printf("completed ");
break;
case CDROM_AUDIO_ERROR:
printf("error ");
break;
case CDROM_AUDIO_NO_STATUS:
printf("no-status ");
break;
default:
printf("unknown=%i ", hw->subchnl.cdsc_audiostatus);
break;
}
DoCr (docr);
}
/* track info */
if ((info == I_TRACK) || (info == I_DISP_ALL)) {
printf("%u ",( (hw->subchnl.cdsc_audiostatus == CDROM_AUDIO_PLAY) ||
(hw->subchnl.cdsc_audiostatus == CDROM_AUDIO_PAUSED) )
? hw->subchnl.cdsc_trk : 0);
DoCr (docr);
}
/* absolute time, i.e., since CD start */
if ((info == I_DISP_ABS) || (info == I_DISP_ALL)) {
printf("%2u:%02u.%02u ",
hw->subchnl.cdsc_absaddr.msf.minute,
hw->subchnl.cdsc_absaddr.msf.second,
hw->subchnl.cdsc_absaddr.msf.frame);
DoCr (docr);
}
/* relative time, i.e., since track start */
if ((info == I_DISP_REL) || (info == I_DISP_ALL)) {
printf("%2u:%02u.%02u ",
hw->subchnl.cdsc_reladdr.msf.minute,
hw->subchnl.cdsc_reladdr.msf.second,
hw->subchnl.cdsc_reladdr.msf.frame);
DoCr (docr);
}
}
#ifdef DEBUG
fprintf (stderr,"do_info: finished\n");
#endif
/* free the hardware buffer.... */
free_hw_buf(hw);
}
/************************************************************************/
/* Procedure: do_dir
* Purpose: to print the directory of a CD-ROM
*
* Inputs: prog name, CD file des., format info, database, CR flag,
* device of CDROm
* Outputs: to stdout/stderr
* Returns: n/a
* Notes:
* 1.
*/
/************************************************************************/
void do_dir(char *progname, int cdfile, int p_format, int usedb,
char *cddevice, int docr)
{
cdhw_t *hw;
char *tracks_buffer;
cd_t *cd;
int iTemp;
int i; /* generic index variable */
#ifdef DEBUG
fprintf (stderr,"do_dir: called, progname=%s, cdfile=%d, pfmt=%d, usedb=%d\n",
progname, cdfile, p_format, usedb);
#endif
hw = check_disc (progname, cdfile, docr, &iTemp, cddevice);
if (iTemp == TRUE) {
/* hw = read_hw(progname, cdfile, cd_device); */
/* if ((hw->iStatus == CD_STATUS_NO_CD) || */
/* (hw->iStatus == CD_STATUS_REMOVED)) { */
/* printf ("nodisc"); */
/* DoCr (docr); */
/* } else if (hw->iStatus == CD_STATUS_MOUNTED) { */
/* printf ("mounted"); */
/* DoCr (docr); */
/* } else { */
tracks_buffer = tracks_line(hw);
cd = read_db(tracks_buffer, usedb);
/* print name & artist info */
if (p_format == P_TEMPL) {
for (i=0; i<strlen(tracks_buffer); i++) /* print "tracks" line */
putchar(tracks_buffer[i]);
DoCr(docr);
printf("cdname %s", cd->cdname);
DoCr(docr);
printf("artist %s", cd->artist);
DoCr(docr);
} else if (p_format != P_RAW) {
printf("%s", cd->artist);
if (cd->cdname[0] && cd->artist[0])
printf(" - ");
printf("%s", cd->cdname);
if (!cd->artist[0] && !cd->cdname[0])
printf("unknown cd");
if (p_format == P_LONG)
printf(" - %2u:%02u in %u tracks",
hw->tocentries[hw->tochdr.cdth_trk1].cdte_addr.msf.minute,
hw->tocentries[hw->tochdr.cdth_trk1].cdte_addr.msf.second,
hw->tochdr.cdth_trk1);
DoCr(docr);
}
/* print tracks */
switch(p_format) {
case P_RAW:
printf("%2u-%2u",hw->tochdr.cdth_trk0, hw->tochdr.cdth_trk1);
DoCr(docr);
for (i = hw->tochdr.cdth_trk0; i<=hw->tochdr.cdth_trk1+1; i++) {
printf("%2X %02u:%02u.%02u %c",
(i<hw->tochdr.cdth_trk1+1) ? ((i/10)*16+i%10) : 0xaa,
hw->tocentries[i-1].cdte_addr.msf.minute,
hw->tocentries[i-1].cdte_addr.msf.second,
hw->tocentries[i-1].cdte_addr.msf.frame,
(hw->tocentries[i-1].cdte_ctrl ==
CDROM_DATA_TRACK) ? 'D' : 'A');
DoCr(docr);
}
break;
case P_LONG:
for (i = hw->tochdr.cdth_trk0; i<=hw->tochdr.cdth_trk1; i++) {
int delfrms
= ( hw->tocentries[i].cdte_addr.msf.minute
- hw->tocentries[i-1].cdte_addr.msf.minute ) * 4500
+ ( hw->tocentries[i].cdte_addr.msf.second
- hw->tocentries[i-1].cdte_addr.msf.second ) * 75
+ ( hw->tocentries[i].cdte_addr.msf.frame
- hw->tocentries[i-1].cdte_addr.msf.frame );
printf(" %2u:%02u.%02u %2u ",
delfrms/4500,(delfrms%4500)/75,delfrms%75, i);
if (hw->tocentries[i-1].cdte_ctrl == CDROM_DATA_TRACK)
printf("[DATA] ");
if (i == hw->subchnl.cdsc_trk) {
if (hw->subchnl.cdsc_audiostatus == CDROM_AUDIO_PLAY)
printf("[PLAYING] ");
else if (hw->subchnl.cdsc_audiostatus == CDROM_AUDIO_PAUSED)
printf("[PAUSED] ");
}
if (usedb)
printf("%s",cd->track_names[i-1]);
DoCr(docr);
}
break; /* P_LONG */
case P_QUICK:
switch(hw->subchnl.cdsc_audiostatus) {
case CDROM_AUDIO_PLAY:
printf(" - ");
if (cd->track_names[hw->subchnl.cdsc_trk-1][0])
printf("%s ", cd->track_names[hw->subchnl.cdsc_trk-1]);
printf("[%u]", hw->subchnl.cdsc_trk);
DoCr(docr);
break;
case CDROM_AUDIO_PAUSED:
printf(" - paused on ");
if (cd->track_names[hw->subchnl.cdsc_trk-1][0])
printf("%s ", cd->track_names[hw->subchnl.cdsc_trk-1]);
printf("[%u]", hw->subchnl.cdsc_trk);
DoCr(docr);
break;
default:
DoCr(docr);
}
break; /* P_QUICK */
case P_TEMPL:
for (i = hw->tochdr.cdth_trk0; i<=hw->tochdr.cdth_trk1; i++) {
printf("track %s", cd->track_names[i-1]);
DoCr(docr);
}
break; /* P_TEMPL */
} /* switch */
}
free_hw_buf(hw);
}
|