Common output routine in utility programs as a concession to

environments which may no have or prefer stdout/stderr such as XBOX.
This commit is contained in:
rocky
2004-11-04 10:08:23 +00:00
parent 6cbcabbe41
commit 152d8508b7
9 changed files with 332 additions and 478 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: util.c,v 1.24 2004/08/27 00:02:10 rocky Exp $
$Id: util.c,v 1.25 2004/11/04 10:08:23 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -44,10 +44,11 @@ print_version (char *program_name, const char *version,
driver_id_t driver_id;
if (no_header == 0)
printf( "%s version %s\nCopyright (c) 2003, 2004 R. Bernstein\n",
report( stdout, "%s version %s\nCopyright (c) 2003, 2004 R. Bernstein\n",
program_name, version);
printf( _("This is free software; see the source for copying conditions.\n\
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
report( stdout,
_("This is free software; see the source for copying conditions.\n\
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n \
PARTICULAR PURPOSE.\n\
"));
@@ -55,14 +56,14 @@ PARTICULAR PURPOSE.\n\
char *default_device;
for (driver_id=DRIVER_UNKNOWN+1; driver_id<=CDIO_MAX_DRIVER; driver_id++) {
if (cdio_have_driver(driver_id)) {
printf("Have driver: %s\n", cdio_driver_describe(driver_id));
report( stdout, "Have driver: %s\n", cdio_driver_describe(driver_id));
}
}
default_device=cdio_get_default_device(NULL);
if (default_device)
printf("Default CD-ROM device: %s\n", default_device);
report( stdout, "Default CD-ROM device: %s\n", default_device);
else
printf("No CD-ROM device found.\n");
report( stdout, "No CD-ROM device found.\n");
free(program_name);
exit(100);
}
@@ -81,7 +82,7 @@ fillout_device_name(const char *device_name)
return strdup(device_name);
else {
char *full_device_name = (char*) malloc(strlen(device_name)+prefix_len);
sprintf(full_device_name, DEV_PREFIX "%s", device_name);
report( stdout, full_device_name, DEV_PREFIX "%s", device_name);
return full_device_name;
}
#endif
@@ -122,256 +123,287 @@ print_mmc_drive_features(CdIo *p_cdio)
{
uint8_t *q;
case CDIO_MMC_FEATURE_PROFILE_LIST:
printf("Profile List Feature\n");
report( stdout, "Profile List Feature\n");
for ( q = p+4 ; q < p + i_feature_additional ; q += 4 ) {
int i_profile=CDIO_MMC_GET_LEN16(q);
switch (i_profile) {
case CDIO_MMC_FEATURE_PROF_NON_REMOVABLE:
printf("\tRe-writable disk, capable of changing behavior");
report( stdout,
"\tRe-writable disk, capable of changing behavior");
break;
case CDIO_MMC_FEATURE_PROF_REMOVABLE:
printf("\tdisk Re-writable; with removable media");
report( stdout,
"\tdisk Re-writable; with removable media");
break;
case CDIO_MMC_FEATURE_PROF_MO_ERASABLE:
printf("\tErasable Magneto-Optical disk with sector erase capability");
report( stdout,
"\tErasable Magneto-Optical disk with sector erase capability");
break;
case CDIO_MMC_FEATURE_PROF_MO_WRITE_ONCE:
printf("\tWrite Once Magneto-Optical write once");
report( stdout,
"\tWrite Once Magneto-Optical write once");
break;
case CDIO_MMC_FEATURE_PROF_AS_MO:
printf("\tAdvance Storage Magneto-Optical");
report( stdout,
"\tAdvance Storage Magneto-Optical");
break;
case CDIO_MMC_FEATURE_PROF_CD_ROM:
printf("\tRead only Compact Disc capable");
report( stdout,
"\tRead only Compact Disc capable");
break;
case CDIO_MMC_FEATURE_PROF_CD_R:
printf("\tWrite once Compact Disc capable");
report( stdout,
"\tWrite once Compact Disc capable");
break;
case CDIO_MMC_FEATURE_PROF_CD_RW:
printf("\tCD-RW Re-writable Compact Disc capable");
report( stdout,
"\tCD-RW Re-writable Compact Disc capable");
break;
case CDIO_MMC_FEATURE_PROF_DVD_ROM:
printf("\tRead only DVD");
report( stdout,
"\tRead only DVD");
break;
case CDIO_MMC_FEATURE_PROF_DVD_R_SEQ:
printf("\tRe-recordable DVD using Sequential recording");
report( stdout,
"\tRe-recordable DVD using Sequential recording");
break;
case CDIO_MMC_FEATURE_PROF_DVD_RAM:
printf("\tRe-writable DVD");
report( stdout,
"\tRe-writable DVD");
break;
case CDIO_MMC_FEATURE_PROF_DVD_RW_RO:
printf("\tRe-recordable DVD using Restricted Overwrite");
report( stdout,
"\tRe-recordable DVD using Restricted Overwrite");
break;
case CDIO_MMC_FEATURE_PROF_DVD_RW_SEQ:
printf("\tRe-recordable DVD using Sequential recording");
report( stdout,
"\tRe-recordable DVD using Sequential recording");
break;
case CDIO_MMC_FEATURE_PROF_DVD_PRW:
printf("\tDVD+RW - DVD ReWritable");
report( stdout,
"\tDVD+RW - DVD ReWritable");
break;
case CDIO_MMC_FEATURE_PROF_DVD_PR:
printf("\tDVD+R - DVD Recordable");
report( stdout,
"\tDVD+R - DVD Recordable");
break;
case CDIO_MMC_FEATURE_PROF_DDCD_ROM:
printf("\tRead only DDCD");
report( stdout,
"\tRead only DDCD");
break;
case CDIO_MMC_FEATURE_PROF_DDCD_R:
printf("\tDDCD-R Write only DDCD");
report( stdout,
"\tDDCD-R Write only DDCD");
break;
case CDIO_MMC_FEATURE_PROF_DDCD_RW:
printf("\tRe-Write only DDCD");
report( stdout,
"\tRe-Write only DDCD");
break;
case CDIO_MMC_FEATURE_PROF_NON_CONFORM:
printf("\tThe Logical Unit does not conform to any Profile.");
report( stdout,
"\tThe Logical Unit does not conform to any Profile.");
break;
default:
printf("\tUnknown Profile %x", i_profile);
report( stdout,
"\tUnknown Profile %x", i_profile);
break;
}
if (q[2] & 1) {
printf(" - on");
report( stdout, " - on");
}
printf("\n");
report( stdout, "\n");
}
printf("\n");
report( stdout, "\n");
break;
case CDIO_MMC_FEATURE_CORE:
{
uint8_t *q = p+4;
uint32_t i_interface_standard = CDIO_MMC_GET_LEN32(q);
printf("Core Feature\n");
report( stdout, "Core Feature\n");
switch(i_interface_standard) {
case 0:
printf("\tunspecified interface\n");
report( stdout, "\tunspecified interface\n");
break;
case 1:
printf("\tSCSI interface\n");
report( stdout, "\tSCSI interface\n");
break;
case 2:
printf("\tATAPI interface\n");
report( stdout, "\tATAPI interface\n");
break;
case 3:
printf("\tIEEE 1394 interface\n");
report( stdout, "\tIEEE 1394 interface\n");
break;
case 4:
printf("\tIEEE 1394A interface\n");
report( stdout, "\tIEEE 1394A interface\n");
break;
case 5:
printf("\tFibre Channel interface\n");
report( stdout, "\tFibre Channel interface\n");
}
printf("\n");
report( stdout, "\n");
break;
}
case CDIO_MMC_FEATURE_REMOVABLE_MEDIUM:
printf("Removable Medium Feature\n");
report( stdout, "Removable Medium Feature\n" );
switch(p[4] >> 5) {
case 0:
printf("\tCaddy/Slot type loading mechanism\n");
report( stdout,
"\tCaddy/Slot type loading mechanism\n" );
break;
case 1:
printf("\tTray type loading mechanism\n");
report( stdout,
"\tTray type loading mechanism\n" );
break;
case 2:
printf("\tPop-up type loading mechanism\n");
report( stdout, "\tPop-up type loading mechanism\n");
break;
case 4:
printf("\tEmbedded changer with individually changeable discs\n");
report( stdout,
"\tEmbedded changer with individually changeable discs\n");
break;
case 5:
printf("\tEmbedded changer using a magazine mechanism\n");
report( stdout,
"\tEmbedded changer using a magazine mechanism\n" );
break;
default:
printf("\tUnknown changer mechanism\n");
report( stdout,
"\tUnknown changer mechanism\n" );
}
printf("\tcan%s eject the medium or magazine via the normal "
"START/STOP command\n",
(p[4] & 8) ? "": "not");
printf("\tcan%s be locked into the Logical Unit\n",
(p[4] & 1) ? "": "not");
printf("\n");
report( stdout,
"\tcan%s eject the medium or magazine via the normal "
"START/STOP command\n",
(p[4] & 8) ? "": "not" );
report( stdout, "\tcan%s be locked into the Logical Unit\n",
(p[4] & 1) ? "": "not" );
report( stdout, "\n" );
break;
case CDIO_MMC_FEATURE_WRITE_PROTECT:
printf("Write Protect Feature\n");
report( stdout, "Write Protect Feature\n" );
break;
case CDIO_MMC_FEATURE_RANDOM_READABLE:
printf("Random Readable Feature\n");
report( stdout, "Random Readable Feature\n" );
break;
case CDIO_MMC_FEATURE_MULTI_READ:
printf("Multi-Read Feature\n");
report( stdout, "Multi-Read Feature\n" );
break;
case CDIO_MMC_FEATURE_CD_READ:
printf("CD Read Feature\n");
printf("\tC2 Error pointers are %ssupported\n",
(p[4] & 2) ? "": "not ");
printf("\tCD-Text is %ssupported\n",
(p[4] & 1) ? "": "not ");
printf("\n");
report( stdout, "CD Read Feature\n" );
report( stdout, "\tC2 Error pointers are %ssupported\n",
(p[4] & 2) ? "": "not " );
report( stdout, "\tCD-Text is %ssupported\n",
(p[4] & 1) ? "": "not " );
report( stdout, "\n" );
break;
case CDIO_MMC_FEATURE_DVD_READ:
printf("DVD Read Feature\n");
report( stdout, "DVD Read Feature\n" );
break;
case CDIO_MMC_FEATURE_RANDOM_WRITABLE:
printf("Random Writable Feature\n");
report( stdout, "Random Writable Feature\n" );
break;
case CDIO_MMC_FEATURE_INCR_WRITE:
printf("Incremental Streaming Writable Feature\n");
report( stdout, "Incremental Streaming Writable Feature\n" );
break;
case CDIO_MMC_FEATURE_SECTOR_ERASE:
printf("Sector Erasable Feature\n");
report( stdout, "Sector Erasable Feature\n" );
break;
case CDIO_MMC_FEATURE_FORMATABLE:
printf("Formattable Feature\n");
report( stdout, "Formattable Feature\n" );
break;
case CDIO_MMC_FEATURE_DEFECT_MGMT:
printf("Management Ability of the Logical Unit/media system "
"to provide an apparently defect-free space.\n");
report( stdout,
"Management Ability of the Logical Unit/media system "
"to provide an apparently defect-free space.\n" );
break;
case CDIO_MMC_FEATURE_WRITE_ONCE:
printf("Write Once Feature\n");
report( stdout, "Write Once Feature\n" );
break;
case CDIO_MMC_FEATURE_RESTRICT_OVERW:
printf("Restricted Overwrite Feature\n");
report( stdout, "Restricted Overwrite Feature\n" );
break;
case CDIO_MMC_FEATURE_CD_RW_CAV:
printf("CD-RW CAV Write Feature\n");
report( stdout, "CD-RW CAV Write Feature\n" );
break;
case CDIO_MMC_FEATURE_MRW:
printf("MRW Feature\n");
report( stdout, "MRW Feature\n" );
break;
case CDIO_MMC_FEATURE_DVD_PRW:
printf("DVD+RW Feature\n");
report( stdout, "DVD+RW Feature\n" );
break;
case CDIO_MMC_FEATURE_DVD_PR:
printf("DVD+R Feature\n");
report( stdout, "DVD+R Feature\n" );
break;
case CDIO_MMC_FEATURE_CD_TAO:
printf("CD Track at Once Feature\n");
report( stdout, "CD Track at Once Feature\n" );
break;
case CDIO_MMC_FEATURE_CD_SAO:
printf("CD Mastering (Session at Once) Feature\n");
report( stdout, "CD Mastering (Session at Once) Feature\n" );
break;
case CDIO_MMC_FEATURE_POWER_MGMT:
printf("Initiator and device directed power management\n");
report( stdout,
"Initiator and device directed power management\n" );
break;
case CDIO_MMC_FEATURE_CDDA_EXT_PLAY:
printf("CD Audio External Play Feature\n");
printf("\tSCAN command is %ssupported\n",
report( stdout, "CD Audio External Play Feature\n" );
report( stdout, "\tSCAN command is %ssupported\n",
(p[4] & 4) ? "": "not ");
printf("\taudio channels can %sbe muted separately\n",
report( stdout,
"\taudio channels can %sbe muted separately\n",
(p[4] & 2) ? "": "not ");
printf("\taudio channels can %shave separate volume levels\n",
report( stdout,
"\taudio channels can %shave separate volume levels\n",
(p[4] & 1) ? "": "not ");
{
uint8_t *q = p+6;
uint16_t i_vol_levels = CDIO_MMC_GET_LEN16(q);
printf("\t%d volume levels can be set\n", i_vol_levels);
report( stdout, "\t%d volume levels can be set\n", i_vol_levels );
}
printf("\n");
report( stdout, "\n");
break;
case CDIO_MMC_FEATURE_MCODE_UPGRADE:
printf("Ability for the device to accept new microcode via "
"the interface\n");
report( stdout, "Ability for the device to accept new microcode via "
"the interface\n" );
break;
case CDIO_MMC_FEATURE_TIME_OUT:
printf("Ability to respond to all commands within a "
"specific time\n");
report( stdout, "Ability to respond to all commands within a "
"specific time\n" );
break;
case CDIO_MMC_FEATURE_DVD_CSS:
printf("Ability to perform DVD CSS/CPPM authentication and"
" RPC\n");
report( stdout, "Ability to perform DVD CSS/CPPM authentication and"
" RPC\n" );
#if 0
printf("\tMedium does%s have Content Scrambling (CSS/CPPM)\n",
(p[2] & 1) ? "": "not ");
report( stdout, "\tMedium does%s have Content Scrambling (CSS/CPPM)\n",
(p[2] & 1) ? "": "not " );
#endif
printf("\tCSS version %d\n", p[7]);
printf("\t\n");
report( stdout, "\tCSS version %d\n", p[7] );
report( stdout, "\t\n");
break;
case CDIO_MMC_FEATURE_RT_STREAMING:
printf("Ability to read and write using Initiator requested performance parameters\n");
report( stdout,
"Ability to read and write using Initiator requested performance parameters\n");
break;
case CDIO_MMC_FEATURE_LU_SN: {
uint8_t i_serial = *(p+3);
char serial[257] = { '\0', };
printf("The Logical Unit has a unique identifier:\n");
memcpy(serial, p+4, i_serial);
printf("\t%s\n\n", serial);
report( stdout, "The Logical Unit has a unique identifier:\n" );
memcpy(serial, p+4, i_serial );
report( stdout, "\t%s\n\n", serial );
break;
}
default:
if ( 0 != (i_feature & 0xFF00) ) {
printf("Vendor-specific feature code %x\n", i_feature);
report( stdout, "Vendor-specific feature code %x\n", i_feature );
} else {
printf("Unknown feature code %x\n", i_feature);
report( stdout, "Unknown feature code %x\n", i_feature );
}
}
p += i_feature_additional + 4;
}
} else {
printf("Didn't get all feature codes\n");
report( stdout, "Didn't get all feature codes\n");
}
}
@@ -383,65 +415,81 @@ print_drive_capabilities(cdio_drive_read_cap_t i_read_cap,
cdio_drive_misc_cap_t i_misc_cap)
{
if (CDIO_DRIVE_CAP_ERROR == i_misc_cap) {
printf("Error in getting drive hardware properties\n");
report( stdout, "Error in getting drive hardware properties\n");
} else if (CDIO_DRIVE_CAP_UNKNOWN == i_misc_cap) {
printf("Uknown drive hardware properties\n");
report( stdout, "Uknown drive hardware properties\n");
} else {
printf(_("Hardware : %s\n"),
report( stdout, _("Hardware : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_FILE
? "Disk Image" : "CD-ROM or DVD");
printf(_("Can eject : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_EJECT ? "Yes" : "No");
printf(_("Can close tray : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_CLOSE_TRAY ? "Yes" : "No");
printf(_("Can disable manual eject : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_LOCK ? "Yes" : "No");
printf(_("Can select juke-box disc : %s\n\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_DISC ? "Yes" : "No");
report( stdout, _("Can eject : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_EJECT ? "Yes" : "No" );
report( stdout, _("Can close tray : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_CLOSE_TRAY ? "Yes" : "No" );
report( stdout, _("Can disable manual eject : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_LOCK ? "Yes" : "No" );
report( stdout, _("Can select juke-box disc : %s\n\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_DISC ? "Yes" : "No" );
printf(_("Can set drive speed : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_SPEED ? "Yes" : "No");
printf(_("Can detect if CD changed : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED ? "Yes" : "No");
printf(_("Can read multiple sessions : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_MULTI_SESSION ? "Yes" : "No");
printf(_("Can hard reset device : %s\n\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_RESET ? "Yes" : "No");
report( stdout, _("Can set drive speed : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_SPEED ? "Yes" : "No" );
report( stdout, _("Can detect if CD changed : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED ? "Yes" : "No" );
report( stdout, _("Can read multiple sessions : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_MULTI_SESSION ? "Yes" : "No" );
report( stdout, _("Can hard reset device : %s\n\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_RESET ? "Yes" : "No" );
}
if (CDIO_DRIVE_CAP_ERROR == i_read_cap) {
printf("Error in getting drive reading properties\n");
report( stdout, "Error in getting drive reading properties\n" );
} else if (CDIO_DRIVE_CAP_UNKNOWN == i_misc_cap) {
printf("Uknown drive reading properties\n");
report( stdout, "Uknown drive reading properties\n" );
} else {
printf("Reading....\n");
printf(_(" Can play audio : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_AUDIO ? "Yes" : "No");
printf(_(" Can read CD-R : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_R ? "Yes" : "No");
printf(_(" Can read CD-RW : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
printf(_(" Can read DVD-ROM : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_DVD_ROM ? "Yes" : "No");
report( stdout, "Reading....\n");
report( stdout, _(" Can play audio : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_AUDIO ? "Yes" : "No" );
report( stdout, _(" Can read CD-R : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_R ? "Yes" : "No" );
report( stdout, _(" Can read CD-RW : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No" );
report( stdout, _(" Can read DVD-ROM : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_DVD_ROM ? "Yes" : "No" );
}
if (CDIO_DRIVE_CAP_ERROR == i_write_cap) {
printf("Error in getting drive writing properties\n");
report( stdout, "Error in getting drive writing properties\n" );
} else if (CDIO_DRIVE_CAP_UNKNOWN == i_misc_cap) {
printf("Uknown drive writing properties\n");
report( stdout, "Uknown drive writing properties\n" );
} else {
printf("\nWriting....\n");
printf(_(" Can write CD-RW : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_CD_RW ? "Yes" : "No");
printf(_(" Can write DVD-R : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_R ? "Yes" : "No");
printf(_(" Can write DVD-RAM : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_RAM ? "Yes" : "No");
printf(_(" Can write DVD-RW : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_RW ? "Yes" : "No");
printf(_(" Can write DVD+RW : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_RPW ? "Yes" : "No");
report( stdout, "\nWriting....\n");
report( stdout, _(" Can write CD-RW : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_CD_RW ? "Yes" : "No" );
report( stdout, _(" Can write DVD-R : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_R ? "Yes" : "No" );
report( stdout, _(" Can write DVD-RAM : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_RAM ? "Yes" : "No" );
report( stdout, _(" Can write DVD-RW : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_RW ? "Yes" : "No" );
report( stdout, _(" Can write DVD+RW : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_WRITE_DVD_RPW ? "Yes" : "No" );
}
}
/* Common place for Output routine. Some environments like XBOX may not
stdout and stderr. */
void
report (FILE *stream, const char *psz_format, ...)
{
va_list args;
va_start (args, psz_format);
#ifdef _XBOX
OutputDebugString(psz_format, args);
#else
vfprintf (stream, psz_format, args);
#endif
va_end(args);
}