lin2cod.c 2.0 KB

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