cod2lin.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/cod2lin.c,v 1.2 1996/07/02 14:33:10 jutta Exp jutta $*/
  7. #include <stdio.h>
  8. #include <assert.h>
  9. #include "gsm.h"
  10. #include "proto.h"
  11. char * pname;
  12. int debug = 0;
  13. int verbosity = 0;
  14. int fast = 0;
  15. int wav = 0;
  16. int error = 0;
  17. usage P0()
  18. {
  19. fprintf(stderr, "Usage: %s [-vwF] [files...]\n", pname);
  20. exit(1);
  21. }
  22. void process P2((f, filename), FILE * f, char * filename)
  23. {
  24. gsm_frame buf;
  25. gsm_signal source[160];
  26. int cc;
  27. gsm r;
  28. (void)memset(source, 0x00, sizeof(source));
  29. if (!(r = gsm_create())) {
  30. perror("gsm_create");
  31. error = 1;
  32. return ;
  33. }
  34. gsm_option(r, GSM_OPT_VERBOSE, &verbosity);
  35. gsm_option(r, GSM_OPT_FAST, &fast);
  36. gsm_option(r, GSM_OPT_WAV49, &wav);
  37. for (;;) {
  38. cc = fread((char *)source, sizeof(*source), 76, f);
  39. if (cc == 0) {
  40. gsm_destroy(r);
  41. return;
  42. }
  43. if (cc != 76) {
  44. error = 1;
  45. fprintf(stderr,
  46. "%s: %s -- %d trailing bytes ignored\n",
  47. pname, filename, cc);
  48. gsm_destroy(r);
  49. return;
  50. }
  51. gsm_implode(r, source, buf);
  52. gsm_decode(r, buf, source);
  53. if (write(1, source, sizeof(source)) != sizeof(source)) {
  54. perror("write");
  55. error = 1;
  56. gsm_destroy(r);
  57. return;
  58. }
  59. }
  60. }
  61. main P2((ac, av), int ac, char ** av)
  62. {
  63. int opt;
  64. extern char * optarg;
  65. extern int optind;
  66. FILE * f;
  67. if (!(pname = av[0])) pname = "cod2out";
  68. while ((opt = getopt(ac, av, "vwF")) != EOF) switch (opt) {
  69. case 'v': verbosity++; break;
  70. case 'w': wav++; break;
  71. case 'F': fast++; break;
  72. default: usage();
  73. }
  74. ac -= optind;
  75. av += optind;
  76. if (!ac) process(stdin, "*stdin*");
  77. else for (; *av; av++) {
  78. if (!(f = fopen(*av, "r"))) perror(*av);
  79. else {
  80. process(f, *av);
  81. fclose(f);
  82. }
  83. }
  84. exit(error);
  85. }