~ubuntu-branches/ubuntu/oneiric/bc/oneiric

« back to all changes in this revision

Viewing changes to bc/execute.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-05 12:24:03 UTC
  • mfrom: (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20071205122403-rv1a7x90ktu1wl95
Tags: 1.06.94-3ubuntu1
* Merge with Debian; remaining changes:
  - Make bc/dc notice read and write errors on its input and output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* execute.c - run a bc program. */
2
 
 
3
1
/*  This file is part of GNU bc.
4
 
    Copyright (C) 1991-1994, 1997, 2000 Free Software Foundation, Inc.
 
2
 
 
3
    Copyright (C) 1991-1994, 1997, 2006 Free Software Foundation, Inc.
5
4
 
6
5
    This program is free software; you can redistribute it and/or modify
7
6
    it under the terms of the GNU General Public License as published by
14
13
    GNU General Public License for more details.
15
14
 
16
15
    You should have received a copy of the GNU General Public License
17
 
    along with this program; see the file COPYING.  If not, write to
 
16
    along with this program; see the file COPYING.  If not, write to:
18
17
      The Free Software Foundation, Inc.
19
 
      59 Temple Place, Suite 330
20
 
      Boston, MA 02111 USA
 
18
      Foundation, Inc.  51 Franklin Street, Fifth Floor,
 
19
      Boston, MA 02110-1301  USA
21
20
 
22
21
    You may contact the author by:
23
22
       e-mail:  philnelson@acm.org
27
26
                Bellingham, WA 98226-9062
28
27
       
29
28
*************************************************************************/
 
29
/* execute.c - run a bc program. */
30
30
 
31
31
#include "bcdefs.h"
32
32
#include <signal.h>
33
 
#include "global.h"
34
33
#include "proto.h"
35
34
 
36
35
 
43
42
     int sig;
44
43
{
45
44
  had_sigint = TRUE;
46
 
  printf ("\n");
47
 
  checkferror_output(stdout);
48
 
  rt_error ("interrupted execution");
49
45
}
50
46
 
51
47
 
86
82
  if (interactive)
87
83
    {
88
84
      signal (SIGINT, stop_execution);
89
 
      had_sigint = FALSE;
90
85
    }
91
86
   
92
 
  while (pc.pc_addr < functions[pc.pc_func].f_code_size && !runtime_error)
 
87
  had_sigint = FALSE;
 
88
  while (pc.pc_addr < functions[pc.pc_func].f_code_size
 
89
         && !runtime_error && !had_sigint)
93
90
    {
94
91
      inst = byte(&pc);
95
92
 
294
291
        case 'I': /* Read function. */
295
292
          push_constant (input_char, i_base);
296
293
          break;
 
294
 
 
295
        case 'X': /* Random function. */
 
296
          push_copy (_zero_);
 
297
          bc_int2num (&ex_stack->s_num, random());
 
298
          break;
297
299
        }
298
300
        break;
299
301
 
354
356
        push_copy (_zero_);
355
357
        break;
356
358
 
357
 
      case '1' : /* Load Constant 0. */
 
359
      case '1' : /* Load Constant 1. */
358
360
        push_copy (_one_);
359
361
        break;
360
362
 
546
548
  if (interactive)
547
549
    {
548
550
      signal (SIGINT, use_quit);
549
 
      if (had_sigint) {
550
 
        printf ("Interruption completed.\n");
551
 
        checkferror_output(stdout);
552
 
      }
 
551
      if (had_sigint)
 
552
        {
 
553
          printf ("\ninterrupted execution.\n");
 
554
          checkferror_output(stdout);
 
555
        }
553
556
    }
554
557
}
555
558
 
557
560
/* Prog_char gets another byte from the program.  It is used for
558
561
   conversion of text constants in the code to numbers. */
559
562
 
560
 
char
 
563
int
561
564
prog_char ()
562
565
{
563
 
  return byte(&pc);
 
566
  return (int) byte(&pc);
564
567
}
565
568
 
566
569
 
567
570
/* Read a character from the standard input.  This function is used
568
571
   by the "read" function. */
569
572
 
570
 
char
 
573
int
571
574
input_char ()
572
575
{
573
 
  char in_ch;
 
576
  int in_ch;
574
577
  
575
578
  /* Get a character from the standard input for the read function. */
576
579
  in_ch = getchar();
579
582
  if (in_ch == '\\')
580
583
    {
581
584
      in_ch = getchar();
582
 
      if (in_ch == '\n')
583
 
        in_ch = getchar();
 
585
      if (in_ch == '\n') {
 
586
          in_ch = getchar();
 
587
          out_col = 0;  /* Saw a new line */
 
588
        }
584
589
    }
585
590
  checkferror_input(stdin);
586
591
 
587
592
  /* Classify and preprocess the input character. */
588
 
  if (isdigit((int)in_ch))
 
593
  if (isdigit(in_ch))
589
594
    return (in_ch - '0');
590
595
  if (in_ch >= 'A' && in_ch <= 'F')
591
596
    return (in_ch + 10 - 'A');
606
611
 
607
612
void
608
613
push_constant (in_char, conv_base)
609
 
   char (*in_char)(VOID);
 
614
   int (*in_char)(VOID);
610
615
   int conv_base;
611
616
{
612
617
  int digits;
613
618
  bc_num build, temp, result, mult, divisor;
614
 
  char  in_ch, first_ch;
 
619
  int   in_ch, first_ch;
615
620
  char  negative;
616
621
 
617
622
  /* Initialize all bc numbers */
703
708
  bc_num build;
704
709
  program_counter look_pc;
705
710
  int kdigits, kscale;
706
 
  char inchar;
 
711
  unsigned char inchar;
707
712
  char *ptr;
708
713
  
709
714
  /* Count the digits and get things ready. */