toast.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /* $Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/toast.c,v 1.8 1996/07/02 10:41:04 jutta Exp $ */
  7. #include "toast.h"
  8. /* toast -- lossy sound compression using the gsm library.
  9. */
  10. char * progname;
  11. int f_decode = 0; /* decode rather than encode (-d) */
  12. int f_cat = 0; /* write to stdout; implies -p (-c) */
  13. int f_force = 0; /* don't ask about replacements (-f) */
  14. int f_precious = 0; /* avoid deletion of original (-p) */
  15. int f_fast = 0; /* use faster fpt algorithm (-F) */
  16. int f_verbose = 0; /* debugging (-V) */
  17. int f_ltp_cut = 0; /* LTP cut-off margin (-C) */
  18. struct stat instat; /* stat (inname) */
  19. FILE *in, *out;
  20. char *inname, *outname;
  21. /*
  22. * The function (*output)() writes a frame of 160 samples given as
  23. * 160 signed 16 bit values (gsm_signals) to <out>.
  24. * The function (*input)() reads one such frame from <in>.
  25. * The function (*init_output)() begins output (e.g. writes a header).,
  26. * The function (*init_input)() begins input (e.g. skips a header).
  27. *
  28. * There are different versions of input, output, init_input and init_output
  29. * for different formats understood by toast; which ones are used
  30. * depends on the command line arguments and, in their absence, the
  31. * filename; the fallback is #defined in toast.h
  32. *
  33. * The specific implementations of input, output, init_input and init_output
  34. * for a format `foo' live in toast_foo.c.
  35. */
  36. int (*output ) P((gsm_signal *)),
  37. (*input ) P((gsm_signal *));
  38. int (*init_input) P((void)),
  39. (*init_output) P((void));
  40. static int generic_init P0() { return 0; } /* NOP */
  41. struct fmtdesc {
  42. char * name, * longname, * suffix;
  43. int (* init_input ) P((void)),
  44. (* init_output) P((void));
  45. int (* input ) P((gsm_signal * )),
  46. (* output) P((gsm_signal * ));
  47. } f_audio = {
  48. "audio",
  49. "8 kHz, 8 bit u-law encoding with Sun audio header", ".au",
  50. audio_init_input,
  51. audio_init_output,
  52. ulaw_input,
  53. ulaw_output
  54. }, f_ulaw = {
  55. "u-law", "plain 8 kHz, 8 bit u-law encoding", ".u",
  56. generic_init,
  57. generic_init,
  58. ulaw_input,
  59. ulaw_output
  60. }, f_alaw = {
  61. "A-law", "8 kHz, 8 bit A-law encoding", ".A",
  62. generic_init,
  63. generic_init,
  64. alaw_input,
  65. alaw_output
  66. }, f_linear = {
  67. "linear",
  68. "16 bit (13 significant) signed 8 kHz signal", ".l",
  69. generic_init,
  70. generic_init,
  71. linear_input,
  72. linear_output
  73. };
  74. struct fmtdesc * alldescs[] = {
  75. &f_audio,
  76. &f_alaw,
  77. &f_ulaw,
  78. &f_linear,
  79. (struct fmtdesc *)NULL
  80. };
  81. #define DEFAULT_FORMAT f_ulaw /* default audio format, others */
  82. /* are: f_alaw,f_audio,f_linear */
  83. struct fmtdesc * f_format = 0;
  84. /*
  85. * basename + suffix of a pathname
  86. */
  87. static char * endname P1((name), char * name)
  88. {
  89. if (name) {
  90. char * s = strrchr(name, '/');
  91. if (s && s[1]) name = s + 1;
  92. }
  93. return name;
  94. }
  95. /*
  96. * Try to figure out what we're supposed to do from the argv[0], if
  97. * any, and set the parameters accordingly.
  98. */
  99. static void parse_argv0 P1((av0), char * av0 )
  100. {
  101. int l;
  102. progname = av0 = endname(av0 ? av0 : "toast");
  103. /* If the name starts with `un', we want to decode, not code.
  104. * If the name ends in `cat', we want to write to stdout,
  105. * and decode as well.
  106. */
  107. if (!strncmp(av0, "un", 2)) f_decode = 1;
  108. if ( (l = strlen(av0)) >= 3 /* strlen("cat") */
  109. && !strcmp( av0 + l - 3, "cat" )) f_cat = f_decode = 1;
  110. }
  111. /*
  112. * Check whether the name (possibly generated by appending
  113. * .gsm to something else) is short enough for this system.
  114. */
  115. static int length_okay P1((name), char * name)
  116. {
  117. long max_filename_length = 0;
  118. char * end;
  119. /* If our _pathname_ is too long, we'll usually not be
  120. * able to open the file at all -- don't worry about that.
  121. *
  122. * But if the _filename_ is too long, there is danger of
  123. * silent truncation on some systems, which results
  124. * in the target replacing the source!
  125. */
  126. if (!name) return 0;
  127. end = endname(name);
  128. #ifdef NAME_MAX
  129. max_filename_length = NAME_MAX;
  130. #else
  131. #ifdef _PC_NAME_MAX
  132. #ifdef USE_PATHCONF
  133. { char * s, tmp;
  134. /* s = dirname(name)
  135. */
  136. if ((s = end) > name) {
  137. if (s > name + 1) s--;
  138. tmp = s;
  139. *s = 0;
  140. }
  141. errno = 0;
  142. max_filename_length = pathconf(s > name ? name : ".",
  143. _PC_NAME_MAX);
  144. if (max_filename_length == -1 && errno) {
  145. perror( s > name ? name : "." );
  146. fprintf(stderr,
  147. "%s: cannot get dynamic filename length limit for %s.\n",
  148. progname, s > name ? name : ".");
  149. return 0;
  150. }
  151. if (s > name) *s = tmp;
  152. }
  153. #endif /* USE_PATHCONF */
  154. #endif /* _PC_NAME_MAX */
  155. #endif /* !NAME_MAX */
  156. if (max_filename_length > 0 && strlen(end) > max_filename_length) {
  157. fprintf(stderr,
  158. "%s: filename \"%s\" is too long (maximum is %ld)\n",
  159. progname, endname(name), max_filename_length );
  160. return 0;
  161. }
  162. return 1;
  163. }
  164. /*
  165. * Return a pointer the suffix of a string, if any.
  166. * A suffix alone has no suffix, an empty suffix can not be had.
  167. */
  168. static char * suffix P2((name, suf), char *name, char * suf)
  169. {
  170. size_t nlen = strlen(name);
  171. size_t slen = strlen(suf);
  172. if (!slen || nlen <= slen) return (char *)0;
  173. name += nlen - slen;
  174. return memcmp(name, suf, slen) ? (char *)0 : name;
  175. }
  176. static void catch_signals P1((fun), SIGHANDLER_T (*fun) ())
  177. {
  178. #ifdef SIGHUP
  179. signal( SIGHUP, fun );
  180. #endif
  181. #ifdef SIGINT
  182. signal( SIGINT, fun );
  183. #endif
  184. #ifdef SIGPIPE
  185. signal( SIGPIPE, fun );
  186. #endif
  187. #ifdef SIGTERM
  188. signal( SIGTERM, fun );
  189. #endif
  190. #ifdef SIGXFSZ
  191. signal( SIGXFSZ, fun );
  192. #endif
  193. }
  194. static SIGHANDLER_T onintr P0()
  195. {
  196. char * tmp = outname;
  197. #ifdef HAS_SYSV_SIGNALS
  198. catch_signals( SIG_IGN );
  199. #endif
  200. outname = (char *)0;
  201. if (tmp) (void)unlink(tmp);
  202. exit(1);
  203. }
  204. /*
  205. * Allocate some memory and complain if it fails.
  206. */
  207. static char * emalloc P1((len), size_t len)
  208. {
  209. char * s;
  210. if (!(s = malloc(len))) {
  211. fprintf(stderr, "%s: failed to malloc %d bytes -- abort\n",
  212. progname, len);
  213. onintr();
  214. exit(1);
  215. }
  216. return s;
  217. }
  218. static char* normalname P3((name, want, cut), char *name, char *want,char *cut)
  219. {
  220. size_t maxlen;
  221. char * s, * p;
  222. p = (char *)0;
  223. if (!name) return p;
  224. maxlen = strlen(name) + 1 + strlen(want) + strlen(cut);
  225. p = strcpy(emalloc(maxlen), name);
  226. if (s = suffix(p, cut)) strcpy(s, want);
  227. else if (*want && !suffix(p, want)) strcat(p, want);
  228. return p;
  229. }
  230. /*
  231. * Generate a `plain' (non-encoded) name from a given name.
  232. */
  233. static char * plainname P1((name), char *name)
  234. {
  235. return normalname(name, "", SUFFIX_TOASTED );
  236. }
  237. /*
  238. * Generate a `code' name from a given name.
  239. */
  240. static char * codename P1((name), char *name)
  241. {
  242. return normalname( name, SUFFIX_TOASTED, "" );
  243. }
  244. /*
  245. * If we're supposed to ask (fileno (stderr) is a tty, and f_force not
  246. * set), ask the user whether to overwrite a file or not.
  247. */
  248. static int ok_to_replace P1(( name ), char * name)
  249. {
  250. int reply, c;
  251. if (f_force) return 1; /* YES, do replace */
  252. if (!isatty(fileno(stderr))) return 0; /* NO, don't replace */
  253. fprintf(stderr,
  254. "%s already exists; do you wish to overwrite %s (y or n)? ",
  255. name, name);
  256. fflush(stderr);
  257. for (c = reply = getchar(); c != '\n' && c != EOF; c = getchar()) ;
  258. if (reply == 'y') return 1;
  259. fprintf(stderr, "\tnot overwritten\n");
  260. return 0;
  261. }
  262. static void update_mode P0()
  263. {
  264. if (!instat.st_nlink) return; /* couldn't stat in */
  265. #ifdef HAS_FCHMOD
  266. if (fchmod(fileno(out), instat.st_mode & 07777)) {
  267. perror(outname);
  268. fprintf(stderr, "%s: could not change file mode of \"%s\"\n",
  269. progname, outname);
  270. }
  271. #else
  272. #ifdef HAS_CHMOD
  273. if (outname && chmod(outname, instat.st_mode & 07777)) {
  274. perror(outname);
  275. fprintf(stderr, "%s: could not change file mode of \"%s\"\n",
  276. progname, outname);
  277. }
  278. #endif /* HAS_CHMOD */
  279. #endif /* HAS_FCHMOD */
  280. }
  281. static void update_own P0()
  282. {
  283. if (!instat.st_nlink) return; /* couldn't stat in */
  284. #ifdef HAS_FCHOWN
  285. (void)fchown(fileno(out), instat.st_uid, instat.st_gid);
  286. #else
  287. #ifdef HAS_CHOWN
  288. (void)chown(outname, instat.st_uid, instat.st_gid);
  289. #endif /* HAS_CHOWN */
  290. #endif /* HAS_FCHOWN */
  291. }
  292. static void update_times P0()
  293. {
  294. if (!instat.st_nlink) return; /* couldn't stat in */
  295. #ifdef HAS_UTIMES
  296. if (outname) {
  297. struct timeval tv[2];
  298. tv[0].tv_sec = instat.st_atime;
  299. tv[1].tv_sec = instat.st_mtime;
  300. tv[0].tv_usec = tv[1].tv_usec = 0;
  301. (void) utimes(outname, tv);
  302. }
  303. #else
  304. #ifdef HAS_UTIME
  305. if (outname) {
  306. #ifdef HAS_UTIMBUF
  307. struct utimbuf ut;
  308. ut.actime = instat.st_atime;
  309. ut.modtime = instat.st_mtime;
  310. # ifdef HAS_UTIMEUSEC
  311. ut.acusec = instat.st_ausec;
  312. ut.modusec = instat.st_musec;
  313. # endif /* HAS_UTIMEUSEC */
  314. (void) utime(outname, &ut);
  315. #else /* UTIMBUF */
  316. time_t ut[2];
  317. ut[0] = instat.st_atime;
  318. ut[1] = instat.st_mtime;
  319. (void) utime(outname, ut);
  320. #endif /* UTIMBUF */
  321. }
  322. #endif /* HAS_UTIME */
  323. #endif /* HAS_UTIMES */
  324. }
  325. static int okay_as_input P3((name,f,st), char* name, FILE* f, struct stat * st)
  326. {
  327. # ifdef HAS_FSTAT
  328. if (fstat(fileno(f), st) < 0)
  329. # else
  330. if (stat(name, st) < 0)
  331. # endif
  332. {
  333. perror(name);
  334. fprintf(stderr, "%s: cannot stat \"%s\"\n", progname, name);
  335. return 0;
  336. }
  337. if (!S_ISREG(st->st_mode)) {
  338. fprintf(stderr,
  339. "%s: \"%s\" is not a regular file -- unchanged.\n",
  340. progname, name);
  341. return 0;
  342. }
  343. if (st->st_nlink > 1 && !f_cat && !f_precious) {
  344. fprintf(stderr,
  345. "%s: \"%s\" has %s other link%s -- unchanged.\n",
  346. progname,name,st->st_nlink - 1,"s" + (st->st_nlink<=2));
  347. return 0;
  348. }
  349. return 1;
  350. }
  351. static void prepare_io P1(( desc), struct fmtdesc * desc)
  352. {
  353. output = desc->output;
  354. input = desc->input;
  355. init_input = desc->init_input;
  356. init_output = desc->init_output;
  357. }
  358. static struct fmtdesc * grok_format P1((name), char * name)
  359. {
  360. char * c;
  361. struct fmtdesc ** f;
  362. if (name) {
  363. c = plainname(name);
  364. for (f = alldescs; *f; f++) {
  365. if ( (*f)->suffix
  366. && *(*f)->suffix
  367. && suffix(c, (*f)->suffix)) {
  368. free(c);
  369. return *f;
  370. }
  371. }
  372. free(c);
  373. }
  374. return (struct fmtdesc *)0;
  375. }
  376. static int open_input P2((name, st), char * name, struct stat * st)
  377. {
  378. struct fmtdesc * f = f_format;
  379. st->st_nlink = 0; /* indicates `undefined' value */
  380. if (!name) {
  381. inname = (char *)NULL;
  382. in = stdin;
  383. #ifdef HAS__FSETMODE
  384. _fsetmode(in, "b");
  385. #endif
  386. }
  387. else {
  388. if (f_decode) inname = codename(name);
  389. else {
  390. if (!f_cat && suffix(name, SUFFIX_TOASTED)) {
  391. fprintf(stderr,
  392. "%s: %s already has \"%s\" suffix -- unchanged.\n",
  393. progname, name, SUFFIX_TOASTED );
  394. return 0;
  395. }
  396. inname = strcpy(emalloc(strlen(name)+1), name);
  397. }
  398. if (!(in = fopen(inname, READ))) {
  399. perror(inname); /* not guaranteed to be valid here */
  400. fprintf(stderr, "%s: cannot open \"%s\" for reading\n",
  401. progname, inname);
  402. return 0;
  403. }
  404. if (!okay_as_input(inname, in, st)) return 0;
  405. if (!f) f = grok_format(inname);
  406. }
  407. prepare_io( f ? f : & DEFAULT_FORMAT );
  408. return 1;
  409. }
  410. static int open_output P1((name), char *name)
  411. {
  412. if (!name || f_cat) {
  413. out = stdout;
  414. outname = (char *)NULL;
  415. #ifdef HAS__FSETMODE
  416. _fsetmode(out, "b");
  417. #endif
  418. }
  419. else {
  420. int outfd = -1;
  421. char * o;
  422. o = (*(f_decode ? plainname : codename))(name);
  423. if (!length_okay(o)) return 0;
  424. if ((outfd = open(o, O_WRITE_EXCL, 0666)) >= 0)
  425. out = fdopen(outfd, WRITE);
  426. else if (errno != EEXIST) out = (FILE *)NULL;
  427. else if (ok_to_replace(o)) out = fopen(o, WRITE);
  428. else return 0;
  429. if (!out) {
  430. perror(o);
  431. fprintf(stderr,
  432. "%s: can't open \"%s\" for writing\n",
  433. progname, o);
  434. if (outfd >= 0) (void)close(outfd);
  435. return 0;
  436. }
  437. outname = o;
  438. }
  439. return 1;
  440. }
  441. static int process_encode P0()
  442. {
  443. gsm r;
  444. gsm_signal s[ 160 ];
  445. gsm_frame d;
  446. int cc;
  447. if (!(r = gsm_create())) {
  448. perror(progname);
  449. return -1;
  450. }
  451. (void)gsm_option(r, GSM_OPT_FAST, &f_fast);
  452. (void)gsm_option(r, GSM_OPT_VERBOSE, &f_verbose);
  453. (void)gsm_option(r, GSM_OPT_LTP_CUT, &f_ltp_cut);
  454. while ((cc = (*input)(s)) > 0) {
  455. if (cc < sizeof(s) / sizeof(*s))
  456. memset((char *)(s+cc), 0, sizeof(s)-(cc * sizeof(*s)));
  457. gsm_encode(r, s, d);
  458. if (fwrite((char *)d, sizeof(d), 1, out) != 1) {
  459. perror(outname ? outname : "stdout");
  460. fprintf(stderr, "%s: error writing to %s\n",
  461. progname, outname ? outname : "stdout");
  462. gsm_destroy(r);
  463. return -1;
  464. }
  465. }
  466. if (cc < 0) {
  467. perror(inname ? inname : "stdin");
  468. fprintf(stderr, "%s: error reading from %s\n",
  469. progname, inname ? inname : "stdin");
  470. gsm_destroy(r);
  471. return -1;
  472. }
  473. gsm_destroy(r);
  474. return 0;
  475. }
  476. static int process_decode P0()
  477. {
  478. gsm r;
  479. gsm_frame s;
  480. gsm_signal d[ 160 ];
  481. int cc;
  482. if (!(r = gsm_create())) { /* malloc failed */
  483. perror(progname);
  484. return -1;
  485. }
  486. (void)gsm_option(r, GSM_OPT_FAST, &f_fast);
  487. (void)gsm_option(r, GSM_OPT_VERBOSE, &f_verbose);
  488. while ((cc = fread(s, 1, sizeof(s), in)) > 0) {
  489. if (cc != sizeof(s)) {
  490. if (cc >= 0) fprintf(stderr,
  491. "%s: incomplete frame (%d byte%s missing) from %s\n",
  492. progname, sizeof(s) - cc,
  493. "s" + (sizeof(s) - cc == 1),
  494. inname ? inname : "stdin" );
  495. gsm_destroy(r);
  496. errno = 0;
  497. return -1;
  498. }
  499. if (gsm_decode(r, s, d)) {
  500. fprintf(stderr, "%s: bad frame in %s\n",
  501. progname, inname ? inname : "stdin");
  502. gsm_destroy(r);
  503. errno = 0;
  504. return -1;
  505. }
  506. if ((*output)(d) < 0) {
  507. perror(outname);
  508. fprintf(stderr, "%s: error writing to %s\n",
  509. progname, outname);
  510. gsm_destroy(r);
  511. return -1;
  512. }
  513. }
  514. if (cc < 0) {
  515. perror(inname ? inname : "stdin" );
  516. fprintf(stderr, "%s: error reading from %s\n", progname,
  517. inname ? inname : "stdin");
  518. gsm_destroy(r);
  519. return -1;
  520. }
  521. gsm_destroy(r);
  522. return 0;
  523. }
  524. static int process P1((name), char * name)
  525. {
  526. int step = 0;
  527. out = (FILE *)0;
  528. in = (FILE *)0;
  529. outname = (char *)0;
  530. inname = (char *)0;
  531. if (!open_input(name, &instat) || !open_output(name))
  532. goto err;
  533. if ((*(f_decode ? init_output : init_input))()) {
  534. fprintf(stderr, "%s: error %s %s\n",
  535. progname,
  536. f_decode ? "writing header to" : "reading header from",
  537. f_decode ? (outname ? outname : "stdout")
  538. : (inname ? inname : "stdin"));
  539. goto err;
  540. }
  541. if ((*(f_decode ? process_decode : process_encode))())
  542. goto err;
  543. if (fflush(out) < 0 || ferror(out)) {
  544. perror(outname ? outname : "stdout");
  545. fprintf(stderr, "%s: error writing \"%s\"\n", progname,
  546. outname ? outname:"stdout");
  547. goto err;
  548. }
  549. if (out != stdout) {
  550. update_times();
  551. update_mode ();
  552. update_own ();
  553. if (fclose(out) < 0) {
  554. perror(outname);
  555. fprintf(stderr, "%s: error writing \"%s\"\n",
  556. progname, outname);
  557. goto err;
  558. }
  559. if (outname != name) free(outname);
  560. outname = (char *)0;
  561. }
  562. out = (FILE *)0;
  563. if (in != stdin) {
  564. (void)fclose(in), in = (FILE *)0;
  565. if (!f_cat && !f_precious) {
  566. if (unlink(inname) < 0) {
  567. perror(inname);
  568. fprintf(stderr,
  569. "%s: source \"%s\" not deleted.\n",
  570. progname, inname);
  571. }
  572. goto err;
  573. }
  574. if (inname != name) free(inname);
  575. inname = (char *)0;
  576. }
  577. return 0;
  578. /*
  579. * Error handling and cleanup.
  580. */
  581. err:
  582. if (out && out != stdout) {
  583. (void)fclose(out), out = (FILE *)0;
  584. if (unlink(outname) < 0 && errno != ENOENT && errno != EINTR) {
  585. perror(outname);
  586. fprintf(stderr, "%s: could not unlink \"%s\"\n",
  587. progname, outname);
  588. }
  589. }
  590. if (in && in != stdin) (void)fclose(in), in = (FILE *)0;
  591. if (inname && inname != name) free(inname);
  592. if (outname && outname != name) free(outname);
  593. return -1;
  594. }
  595. static void version P0()
  596. {
  597. printf( "%s 1.0, version %s\n",
  598. progname,
  599. "$Id: toast.c,v 1.8 1996/07/02 10:41:04 jutta Exp $" );
  600. }
  601. static void help P0()
  602. {
  603. printf("Usage: %s [-fcpdhvaulsFC] [files...]\n", progname);
  604. printf("\n");
  605. printf(" -f force Replace existing files without asking\n");
  606. printf(" -c cat Write to stdout, do not remove source files\n");
  607. printf(" -d decode Decode data (default is encode)\n");
  608. printf(" -p precious Do not delete the source\n");
  609. printf("\n");
  610. printf(" -u u-law Force 8 kHz/8 bit u-law in/output format\n");
  611. printf(" -s sun .au Force Sun .au u-law in/output format\n");
  612. printf(" -a A-law Force 8 kHz/8 bit A-law in/output format\n");
  613. printf(" -l linear Force 16 bit linear in/output format\n");
  614. printf("\n");
  615. printf(" -F fast Sacrifice conformance to performance\n");
  616. printf(" -C cutoff Ignore most samples during LTP\n");
  617. printf(" -v version Show version information\n");
  618. printf(" -h help Print this text\n");
  619. printf("\n");
  620. }
  621. static void set_format P1((f), struct fmtdesc * f)
  622. {
  623. if (f_format && f_format != f) {
  624. fprintf( stderr,
  625. "%s: only one of -[uals] is possible (%s -h for help)\n",
  626. progname, progname);
  627. exit(1);
  628. }
  629. f_format = f;
  630. }
  631. int main P2((ac, av), int ac, char **av)
  632. {
  633. int opt;
  634. extern int optind;
  635. extern char * optarg;
  636. parse_argv0(*av);
  637. while ((opt = getopt(ac, av, "fcdpvhuaslVFC:")) != EOF) switch (opt) {
  638. case 'd': f_decode = 1; break;
  639. case 'f': f_force = 1; break;
  640. case 'c': f_cat = 1; break;
  641. case 'p': f_precious = 1; break;
  642. case 'F': f_fast = 1; break;
  643. case 'C': f_ltp_cut = 100; break;
  644. #ifndef NDEBUG
  645. case 'V': f_verbose = 1; break; /* undocumented */
  646. #endif
  647. case 'u': set_format( &f_ulaw ); break;
  648. case 'l': set_format( &f_linear ); break;
  649. case 'a': set_format( &f_alaw ); break;
  650. case 's': set_format( &f_audio ); break;
  651. case 'v': version(); exit(0);
  652. case 'h': help(); exit(0);
  653. default:
  654. usage:
  655. fprintf(stderr,
  656. "Usage: %s [-fcpdhvuaslFC] [files...] (-h for help)\n",
  657. progname);
  658. exit(1);
  659. }
  660. f_precious |= f_cat;
  661. av += optind;
  662. ac -= optind;
  663. catch_signals(onintr);
  664. if (ac <= 0) process( (char *)0 );
  665. else while (ac--) process( *av++ );
  666. exit(0);
  667. }