~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/third_party/gsm/add-test/add_test.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/add_test.c,v 1.2 1994/05/10 20:18:17 jutta Exp $ */
8
 
 
9
 
#include <stdio.h>
10
 
#include <stdlib.h>
11
 
#include <string.h>
12
 
 
13
 
#include "gsm.h"
14
 
 
15
 
#include "../src/add.c"
16
 
 
17
 
int             interactive = 1;
18
 
 
19
 
char            * opname;
20
 
longword        L_op1, L_op2, L_expect;
21
 
word            op1, op2, expect;
22
 
int             do_expect;
23
 
 
24
 
word M_gsm_add P((word op1, word op2));
25
 
word M_gsm_sub P((word op1, word op2));
26
 
word M_gsm_mult P((word op1, word op2));
27
 
word M_gsm_mult_r P((word op1, word op2));
28
 
word M_gsm_abs P((word op1));
29
 
longword M_gsm_L_mult P((word op1, word op2));
30
 
longword M_gsm_L_add P((longword op1, longword op2));
31
 
 
32
 
help()
33
 
{
34
 
puts( "  add a b      sub a b     mult a b   div    a b" );
35
 
puts( "L_add A B    L_sub A B   L_mult A B   mult_r a b" );
36
 
puts( "" );
37
 
puts( "abs   a      norm  a        >> a b      << a b" );
38
 
puts( "                          L_>> A B    L_<< A B" );
39
 
 
40
 
}
41
 
 
42
 
char * strtek P2((str, sep), char * str, char * sep) {
43
 
 
44
 
        static char     * S = (char *)0;
45
 
        char            * c, * base;
46
 
 
47
 
        if (str) S = str;
48
 
 
49
 
        if (!S || !*S) return (char *)0;
50
 
 
51
 
        /*  Skip delimiters.
52
 
         */
53
 
        while (*S) {
54
 
                for (c = sep; *c && *c != *S; c++) ;
55
 
                if (*c) *S++ = 0;
56
 
                else break;
57
 
        }
58
 
 
59
 
        base = S;
60
 
 
61
 
        /*   Skip non-delimiters.
62
 
         */
63
 
        for (base = S; *S; S++) {
64
 
 
65
 
                for (c = sep; *c; c++)
66
 
                        if (*c == *S) {
67
 
                                *S++ = 0;
68
 
                                return base;
69
 
                        }
70
 
        }
71
 
 
72
 
        return base == S ? (char *)0 : base;
73
 
}
74
 
 
75
 
long value P1((s), char * s)
76
 
{
77
 
        switch (*s) {
78
 
        case '-': switch (s[1]) {
79
 
                  case '\0': return MIN_WORD;
80
 
                  case '-':  return MIN_LONGWORD;
81
 
                  default:   break;
82
 
                  }
83
 
                  break;
84
 
 
85
 
        case '+': switch (s[1]) {
86
 
                  case '\0': return MAX_WORD;
87
 
                  case '+':  return MAX_LONGWORD;
88
 
                  default:   break;
89
 
                  }
90
 
        default:  break;
91
 
        }
92
 
 
93
 
        return strtol(s, (char **)0, 0);
94
 
}
95
 
 
96
 
char * parse P1((buf), char * buf)
97
 
{
98
 
        char  * s, * a;
99
 
        long    l;
100
 
 
101
 
        if (a = strchr(buf, '=')) *a++ = 0;
102
 
 
103
 
        opname = s = strtek(buf, " \t(");
104
 
        if (!s) return (char *)0;
105
 
 
106
 
        op1 = op2 = L_op1 = L_op2 = 0;
107
 
 
108
 
        if (s = strtek( (char *)0, "( \t,")) {
109
 
                op1 = L_op1 = value(s);
110
 
                if (s = strtek( (char *)0, ", \t)")) op2 = L_op2 = value(s);
111
 
        }
112
 
 
113
 
        if (a) {
114
 
                do_expect = 1;
115
 
                while (*a == ' ' || *a == '\t') a++;
116
 
                expect = L_expect = value(a);
117
 
        }
118
 
 
119
 
        return opname;
120
 
}
121
 
 
122
 
void fprint_word P2((f, w), FILE * f,  word w)
123
 
{
124
 
        if (!w) putc('0', f);
125
 
        else fprintf(f, "0x%4.4x (%d%s)",
126
 
                (unsigned int)w,
127
 
                (int)w,
128
 
                w == MIN_WORD? "/-" : (w == MAX_WORD ? "/+" : ""));
129
 
}
130
 
 
131
 
void print_word P1((w), word w)
132
 
{
133
 
        fprint_word( stdout, w );
134
 
}
135
 
 
136
 
void fprint_longword P2((f, w), FILE * f, longword w)
137
 
{
138
 
        if (!w) putc('0', f);
139
 
        else fprintf(f, "0x%8.8x (%ld%s)",
140
 
                w, w, w == MIN_WORD ? "/-"
141
 
                : (w == MAX_WORD ? "/+"
142
 
                : (w == MIN_LONGWORD ? "/--"
143
 
                : (w == MAX_LONGWORD ? "/++" : ""))));
144
 
}
145
 
 
146
 
void print_longword P1((w),longword w)
147
 
{
148
 
        fprint_longword(stdout, w);
149
 
}
150
 
 
151
 
void do_longword P1((w), longword w)
152
 
{
153
 
        if (interactive) print_longword(w);
154
 
        if (do_expect) {
155
 
                if (w != L_expect) {
156
 
                        if (!interactive) fprint_longword(stderr, w);
157
 
                        fprintf(stderr, " != %s (%ld, %ld) -- expected ",
158
 
                                opname, L_op1, L_op2 );
159
 
                        fprint_longword(stderr, L_expect);
160
 
                        putc( '\n', stderr );
161
 
                }
162
 
        } else if (interactive) putchar('\n');
163
 
}
164
 
 
165
 
void do_word P1((w), word w )
166
 
{
167
 
        if (interactive) print_word(w);
168
 
        if (do_expect) {
169
 
                if (w != expect) {
170
 
                        if (!interactive) fprint_word(stderr, w);
171
 
                        fprintf(stderr, " != %s (%ld, %ld) -- expected ",
172
 
                                opname, L_op1, L_op2 );
173
 
                        fprint_word(stderr, expect);
174
 
                        putc('\n', stderr);
175
 
                }
176
 
        } else if (interactive) putchar('\n');
177
 
}
178
 
 
179
 
int main(ac, av) char ** av;
180
 
{
181
 
        char    buf[299];
182
 
        char    * c;
183
 
        FILE    * in;
184
 
 
185
 
        if (ac > 2) {
186
 
                fprintf(stderr, "Usage: %s [filename]\n", av[0]);
187
 
fail:
188
 
#ifdef EXIT_FAILURE
189
 
                exit(EXIT_FAILURE);
190
 
#else
191
 
                exit(1);
192
 
#endif
193
 
        }
194
 
        if (ac < 2) in = stdin;
195
 
        else if (!(in = fopen(av[1], "r"))) {
196
 
                perror(av[1]);
197
 
                fprintf(stderr, "%s: cannot open file \"%s\" for reading\n",
198
 
                        av[0], av[1]);
199
 
                goto fail;
200
 
        }
201
 
 
202
 
        interactive = isatty(fileno(in));
203
 
 
204
 
        for (;;) {
205
 
                if (interactive) fprintf(stderr, "? ");
206
 
 
207
 
                if (!fgets(buf, sizeof(buf), in)) exit(0);
208
 
                if (c = strchr(buf, '\n')) *c = 0;
209
 
 
210
 
                if (*buf == ';' || *buf == '#') continue;
211
 
                if (*buf == '\'') {
212
 
                        puts(buf + 1);
213
 
                        continue;
214
 
                }
215
 
                if (*buf == '\"') {
216
 
                        fprintf(stderr,  "%s\n", buf + 1);
217
 
                        continue;
218
 
                }
219
 
 
220
 
                c = parse(buf);
221
 
 
222
 
                if (!c) continue;
223
 
                if (!strcmp(c,   "add")) {
224
 
                        do_word(    gsm_add( op1, op2 ));
225
 
                        continue;
226
 
                }
227
 
                if (!strcmp(c,   "M_add")) {
228
 
                        do_word(    M_gsm_add( op1, op2 ));
229
 
                        continue;
230
 
                }
231
 
                if (!strcmp(c, "sub")) {
232
 
                        do_word(    gsm_sub( op1, op2 ));
233
 
                        continue;
234
 
                }
235
 
                if (!strcmp(c, "M_sub")) {
236
 
                        do_word(    M_gsm_sub( op1, op2 ));
237
 
                        continue;
238
 
                }
239
 
                if (!strcmp(c, "mult")) {
240
 
                        do_word(    gsm_mult( op1, op2 ));
241
 
                        continue;
242
 
                }
243
 
                if (!strcmp(c, "M_mult")) {
244
 
                        do_word(    M_gsm_mult( op1, op2 ));
245
 
                        continue;
246
 
                }
247
 
                if (!strcmp(c, "mult_r")) {
248
 
                        do_word(    gsm_mult_r(op1, op2));
249
 
                        continue;
250
 
                }
251
 
                if (!strcmp(c, "M_mult_r")) {
252
 
                        do_word(    M_gsm_mult_r(op1, op2));
253
 
                        continue;
254
 
                }
255
 
                if (!strcmp(c, "abs" )) {
256
 
                        do_word(    gsm_abs(op1) );
257
 
                        continue;
258
 
                }
259
 
                if (!strcmp(c, "M_abs" )) {
260
 
                        do_word(    M_gsm_abs(op1) );
261
 
                        continue;
262
 
                }
263
 
                if (!strcmp(c, "div" )) {
264
 
                        do_word(    gsm_div( op1, op2 ));
265
 
                        continue;
266
 
                }
267
 
                if (!strcmp(c,  "norm" )) {
268
 
                        do_word(        gsm_norm(L_op1));
269
 
                        continue;
270
 
                }
271
 
                if (!strcmp(c,  "<<" )) {
272
 
                        do_word(    gsm_asl( op1, op2));
273
 
                        continue;
274
 
                }
275
 
                if (!strcmp(c,  ">>" )) {
276
 
                        do_word(    gsm_asr( op1, op2 ));
277
 
                        continue;
278
 
                }
279
 
                if (!strcmp(c,  "L_mult")) {
280
 
                        do_longword( gsm_L_mult( op1, op2 ));
281
 
                        continue;
282
 
                }
283
 
                if (!strcmp(c,  "M_L_mult")) {
284
 
                        do_longword( M_gsm_L_mult( op1, op2 ));
285
 
                        continue;
286
 
                }
287
 
                if (!strcmp(c,  "L_add" )) {
288
 
                        do_longword( gsm_L_add( L_op1, L_op2 ));
289
 
                        continue;
290
 
                }
291
 
                if (!strcmp(c,  "M_L_add" )) {
292
 
                        do_longword( M_gsm_L_add( L_op1, L_op2 ));
293
 
                        continue;
294
 
                }
295
 
                if (!strcmp(c,  "L_sub" )) {
296
 
                        do_longword( gsm_L_sub( L_op1, L_op2 ));
297
 
                        continue;
298
 
                }
299
 
                if (!strcmp(c,  "L_<<" )) {
300
 
                        do_longword(    gsm_L_asl( L_op1, L_op2 ));
301
 
                        continue;
302
 
                }
303
 
                if (!strcmp(c,  "L_>>")) {
304
 
                        do_longword(    gsm_L_asr( L_op1, L_op2 ));
305
 
                        continue;
306
 
                }
307
 
                help();
308
 
        }
309
 
}
310
 
 
311
 
#include "private.h"
312
 
 
313
 
/*
314
 
 * Function stubs for macro implementations of commonly used
315
 
 * math functions
316
 
 */
317
 
word M_gsm_add P2((op1, op2),word op1, word op2)
318
 
{
319
 
        longword ltmp;
320
 
        return GSM_ADD(op1, op2);
321
 
}
322
 
 
323
 
word M_gsm_sub P2((op1, op2), word op1, word op2)
324
 
{
325
 
        longword ltmp;
326
 
        return GSM_SUB(op1, op2);
327
 
}
328
 
 
329
 
word M_gsm_mult P2((op1, op2), word op1, word op2)
330
 
{
331
 
        return GSM_MULT(op1, op2);
332
 
}
333
 
 
334
 
word M_gsm_mult_r P2((op1, op2), word op1, word op2)
335
 
{
336
 
        return GSM_MULT_R(op1, op2);
337
 
}
338
 
 
339
 
word M_gsm_abs P1((op1), word op1)
340
 
{
341
 
        return GSM_ABS(op1);
342
 
}
343
 
 
344
 
longword M_gsm_L_mult P2((op1, op2), word op1, word op2)
345
 
{
346
 
        return GSM_L_MULT(op1, op2);
347
 
}
348
 
 
349
 
longword M_gsm_L_add P2((op1, op2), longword op1, longword op2)
350
 
{
351
 
        ulongword utmp;
352
 
        return GSM_L_ADD(op1, op2);
353
 
}