forked from mohuangrui/ArtraCFD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.c
742 lines (741 loc) · 24.8 KB
/
calculator.c
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/****************************************************************************
* ArtraCFD *
* <By Huangrui Mo> *
* Copyright (C) Huangrui Mo <[email protected]> *
* This file is part of ArtraCFD. *
* ArtraCFD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
****************************************************************************/
/****************************************************************************
* Required Header Files
****************************************************************************/
#include "calculator.h"
#include <stdio.h> /* standard library for input and output */
#include <math.h> /* common mathematical functions */
#include <string.h> /* manipulating strings */
#include "commons.h"
/****************************************************************************
* Local Data Structure
****************************************************************************/
typedef enum {
DIMOP = 19, /* number of operator types */
NOPRD = 50, /* number of operands */
NOPRT = 50, /* number of operators */
LENOPRT = 5, /* longest length of operator symbol */
} CalcConst;
typedef struct {
Real *const bom; /* pointer to stack bottom */
Real *top; /* pointer to stack top */
const int size; /* stack size */
Real space[NOPRD]; /* stack space */
} Operand;
typedef struct {
char *const bom; /* pointer to stack bottom */
char *top; /* pointer to stack top */
const int size; /* stack size */
char space[NOPRT]; /* stack space */
const char priority[DIMOP][DIMOP]; /* store the priority of operators */
} Operator;
/****************************************************************************
* Static Function Declarations
****************************************************************************/
static int SolveExpression(CalcVar *, const char *, Operand *, Operator *);
static int TranslateToMath(char *);
static char QueryPriority(const Operator *, const char, const char);
static int QueryIndex(const char);
static int PushOperator(Operator *, const char);
static int PushOperand(Operand *, const Real);
static int PopOperator(Operator *, char *);
static int PopOperand(Operand *, Real *);
static char GetTopOperator(const Operator *);
static Real GetTopOperand(const Operand *);
static int IsOperator(const char);
static int IsPureUnaryOperator(const char);
static int IsPureBinaryOperator(const char);
static int IsDualOperator(const char);
static int IsDualOperatorActAsUnary(const char *);
static int IsLeftParentheses(const char);
static int IsRightParentheses(const char);
static int IsConstant(const char);
static int IsEndTag(const char);
static int IsDigit(const char);
static int IsDot(const char);
static Real ExtractFirstFloat(char **);
static Real ExtractConstant(const CalcVar *, char **);
static int DoUnary(const char, const Real, Real *);
static int DoBinary(const Real, const char, const Real, Real *);
static void ShowCalcManual(void);
static int SetVariable(CalcVar *);
/****************************************************************************
* Function definitions
****************************************************************************/
int RunCalculator(void)
{
CalcVar theVar = {
.t = 0.0,
.x = 0.0,
.y = 0.0,
.z = 0.0,
.ans = 0.0,
.pi = PI,
};
ShowInfo("Session");
ShowInfo("* Expression Calculator *\n");
ShowInfo("* <By Huangrui Mo> *\n");
ShowInfo("* Copyright (C) Huangrui Mo <[email protected]> *\n");
ShowInfo("Session");
ShowInfo("Enter 'help' for more information\n");
ShowInfo("Session");
String str = {'\0'}; /* store the input information */
while (1) {
ShowInfo("\nCalc << ");
ParseCommand(fgets(str, sizeof str, stdin));
ShowInfo("\n");
if (0 == strncmp(str, "help", sizeof str)) {
ShowInfo("Options:\n");
ShowInfo("[help] show this information\n");
ShowInfo("[set] set variable values\n");
ShowInfo("[math expr] compute math expression\n");
ShowInfo("[manual] show user manual\n");
ShowInfo("[exit] return\n");
continue;
}
if (0 == strncmp(str, "set", sizeof str)) {
SetVariable(&theVar);
continue;
}
if (0 == strncmp(str, "manual", sizeof str)) {
ShowCalcManual();
continue;
}
if ('\0' == str[0]) {
continue;
}
if (0 == strncmp(str, "exit", sizeof str)) {
ShowInfo("Session");
return 0;
}
/* if non of above is true, then compute the expression */
ComputeExpression(&theVar, str);
ShowInfo("ans = %.6g\n", theVar.ans);
}
return 0;
}
Real ComputeExpression(CalcVar *var, const char *str)
{
Operand theOprd = {
.bom = theOprd.space,
.top = theOprd.space,
.size = NOPRD - 1,
.space = {0.0}
};
Operator theOprt = {
.bom = theOprt.space,
.top = theOprt.space,
.size = NOPRT - 1,
.space = {'\0'},
.priority = { /* + - * / ^ exp ln lg abs sin cos tan ( ) [ ] { } \0 */
{'>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'>', '>', '>', '>', '>', '<', '<', '<', '<', '<', '<', '<', '<', '>', '<', '>', '<', '>', '>'},
{'<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '=', '<', 'w', '<', 'w', 'w'},
{'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'},
{'<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', 'w', '<', '=', '<', 'w', 'w'},
{'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'},
{'<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', 'w', '<', 'w', '<', '=', 'w'},
{'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'},
{'<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', 'w', '<', 'w', '<', 'w', '='}
}
};
SolveExpression(var, str, &theOprd, &theOprt);
return var->ans;
}
/*
* The flow control of this program is important, thus, every function
* call which may result an important error will be monitored.
* These functional functions return 0 means true, 1 means false.
*/
static int SolveExpression(CalcVar *var, const char *str, Operand *oprd, Operator *oprt)
{
/* use a new space to avoid modify the original expression */
String space = {'\0'};
/*
* Use as a flag to check whether '+' and '-' are unary operator based on
* the assumption that if "+" "-" appears as unary operator then it must
* after a parentheses except at the beginning of an expression. By putting
* a "(" at the front of the expression, then this rule is always true.
*/
space[0] = '(';
/* target expression begins at the second position of storage address */
char *expr = space + 1;
/*
* Copy the expression to space, because need to access expr[2] and even
* later position when search and convert the expr to math expression,
* limit the available space for copy is a safety choice.
*/
strncpy(expr, str, (int)(sizeof space) - LENOPRT);
if (0 != TranslateToMath(expr)) {
return 1;
}
char toprt = '\0'; /* store the top operator of operator stack */
char coprt = '\0'; /* store the current operator */
Real oprdx = 0.0; /* first top operand in stack */
Real oprdy = 0.0; /* second top operand in stack */
Real coprd = 0.0; /* store the current operand */
/* always initialize and reset the stack status */
oprt->top = oprt->bom;
oprd->top = oprd->bom;
PushOperator(oprt,'\0'); /* push a end flag to the operator stack */
/* calculation loop */
while (('\0' != *expr) || ('\0' != GetTopOperator(oprt))) {
if (IsDigit(*expr)) { /* find a operand */
coprd = ExtractFirstFloat(&expr);
if (0 != PushOperand(oprd, coprd)) {
return 1;
}
continue;
}
if (IsConstant(*expr)) { /* find a constant */
coprd = ExtractConstant(var, &expr);
if (0 != PushOperand(oprd, coprd)) {
return 1;
}
continue;
}
/* treat everything left as an operator */
if (!IsOperator(*expr)) {
ShowWarning("undefined operator in expression");
return 1;
}
coprt = *expr;
switch (QueryPriority(oprt, GetTopOperator(oprt), coprt)) {
case '<': /* push the new high-priority operator into stack */
if (IsDualOperatorActAsUnary(expr)) {
/*
* Dual operator (they can both be unary and binary)
* '+' '-' show as a unary operator, then push a 0 to
* operand stack to make them become binary operator
*/
if (0 != PushOperand(oprd, 0)) {
return 1;
}
}
if (0 != PushOperator(oprt, coprt)) {
return 1;
}
++expr;
break;
case '=': /* dump the two same-priority operators as they are control operators */
if (0 != PopOperator(oprt, &coprt)) {
return 1;
}
++expr;
break;
case '>': /* hold the new low-priority operator and finish the old high-priority operator */
if (0 != PopOperator(oprt, &toprt)) {
return 1;
}
if (IsPureUnaryOperator(toprt)) {
if (0 != PopOperand(oprd, &oprdx)) {
return 1;
}
if (0 != DoUnary(toprt, oprdx, &coprd)) {
return 1;
}
if (0 != PushOperand(oprd, coprd)) {
return 1;
}
} else {
if (0 != PopOperand(oprd, &oprdx)) {
return 1;
}
if (0 != PopOperand(oprd, &oprdy)) {
return 1;
}
if (0 != DoBinary(oprdy, toprt, oprdx, &coprd)) {
return 1;
}
if (0 != PushOperand(oprd, coprd)) {
return 1;
}
}
break;
default:
ShowWarning("can not match parenthesis");
return 1;
}
}
/*
* If the loop successfully exit, then it means the expression
* and operator stack are all processed, now need to check the
* operand stack, if there are more than one element left,
* it means something wrong happened.
*/
if (1 != (oprd->top - oprd->bom)) {
ShowWarning("wrong expression");
return 1;
}
/* save the result to answer */
var->ans = GetTopOperand(oprd);
return 0;
}
/*
* Obtain the priority between two operators from the priority matrix
*/
static char QueryPriority(const Operator *oprt, const char oprtx, const char oprty)
{
const int i = QueryIndex(oprtx);
const int j = QueryIndex(oprty);
return oprt->priority[i][j];
}
/*
* Query the index of a operator in the priority matrix
*/
static int QueryIndex(const char op)
{
int i = 0;
switch(op) {
case '+':
i = 0; break;
case '-':
i = 1; break;
case '*':
i = 2; break;
case '/':
i = 3; break;
case '^':
i = 4; break;
case 'e':
i = 5; break;
case 'n':
i = 6; break;
case 'g':
i = 7; break;
case 'a':
i = 8; break;
case 's':
i = 9; break;
case 'c':
i = 10; break;
case 't':
i = 11; break;
case '(':
i = 12; break;
case ')':
i = 13; break;
case '[':
i = 14; break;
case ']':
i = 15; break;
case '{':
i = 16; break;
case '}':
i = 17; break;
case '\0':
i = 18; break;
default:
ShowWarning("unidentified operator");
break;
}
return i;
}
static int PushOperand(Operand *oprd, const Real op)
{
if ((oprd->top - oprd->bom) >= oprd->size) {
ShowWarning("operand stack is overflowing...");
return 1;
}
*oprd->top = op;
++(oprd->top);
return 0;
}
static int PopOperand(Operand *oprd, Real *pop)
{
if (oprd->top == oprd->bom) {
ShowWarning("no sufficient operands in expression...");
return 1;
}
--(oprd->top);
*pop = *oprd->top;
return 0;
}
static Real GetTopOperand(const Operand *oprd)
{
return oprd->top[-1];
}
static int PushOperator(Operator *oprt, const char op)
{
if ((oprt->top - oprt->bom) >= oprt->size) {
ShowWarning("operator stack is overflowing...");
return 1;
}
*oprt->top = op;
++(oprt->top);
return 0;
}
static int PopOperator(Operator *oprt, char *pop)
{
if (oprt->top == oprt->bom) {
ShowWarning("no sufficient operators in expression...");
return 1;
}
--(oprt->top);
*pop = *oprt->top;
return 0;
}
static char GetTopOperator(const Operator *oprt)
{
return oprt->top[-1];
}
/*
* Translate the input string to a specific format that the program
* can recognize every operator and operand correctly.
*/
static int TranslateToMath(char *str)
{
char *scanner = str;
char *receiver = str;
while ('\0' != *scanner) {
switch (*scanner) {
case 'e':
if (('x' == scanner[1]) && ('p' == scanner[2])) { /* exp */
*receiver = 'e';
++receiver;
scanner += 3;
} else {
ShowWarning("unknown operator: e..");
return 1;
}
break;
case 'l':
if (('n' == scanner[1])) {/* ln */
*receiver = 'n';
++receiver;
scanner += 2;
} else {
if (('g' == scanner[1])) { /* lg */
*receiver = 'g';
++receiver;
scanner += 2;
} else {
ShowWarning("unknown operator: l..");
return 1;
}
}
break;
case 'a':
if (('b' == scanner[1]) && ('s' == scanner[2])) { /* abs */
*receiver = 'a';
++receiver;
scanner += 3;
} else {
if (('n' == scanner[1]) && ('s' == scanner[2])) { /* ans */
*receiver = 'q';
++receiver;
scanner += 3;
} else {
ShowWarning("unknown operator: a..");
return 1;
}
}
break;
case 's':
if (('i' == scanner[1]) && ('n' == scanner[2])) { /* sin */
*receiver = 's';
++receiver;
scanner += 3;
} else {
ShowWarning("unknown operator: s..");
return 1;
}
break;
case 'c':
if (('o' == scanner[1]) && ('s' == scanner[2])) { /* cos */
*receiver = 'c';
++receiver;
scanner += 3;
} else {
ShowWarning("unknown operator: c..");
return 1;
}
break;
case 't':
if (('a' == scanner[1]) && ('n' == scanner[2])) { /* tan */
*receiver = 't';
++receiver;
scanner += 3;
} else { /* t */
*receiver = 'u';
++receiver;
++scanner;
}
break;
case 'p':
if (('i' == scanner[1])) { /* pi */
*receiver = 'p';
++receiver;
scanner += 2;
} else {
ShowWarning("unknown operator: p..");
return 1;
}
break;
case 'x': /* x */
*receiver = 'x';
++receiver;
++scanner;
break;
case 'y': /* y */
*receiver = 'y';
++receiver;
++scanner;
break;
case 'z': /* z */
*receiver = 'z';
++receiver;
++scanner;
break;
case '.':
if (IsDigit(scanner[1]) && IsDigit(scanner[-1])) {
*receiver = *scanner;
++receiver;
++scanner;
} else {
ShowWarning(". is preceded or followed by non digits");
return 1;
}
break;
case ' ':
++scanner; /* ignore space */
break;
default:
if (IsDigit(*scanner) || IsPureBinaryOperator(*scanner) ||
IsDualOperator(*scanner) || IsLeftParentheses(*scanner) ||
IsRightParentheses(*scanner)) { /* legal input single character */
*receiver = *scanner;
++receiver;
++scanner;
} else {
ShowWarning("unknown operator in expression");
return 1;
}
break;
}
}
*receiver='\0';
return 0;
}
static int IsOperator(const char op)
{
return (IsPureUnaryOperator(op) || IsPureBinaryOperator(op) ||
IsDualOperator(op) || IsLeftParentheses(op) ||
IsRightParentheses(op) || IsEndTag(op));
}
static int IsPureUnaryOperator(const char op)
{
return (('e' == op) || ('n' == op) || ('g' == op) ||
('a' == op) || ('s' == op) ||
('c' == op) || ('t' == op));
}
static int IsDualOperator(const char op)
{
return (('+' == op) || ('-' == op));
}
static int IsDualOperatorActAsUnary(const char *pop)
{
return (IsDualOperator(pop[0]) && IsLeftParentheses(pop[-1]));
}
static int IsPureBinaryOperator(const char op)
{
return (('*' == op) || ('/' == op) || ('^' == op));
}
static int IsLeftParentheses(const char op)
{
return (('(' == op) || ('[' == op) || ('{' == op));
}
static int IsRightParentheses(const char op)
{
return ((')' == op) || (']' == op) || ('}' == op));
}
static int IsConstant(const char op)
{
return (('u' == op) || ('x' == op) || ('y' == op) ||
('z' == op) || ('p' == op) || ('q' == op));
}
static int IsEndTag(const char op)
{
return ('\0' == op);
}
static int IsDigit(const char op)
{
return (('0' <= op) && ('9' >= op));
}
static int IsDot(const char op)
{
return ('.' == op);
}
static Real ExtractFirstFloat(char **pstr)
{
const char *fmtI = ParseFormat("%lg");
char *str = *pstr;
Real oprd = 0.0;
Sscanf(str, 1, fmtI, &oprd);
while (IsDigit(*str)) {
++str;
}
if (IsDot(*str)) {
++str;
}
while (IsDigit(*str)) {
++str;
}
*pstr = str;
return oprd;
}
static Real ExtractConstant(const CalcVar *var, char **pstr)
{
char *str = *pstr;
Real oprd = 0.0;
switch (*str) {
case 'u':
oprd = var->t;
++str;
break;
case 'x':
oprd = var->x;
++str;
break;
case 'y':
oprd = var->y;
++str;
break;
case 'z':
oprd = var->z;
++str;
break;
case 'p':
oprd = var->pi;
++str;
break;
case 'q':
oprd = var->ans;
++str;
break;
default:
ShowWarning("undefined constant value");
break;
}
*pstr = str;
return oprd;
}
static int DoUnary(const char toprt, const Real oprdx, Real *pcoprd)
{
const Real zero = 0.0;
switch (toprt) {
case 'e':
*pcoprd = exp(oprdx);
break;
case 'n':
if (zero >= oprdx) {
ShowWarning("non-positive argument of ln(x)");
*pcoprd = zero;
return 1;
}
*pcoprd = log(oprdx);
break;
case 'g':
if (zero >= oprdx) {
ShowWarning("non-positive argument of lg(x)");
*pcoprd = zero;
return 1;
}
*pcoprd = log10(oprdx);
break;
case 'a':
*pcoprd = fabs(oprdx);
break;
case 's':
*pcoprd = sin(oprdx);
break;
case 'c':
*pcoprd = cos(oprdx);
break;
case 't':
if (zero == cos(oprdx)) {
ShowWarning("illegal argument of tangent");
*pcoprd = zero;
return 1;
}
*pcoprd = sin(oprdx) / cos(oprdx);
break;
default:
*pcoprd = zero;
return 1;
}
return 0;
}
static int DoBinary(const Real oprdy, const char toprt, const Real oprdx, Real *pcoprd)
{
const Real zero = 0.0;
switch(toprt)
{
case '+':
*pcoprd = oprdy + oprdx;
break;
case '-':
*pcoprd = oprdy - oprdx;
break;
case '*':
*pcoprd = oprdy * oprdx;
break;
case '/':
if (zero == oprdx) {
ShowWarning("divide by zero");
*pcoprd = zero;
return 1;
}
*pcoprd = oprdy / oprdx;
break;
case '^':
*pcoprd = pow(oprdy, oprdx);
break;
default:
*pcoprd = zero;
return 1;
}
return 0;
}
static void ShowCalcManual(void)
{
ShowInfo("\n Calculator User Manual\n");
ShowInfo("Operators: +, -, *, /, x^y, exp(x), ln(x), lg(x), abs(x), sin(x), cos(x), tan(x)\n");
ShowInfo(" x, y are numbers or variables or expressions; angle should be radian;\n");
ShowInfo("Variables: t, x, y, z, ans, pi;\n");
ShowInfo("Parenthesis: (), [], {}\n");
ShowInfo("Example: 1.5*sin(-pi/6)-[cos(pi/3)]^2+ln{exp[5*lg(abs(-100))]} = 9\n");
}
static int SetVariable(CalcVar *var)
{
const char *fmtI = ParseFormat("%lg");
ShowInfo("\n t=");
Sread(stdin, -1, fmtI, &(var->t));
ShowInfo("\n x=");
Sread(stdin, -1, fmtI, &(var->x));
ShowInfo("\n y=");
Sread(stdin, -1, fmtI, &(var->y));
ShowInfo("\n z=");
Sread(stdin, -1, fmtI, &(var->z));
return 0;
}
/* a good practice: end file with a newline */