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