• 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/lin2txt.c,v 1.1 1994/10/21 20:52:11 jutta Exp $*/
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	error      = 0;
19 
P0()20 usage P0()
21 {
22 	fprintf(stderr, "Usage: %s [-v] [files...]\n", pname);
23 	exit(1);
24 }
25 
26 void process P2((f, filename), FILE * f, char * filename)
27 {
28 	short		source[160];
29 	int		cc, j, k;
30 	gsm		r;
31 
32 	if (!(r = gsm_create())) {
33 		perror("gsm_create");
34 		error = 1;
35 		return ;
36 	}
37 	gsm_option(r, GSM_OPT_VERBOSE, &verbosity);
38 	for (;;) {
39 
40 		if ((cc = fread((char *)source, 1, sizeof(source), f)) == 0) {
41 			gsm_destroy(r);
42 #ifdef	COUNT_OVERFLOW
43 			dump_overflow(stderr);
44 #endif
45 			return;
46 		}
47 
48 		printf("{\t");
49 		for (j = 0; j < 4; j++) {
50 			printf("{\t");
51 			for (k = 0; k < 40; k++) {
52 				printf("%d", (int)source[ j * 40 + k ]);
53 				if (k < 39) {
54 					printf(", ");
55 					if (k % 4 == 3) printf("\n\t\t");
56 				} else {
57 					printf("\t}");
58 					if (j == 3) printf("\t},\n");
59 					else printf(",\n\t");
60 				}
61 			}
62 		}
63 	}
64 }
65 
66 main P2((ac, av), int ac, char ** av)
67 {
68 	int 		opt;
69 	extern char   * optarg;
70 	extern int	optind;
71 
72 	FILE		* f;
73 
74 	if (!(pname = av[0])) pname = "inp2txt";
75 
76 	while ((opt = getopt(ac, av, "v")) != EOF) switch (opt) {
77 	case 'v': verbosity++;    break;
78 	default:  usage();
79 	}
80 
81 	ac -= optind;
82 	av += optind;
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