~ubuntu-branches/ubuntu/saucy/bc/saucy-proposed

« back to all changes in this revision

Viewing changes to dc/eval.c

  • Committer: Package Import Robot
  • Author(s): John G. Hasler
  • Date: 2012-06-22 21:00:45 UTC
  • Revision ID: package-import@ubuntu.com-20120622210045-cpu8v54e1x1z0ep0
Tags: 1.06.95-3
* Applied patch from Pádraig Brady.
  Closes: #608255: bc uses uninitialized memory

* Applied patch from Paul Dwerryhouse.
  Closes: #472250: please return support for .dcrc file

* Applied patch from Ian Jackson.
  Closes: #488735: notice read and write errors on input and output

* Generated bc.html and dc.html but something is still wrong.

* Added homepage field to debian/control.

* I can't see the problem with hyphens.

* Fixed doc-base white space.

* Added watch file.

* I believe that the above changes deal with 558188.
  Closes: #558188: Changes made in 1.06.94-3.1 NMU have been lost

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
static int
95
95
input_fil DC_DECLVOID()
96
96
{
 
97
        int c;
97
98
        if (input_pushback != EOF){
98
 
                int c = input_pushback;
 
99
                c = input_pushback;
99
100
                input_pushback = EOF;
100
101
                return c;
101
102
        }
102
 
        return getc(input_fil_fp);
 
103
        c = getc(input_fil_fp);
 
104
        checkferror_input(input_fil_fp);
 
105
        return c;
103
106
}
104
107
 
105
108
/* passed as an argument to dc_getnum */
298
301
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
299
302
                        if (2 <= tmpint  &&  tmpint <= DC_IBASE_MAX)
300
303
                                dc_ibase = tmpint;
301
 
                        else
 
304
                        else {
302
305
                                fprintf(stderr,
303
306
                                                "%s: input base must be a number \
304
307
between 2 and %d (inclusive)\n",
305
308
                                                progname, DC_IBASE_MAX);
 
309
                                checkferror_output(stderr);
 
310
                        }
306
311
                }
307
312
                break;
308
313
        case 'k':       /* set scale to value on top of stack */
310
315
                        tmpint = -1;
311
316
                        if (datum.dc_type == DC_NUMBER)
312
317
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
313
 
                        if ( ! (tmpint >= 0) )
 
318
                        if ( ! (tmpint >= 0) ) {
314
319
                                fprintf(stderr,
315
320
                                                "%s: scale must be a nonnegative number\n",
316
321
                                                progname);
317
 
                        else
 
322
                                checkferror_output(stderr);
 
323
                        } else
318
324
                                dc_scale = tmpint;
319
325
                }
320
326
                break;
338
344
                        tmpint = 0;
339
345
                        if (datum.dc_type == DC_NUMBER)
340
346
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
341
 
                        if ( ! (tmpint > 1) )
 
347
                        if ( ! (tmpint > 1) ) {
342
348
                                fprintf(stderr,
343
349
                                                "%s: output base must be a number greater than 1\n",
344
350
                                                progname);
345
 
                        else
 
351
                                checkferror_output(stderr);
 
352
                        } else
346
353
                                dc_obase = tmpint;
347
354
                }
348
355
                break;
383
390
                                fprintf(stderr,
384
391
                                                "%s: square root of nonnumeric attempted\n",
385
392
                                                progname);
 
393
                                checkferror_output(stderr);
386
394
                        }else if (dc_sqrt(datum.v.number, dc_scale, &tmpnum) == DC_SUCCESS){
387
395
                                dc_free_num(&datum.v.number);
388
396
                                datum.v.number = tmpnum;
444
452
                        fprintf(stderr,
445
453
                                        "%s: Q command requires a number >= 1\n",
446
454
                                        progname);
 
455
                        checkferror_output(stderr);
447
456
                }
448
457
                break;
449
458
#if 0
489
498
                        if (datum.dc_type == DC_NUMBER)
490
499
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
491
500
                        if (dc_pop(&datum) == DC_SUCCESS){
492
 
                                if (tmpint < 0)
 
501
                                if (tmpint < 0) {
493
502
                                        fprintf(stderr,
494
503
                                                        "%s: array index must be a nonnegative integer\n",
495
504
                                                        progname);
496
 
                                else
 
505
                                        checkferror_output(stderr);
 
506
                                } else
497
507
                                        dc_array_set(peekc, tmpint, datum);
498
508
                        }
499
509
                }
505
515
                        tmpint = -1;
506
516
                        if (datum.dc_type == DC_NUMBER)
507
517
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
508
 
                        if (tmpint < 0)
 
518
                        if (tmpint < 0) {
509
519
                                fprintf(stderr,
510
520
                                                "%s: array index must be a nonnegative integer\n",
511
521
                                                progname);
512
 
                        else
 
522
                                checkferror_output(stderr);
 
523
                        } else
513
524
                                dc_push(dc_array_get(peekc, tmpint));
514
525
                }
515
526
                return DC_EATONE;
516
527
 
517
528
        default:        /* What did that user mean? */
518
529
                fprintf(stderr, "%s: ", progname);
 
530
                checkferror_output(stderr);
519
531
                dc_show_id(stdout, c, " unimplemented\n");
520
532
                break;
521
533
        }
544
556
                fprintf(stderr,
545
557
                                "%s: eval called with non-string argument\n",
546
558
                                progname);
 
559
                checkferror_output(stderr);
547
560
                return DC_OKAY;
548
561
        }
549
562
        interrupt_seen = 0;
640
653
                                return DC_FAIL;
641
654
                        }
642
655
                        fprintf(stderr, "%s: unexpected EOS\n", progname);
 
656
                        checkferror_output(stderr);
643
657
                        return DC_OKAY;
644
658
                }
645
659
        }
665
679
        stdin_lookahead = EOF;
666
680
        for (c=getc(fp); c!=EOF; c=peekc){
667
681
                peekc = getc(fp);
 
682
                checkferror_input(stdin);
668
683
                /*
669
684
                 * The following if() is the only place where ``stdin_lookahead''
670
685
                 * might be set to other than EOF:
716
731
                                                        return DC_SUCCESS;
717
732
                                                fprintf(stderr, "%s: Q command argument exceeded \
718
733
string execution depth\n", progname);
 
734
                                                checkferror_output(stderr);
719
735
                                        }
720
736
                                }else{
721
737
                                        dc_garbage("at top of stack", -1);
728
744
                        fprintf(stderr,
729
745
                                        "%s: Q command argument exceeded string execution depth\n",
730
746
                                        progname);
731
 
                        if (stdin_lookahead != peekc  &&  fp == stdin)
 
747
                        checkferror_output(stderr);
 
748
                        if (stdin_lookahead != peekc  &&  fp == stdin) {
732
749
                                peekc = getc(fp);
 
750
                                checkferror_input(stdin);
 
751
                        }
733
752
                        break;
734
753
 
735
754
                case DC_INT:
771
790
                        if (ferror(fp))
772
791
                                goto error_fail;
773
792
                        fprintf(stderr, "%s: unexpected EOF\n", progname);
 
793
                        checkferror_output(stderr);
774
794
                        return DC_FAIL;
775
795
                }
776
796
        }