$NetBSD: patch-ae,v 1.7 2009/08/09 16:00:53 drochner Exp $

--- main.c.orig	2008-09-11 23:11:02.000000000 +0200
+++ main.c
@@ -25,7 +25,9 @@
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
+#ifdef GETOPT_LONG
 #include <getopt.h>
+#endif
 #include <errno.h>
 #include <math.h>
 #include <sys/time.h>
@@ -204,6 +206,7 @@ VERSION"\n"
 "  cdparanoia [options] <span> [outfile]\n\n"
 
 "OPTIONS:\n"
+#ifdef GETOPT_LONG
 "  -A --analyze-drive              : run and log a complete analysis of drive\n"
 "                                    caching, timing and reading behavior;\n"
 "                                    verifies that cdparanoia is correctly\n"
@@ -239,6 +242,7 @@ VERSION"\n"
 "                                    to n sectors\n"
 "  -o --force-search-overlap  <n>  : force minimum overlap search during\n"
 "                                    verification to n sectors\n"
+#if !(defined(__APPLE__) && defined(__MACH__))
 "  -d --force-cdrom-device   <dev> : use specified device; disallow \n"
 "                                    autosense\n"
 "  -k --force-cooked-device  <dev> : use specified cdrom device and force\n"
@@ -248,6 +252,7 @@ VERSION"\n"
 "  -g --force-generic-device <dev> : use specified generic scsi device and\n"
 "                                    force use of the old SG kernel\n"
 "                                    interface. -g cannot be used with -k.\n"
+#endif
 "  -S --force-read-speed <n>       : read from device at specified speed; by\n"
 "                                    default, cdparanoia sets drive to full\n"
 "                                    speed.\n"
@@ -267,6 +272,52 @@ VERSION"\n"
 "  -Z --disable-paranoia           : disable all paranoia checking\n"
 "  -Y --disable-extra-paranoia     : only do cdda2wav-style overlap checking\n"
 "  -X --abort-on-skip              : abort on imperfect reads/skips\n\n"
+#else
+"  -v         : extra verbose operation\n"
+"  -q         : quiet operation\n"
+"  -e         : force output of progress information to\n"
+"               stderr (for wrapper scripts)\n"
+"  -V         : print version info and quit\n"
+"  -Q         : autosense drive, query disc and quit\n"
+"  -B         : 'batch' mode (saves each track to a seperate file.\n"
+"  -s         : do an exhaustive search for drive\n"
+"  -h         : print help\n\n"
+
+"  -p         : output raw 16 bit PCM in host byte order\n"
+"  -r         : output raw 16 bit little-endian PCM\n"
+"  -R         : output raw 16 bit big-endian PCM\n"
+"  -w         : output as WAV file (default)\n"
+"  -f         : output as AIFF file\n"
+"  -a         : output as AIFF-C file\n"
+"  -i <file>  : output human readable ripping info to file\n\n"
+
+"  -c         : force treating drive as little endian\n"
+"  -C         : force treating drive as big endian\n"
+"  -n <n>     : force default number of sectors in read to n sectors\n"
+"  -o <n>     : force minimum overlap search during\n"
+"               verification to n sectors\n"
+#if !(defined(__APPLE__) && defined(__MACH__))
+"  -d <dev>   : use specified device; disallow autosense\n"
+"  -g <dev>   : use specified generic scsi device\n"
+#endif
+"  -S <n>     : read from device at specified speed\n"
+"  -t <n>     : Add <n> sectors to the values reported\n"
+"               when addressing tracks. May be negative\n"
+"  -T         : Assume that the beginning offset of\n"
+"               track 1 as reported in the TOC will be\n"
+"               addressed as LBA 0.  Necessary for some\n"
+"               Toshiba drives to get track boundaries\n"
+"               correct\n"
+"  -O <n>     : Add <n> samples to the offset when\n"
+"               reading data.  May be negative.\n"
+"  -z[=n]     : never accept any less than perfect\n"
+"               data reconstruction (don't allow 'V's)\n"
+"               but if [n] is given, skip after [n]\n"
+"               retries without progress.\n"
+"  -Z         : disable all paranoia checking\n"
+"  -Y         : only do cdda2wav-style overlap checking\n"
+"  -X         : abort on imperfect reads/skips\n\n"
+#endif
 
 "OUTPUT SMILIES:\n"
 "  :-)   Normal operation, low/no jitter\n"
@@ -606,6 +657,7 @@ static void callback(long inpos, int fun
 
 const char *optstring = "escCn:o:O:d:g:k:S:prRwafvqVQhZz::YXWBi:Tt:l::L::A";
 
+#ifdef GETOPT_LONG
 struct option options [] = {
 	{"stderr-progress",no_argument,NULL,'e'},
 	{"search-for-drive",no_argument,NULL,'s'},
@@ -644,6 +696,7 @@ struct option options [] = {
 
 	{NULL,0,NULL,0}
 };
+#endif
 
 long blocking_write(int outf, char *buffer, long num){
   long words=0,temp;
@@ -703,7 +756,12 @@ int main(int argc,char *argv[]){
 
   atexit(cleanup);
 
-  while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF){
+#ifdef GETOPT_LONG
+  while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF)
+#else
+  while((c=getopt(argc,argv,optstring))!=EOF)
+#endif
+  {
     switch(c){
     case 'B':
       batch=1;
@@ -720,6 +778,7 @@ int main(int argc,char *argv[]){
     case 'o':
       force_cdrom_overlap=atoi(optarg);
       break;
+#if !(defined(__APPLE__) && defined(__MACH__))
     case 'd':
       if(force_cdrom_device)free(force_cdrom_device);
       force_cdrom_device=copystring(optarg);
@@ -733,6 +792,7 @@ int main(int argc,char *argv[]){
       if(force_generic_device)free(force_generic_device);
       force_generic_device=copystring(optarg);
       break;
+#endif
     case 'k':
       if(force_generic_device || force_cdrom_device){
 	report("-k option incompatable with -d and -g\n");
@@ -939,6 +999,18 @@ int main(int argc,char *argv[]){
 
   /* Query the cdrom/disc; we may need to override some settings */
 
+#if defined(__APPLE__) && defined(__MACH__)
+  d=cdda_find_a_cdrom(verbose,NULL);
+#else
+#ifndef __linux__	/* XXX */
+#ifndef __NetBSD__ /* XXX: is this needed? */
+  if (!force_generic_device)
+    errx(1, "-g option is currently required by the NetBSD pkg version");
+#endif
+  if (!force_cdrom_device)
+    force_cdrom_device=copystring(force_generic_device);
+#endif
+
   if(force_cooked_device){
     d=cdda_identify_cooked(force_cooked_device,verbose,NULL);
   }else if(force_generic_device)
@@ -971,6 +1043,7 @@ int main(int argc,char *argv[]){
 	    report(" ");
 	}
       }
+#endif /* __APPLE__ && __DARWIN__ */
 
   if(!d){
     if(!verbose)
@@ -1005,7 +1078,9 @@ int main(int argc,char *argv[]){
     report("Forcing default to read %d sectors; "
 	   "ignoring preset and autosense",force_cdrom_sectors);
     d->nsectors=force_cdrom_sectors;
+#if !(defined(__APPLE__) && defined(__MACH__))
     d->bigbuff=force_cdrom_sectors*CD_FRAMESIZE_RAW;
+#endif
   }
   if(force_cdrom_overlap!=-1){
     if(force_cdrom_overlap<0 || force_cdrom_overlap>75){
