~ubuntu-branches/ubuntu/natty/bc/natty

« back to all changes in this revision

Viewing changes to bc/execute.c

  • Committer: Bazaar Package Importer
  • Author(s): John Hasler
  • Date: 2007-12-02 14:46:56 UTC
  • mto: (3.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20071202144656-vz98qh9dd1zwdyny
Tags: upstream-1.06.94
ImportĀ upstreamĀ versionĀ 1.06.94

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
 
  rt_error ("interrupted execution");
48
45
}
49
46
 
50
47
 
85
82
  if (interactive)
86
83
    {
87
84
      signal (SIGINT, stop_execution);
88
 
      had_sigint = FALSE;
89
85
    }
90
86
   
91
 
  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)
92
90
    {
93
91
      inst = byte(&pc);
94
92
 
290
288
        case 'I': /* Read function. */
291
289
          push_constant (input_char, i_base);
292
290
          break;
 
291
 
 
292
        case 'X': /* Random function. */
 
293
          push_copy (_zero_);
 
294
          bc_int2num (&ex_stack->s_num, random());
 
295
          break;
293
296
        }
294
297
        break;
295
298
 
349
352
        push_copy (_zero_);
350
353
        break;
351
354
 
352
 
      case '1' : /* Load Constant 0. */
 
355
      case '1' : /* Load Constant 1. */
353
356
        push_copy (_one_);
354
357
        break;
355
358
 
542
545
    {
543
546
      signal (SIGINT, use_quit);
544
547
      if (had_sigint)
545
 
        printf ("Interruption completed.\n");
 
548
        printf ("\ninterrupted execution.\n");
546
549
    }
547
550
}
548
551
 
550
553
/* Prog_char gets another byte from the program.  It is used for
551
554
   conversion of text constants in the code to numbers. */
552
555
 
553
 
char
 
556
int
554
557
prog_char ()
555
558
{
556
 
  return byte(&pc);
 
559
  return (int) byte(&pc);
557
560
}
558
561
 
559
562
 
560
563
/* Read a character from the standard input.  This function is used
561
564
   by the "read" function. */
562
565
 
563
 
char
 
566
int
564
567
input_char ()
565
568
{
566
 
  char in_ch;
 
569
  int in_ch;
567
570
  
568
571
  /* Get a character from the standard input for the read function. */
569
572
  in_ch = getchar();
572
575
  if (in_ch == '\\')
573
576
    {
574
577
      in_ch = getchar();
575
 
      if (in_ch == '\n')
576
 
        in_ch = getchar();
 
578
      if (in_ch == '\n') {
 
579
          in_ch = getchar();
 
580
          out_col = 0;  /* Saw a new line */
 
581
        }
577
582
    }
578
583
 
579
584
  /* Classify and preprocess the input character. */
580
 
  if (isdigit((int)in_ch))
 
585
  if (isdigit(in_ch))
581
586
    return (in_ch - '0');
582
587
  if (in_ch >= 'A' && in_ch <= 'F')
583
588
    return (in_ch + 10 - 'A');
598
603
 
599
604
void
600
605
push_constant (in_char, conv_base)
601
 
   char (*in_char)(VOID);
 
606
   int (*in_char)(VOID);
602
607
   int conv_base;
603
608
{
604
609
  int digits;
605
610
  bc_num build, temp, result, mult, divisor;
606
 
  char  in_ch, first_ch;
 
611
  int   in_ch, first_ch;
607
612
  char  negative;
608
613
 
609
614
  /* Initialize all bc numbers */
695
700
  bc_num build;
696
701
  program_counter look_pc;
697
702
  int kdigits, kscale;
698
 
  char inchar;
 
703
  unsigned char inchar;
699
704
  char *ptr;
700
705
  
701
706
  /* Count the digits and get things ready. */