use short options when getopt.h isn't present

This commit is contained in:
Ron Pedde 2005-02-28 21:49:51 +00:00
parent f4e8bc9625
commit f3b6ef46f9

View File

@ -23,13 +23,20 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif
char *av0; char *av0;
@ -176,8 +183,7 @@ size_t patch_hdr(unsigned char *hdr, size_t hdr_len,
bytes_per_sample = channel_count * ((sample_bit_length + 7) / 8); bytes_per_sample = channel_count * ((sample_bit_length + 7) / 8);
if (samples == 0) if (samples == 0) {
{
samples = sample_rate * sec; samples = sample_rate * sec;
samples += ((sample_rate / 100) * (us / 10)) / 1000; samples += ((sample_rate / 100) * (us / 10)) / 1000;
} }
@ -227,6 +233,11 @@ static void usage(int exitval)
fprintf(stderr, fprintf(stderr,
"--samples and --length are mutually exclusive.\n"); "--samples and --length are mutually exclusive.\n");
#ifndef HAVE_GETOPT_H
fprintf(stderr,
"\n\nLong options are not availabl eon this system.\n");
#endif
exit(exitval); exit(exitval);
} }
@ -249,9 +260,12 @@ int main(int argc, char **argv)
else else
av0 = argv[0]; av0 = argv[0];
while ((c = getopt_long(argc, argv, "+hl:o:s:", longopts, NULL)) != EOF) #ifdef HAVE_GETOPT_H
switch(c) while ((c = getopt_long(argc, argv, "+hl:o:s:", longopts, NULL)) != EOF) {
{ #else
while ((c = getopt(argc, argv, "hl:o:s:")) != -1) {
#endif
switch(c) {
case 'h': case 'h':
usage(0); usage(0);
/*NOTREACHED*/ /*NOTREACHED*/
@ -274,10 +288,12 @@ int main(int argc, char **argv)
} else { } else {
us = 0; us = 0;
} }
if ((sec == 0) && (us == 0)) { if ((sec == 0) && (us == 0)) {
fprintf(stderr, "%s: Invalid -l argument (zero is not acceptable).\n", av0); fprintf(stderr, "%s: Invalid -l argument (zero is not acceptable).\n", av0);
exit(-1); exit(-1);
} }
if (samples != 0) { if (samples != 0) {
fprintf(stderr, "%s: Parameters -s and -l are mutually exclusive.\n", av0); fprintf(stderr, "%s: Parameters -s and -l are mutually exclusive.\n", av0);
exit(-1); exit(-1);
@ -312,6 +328,7 @@ int main(int argc, char **argv)
fprintf(stderr, "%s: Bad command line option -%c.\n", av0, optopt); fprintf(stderr, "%s: Bad command line option -%c.\n", av0, optopt);
usage(-1); usage(-1);
} }
}
argc -= optind; argc -= optind;
argv += optind; argv += optind;