annotate miscutil/fc-fr2tch.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents 7eaa3307e5df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility converts a GSM 06.10 speech recording from the format that is
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * commonly accepted as standard in the Unix/Linux world (libgsm format) into
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * hex strings of TCH bits to be fed to the GSM 05.03 channel encoder by way
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * of a TI Calypso GSM device, a FreeCalypso GSM firmware version with the
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * TCH rerouting feature, and fc-shell's tch play command.
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 */
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/types.h>
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 main(argc, argv)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *inf, *outf;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char libgsm_bytes[33], tidsp_bytes[33];
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int cc, i, gotsome = 0;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (argc != 3) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 inf = fopen(argv[1], "r");
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (!inf) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 perror(argv[1]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 outf = fopen(argv[2], "w");
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (!outf) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 perror(argv[2]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (;;) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cc = fread(libgsm_bytes, 1, 33, inf);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (cc < 33)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 break;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if ((libgsm_bytes[0] & 0xF0) != 0xD0) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 invalid: fprintf(stderr, "error: %s is not in libgsm format\n",
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 argv[1]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 gsm0610_libgsm_to_tidsp(libgsm_bytes, tidsp_bytes);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (i = 0; i < 33; i++)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(outf, "%02X", tidsp_bytes[i]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 putc('\n', outf);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 gotsome = 1;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fclose(outf);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (cc) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (gotsome)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(stderr,
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 "warning: extra non-33 bytes at the end of %s\n",
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 argv[1]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 else
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 goto invalid;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(0);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }