More integration/cleanup. Now uses cdio bytesex.h's BE/LE routines.

copystring -> strdup.

Some int's changed to track_t. But I need to be careful *not* to change
cdda_interface.h.
This commit is contained in:
rocky
2004-12-19 01:43:38 +00:00
parent 81d0304b7e
commit 0c35a965fc
13 changed files with 243 additions and 314 deletions

View File

@@ -1,3 +1,24 @@
/*
$Id: buffering_write.c,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998, 1999 Monty <xiphmont@mit.edu>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Eliminate teeny little writes. patch submitted by
Rob Ross <rbross@parl.ces.clemson.edu> --Monty 19991008 */
@@ -18,56 +39,75 @@ static long bw_pos = 0;
static char bw_outbuf[OUTBUFSZ];
/* buffering_write() - buffers data to a specified size before writing.
long int
blocking_write(int outf, char *buffer, long num){
long int words=0,temp;
while(words<num){
temp=write(outf,buffer+words,num-words);
if(temp==-1){
if(errno!=EINTR && errno!=EAGAIN)
return(-1);
temp=0;
}
words+=temp;
}
return(0);
}
/** buffering_write() - buffers data to a specified size before writing.
*
* Restrictions:
* - MUST CALL BUFFERING_CLOSE() WHEN FINISHED!!!
*
*/
long buffering_write(int fd, char *buffer, long num)
long int
buffering_write(int fd, char *buffer, long num)
{
if (fd != bw_fd) {
/* clean up after buffering for some other file */
if (bw_fd >= 0 && bw_pos > 0) {
if (blocking_write(bw_fd, bw_outbuf, bw_pos)) {
perror("write (in buffering_write, flushing)");
}
}
bw_fd = fd;
bw_pos = 0;
}
if (bw_pos + num > OUTBUFSZ) {
/* fill our buffer first, then write, then modify buffer and num */
memcpy(&bw_outbuf[bw_pos], buffer, OUTBUFSZ - bw_pos);
if (blocking_write(fd, bw_outbuf, OUTBUFSZ)) {
perror("write (in buffering_write, full buffer)");
return(-1);
}
num -= (OUTBUFSZ - bw_pos);
buffer += (OUTBUFSZ - bw_pos);
bw_pos = 0;
}
/* save data */
memcpy(&bw_outbuf[bw_pos], buffer, num);
bw_pos += num;
return(0);
if (fd != bw_fd) {
/* clean up after buffering for some other file */
if (bw_fd >= 0 && bw_pos > 0) {
if (blocking_write(bw_fd, bw_outbuf, bw_pos)) {
perror("write (in buffering_write, flushing)");
}
}
bw_fd = fd;
bw_pos = 0;
}
if (bw_pos + num > OUTBUFSZ) {
/* fill our buffer first, then write, then modify buffer and num */
memcpy(&bw_outbuf[bw_pos], buffer, OUTBUFSZ - bw_pos);
if (blocking_write(fd, bw_outbuf, OUTBUFSZ)) {
perror("write (in buffering_write, full buffer)");
return(-1);
}
num -= (OUTBUFSZ - bw_pos);
buffer += (OUTBUFSZ - bw_pos);
bw_pos = 0;
}
/* save data */
memcpy(&bw_outbuf[bw_pos], buffer, num);
bw_pos += num;
return(0);
}
/* buffering_close() - writes out remaining buffered data before closing
* file.
/** buffering_close() - writes out remaining buffered data before
* closing file.
*
*/
int buffering_close(int fd)
int
buffering_close(int fd)
{
if (fd == bw_fd && bw_pos > 0) {
/* write out remaining data and clean up */
if (blocking_write(fd, bw_outbuf, bw_pos)) {
perror("write (in buffering_close)");
}
bw_fd = -1;
bw_pos = 0;
}
return(close(fd));
if (fd == bw_fd && bw_pos > 0) {
/* write out remaining data and clean up */
if (blocking_write(fd, bw_outbuf, bw_pos)) {
perror("write (in buffering_close)");
}
bw_fd = -1;
bw_pos = 0;
}
return(close(fd));
}

View File

@@ -1,23 +1,39 @@
/*
* Copyright: GNU Public License 2 applies
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
* (C) 1998 Monty <xiphmont@mit.edu>
*
$Id: buffering_write.h,v 1.2 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty <xiphmont@mit.edu>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
extern long blocking_write(int outf, char *buffer, long i_num);
/** buffering_write() - buffers data to a specified size before writing.
*
* Restrictions:
* - MUST CALL BUFFERING_CLOSE() WHEN FINISHED!!!
*
*/
extern long buffering_write(int outf, char *buffer, long num);
/** buffering_close() - writes out remaining buffered data before
* closing file.
*
*/
extern int buffering_close(int fd);

View File

@@ -1,5 +1,6 @@
/*
* Copyright: GNU Public License 2 applies
* Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
* (C) 1998 Monty <xiphmont@mit.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,8 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
* (C) 1998 Monty <xiphmont@mit.edu>
*
* See ChangeLog for recent changes.
*
@@ -71,6 +70,17 @@
extern int verbose;
extern int quiet;
/* I wonder how many alignment issues this is gonna trip in the
future... it shouldn't trip any... I guess we'll find out :) */
static int bigendianp(void)
{
int test=1;
char *hack=(char *)(&test);
if(hack[0])return(0);
return(1);
}
static long parse_offset(cdrom_drive_t *d, char *offset, int begin){
long track=-1;
long hours=-1;
@@ -196,7 +206,7 @@ static long parse_offset(cdrom_drive_t *d, char *offset, int begin){
static void display_toc(cdrom_drive_t *d){
long audiolen=0;
int i;
track_t i;
report("\nTable of contents (audio tracks only):\n"
"track length begin copy pre ch\n"
"===========================================================");
@@ -642,21 +652,6 @@ struct option options [] = {
{NULL,0,NULL,0}
};
long blocking_write(int outf, char *buffer, long num){
long words=0,temp;
while(words<num){
temp=write(outf,buffer+words,num-words);
if(temp==-1){
if(errno!=EINTR && errno!=EAGAIN)
return(-1);
temp=0;
}
words+=temp;
}
return(0);
}
static cdrom_drive_t *d=NULL;
static cdrom_paranoia_t *p=NULL;
@@ -665,22 +660,25 @@ static void cleanup(void){
if(d)cdda_close(d);
}
int main(int argc,char *argv[]){
int toc_bias=0;
int toc_offset=0;
int sample_offset=0;
int force_cdrom_endian=-1;
int force_cdrom_sectors=-1;
int force_cdrom_overlap=-1;
char *force_cdrom_device=NULL;
char *force_generic_device=NULL;
int force_cdrom_speed=-1;
int max_retries=20;
char *span=NULL;
int output_type=1; /* 0=raw, 1=wav, 2=aifc */
int output_endian=0; /* -1=host, 0=little, 1=big */
int query_only=0;
int batch=0,i;
int
main(int argc,char *argv[])
{
int toc_bias = 0;
int toc_offset = 0;
int sample_offset = 0;
int force_cdrom_endian = -1;
int force_cdrom_sectors = -1;
int force_cdrom_overlap = -1;
char *force_cdrom_device = NULL;
char *force_generic_device = NULL;
int force_cdrom_speed = -1;
int max_retries = 20;
char *span = NULL;
int output_type = 1; /* 0=raw, 1=wav, 2=aifc */
int output_endian = 0; /* -1=host, 0=little, 1=big */
int query_only = 0;
int batch = 0;
int i;
/* full paranoia, but allow skipping */
int paranoia_mode=PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP;
@@ -712,11 +710,11 @@ int main(int argc,char *argv[]){
break;
case 'd':
if(force_cdrom_device)free(force_cdrom_device);
force_cdrom_device=copystring(optarg);
force_cdrom_device=strdup(optarg);
break;
case 'g':
if(force_generic_device)free(force_generic_device);
force_generic_device=copystring(optarg);
force_generic_device=strdup(optarg);
break;
case 'S':
force_cdrom_speed=atoi(optarg);
@@ -799,7 +797,7 @@ int main(int argc,char *argv[]){
break;
case 'i':
if(info_file)free(info_file);
info_file=copystring(info_file);
info_file=strdup(info_file);
break;
case 'T':
toc_bias=-1;
@@ -825,7 +823,7 @@ int main(int argc,char *argv[]){
exit(1);
}
}else
span=copystring(argv[optind]);
span=strdup(argv[optind]);
report(VERSION);
@@ -979,6 +977,7 @@ int main(int argc,char *argv[]){
char *span2=strchr(span,'-');
if(strrchr(span,'-')!=span2){
report("Error parsing span argument");
free(span);
cdda_close(d);
d=NULL;
exit(1);
@@ -1322,6 +1321,9 @@ int main(int argc,char *argv[]){
report("Done.\n\n");
cdda_close(d);
if (span) free(span);
if (force_cdrom_device) free(force_cdrom_device);
if (force_generic_device) free(force_generic_device);
d=NULL;
return 0;
}

View File

@@ -1,5 +1,5 @@
/*
$Id: utils.h,v 1.2 2004/12/19 00:02:09 rocky Exp $
$Id: utils.h,v 1.3 2004/12/19 01:43:38 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -20,92 +20,12 @@
*/
#include <stdlib.h>
#include <endian.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <cdio/types.h>
#include <cdio/bytesex.h>
extern long buffering_write(int outf, char *buffer, long num);
extern int buffering_close(int fd);
/* I wonder how many alignment issues this is gonna trip in the
future... it shouldn't trip any... I guess we'll find out :) */
static inline int bigendianp(void){
int test=1;
char *hack=(char *)(&test);
if(hack[0])return(0);
return(1);
}
#if BYTE_ORDER == LITTLE_ENDIAN
static inline int32_t be32_to_cpu(int32_t x){
return(UINT32_SWAP_LE_BE_C(x));
}
static inline int16_t be16_to_cpu(int16_t x){
return(UINT16_SWAP_LE_BE_C(x));
}
static inline int32_t le32_to_cpu(int32_t x){
return(x);
}
static inline int16_t le16_to_cpu(int16_t x){
return(x);
}
#else
static inline int32_t be32_to_cpu(int32_t x){
return(x);
}
static inline int16_t be16_to_cpu(int16_t x){
return(x);
}
static inline int32_t le32_to_cpu(int32_t x){
return(UINT32_SWAP_LE_BE_C(x));
}
static inline int16_t le16_to_cpu(int16_t x){
return(UINT16_SWAP_LE_BE_C(x));
}
#endif
static inline int32_t cpu_to_be32(int32_t x){
return(be32_to_cpu(x));
}
static inline int32_t cpu_to_le32(int32_t x){
return(le32_to_cpu(x));
}
static inline int16_t cpu_to_be16(int16_t x){
return(be16_to_cpu(x));
}
static inline int16_t cpu_to_le16(int16_t x){
return(le16_to_cpu(x));
}
static inline char *copystring(const char *s){
if(s){
char *ret=malloc((strlen(s)+1)*sizeof(char));
strcpy(ret,s);
return(ret);
}
return(NULL);
}
static inline char *catstring(char *buff,const char *s){
static inline char *
catstring(char *buff, const char *s)
{
if(s){
if(buff)
buff=realloc(buff,strlen(buff)+strlen(s)+1);