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