summaryrefslogtreecommitdiff
path: root/support/dktools/test-dk4maaui.c
blob: 4f0bb90af5abdd8620105ac3d335b49831d02410 (plain)
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
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: test-dk4maaui.ctr
*/

/**	@file test-dk4maaui.c The test-dk4maaui module.
*/


#line 1 "test-dk4maaui.ctr"

#include "dk4conf.h"

#include <stdio.h>

#include "dk4error.h"
#include "dk4maaui.h"



#line 10 "test-dk4maaui.ctr"


static
void
show_error(dk4_er_t *erp)
{
  if (DK4_E_NONE != erp->ec) {
    switch(erp->ec) {
      case DK4_E_MATH_OVERFLOW: {
        printf(" overflow");
      } break;
      case DK4_E_MATH_DIVZERO: {
        printf(" divzero");
      } break;
      default: {
        printf(" %u", erp->ec);
      } break;
    }
  }
}



int main(void)
{
  char		buffer[128];	/* Input line buffer */
  dk4_er_t	er;		/* Error report */
  unsigned	i1;		/* First operand */
  unsigned	i2;		/* Second operand */
  int		exc;		/* Exit code */
  int		cc;		/* Flag: Can continue */
  unsigned	c1;		/* First operand as char */
  unsigned	c2;		/* Second operand as char */
  unsigned	c3;		/* Result as char */

  

#line 46 "test-dk4maaui.ctr"
  

#line 47 "test-dk4maaui.ctr"
  exc = 0;
  cc = 1;
  while((1 == cc) && (fgets(buffer, sizeof(buffer), stdin))) {
    if (sscanf(buffer, "%u %u", &i1, &i2) == 2) {
      c1 = i1;
      c2 = i2;
      printf("%u %u\n", (unsigned)c1, (unsigned)c2);
      dk4error_init(&er);
      c3 = dk4ma_uint_add(c1, c2, &er);
      printf("\t+ %u", (unsigned)c3);
      show_error(&er);
      printf("\n");

      dk4error_init(&er);
      c3 = dk4ma_uint_sub(c1, c2, &er);
      printf("\t- %u", (unsigned)c3);
      show_error(&er);
      printf("\n");

      dk4error_init(&er);
      c3 = dk4ma_uint_mul(c1, c2, &er);
      printf("\t* %u", (unsigned)c3);
      show_error(&er);
      printf("\n");

      dk4error_init(&er);
      c3 = dk4ma_uint_div(c1, c2, &er);
      printf("\t/ %u", (unsigned)c3);
      show_error(&er);
      printf("\n");
    } else {
      exc = 1;
      fprintf(stderr, "test-dk4maac:ERROR: Invalid input line!\n");
      fflush(stderr);
      cc = 0;
    }
  }
  

#line 85 "test-dk4maaui.ctr"
  

#line 86 "test-dk4maaui.ctr"
  return exc;
}