~ubuntu-branches/ubuntu/wily/morse/wily-proposed

« back to all changes in this revision

Viewing changes to morse.d/morse.c

  • Committer: Bazaar Package Importer
  • Author(s): Nanakos Chrysostomos
  • Date: 2011-05-01 16:53:08 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110501165308-8jhrp37887qmr8u7
Tags: 2.3-1
* New upstream release
* Update debian/control
  - Update to S-V 3.9.2: no changes needed.
  - Fixed lintian warning for the description synopsis.
* Fixed the -A, -B, and -S options (-B was always active, 
  -A and -S had no effect).
* Only include prosigns if -B is specified, per the documentation.
* Added '@' character (.--.-.), in use if -B is enabled.
* Changed representation of <SN> prosign from '@' to '~' to accommodate '@'.
* Don't crash if char is signed and a negative value is sent.
* Added an xml stub for morseX11.1 and morseLinux.1 man files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
static int      charbychar = 0;
95
95
static int      international = 0;
96
96
static int      allprosigns = 0;
97
 
static int      allpunctuation = 1;
 
97
static int      allpunctuation = 0;
98
98
static int      tryagaincount = 1;
99
99
static float    words_per_minute = WORDS_PER_MINUTE;
100
100
static float    error_frequency = ERROR_FREQUENCY;
123
123
static int      yourlength = 0;
124
124
static char     yourstring[TESTBUFSZ];
125
125
static int      linepos = 0;
 
126
static char     *user_charset = NULL;
126
127
 
127
128
/*
128
129
 * How many times can a given character not be asked before
346
347
        exit (0);
347
348
    }
348
349
 
 
350
    /* DGHJKLMOPQUVWYZhjkouyz are still available */
 
351
    while ((ch = getopt (argc, argv, "ABC:E:F:IM:N:R:STXabcdef:g:ilmn:p:qrstv:w:x:")) != EOF)
 
352
        switch ((char) ch)
 
353
        {
 
354
        case 'A':
 
355
            international = 1;
 
356
            break;
 
357
        case 'B':
 
358
            allpunctuation = 1;
 
359
            break;
 
360
        case 'C':
 
361
            user_charset = optarg;
 
362
            break;
 
363
        case 'E':
 
364
            testing = 1;
 
365
            sscanf (optarg, "%d", &error_threshold);
 
366
            if (error_threshold < error_floor)
 
367
                error_floor = error_threshold;
 
368
            break;
 
369
        case 'F':
 
370
            sscanf (optarg, "%f", &fwords_per_minute);
 
371
            break;
 
372
        case 'I':
 
373
            typeaway = LETMESEE;
 
374
            break;
 
375
        case 'M':
 
376
            testing = 1;
 
377
            sscanf (optarg, "%d", &max_behindness);
 
378
            if (max_behindness < 1)
 
379
                max_behindness = 0;
 
380
            break;
 
381
        case 'N':
 
382
            sscanf (optarg, "%d", &wordcount);
 
383
            if (wordcount < 1) wordcount = -1;
 
384
            break;
 
385
        case 'R':
 
386
            sscanf (optarg, "%d", &timeout);
 
387
            timeout *= 60;
 
388
            if (timeout < 1) timeout = -1;
 
389
            break;
 
390
        case 'S':
 
391
            allprosigns = 1;
 
392
            break;
 
393
        case 'T':
 
394
            testing = 1;
 
395
            showtesting = 1;
 
396
            break;
 
397
        case 'X':
 
398
            sscanf (optarg, "%f", &error_volume);
 
399
            break;
 
400
        case 'a':
 
401
            wordsafter = 1;
 
402
            break;
 
403
        case 'b':
 
404
            wordsbefore = 1;
 
405
            break;
 
406
        case 'c':
 
407
            noticebad = 1;
 
408
            break;
 
409
        case 'd':
 
410
            dynamicspeed = 1;
 
411
            break;
 
412
        case 'e':
 
413
            fancyending = 0;
 
414
            break;
 
415
        case 'f':
 
416
            sscanf (optarg, "%f", &frequency1);
 
417
            break;
 
418
        case 'g':
 
419
            sscanf (optarg, "%f", &frequency2);
 
420
            break;
 
421
        case 'i':
 
422
            typeaway = 1;
 
423
            break;
 
424
        case 'l':
 
425
            showletters = 1;
 
426
            break;
 
427
        case 'm':
 
428
            showmorse = 1;
 
429
            break;
 
430
        case 'n':
 
431
            sscanf (optarg, "%d", &wordlen);
 
432
            if (wordlen < 1) wordlen = 1;
 
433
            if (wordlen > MAXWORDLEN) wordlen = MAXWORDLEN;
 
434
            break;
 
435
        case 'p':
 
436
            charbychar = 1;
 
437
            testing = 1;
 
438
            sscanf (optarg, "%d", &tryagaincount);
 
439
            break;
 
440
        case 'q':
 
441
            keepquiet = 1;
 
442
            break;
 
443
        case 'r':
 
444
            randomletters = 1;
 
445
            break;
 
446
        case 's':
 
447
            charbychar = 1;
 
448
            testing = 1;
 
449
            break;
 
450
        case 't':
 
451
            testing = 1;
 
452
            break;
 
453
        case 'v':
 
454
            sscanf (optarg, "%f", &volume);
 
455
            if (volume < 0.)
 
456
                volume = 0.;
 
457
            if (volume > 1.)
 
458
                volume = 1.;
 
459
            break;
 
460
        case 'w':
 
461
            sscanf (optarg, "%f", &words_per_minute);
 
462
            break;
 
463
        case 'x':
 
464
            sscanf (optarg, "%f", &error_frequency);
 
465
            break;
 
466
        default:
 
467
            fprintf (stderr, "Type \"morse\" without arguments to get self-doc!\n");
 
468
            exit (1);
 
469
            break;
 
470
        }
 
471
    argc -= optind;
 
472
    argv += optind;
 
473
 
 
474
    if (fwords_per_minute <= 0.)
 
475
        fwords_per_minute = words_per_minute;
 
476
    new_words_per_minute ();
 
477
 
 
478
    frequency = frequency1;
 
479
 
 
480
    if (BeepInit () != 0)
 
481
    {
 
482
        fprintf (stderr, "Can't access speaker.\n");
 
483
        exit (1);
 
484
    }
 
485
 
349
486
    for (ii = 0; ii < TWOFIFTYSIX; ii++)
350
487
        code[ii] = NULL;
351
488
 
405
542
    code[(int) ';'] = "-.-.-.";
406
543
    code[(int) '$'] = "...-..-";
407
544
    code[(int) '!'] = "-.-.--";
 
545
    code[(int) '@'] = ".--.-.";
408
546
    }
409
547
 
 
548
    if (allpunctuation) {
410
549
    /* Commonly used procedure signs ("prosigns") */
411
550
    code[(int) '+'] = ".-.-.";  /* <AR> end of message */
412
551
    code[(int) '*'] = ".-...";  /* <AS> wait, stand-by */
413
552
    code[(int) '='] = "-...-";  /* <BT> (double dash) pause, break for text */
414
553
    code[(int) '('] = "-.--.";  /* <KN> over-specified station only */
415
554
    code[(int) '%'] = "...-.-"; /* <SK> end of contact, known also as <VA> */
 
555
    }
416
556
 
417
557
    if (allprosigns) {
418
558
    /* Not so commonly used procedure signs ("prosigns") */
419
559
    code[(int) '^'] = ".-.-";   /* <AA> new line, the same as :a, ae */
420
560
    code[(int) '#'] = "-...-.-";/* <BK> invite receiving station to transmit */
421
561
    code[(int) '&'] = "-.-.-";  /* <KA> attention */
422
 
    code[(int) '@'] = "...-.";  /* <SN> understood */
 
562
    code[(int) '~'] = "...-.";  /* <SN> understood */
423
563
    }
424
564
 
425
565
    if (international) {
437
577
    code[(int) ((unsigned char)'\247')] = ".-.-.."; /* paragraph */
438
578
    }
439
579
 
 
580
    if (user_charset)
 
581
    {
 
582
        for (ii = 0; ii < strlen(user_charset); ii++)
 
583
        {
 
584
            *(user_charset+ii) = tolower(*(user_charset+ii));
 
585
        }
 
586
        for (ii = 0; ii < TWOFIFTYSIX; ii++)
 
587
        {
 
588
            if (code[ii] != NULL)
 
589
            {
 
590
                if (strchr(user_charset, ii) != NULL)
 
591
                {
 
592
                    randomfactor[ii] = RANDOMBASELEVEL - 1;
 
593
                } else {
 
594
                    code[ii] = NULL;
 
595
                    randomfactor[ii] = 0;
 
596
                }
 
597
            }
 
598
        }
 
599
    }
 
600
 
440
601
    for (ii = 0; ii < TWOFIFTYSIX; ii++)
441
602
    {
442
603
        /* Everything starts equally fresh */
461
622
    words_per_minute = WORDS_PER_MINUTE;
462
623
    fwords_per_minute = -1.;
463
624
 
464
 
    /* DGHJKLMOPQUVWYZhjkouyz are still available */
465
 
    while ((ch = getopt (argc, argv, "ABC:E:F:IM:N:R:STXabcdef:g:ilmn:p:qrstv:w:x:")) != EOF)
466
 
        switch ((char) ch)
467
 
        {
468
 
        case 'A':
469
 
            international = 1;
470
 
            break;
471
 
        case 'B':
472
 
            allpunctuation = 1;
473
 
            break;
474
 
        case 'C':
475
 
            for (ii = 0; ii < strlen(optarg); ii++)
476
 
              {
477
 
                *(optarg+ii) = tolower(*(optarg+ii));
478
 
              }
479
 
            for (ii = 0; ii < TWOFIFTYSIX; ii++)
480
 
              {
481
 
                if (code[ii] != NULL)
482
 
                  {
483
 
                    if (strchr(optarg, ii) != NULL)
484
 
                      {
485
 
                        randomfactor[ii] = RANDOMBASELEVEL - 1;
486
 
                      } else {
487
 
                        code[ii] = NULL;
488
 
                        randomfactor[ii] = 0;
489
 
                      }
490
 
                  }
491
 
              }
492
 
            break;
493
 
        case 'E':
494
 
            testing = 1;
495
 
            sscanf (optarg, "%d", &error_threshold);
496
 
            if (error_threshold < error_floor)
497
 
                error_floor = error_threshold;
498
 
            break;
499
 
        case 'F':
500
 
            sscanf (optarg, "%f", &fwords_per_minute);
501
 
            break;
502
 
        case 'I':
503
 
            typeaway = LETMESEE;
504
 
            break;
505
 
        case 'M':
506
 
            testing = 1;
507
 
            sscanf (optarg, "%d", &max_behindness);
508
 
            if (max_behindness < 1)
509
 
                max_behindness = 0;
510
 
            break;
511
 
        case 'N':
512
 
            sscanf (optarg, "%d", &wordcount);
513
 
            if (wordcount < 1) wordcount = -1;
514
 
            break;
515
 
        case 'R':
516
 
            sscanf (optarg, "%d", &timeout);
517
 
            timeout *= 60;
518
 
            if (timeout < 1) timeout = -1;
519
 
            break;
520
 
        case 'S':
521
 
            allprosigns = 1;
522
 
            break;
523
 
        case 'T':
524
 
            testing = 1;
525
 
            showtesting = 1;
526
 
            break;
527
 
        case 'X':
528
 
            sscanf (optarg, "%f", &error_volume);
529
 
            break;
530
 
        case 'a':
531
 
            wordsafter = 1;
532
 
            break;
533
 
        case 'b':
534
 
            wordsbefore = 1;
535
 
            break;
536
 
        case 'c':
537
 
            noticebad = 1;
538
 
            break;
539
 
        case 'd':
540
 
            dynamicspeed = 1;
541
 
            break;
542
 
        case 'e':
543
 
            fancyending = 0;
544
 
            break;
545
 
        case 'f':
546
 
            sscanf (optarg, "%f", &frequency1);
547
 
            break;
548
 
        case 'g':
549
 
            sscanf (optarg, "%f", &frequency2);
550
 
            break;
551
 
        case 'i':
552
 
            typeaway = 1;
553
 
            break;
554
 
        case 'l':
555
 
            showletters = 1;
556
 
            break;
557
 
        case 'm':
558
 
            showmorse = 1;
559
 
            break;
560
 
        case 'n':
561
 
            sscanf (optarg, "%d", &wordlen);
562
 
            if (wordlen < 1) wordlen = 1;
563
 
            if (wordlen > MAXWORDLEN) wordlen = MAXWORDLEN;
564
 
            break;
565
 
        case 'p':
566
 
            charbychar = 1;
567
 
            testing = 1;
568
 
            sscanf (optarg, "%d", &tryagaincount);
569
 
            break;
570
 
        case 'q':
571
 
            keepquiet = 1;
572
 
            break;
573
 
        case 'r':
574
 
            randomletters = 1;
575
 
            break;
576
 
        case 's':
577
 
            charbychar = 1;
578
 
            testing = 1;
579
 
            break;
580
 
        case 't':
581
 
            testing = 1;
582
 
            break;
583
 
        case 'v':
584
 
            sscanf (optarg, "%f", &volume);
585
 
            if (volume < 0.)
586
 
                volume = 0.;
587
 
            if (volume > 1.)
588
 
                volume = 1.;
589
 
            break;
590
 
        case 'w':
591
 
            sscanf (optarg, "%f", &words_per_minute);
592
 
            break;
593
 
        case 'x':
594
 
            sscanf (optarg, "%f", &error_frequency);
595
 
            break;
596
 
        default:
597
 
            fprintf (stderr, "Type \"morse\" without arguments to get self-doc!\n");
598
 
            exit (1);
599
 
            break;
600
 
        }
601
 
    argc -= optind;
602
 
    argv += optind;
603
 
 
604
 
    if (fwords_per_minute <= 0.)
605
 
        fwords_per_minute = words_per_minute;
606
 
    new_words_per_minute ();
607
 
 
608
 
    frequency = frequency1;
609
 
 
610
 
    if (BeepInit () != 0)
611
 
    {
612
 
        fprintf (stderr, "Can't access speaker.\n");
613
 
        exit (1);
614
 
    }
615
 
 
616
625
    time(&starttime);
617
626
 
618
627
    handler.sa_handler = die;
1243
1252
            printf ("<KN>");
1244
1253
        else if (c == '%' && showmorse)
1245
1254
            printf ("<SK>");
1246
 
#ifdef ALLPROSIGNS
1247
 
        else if (c == '^' && (code[(int) '^'] != NULL) && showmorse)
1248
 
            printf ("<AA>");
1249
 
        else if (c == '#' && showmorse)
1250
 
            printf ("<BK>");
1251
 
        else if (c == '&' && showmorse)
1252
 
            printf ("<KA>");
1253
 
        else if (c == '@' && showmorse)
1254
 
            printf ("<SN>");
1255
 
#endif
 
1255
        else if (allprosigns) {
 
1256
             if (c == '^' && (code[(int) '^'] != NULL) && showmorse)
 
1257
                printf ("<AA>");
 
1258
            else if (c == '#' && showmorse)
 
1259
                printf ("<BK>");
 
1260
            else if (c == '&' && showmorse)
 
1261
                printf ("<KA>");
 
1262
            else if (c == '~' && showmorse)
 
1263
                printf ("<SN>");
 
1264
        }
1256
1265
        else
1257
1266
            printf ("%c", c);
1258
1267