1 /*
2 	WARNING: This file was generated by the dkct program (see
3 	http://dktools.sourceforge.net/ for details).
4 	Changes you make here will be lost if dkct is run again!
5 	You should modify the original source and run dkct on it.
6 	Original source: test-dk4maac.ctr
7 */
8 
9 /**	@file test-dk4maac.c The test-dk4maac module.
10 */
11 
12 
13 #include "dk4conf.h"
14 
15 #include <stdio.h>
16 
17 #include <libdk4base/dk4error.h>
18 #include <libdk4ma/dk4maac.h>
19 
20 
21 
22 
23 static
24 void
show_error(dk4_er_t * erp)25 show_error(dk4_er_t *erp)
26 {
27   if (DK4_E_NONE != erp->ec) {
28     switch(erp->ec) {
29       case DK4_E_MATH_OVERFLOW: {
30         printf(" overflow");
31       } break;
32       case DK4_E_MATH_DIVZERO: {
33         printf(" divzero");
34       } break;
35       default: {
36         printf(" %d", erp->ec);
37       } break;
38     }
39   }
40 }
41 
42 
43 
main(void)44 int main(void)
45 {
46   char		buffer[128];	/* Input line buffer */
47   dk4_er_t	er;		/* Error report */
48   int		i1;		/* First operand */
49   int		i2;		/* Second operand */
50   int		exc;		/* Exit code */
51   int		cc;		/* Flag: Can continue */
52   char		c1;		/* First operand as char */
53   char		c2;		/* Second operand as char */
54   char		c3;		/* Result as char */
55 
56 
57 
58   exc = 0;
59   cc = 1;
60   while((1 == cc) && (fgets(buffer, sizeof(buffer), stdin))) {
61     if (sscanf(buffer, "%d %d", &i1, &i2) == 2) {
62       c1 = i1;
63       c2 = i2;
64       printf("%d %d\n", (int)c1, (int)c2);
65       dk4error_init(&er);
66       c3 = dk4ma_char_add(c1, c2, &er);
67       printf("\t+ %d", (int)c3);
68       show_error(&er);
69       printf("\n");
70 
71       dk4error_init(&er);
72       c3 = dk4ma_char_sub(c1, c2, &er);
73       printf("\t- %d", (int)c3);
74       show_error(&er);
75       printf("\n");
76 
77       dk4error_init(&er);
78       c3 = dk4ma_char_mul(c1, c2, &er);
79       printf("\t* %d", (int)c3);
80       show_error(&er);
81       printf("\n");
82 
83       dk4error_init(&er);
84       c3 = dk4ma_char_div(c1, c2, &er);
85       printf("\t/ %d", (int)c3);
86       show_error(&er);
87       printf("\n");
88     } else {
89       exc = 1;
90       fprintf(stderr, "test-dk4maac:ERROR: Invalid input line!\n");
91       fflush(stderr);
92       cc = 0;
93     }
94   }
95 
96 
97   return exc;
98 }
99 
100