• 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/cod2txt.c,v 1.1 1994/10/21 20:52:11 jutta Exp $*/
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	error      = 0;
20 
P0()21 usage P0()
22 {
23 	fprintf(stderr, "Usage: %s [files...]\n", pname);
24 	exit(1);
25 }
26 
27 void process P2((f, filename), FILE * f, char * filename)
28 {
29 	gsm_frame	buf;
30 	gsm_signal	source[160];
31 
32 	int		cc;
33 	gsm		r;
34 	int		nr=0;
35 
36 	(void)memset(source, 0, sizeof(source));
37 
38 	if (!(r = gsm_create())) {
39 		perror("gsm_create");
40 		error = 1;
41 		return ;
42 	}
43 	gsm_option(r, GSM_OPT_VERBOSE, &verbosity);
44 	for (;;) {
45 		cc = fread((char *)source, sizeof(*source), 76, f);
46 		if (cc == 0) {
47 			gsm_destroy(r);
48 			return;
49 		}
50 		if (cc != 76) {
51 			error = 1;
52 			fprintf(stderr,
53 				"%s: %s -- %d trailing bytes ignored\n",
54 				pname, filename, cc);
55 			gsm_destroy(r);
56 			return;
57 		}
58 
59 		gsm_implode(r, source, buf);
60 		printf("[%d] ", ++nr);
61 		if (gsm_print(stdout, r, buf)) {
62 			fprintf(stderr,
63 				"%s: %s: bad magic\n", pname, filename);
64 			gsm_destroy(r);
65 			return;
66 
67 		}
68 	}
69 }
70 
71 main P2((ac, av), int ac, char ** av)
72 {
73 	int 		opt;
74 	extern char   * optarg;
75 	extern int	optind;
76 
77 	FILE		* f;
78 
79 	if (!(pname = av[0])) pname = "cod2txt";
80 
81 	ac--;
82 	av++;
83 
84 	if (!ac) process(stdin, "*stdin*");
85 	else for (; *av; av++) {
86 		if (!(f = fopen(*av, "r"))) perror(*av);
87 		else {
88 			process(f, *av);
89 			fclose(f);
90 		}
91 	}
92 
93 	exit(error);
94 }
95