-
Notifications
You must be signed in to change notification settings - Fork 25
/
fft_eval_sdl.c
741 lines (619 loc) · 18.7 KB
/
fft_eval_sdl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/* SPDX-License-Identifier: GPL-2.0-only
* SPDX-FileCopyrightText: 2012 Simon Wunderlich <[email protected]>
* SPDX-FileCopyrightText: 2012 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
* SPDX-FileCopyrightText: 2013 Gui Iribarren <[email protected]>
* SPDX-FileCopyrightText: 2017 Nico Pace <[email protected]>
*/
/*
* This program has been created to aid open source spectrum
* analyzer development for Qualcomm/Atheros AR92xx and AR93xx
* based chipsets.
*/
#include <errno.h>
#include <stdio.h>
#include <math.h>
#ifndef __NOSDL__
#include <SDL.h>
#include <SDL_ttf.h>
#endif
#include <inttypes.h>
#include <unistd.h>
#include "fft_eval.h"
#define WIDTH 1600
#define HEIGHT 650
#define BPP 32
#define X_SCALE 10
#define Y_SCALE 4
#define RMASK 0x000000ff
#define RBITS 0
#define GMASK 0x0000ff00
#define GBITS 8
#define BMASK 0x00ff0000
#define BBITS 16
#define AMASK 0xff000000
static SDL_Renderer *renderer = NULL;
static TTF_Font *font = NULL;
static int color_invert = 0;
static int graphics_init_sdl(char *name, const char *fontdir)
{
SDL_Window *window;
int SDLFlags = 0;
char buf[1024];
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
fprintf(stderr, "Initializing SDL failed\n");
return -1;
}
SDLFlags |= SDL_WINDOW_RESIZABLE;
window = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT,
SDLFlags);
if (!window) {
fprintf(stderr, "Initializing SDL window failed\n");
return -1;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
fprintf(stderr, "Initializing SDL renderer failed\n");
return -1;
}
if (TTF_Init() < 0) {
fprintf(stderr, "Initializing SDL TTF failed\n");
return -1;
}
snprintf(buf, sizeof(buf), "%s/LiberationSans-Regular.ttf", fontdir);
font = TTF_OpenFont(buf, 14);
if (!font) {
fprintf(stderr, "Opening font (%s) failed: %s\n",
buf,
strerror(errno));
return -1;
}
return 0;
}
static void graphics_quit_sdl(void)
{
if (font) {
TTF_CloseFont(font);
font = NULL;
}
TTF_Quit();
SDL_Quit();
}
#define SIZE 3
/* this function blends a 2*SIZE x 2*SIZE blob at the given position with
* the defined opacity. */
static int bigpixel(Uint32 *pixels, int x, int y, Uint32 color, uint8_t opacity)
{
int x1, y1;
if (x - SIZE < 0 || x + SIZE >= WIDTH)
return -1;
if (y - SIZE < 0 || y + SIZE >= HEIGHT)
return -1;
if (color_invert)
color ^= RMASK | GMASK | BMASK;
for (x1 = x - SIZE; x1 < x + SIZE; x1++)
for (y1 = y - SIZE; y1 < y + SIZE; y1++) {
int r, g, b;
if (color_invert) {
r = ((pixels[x1 + y1 * WIDTH] & RMASK) >> RBITS) - ((((color & RMASK) >> RBITS) * opacity) / 255);
if (r < 0) r = 0;
g = ((pixels[x1 + y1 * WIDTH] & GMASK) >> GBITS) - ((((color & GMASK) >> GBITS) * opacity) / 255);
if (g < 0) g = 0;
b = ((pixels[x1 + y1 * WIDTH] & BMASK) >> BBITS) - ((((color & BMASK) >> BBITS) * opacity) / 255);
if (b < 0) b = 0;
} else {
r = ((pixels[x1 + y1 * WIDTH] & RMASK) >> RBITS) + ((((color & RMASK) >> RBITS) * opacity) / 255);
if (r > 255) r = 255;
g = ((pixels[x1 + y1 * WIDTH] & GMASK) >> GBITS) + ((((color & GMASK) >> GBITS) * opacity) / 255);
if (g > 255) g = 255;
b = ((pixels[x1 + y1 * WIDTH] & BMASK) >> BBITS) + ((((color & BMASK) >> BBITS) * opacity) / 255);
if (b > 255) b = 255;
}
pixels[x1 + y1 * WIDTH] = r << RBITS | g << GBITS | b << BBITS | (color & AMASK);
}
return 0;
}
static int render_text(SDL_Surface *surface, char *text, int x, int y)
{
SDL_Surface *text_surface;
SDL_Color fontcolor_white = {255, 255, 255, 255};
SDL_Color fontcolor_black = {0, 0, 0, 255};
SDL_Color fontcolor;
SDL_Rect fontdest = {0, 0, 0, 0};
fontdest.x = x;
fontdest.y = y;
if (color_invert) {
fontcolor = fontcolor_black;
} else {
fontcolor = fontcolor_white;
}
text_surface = TTF_RenderText_Solid(font, text, fontcolor);
if (!text_surface)
return -1;
SDL_BlitSurface(text_surface, NULL, surface, &fontdest);
SDL_FreeSurface(text_surface);
return 0;
}
static int plot_datapoint(Uint32 *pixels, float freq, float startfreq,
int noise, int rssi, int data, int datasquaresum,
int highlight)
{
Uint32 color, opacity;
int x, y;
float signal;
/* This is where the "magic" happens: interpret the signal
* to output some kind of data which looks useful. */
x = (X_SCALE * (freq - startfreq));
if (data == 0)
data = 1;
signal = noise + rssi + 20 * log10f(data) - log10f(datasquaresum) * 10;
y = 400 - (400.0 + Y_SCALE * signal);
if (highlight) {
color = RMASK | AMASK;
opacity = 255;
} else {
color = BMASK | AMASK;
opacity = 30;
}
if (bigpixel(pixels, x, y, color, opacity) < 0)
return -1;
return 0;
}
static int draw_sample_ht20(Uint32 *pixels, struct scanresult *result,
float startfreq, int highlight)
{
int datamax = 0, datamin = 65536;
int datasquaresum = 0;
int i;
for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) {
int data;
data = (result->sample.ht20.data[i] << result->sample.ht20.max_exp);
data *= data;
datasquaresum += data;
if (data > datamax) datamax = data;
if (data < datamin) datamin = data;
}
if (highlight) {
/* prints some statistical data about the currently selected
* data sample and auxiliary data. */
printf("result: freq %04d rssi %03d, noise %03d, max_magnitude %04d max_index %03d bitmap_weight %03d tsf %"PRIu64" | ",
result->sample.ht20.freq, result->sample.ht20.rssi, result->sample.ht20.noise,
result->sample.ht20.max_magnitude, result->sample.ht20.max_index, result->sample.ht20.bitmap_weight,
result->sample.ht20.tsf);
printf("datamax = %d, datamin = %d, datasquaresum = %d\n", datamax, datamin, datasquaresum);
}
for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) {
float freq;
int data;
/*
* According to Dave Aragon from University of Washington,
* formerly Trapeze/Juniper Networks, in 2.4 GHz it should
* divide 22 MHz channel width into 64 subcarriers but
* only report the middle 56 subcarriers.
*
* For 5 GHz we do not know (Atheros claims it does not support
* this frequency band, but it works).
*
* Since all these calculations map pretty much to -10/+10 MHz,
* and we don't know better, use this assumption as well in 5 GHz.
*/
freq = result->sample.ht20.freq -
(22.0 * SPECTRAL_HT20_NUM_BINS / 64.0) / 2 +
(22.0 * (i + 0.5) / 64.0);
data = result->sample.ht20.data[i] << result->sample.ht20.max_exp;
plot_datapoint(pixels, freq, startfreq, result->sample.ht20.noise,
result->sample.ht20.rssi, data, datasquaresum,
highlight);
}
return 0;
}
static int draw_sample_ht20_40(Uint32 *pixels, struct scanresult *result,
float startfreq, int highlight)
{
int datamax = 0, datamin = 65536;
int datasquaresum_lower = 0;
int datasquaresum_upper = 0;
int datasquaresum;
int i;
int centerfreq;
s8 noise;
s8 rssi;
for (i = 0; i < SPECTRAL_HT20_40_NUM_BINS / 2; i++) {
int data;
data = result->sample.ht40.data[i];
data <<= result->sample.ht40.max_exp;
data *= data;
datasquaresum_lower += data;
if (data > datamax) datamax = data;
if (data < datamin) datamin = data;
}
for (i = SPECTRAL_HT20_40_NUM_BINS / 2; i < SPECTRAL_HT20_40_NUM_BINS; i++) {
int data;
data = result->sample.ht40.data[i];
data <<= result->sample.ht40.max_exp;
datasquaresum_upper += data;
if (data > datamax) datamax = data;
if (data < datamin) datamin = data;
}
switch (result->sample.ht40.channel_type) {
case NL80211_CHAN_HT40PLUS:
centerfreq = result->sample.ht40.freq + 10;
break;
case NL80211_CHAN_HT40MINUS:
centerfreq = result->sample.ht40.freq - 10;
break;
default:
return -1;
}
if (highlight) {
/* prints some statistical data about the currently selected
* data sample and auxiliary data. */
printf("result: freq %04d lower_rssi %03d, upper_rssi %03d, lower_noise %03d, upper_noise %03d, lower_max_magnitude %04d upper_max_magnitude %04d lower_max_index %03d upper_max_index %03d lower_bitmap_weight %03d upper_bitmap_weight %03d tsf %"PRIu64" | ",
result->sample.ht40.freq, result->sample.ht40.lower_rssi,
result->sample.ht40.upper_rssi,
result->sample.ht40.lower_noise,
result->sample.ht40.upper_noise,
result->sample.ht40.lower_max_magnitude,
result->sample.ht40.upper_max_magnitude,
result->sample.ht40.lower_max_index,
result->sample.ht40.upper_max_index,
result->sample.ht40.lower_bitmap_weight,
result->sample.ht40.upper_bitmap_weight,
result->sample.ht40.tsf);
printf("datamax = %d, datamin = %d, datasquaresum_lower = %d\n",
datamax, datamin, datasquaresum_lower);
printf("datamax = %d, datamin = %d, datasquaresum_upper = %d\n",
datamax, datamin, datasquaresum_upper);
}
for (i = 0; i < SPECTRAL_HT20_40_NUM_BINS; i++) {
float freq;
int data;
freq = centerfreq -
(40.0 * SPECTRAL_HT20_40_NUM_BINS / 128.0) / 2 +
(40.0 * (i + 0.5) / 128.0);
if (i < SPECTRAL_HT20_40_NUM_BINS / 2) {
noise = result->sample.ht40.lower_noise;
datasquaresum = datasquaresum_lower;
rssi = result->sample.ht40.lower_rssi;
} else {
noise = result->sample.ht40.upper_noise;
datasquaresum = datasquaresum_upper;
rssi = result->sample.ht40.upper_rssi;
}
data = result->sample.ht40.data[i];
data <<= result->sample.ht40.max_exp;
plot_datapoint(pixels, freq, startfreq, noise, rssi, data,
datasquaresum, highlight);
}
return 0;
}
static int draw_sample_ath10k(Uint32 *pixels, struct scanresult *result,
float startfreq, int highlight)
{
int datamax = 0, datamin = 65536;
int datasquaresum = 0;
int i, bins;
bins = result->sample.tlv.length -
(sizeof(result->sample.ath10k.header) -
sizeof(result->sample.ath10k.header.tlv));
for (i = 0; i < bins; i++) {
int data;
data = (result->sample.ath10k.data[i] << result->sample.ath10k.header.max_exp);
data *= data;
datasquaresum += data;
if (data > datamax) datamax = data;
if (data < datamin) datamin = data;
}
if (highlight) {
/* prints some statistical data about the currently selected
* data sample and auxiliary data. */
printf("result: freq %04d/%04d (width %d MHz), %d bins, rssi %03d, noise %03d, max_magnitude %04d max_index %03d tsf %"PRIu64" | ",
result->sample.ath10k.header.freq1, result->sample.ath10k.header.freq1,
result->sample.ath10k.header.chan_width_mhz,
bins, result->sample.ath10k.header.rssi,
result->sample.ath10k.header.noise, result->sample.ath10k.header.max_magnitude,
result->sample.ath10k.header.max_index, result->sample.ath10k.header.tsf);
printf("datamax = %d, datamin = %d, datasquaresum = %d\n", datamax, datamin, datasquaresum);
}
for (i = 0; i < bins; i++) {
float freq;
int data;
freq = result->sample.ath10k.header.freq1 -
(result->sample.ath10k.header.chan_width_mhz ) / 2 +
(result->sample.ath10k.header.chan_width_mhz * (i + 0.5) / bins);
data = result->sample.ath10k.data[i] << result->sample.ath10k.header.max_exp;
plot_datapoint(pixels, freq, startfreq, result->sample.ath10k.header.noise,
result->sample.ath10k.header.rssi, data, datasquaresum,
highlight);
}
return 0;
}
static int draw_sample_ath11k(Uint32 *pixels, struct scanresult *result,
float startfreq, int highlight)
{
int datamax = 0, datamin = 65536;
int datasquaresum = 0;
int i, bins;
bins = result->sample.tlv.length -
(sizeof(result->sample.ath11k.header) -
sizeof(result->sample.ath11k.header.tlv));
for (i = 0; i < bins; i++) {
int data;
data = (result->sample.ath11k.data[i] << result->sample.ath11k.header.max_exp);
data *= data;
datasquaresum += data;
if (data > datamax) datamax = data;
if (data < datamin) datamin = data;
}
if (highlight) {
/* prints some statistical data about the currently selected
* data sample and auxiliary data. */
printf("result: freq %04d/%04d (width %d MHz), %d bins, rssi %04d, noise %04d, max_magnitude %04d max_index %03d max_exp %03d tsf %08d | ",
result->sample.ath11k.header.freq1, result->sample.ath11k.header.freq1,
result->sample.ath11k.header.chan_width_mhz,
bins, result->sample.ath11k.header.rssi,
result->sample.ath11k.header.noise, result->sample.ath11k.header.max_magnitude,
result->sample.ath11k.header.max_index, result->sample.ath11k.header.max_exp,
result->sample.ath11k.header.tsf);
printf("datamax = %d, datamin = %d, datasquaresum = %d\n", datamax, datamin, datasquaresum);
}
for (i = 0; i < bins; i++) {
float freq;
int data;
freq = result->sample.ath11k.header.freq1 -
(result->sample.ath11k.header.chan_width_mhz ) / 2 +
(result->sample.ath11k.header.chan_width_mhz * (i + 0.5) / bins);
data = result->sample.ath11k.data[i] << result->sample.ath11k.header.max_exp;
plot_datapoint(pixels, freq, startfreq, result->sample.ath11k.header.noise,
result->sample.ath11k.header.rssi, data, datasquaresum,
highlight);
}
return 0;
}
/*
* draw_picture - draws the current screen.
*
* @highlight: the index of the dataset to be highlighted
*
* returns the center frequency of the currently highlighted dataset
*/
static int draw_picture(int highlight, int startfreq)
{
Uint32 *pixels;
int x, y, i, rnum;
int highlight_freq = startfreq + 20;
char text[1024];
struct scanresult *result;
SDL_Surface *surface;
SDL_Rect DestR;
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, WIDTH, HEIGHT, BPP, RMASK, GMASK, BMASK, AMASK);
pixels = (Uint32 *) surface->pixels;
for (y = 0; y < HEIGHT; y++)
for (x = 0; x < WIDTH; x++) {
if (color_invert)
pixels[x + y * WIDTH] = RMASK | GMASK | BMASK | AMASK;
else
pixels[x + y * WIDTH] = AMASK;
}
/* vertical lines (frequency) */
for (i = 2300; i < 6000; i += 10) {
x = (X_SCALE * (i - startfreq));
if (x < 0 || x > WIDTH)
continue;
for (y = 0; y < HEIGHT - 20; y++)
pixels[x + y * WIDTH] = 0x40404040 | AMASK;
snprintf(text, sizeof(text), "%d MHz", i);
render_text(surface, text, x - 30, HEIGHT - 20);
}
/* horizontal lines (dBm) */
for (i = 0; i < 150; i += 10) {
y = 600 - Y_SCALE * i;
for (x = 0; x < WIDTH; x++)
pixels[x + y * WIDTH] = 0x40404040 | AMASK;
snprintf(text, sizeof(text), "-%d dBm", (150 - i));
render_text(surface, text, 5, y - 15);
}
rnum = 0;
for (result = result_list; result ; result = result->next) {
switch (result->sample.tlv.type) {
case ATH_FFT_SAMPLE_HT20:
if (rnum == highlight)
highlight_freq = result->sample.ht20.freq;
draw_sample_ht20(pixels, result, startfreq, rnum == highlight);
break;
case ATH_FFT_SAMPLE_HT20_40:
if (rnum == highlight)
highlight_freq = result->sample.ht40.freq;
draw_sample_ht20_40(pixels, result, startfreq, rnum == highlight);
break;
case ATH_FFT_SAMPLE_ATH10K:
if (rnum == highlight)
highlight_freq = result->sample.ath10k.header.freq1;
draw_sample_ath10k(pixels, result, startfreq, rnum == highlight);
/* TODO */
break;
case ATH_FFT_SAMPLE_ATH11K:
if (rnum == highlight)
highlight_freq = result->sample.ath11k.header.freq1;
draw_sample_ath11k(pixels, result, startfreq, rnum == highlight);
break;
}
rnum++;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
DestR.x = 0;
DestR.y = 0;
DestR.w = WIDTH;
DestR.h = HEIGHT;
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, &DestR);
SDL_DestroyTexture(texture);
SDL_RenderPresent(renderer);
return highlight_freq;
}
/*
* graphics_main - sets up the data and holds the mainloop.
*
*/
static void graphics_main(char *name, char *fontdir)
{
SDL_Event event;
char *videodrv;
int quit = 0;
int highlight = 0;
int change = 1, scroll = 0;
int startfreq = 2350, accel = 0;
int highlight_freq = startfreq;
if (graphics_init_sdl(name, fontdir) < 0) {
fprintf(stderr, "Failed to initialize graphics.\n");
return;
}
/* don't hang forever with dummy video driver */
videodrv = getenv("SDL_VIDEODRIVER");
if (videodrv && strcmp(videodrv, "dummy") == 0)
quit = 1;
while (!quit) {
if (change) {
highlight_freq = draw_picture(highlight, startfreq);
change = 0;
}
if (!scroll) {
/* move to highlighted object */
if (highlight_freq - 20 < startfreq)
accel = -10;
if (highlight_freq > (startfreq + WIDTH/X_SCALE))
accel = 10;
/* if we are "far off", move a little bit faster */
if (highlight_freq + 300 < startfreq)
accel = -100;
if (highlight_freq - 300 > (startfreq + WIDTH/X_SCALE))
accel = 100;
}
if (accel)
SDL_PollEvent(&event);
else
SDL_WaitEvent(&event);
switch (event.type) {
case SDL_QUIT:
quit = 1;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_LEFT:
if (highlight > 0) {
highlight--;
scroll = 0;
change = 1;
}
break;
case SDLK_RIGHT:
if (highlight < scanresults_n - 1){
highlight++;
scroll = 0;
change = 1;
}
break;
case SDLK_PAGEUP:
accel-= 2;
scroll = 1;
break;
case SDLK_PAGEDOWN:
accel+= 2;
scroll = 1;
break;
case SDLK_2:
startfreq = 2370;
accel +=1;
scroll = 1;
break;
case SDLK_5:
startfreq = 5150;
accel +=1;
scroll = 1;
break;
case 'i':
color_invert = !color_invert;
change = 1;
break;
default:
break;
}
break;
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_EXPOSED:
change = 1;
break;
}
}
if (accel) {
startfreq += accel;
if (accel > 0) accel--;
if (accel < 0) accel++;
change = 1;
}
if (startfreq < 2300) startfreq = 2300;
if (startfreq > 6000) startfreq = 6000;
if (accel < -20) accel = -20;
if (accel > 20) accel = 20;
}
graphics_quit_sdl();
}
static void usage(const char *prog)
{
if (!prog)
prog = "fft_eval";
fprintf(stderr, "Usage: %s [-f fontdir] scanfile\n", prog);
fft_eval_usage(prog);
}
int main(int argc, char *argv[])
{
int ch;
char *ss_name = NULL;
char *prog = NULL;
char *fontdir = NULL;
if (argc >= 1)
prog = argv[0];
while ((ch = getopt(argc, argv, "f:")) != -1) {
switch (ch) {
case 'f':
if (fontdir)
free(fontdir);
fontdir = strdup(optarg);
break;
case 's':
if (ss_name)
free(ss_name);
ss_name = strdup(optarg);
break;
case 'h':
default:
usage(prog);
exit(127);
}
}
argc -= optind;
argv += optind;
if (argc >= 1)
ss_name = argv[0];
fprintf(stderr, "WARNING: Experimental Software! Don't trust anything you see. :)\n");
fprintf(stderr, "\n");
if (fontdir == NULL) {
fontdir = strdup("./font/");
}
if (ss_name == NULL) {
fprintf(stderr, "ERROR: need scan file\n");
usage(prog);
exit(127);
}
if (fft_eval_init(ss_name) < 0) {
fprintf(stderr, "Couldn't read scanfile ...\n");
usage(prog);
return -1;
}
graphics_main(ss_name, fontdir);
free(fontdir);
fft_eval_exit();
return 0;
}